Browse Source

修改接口

DESKTOP-USV654P\pc 1 year ago
parent
commit
ad2ae82362

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

@@ -15,35 +15,26 @@ import com.xjrsoft.common.model.result.R;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
 import com.xjrsoft.common.utils.VoToColumnUtil;
-import com.xjrsoft.module.authority.entity.DataAuth;
-import com.xjrsoft.module.authority.vo.DataAuthListVo;
-import com.xjrsoft.module.authority.vo.DataAuthPageVo;
 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;
+import com.xjrsoft.module.oa.entity.NewsRelationConfig;
 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.NewsPageVo;
-import com.xjrsoft.module.oa.vo.NewsRelationVo;
-import com.xjrsoft.module.oa.vo.NewsVo;
-import com.xjrsoft.module.organization.entity.User;
-import com.xjrsoft.module.student.entity.BaseStudent;
-import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
-import com.xjrsoft.module.student.entity.BaseStudentUser;
-import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
+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.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -64,6 +55,7 @@ public class NewsController {
 
     private INewsRelationService newsRelationService;
     private INewsAppendixService newsAppendixService;
+    private INewsRelationConfigService newsRelationConfigService;
 
 
     @GetMapping
@@ -97,6 +89,7 @@ public class NewsController {
         return R.ok(pageOutput);
     }
 
+
     @PostMapping
     @ApiOperation(value = "新增新闻")
     public R add(@RequestBody AddNewsDto addNewsDto) {
@@ -241,13 +234,29 @@ public class NewsController {
         PageOutput<NewsRelationVo> pageOutput = ConventPage.getPageOutput(page);
         return R.ok(pageOutput);
     }
+
+
+    @GetMapping("/page-relation-config")
+    @ApiOperation(value = "获取新闻权限分页")
+    public R pageRelationConfig(NewsRelationPageDto dto) {
+        Wrapper<NewsRelationConfig> wrapper = Wrappers.<NewsRelationConfig>query().lambda()
+                .eq(NewsRelationConfig::getNewsId, dto.getNewsId())
+                .select(NewsRelationConfig.class, x -> VoToColumnUtil.fieldsToColumns(NewsRelationConfigVo.class).contains(x.getProperty()));
+
+        IPage<NewsRelationConfig> page = newsRelationConfigService.page(ConventPage.getPage(dto), wrapper);
+        PageOutput<NewsRelationConfigVo> pageOutput = ConventPage.getPageOutput(page, NewsRelationConfigVo.class);
+        return R.ok(pageOutput);
+    }
+
     @GetMapping("/count-relation")
     @ApiOperation(value = "新闻阅读权限统计")
-    public  R countRelation(@RequestParam Long id) {
+    public R countRelation(@RequestParam Long id) {
         Long total = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getNewsId, id));
         Long notRead = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getNewsId, id).eq(NewsRelation::getReadMark, 0));
         Long isRead = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getNewsId, id).eq(NewsRelation::getReadMark, 1));
-        Long[] arrayRefVar = {total, notRead, isRead};
+        Long isReply = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getNewsId, id).isNull(NewsRelation::getReplyContent));
+        Long notReply = newsRelationService.count(Wrappers.<NewsRelation>query().lambda().eq(NewsRelation::getNewsId, id).isNotNull(NewsRelation::getReplyContent));
+        Long[] arrayRefVar = {total, notRead, isRead, isReply, notReply};
         return R.ok(arrayRefVar);
     }
 
@@ -262,4 +271,24 @@ public class NewsController {
     public R deleteRelation(@RequestBody DeleteNewsRelationDto deleteNewsRelationDto) {
         return R.ok(newsService.deleteRelation(deleteNewsRelationDto));
     }
+
+    @GetMapping("/count-type")
+    @ApiOperation(value = "未读类型统计")
+    public R countType() {
+        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 type_id=" + typeId));
+            NewsCountTypeVo newsCountTypeVo = new NewsCountTypeVo();
+            newsCountTypeVo.setTypeId(typeId);
+            newsCountTypeVo.setTotal(totalType);
+            News news = newsService.getOne(Wrappers.<News>query().lambda().eq(News::getTypeId, typeId).orderByDesc(News::getReleaseTime).last("limit 1"));
+            if (news != null) {
+                newsCountTypeVo.setTime(news.getReleaseTime());
+                newsCountTypeVo.setTitle(news.getBriefHead());
+            }
+            newsCountTypeVoList.add(newsCountTypeVo);
+        }
+        return R.ok(newsCountTypeVoList);
+    }
 }

+ 13 - 0
src/main/java/com/xjrsoft/module/oa/dto/NewsRelationConfigDto.java

@@ -0,0 +1,13 @@
+package com.xjrsoft.module.oa.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class NewsRelationConfigDto {
+    @ApiModelProperty("关系ID")
+    private Long relationId;
+
+    @ApiModelProperty("关系名称")
+    private Long relationName;
+}

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

@@ -15,5 +15,5 @@ public class UpdateNewsRelationDto {
     private Integer relationType;
 
     @ApiModelProperty("关系列表")
-    private List<Long> relationIds;
+    private List<NewsRelationConfigDto> relationList;
 }

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

@@ -24,4 +24,7 @@ public class NewsRelationConfig {
 
     @ApiModelProperty("关系ID")
     private Long relationId;
+
+    @ApiModelProperty("关系名称")
+    private Long relationName;
 }

+ 7 - 6
src/main/java/com/xjrsoft/module/oa/service/impl/NewsServiceImpl.java

@@ -135,18 +135,19 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
     @Transactional(rollbackFor = Exception.class)
     public  boolean updateRelation(UpdateNewsRelationDto updateRelationDto) {
 
-        if (updateRelationDto.getRelationIds() != null) {
-            for (Long relationId : updateRelationDto.getRelationIds()) {
+        if (updateRelationDto.getRelationList() != null) {
+            for (NewsRelationConfigDto newsRelationConfigDto : updateRelationDto.getRelationList()) {
                 NewsRelationConfig newsRelationConfig = new NewsRelationConfig();
                 newsRelationConfig.setNewsId(updateRelationDto.getId());
-                newsRelationConfig.setRelationId(relationId);
+                newsRelationConfig.setRelationId(newsRelationConfigDto.getRelationId());
+                newsRelationConfig.setRelationName(newsRelationConfigDto.getRelationName());
                 newsRelationConfig.setRelationType(updateRelationDto.getRelationType());
                 newsRelationConfigMapper.insert(newsRelationConfig);
 
                 // 部门
                 if (updateRelationDto.getRelationType() == 1) {
                     List<UserDeptRelation> userDeptRelationList = userDeptRelationMapper.selectList(Wrappers.<UserDeptRelation>query().lambda()
-                            .eq(UserDeptRelation::getDeptId, relationId));
+                            .eq(UserDeptRelation::getDeptId, newsRelationConfigDto.getRelationId()));
                     for (UserDeptRelation userDeptRelation : userDeptRelationList) {
                         NewsRelation newsRelation = new NewsRelation();
                         newsRelation.setUserId(userDeptRelation.getUserId());
@@ -159,7 +160,7 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
                 // 人员
                 if (updateRelationDto.getRelationType() == 2) {
                     NewsRelation newsRelation = new NewsRelation();
-                    newsRelation.setUserId(relationId);
+                    newsRelation.setUserId(newsRelationConfigDto.getRelationId());
                     newsRelation.setNewsId(updateRelationDto.getId());
                     newsRelation.setReadMark(0);
                     newsRelationMapper.insert(newsRelation);
@@ -168,7 +169,7 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
                 // 班级
                 if (updateRelationDto.getRelationType() == 3) {
                     List<BaseStudentSchoolRoll> baseStudentSchoolRollList = baseStudentSchoolRollMapper.selectList(Wrappers.<BaseStudentSchoolRoll>query().lambda()
-                            .eq(BaseStudentSchoolRoll::getClassId, relationId));
+                            .eq(BaseStudentSchoolRoll::getClassId, newsRelationConfigDto.getRelationId()));
 
                     for (BaseStudentSchoolRoll baseStudentSchoolRoll : baseStudentSchoolRollList) {
                         NewsRelation newsRelation = new NewsRelation();

+ 22 - 0
src/main/java/com/xjrsoft/module/oa/vo/NewsCountTypeVo.java

@@ -0,0 +1,22 @@
+package com.xjrsoft.module.oa.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+public class NewsCountTypeVo {
+
+    @ApiModelProperty("类型(1-新闻2-公告)")
+    private Integer typeId;
+
+    @ApiModelProperty("最后一条标题")
+    private String title;
+
+    @ApiModelProperty("时间")
+    private LocalDateTime time;
+
+    @ApiModelProperty("未读数量")
+    private Long total;
+}

+ 22 - 0
src/main/java/com/xjrsoft/module/oa/vo/NewsRelationConfigVo.java

@@ -0,0 +1,22 @@
+package com.xjrsoft.module.oa.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class NewsRelationConfigVo {
+    @ApiModelProperty("主键")
+    private Long id;
+
+    @ApiModelProperty("新闻主键")
+    private Long newsId;
+
+    @ApiModelProperty("关系类型 1=部门 2=人员")
+    private Integer relationType;
+
+    @ApiModelProperty("关系ID")
+    private Long relationId;
+
+    @ApiModelProperty("关系名称")
+    private Long relationName;
+}

+ 1 - 0
src/main/resources/sqlScript/init_sql.sql

@@ -43,6 +43,7 @@ CREATE TABLE `xjr_oa_news_relation_config` (
     `news_id` bigint NULL DEFAULT NULL COMMENT '新闻ID',
     `relation_type` int NULL DEFAULT NULL COMMENT '关系类型 1=部门 2=人员',
     `relation_id` bigint NULL DEFAULT NULL COMMENT '关系ID',
+    `relation_name` varchar(100) NULL DEFAULT NULL COMMENT '关系名称',
     PRIMARY KEY (`id`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '新闻关联配置'