소스 검색

获取新闻

phoenix 1 년 전
부모
커밋
7ced581657

+ 79 - 53
src/main/java/com/xjrsoft/module/oa/controller/NewsController.java

@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.constant.GlobalConstant;
-import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
@@ -201,18 +200,27 @@ public class NewsController {
     @PutMapping("/read")
     @ApiOperation(value = "读新闻")
     public RT<Boolean> read(@RequestBody List<Long> ids) {
-        List<NewsRelation> toSaveList = newsRelationService.list(
-                Wrappers.<NewsRelation>query().lambda()
-                        .in(NewsRelation::getNewsId, ids)
-                        .eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong()));
-        for (NewsRelation newsRelation : toSaveList) {
-            newsRelation.setReadMark(1);
-            newsRelation.setReadDate(LocalDateTime.now());
+        for (Long id : ids) {
+            NewsRelation newsRelation = newsRelationService.getOne(
+                    Wrappers.<NewsRelation>query().lambda()
+                            .eq(NewsRelation::getNewsId, id)
+                            .eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong()));
+            if (newsRelation == null) {
+                newsRelationService.save(new NewsRelation(){{
+                    setNewsId(id);
+                    setUserId(StpUtil.getLoginIdAsLong());
+                    setReadMark(1);
+                    setReadDate(LocalDateTime.now());
+                }});
+                continue;
+            }
+            newsRelationService.updateById(new NewsRelation(){{
+                setId(newsRelation.getId());
+                setReadMark(1);
+                setReadDate(LocalDateTime.now());
+            }});
         }
-//        newsRelationService.remove(Wrappers.<NewsRelation>query().lambda()
-//                .in(NewsRelation::getNewsId, ids)
-//                .eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong()));
-        return RT.ok(newsRelationService.updateBatchById(toSaveList));
+        return RT.ok(true);
     }
 
     @PutMapping("/reply")
@@ -301,35 +309,54 @@ public class NewsController {
         List<NewsCountTypeVo> newsCountTypeVoList = new ArrayList<>();
         Integer typeIds[] = {1, 2, 3};
         for (Integer typeId : typeIds) {
-            Long totalType = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong()).eq(NewsRelation::getReadMark, 0).in(NewsRelation::getNewsId, "SELECT id from xjr_oa_news where delete_mark = 0 and type_id=" + typeId));
             NewsCountTypeVo newsCountTypeVo = new NewsCountTypeVo();
-            newsCountTypeVo.setTypeId(typeId);
-            newsCountTypeVo.setTotal(totalType);
             News news = new News();
+
+            //新闻
             if(typeId == 1){
-                news = newsService.getOne(Wrappers.<News>query().lambda().eq(News::getTypeId, typeId).orderByDesc(News::getReleaseTime).last("limit 1"));
+                Long notReadCount = newsService.count(Wrappers.<News>query().lambda()
+                        .eq(News::getTypeId, typeId)
+                        .gt(News::getSendEndDate, LocalDateTime.now())
+                        .eq(News::getDeleteMark, 0)
+                        .eq(News::getWfStatus, 1)
+                        .notIn(News::getId, "select distinct news_id from xjr_oa_news_relation where user_id = " + StpUtil.getLoginIdAsLong()));
+
+                newsCountTypeVo.setTypeId(typeId);
+                newsCountTypeVo.setTotal(notReadCount);
+
+                news = newsService.getOne(Wrappers.<News>query().lambda()
+                        .eq(News::getTypeId, typeId)
+                        .gt(News::getSendEndDate, LocalDateTime.now())
+                        .eq(News::getDeleteMark, 0)
+                        .eq(News::getWfStatus, 1)
+                        .notIn(News::getId, "select distinct news_id from xjr_oa_news_relation where user_id = " + StpUtil.getLoginIdAsLong())
+                        .orderByDesc(News::getReleaseTime)
+                        .last("limit 1"));
             }
+
+            //公告
             if(typeId == 2){
-                //找到和该登录用户有关系的最后一条公告
-                News newsRelation = newsService.selectJoinOne(News.class,
-                        new MPJLambdaWrapper<News>()
-                                .disableSubLogicDel()
-                                .eq(News::getTypeId, typeId)
-                                .eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong())
-                                .orderByDesc(News::getReleaseTime)
-                                .last("limit 1")
-                                .innerJoin(NewsRelation.class, NewsRelation::getNewsId, News::getId));
-
-                news = newsRelation;
-                //找到晚于和该登录用户有关系的所有公告
-                List<News> newsList = newsService.list(Wrappers.<News>query().lambda().eq(News::getTypeId, typeId).lt(News::getReleaseTime, newsRelation.getReleaseTime()).orderByDesc(News::getReleaseTime));
-                for (News n : newsList) {
-                    if(n.getSendRange() == 1){//是发给所有人的
-                        news = n;
-                        break;
-                    }
-                }
+                Long notReadCount = newsService.count(Wrappers.<News>query().lambda()
+                        .eq(News::getTypeId, typeId)
+                        .eq(News::getDeleteMark, 0)
+                        .notIn(News::getId, "select distinct news_id from xjr_oa_news_relation where read_mark = 1 and user_id = " + StpUtil.getLoginIdAsLong())
+                        .and(wp -> wp.gt(News::getSendEndDate, LocalDateTime.now())
+                                .or()
+                                .isNull(News::getSendEndDate)));
+
+                news = newsService.getOne(Wrappers.<News>query().lambda()
+                        .eq(News::getTypeId, typeId)
+                        .eq(News::getDeleteMark, 0)
+                        .notIn(News::getId, "select distinct news_id from xjr_oa_news_relation where read_mark = 1 and user_id = " + StpUtil.getLoginIdAsLong())
+                        .and(wp -> wp.gt(News::getSendEndDate, LocalDateTime.now())
+                                .or()
+                                .isNull(News::getSendEndDate))
+                        .orderByDesc(News::getReleaseTime)
+                        .last("limit 1"));
+                newsCountTypeVo.setTypeId(typeId);
+                newsCountTypeVo.setTotal(notReadCount);
             }
+
             if (news != null) {
                 newsCountTypeVo.setTime(news.getReleaseTime());
                 newsCountTypeVo.setTitle(news.getBriefHead());
@@ -347,23 +374,22 @@ public class NewsController {
 
     @GetMapping("/unread-count")
     @ApiOperation(value = "获取登录人未读消息数量")
-    public RT<Integer> unreadCount() {
-        Integer count =  newsService.selectJoinCount(
-                new MPJLambdaWrapper<News>()
-                        .eq(NewsRelation::getReadMark, 0)
-                        .eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong())
-                        .eq(News::getDeleteMark, DeleteMark.NODELETE.getCode())
-                        .innerJoin(NewsRelation.class, NewsRelation::getNewsId, News::getId)
-        );
-
-        List<News> newsList = newsService.list(Wrappers.<News>query().lambda().eq(News::getSendRange, 1));
-        for (News news : newsList) {
-            Long cou = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getNewsId, news.getId()).eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong()));
-            if(cou <= 0){
-                count++;
-            }
-        }
-
-        return RT.ok(count);
+    public RT<Long> unreadCount() {
+        Long notReadCountNews = newsService.count(Wrappers.<News>query().lambda()
+                .eq(News::getTypeId, 1)
+                .gt(News::getSendEndDate, LocalDateTime.now())
+                .eq(News::getDeleteMark, 0)
+                .eq(News::getWfStatus, 1)
+                .notIn(News::getId, "select distinct news_id from xjr_oa_news_relation where user_id = " + StpUtil.getLoginIdAsLong()));
+
+        Long notReadCountProclamation = newsService.count(Wrappers.<News>query().lambda()
+                .eq(News::getTypeId, 2)
+                .eq(News::getDeleteMark, 0)
+                .notIn(News::getId, "select distinct news_id from xjr_oa_news_relation where read_mark = 1 and user_id = " + StpUtil.getLoginIdAsLong())
+                .and(wp -> wp.gt(News::getSendEndDate, LocalDateTime.now())
+                        .or()
+                        .isNull(News::getSendEndDate)));
+        Long notReadCount = notReadCountNews + notReadCountProclamation;
+        return RT.ok(notReadCount);
     }
 }

+ 0 - 12
src/main/java/com/xjrsoft/module/oa/dto/NewsPageDto.java

@@ -21,18 +21,6 @@ public class NewsPageDto extends PageInput {
     @Min(value = 1, message = "类型必须大于0")
     private Integer type;
 
-    @ApiModelProperty("班级(base_class)")
-    private Long classId;
-
-    @ApiModelProperty("级别 1=校级 2=班级")
-    private Integer level;
-
-    /**
-     * 作者
-     */
-    @ApiModelProperty("作者")
-    private String authorName;
-
     /**
      * 完整标题
      */

+ 3 - 0
src/main/java/com/xjrsoft/module/oa/entity/News.java

@@ -116,6 +116,9 @@ public class News extends AuditEntity implements Serializable {
     @ApiModelProperty("发送范围 1=所有人 2=根据权限")
     private Integer sendRange;
 
+    @ApiModelProperty("审核是否通过")
+    private Integer wfStatus;
+
     /**
      * 附件子表
      */

+ 3 - 22
src/main/resources/mapper/oa/NewsMapper.xml

@@ -9,7 +9,6 @@
         t.*,
         t2.name as classIdCN
         from xjr_oa_news t
-        left join base_class t2 on t2.id = t.class_id
         where t.delete_mark = 0
         <if test="dto.type != null and dto.type > 0">
             and t.type_id = #{dto.type}
@@ -17,17 +16,9 @@
         <if test="dto.type != null and dto.type = 1">
             and t.wf_status = 1
         </if>
-        <if test="dto.authorName != null and dto.authorName != ''">
-            and t.author_name LIKE CONCAT('%',#{dto.authorName},'%')
-        </if>
         <if test="dto.fullHead != null and dto.fullHead != ''">
             and t.full_head LIKE CONCAT('%',#{dto.fullHead},'%')
         </if>
-        <if test="dto.keyword != null and dto.keyword != ''">
-            and (t.keyword LIKE CONCAT('%',#{dto.keyword},'%')
-            or t.full_head LIKE CONCAT('%',#{dto.keyword},'%')
-            or t.author_name LIKE CONCAT('%',#{dto.keyword},'%'))
-        </if>
         <if test="dto.loginId != null and dto.loginId > 0">
             and t.create_user_id = #{dto.loginId}
         </if>
@@ -37,36 +28,26 @@
     <select id="receiptBox" parameterType="com.xjrsoft.module.oa.dto.NewsPageDto"
             resultType="com.xjrsoft.module.oa.vo.NewsPageVo">
         select
-        t.*,
-        t2.name as classIdCN
+        t.*
         from xjr_oa_news t
         left join xjr_oa_news_relation t1 on t1.news_id = t.id
-        left join base_class t2 on t2.id = t.class_id
         where t.delete_mark = 0 and
         (t.send_end_date > now() or t.send_end_date is null)
           and t.status = 2
         <if test="dto.type != null and dto.type == 2 and dto.loginId != null and dto.loginId > 0">
             and (t1.user_id = #{dto.loginId} or t.send_range = 1)
         </if>
-        <if test="dto.type != null and dto.type = 1">
+        <if test="dto.type != null and dto.type == 1">
             and t.wf_status = 1
         </if>
         <if test="dto.type != null and dto.type > 0">
             and t.type_id = #{dto.type}
         </if>
-        <if test="dto.authorName != null and dto.authorName != ''">
-            and t.author_name LIKE CONCAT('%',#{dto.authorName},'%')
-        </if>
         <if test="dto.fullHead != null and dto.fullHead != ''">
             and t.full_head LIKE CONCAT('%',#{dto.fullHead},'%')
         </if>
-        <if test="dto.keyword != null and dto.keyword != ''">
-            and (t.keyword LIKE CONCAT('%',#{dto.keyword},'%')
-                or t.full_head LIKE CONCAT('%',#{dto.keyword},'%')
-                or t.author_name LIKE CONCAT('%',#{dto.keyword},'%'))
-        </if>
         order by
-        t.send_start_date desc,t.release_time desc
+        t.release_time desc
     </select>
 
     <select id="getDeptIdOrClassId" parameterType="java.util.List"