Ver código fonte

/oa/news/box 给接口拆分成两个接口
/oa/news/manage-box 新闻管理接口,登录用户只能看见自己创建的新闻
/oa/news/receipt-box 新闻接受接口,登录用户只能看

phoenix 1 ano atrás
pai
commit
c7f370c318

+ 15 - 26
src/main/java/com/xjrsoft/module/oa/controller/NewsController.java

@@ -7,20 +7,13 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.github.yulichang.toolkit.MPJWrappers;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.constant.GlobalConstant;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
 import com.xjrsoft.common.utils.VoToColumnUtil;
-import com.xjrsoft.module.oa.dto.AddNewsDto;
-import com.xjrsoft.module.oa.dto.DeleteNewsRelationDto;
-import com.xjrsoft.module.oa.dto.NewsPageDto;
-import com.xjrsoft.module.oa.dto.NewsRelationPageDto;
-import com.xjrsoft.module.oa.dto.NewsReplyDto;
-import com.xjrsoft.module.oa.dto.UpdateNewsDto;
-import com.xjrsoft.module.oa.dto.UpdateNewsRelationDto;
+import com.xjrsoft.module.oa.dto.*;
 import com.xjrsoft.module.oa.entity.News;
 import com.xjrsoft.module.oa.entity.NewsAppendix;
 import com.xjrsoft.module.oa.entity.NewsRelation;
@@ -29,26 +22,14 @@ import com.xjrsoft.module.oa.service.INewsAppendixService;
 import com.xjrsoft.module.oa.service.INewsRelationConfigService;
 import com.xjrsoft.module.oa.service.INewsRelationService;
 import com.xjrsoft.module.oa.service.INewsService;
-import com.xjrsoft.module.oa.vo.NewsAppendixVo;
-import com.xjrsoft.module.oa.vo.NewsCountTypeVo;
-import com.xjrsoft.module.oa.vo.NewsPageVo;
-import com.xjrsoft.module.oa.vo.NewsRelationConfigVo;
-import com.xjrsoft.module.oa.vo.NewsRelationVo;
-import com.xjrsoft.module.oa.vo.NewsVo;
+import com.xjrsoft.module.oa.vo.*;
 import com.xjrsoft.module.system.entity.File;
 import com.xjrsoft.module.teacher.entity.XjrUser;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.BooleanUtils;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
 import java.util.ArrayList;
@@ -87,10 +68,18 @@ public class NewsController {
         return RT.ok(pageOutput);
     }
 
-    @GetMapping("/box")
-    @ApiOperation(value = "获取新闻分页")
-    public RT<PageOutput<NewsPageVo>> box(NewsPageDto dto) {
-        IPage<NewsPageVo> page = newsService.box(dto);
+    @GetMapping("/manage-box")
+    @ApiOperation(value = "获取管理新闻分页")
+    public RT<PageOutput<NewsPageVo>> manageBox(NewsPageDto dto) {
+        IPage<NewsPageVo> page = newsService.manageBox(dto);
+        PageOutput<NewsPageVo> pageOutput = ConventPage.getPageOutput(page, NewsPageVo.class);
+        return RT.ok(pageOutput);
+    }
+
+    @GetMapping("/receipt-box")
+    @ApiOperation(value = "获取接受新闻分页")
+    public RT<PageOutput<NewsPageVo>> receiptBox(NewsPageDto dto) {
+        IPage<NewsPageVo> page = newsService.receiptBox(dto);
         PageOutput<NewsPageVo> pageOutput = ConventPage.getPageOutput(page, NewsPageVo.class);
         return RT.ok(pageOutput);
     }

+ 3 - 1
src/main/java/com/xjrsoft/module/oa/dto/NewsPageDto.java

@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import javax.validation.constraints.Min;
 import javax.validation.constraints.NotNull;
 
 /**
@@ -18,6 +19,7 @@ public class NewsPageDto extends PageInput {
 
     @ApiModelProperty(value = "类型(1-新闻2-公告)")
     @NotNull(message = "类型不能为空!")
+    @Min(value = 1, message = "类型必须大于0")
     private Integer type;
 
     @ApiModelProperty("班级(base_class)")
@@ -47,7 +49,7 @@ public class NewsPageDto extends PageInput {
     /**
      * 当前用户id
      */
-    @ApiModelProperty(value = "当前用户id",hidden = true)
+    @ApiModelProperty(value = "当前用户id", hidden = true)
     @JsonIgnore
     private Long loginId;
 

+ 3 - 1
src/main/java/com/xjrsoft/module/oa/mapper/NewsMapper.java

@@ -17,5 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface NewsMapper extends MPJBaseMapper<News> {
-    IPage<NewsPageVo> box(IPage<NewsPageDto> page,NewsPageDto dto);
+    IPage<NewsPageVo> manageBox(IPage<NewsPageDto> page,NewsPageDto dto);
+
+    IPage<NewsPageVo> receiptBox(IPage<NewsPageDto> page,NewsPageDto dto);
 }

+ 9 - 1
src/main/java/com/xjrsoft/module/oa/service/INewsService.java

@@ -31,7 +31,15 @@ public interface INewsService extends MPJBaseService<News> {
      * @param dto
      * @return
      */
-    IPage<NewsPageVo> box(NewsPageDto dto);
+    IPage<NewsPageVo> manageBox(NewsPageDto dto);
+
+    /**
+     * 获取新闻分页
+     *
+     * @param dto
+     * @return
+     */
+    IPage<NewsPageVo> receiptBox(NewsPageDto dto);
     /**
      * 修改新闻
      *

+ 14 - 20
src/main/java/com/xjrsoft/module/oa/service/impl/NewsServiceImpl.java

@@ -8,7 +8,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.yulichang.base.MPJBaseServiceImpl;
-import com.github.yulichang.toolkit.MPJWrappers;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.EnabledMark;
 import com.xjrsoft.common.page.ConventPage;
@@ -108,30 +107,25 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
                 }
             }
         }
-
-        SendMessage(news.getId());
+        //添加新闻和公告的时候,如果状态是2,表示新闻和公告实时发布了,需要发送消息
+        if(ObjectUtil.isNotNull(addNewsDto.getStatus()) && addNewsDto.getStatus() == 2){
+            SendMessage(news.getId());
+        }
 
         return news.getId();
     }
 
     @Override
-    public IPage<NewsPageVo> box(NewsPageDto dto) {
-        /*MPJLambdaWrapper<News> wrapper = MPJWrappers.<News>lambdaJoin()
-                .eq(ObjectUtil.isNotEmpty(dto.getType()) && dto.getType() > 0, News::getTypeId, dto.getType())
-                .and(wq -> wq.eq(News::getLevel, 1).or().eq(News::getLevel, 2).eq(News::getClassId, dto.getClassId()))
-                .eq(ObjectUtil.isNotEmpty(dto.getLevel()) && dto.getLevel() > 0, News::getLevel, dto.getLevel())
-                .and(wq -> wq.eq(News::getSendRange, 1).or().eq(News::getSendRange, 2).in(News::getId, "select id from xjr_oa_news_relation where news_id=t.id and user_id=" + StpUtil.getLoginIdAsLong()))
-                .like(StrUtil.isNotBlank(dto.getKeyword()), News::getFullHead, dto.getKeyword())
-                .leftJoin(NewsRelation.class, onWrapper -> onWrapper.eq(NewsRelation::getNewsId, News::getId).eq(NewsRelation::getUserId, StpUtil.getLoginIdAsLong()))
-                .selectAs(NewsRelation::getId, NewsPageVo::getReadId)
-                .selectAs(News::getId, NewsPageVo::getId)
-                .select(News.class, x -> VoToColumnUtil.fieldsToColumns(NewsPageVo.class).contains(x.getProperty()))
-                .orderByDesc(News::getCreateDate);//新闻按照创建时间倒序排*/
-
-        if(ObjectUtil.isNotNull(dto.getType()) && dto.getType() == 2){
-            dto.setLoginId(StpUtil.getLoginIdAsLong());
-        }
-        IPage<NewsPageVo> page = newsMapper.box(ConventPage.getPage(dto),dto);
+    public IPage<NewsPageVo> manageBox(NewsPageDto dto) {
+        dto.setLoginId(StpUtil.getLoginIdAsLong());
+        IPage<NewsPageVo> page = newsMapper.manageBox(ConventPage.getPage(dto), dto);
+        return page;
+    }
+
+    @Override
+    public IPage<NewsPageVo> receiptBox(NewsPageDto dto) {
+        dto.setLoginId(StpUtil.getLoginIdAsLong());
+        IPage<NewsPageVo> page = newsMapper.receiptBox(ConventPage.getPage(dto), dto);
         return page;
     }
 

+ 51 - 24
src/main/resources/mapper/oa/NewsMapper.xml

@@ -3,34 +3,61 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.xjrsoft.module.oa.mapper.NewsMapper">
-    <select id="box" parameterType="com.xjrsoft.module.oa.dto.NewsPageDto"
+    <select id="manageBox" parameterType="com.xjrsoft.module.oa.dto.NewsPageDto"
             resultType="com.xjrsoft.module.oa.vo.NewsPageVo">
         select
-            t.*,
-            t2.name as classIdCN,
-            (select count(*) from xjr_oa_news_relation where reply_content is not null ) as replyContentNum
+        t.*,
+        t2.name as classIdCN,
+        (select count(*) from xjr_oa_news_relation where reply_content is not null ) as replyContentNum
         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
+        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
-            <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},'%')
-            </if>
-            <if test="dto.type != null and dto.type == 2 and dto.loginId != null and dto.loginId > 0">
-                and t1.user_id = #{dto.loginId}
-            </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},'%')
+        </if>
+        <if test="dto.loginId != null and dto.loginId > 0">
+            and t.create_user_id = #{dto.loginId}
+        </if>
         order by t.release_time desc
-            <if test="dto.type != null and dto.type == 2">
-                ,t.send_start_date desc
-            </if>
+    </select>
+
+    <select id="receiptBox" parameterType="com.xjrsoft.module.oa.dto.NewsPageDto"
+            resultType="com.xjrsoft.module.oa.vo.NewsPageVo">
+        select
+        t.*,
+        t2.name as classIdCN,
+        (select count(*) from xjr_oa_news_relation where reply_content is not null ) as replyContentNum
+        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)
+        <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},'%')
+        </if>
+        <if test="dto.type != null and dto.type == 2 and dto.loginId != null and dto.loginId > 0">
+            and t1.user_id = #{dto.loginId}
+        </if>
+        order by
+        t.send_start_date desc
     </select>
 </mapper>