Răsfoiți Sursa

作者:张哲
时间:2023/07/26
类型:需求变更
描述:部分需求修改

zizg 1 an în urmă
părinte
comite
c739168723

+ 13 - 0
src/main/java/com/redxun/knowledge/controller/KnowledgeController.java

@@ -275,5 +275,18 @@ public class KnowledgeController extends BaseController<Knowledge> {
         }
         return jsonResult.setMessage("转移成功!");
     }
+
+    @ApiOperation("知识撤回")
+    @GetMapping("knowledgeWithdraw")
+    public JsonResult knowledgeWithdraw(@RequestParam("knowledgeId") String knowledgeId){
+        JsonResult jsonResult = JsonResult.Success();
+        try {
+            knowledgeService.knowledgeWithdraw(knowledgeId);
+        } catch (Exception e) {
+            jsonResult.setSuccess(false);
+            return jsonResult.setMessage(e.getMessage());
+        }
+        return jsonResult.setMessage("知识撤回成功!");
+    }
 }
 

+ 6 - 0
src/main/java/com/redxun/knowledge/controller/TestController.java

@@ -140,6 +140,12 @@ public class TestController extends BaseController {
         userService.downLoadXlsx(response);
     }
 
+    @GetMapping(value = "/testByUserNo")
+    public JPaasUser testByUserNo(@RequestParam("userNo") String userNo){
+        JPaasUser admin = userService.queryByUsername(userNo);
+        return admin;
+    }
+
 
 
 }

+ 2 - 0
src/main/java/com/redxun/knowledge/entity/dto/KnowledgeDto.java

@@ -51,4 +51,6 @@ public class KnowledgeDto {
     private Integer isDraft;
 
     private OrganizationDto organizationIds;
+
+    private String customNodes;
 }

+ 2 - 0
src/main/java/com/redxun/knowledge/entity/vo/KnowledgeVo.java

@@ -170,4 +170,6 @@ public class KnowledgeVo {
             timezone = "GMT+8"
     )
     private Date endTime;
+
+    private Integer isWithdraw;
 }

+ 1 - 1
src/main/java/com/redxun/knowledge/service/KnowledgeApprovalNodeServiceImpl.java

@@ -144,7 +144,7 @@ public class KnowledgeApprovalNodeServiceImpl extends SuperServiceImpl<Knowledge
                 knowledgeApprovalNodeCategory.setCategoryId(e);
                 knowledgeApprovalNodeCategory.setFlowerId(knowledgeApprovalNodeFlower.getPkId());
                 List<String> pathList = knowledgeCategoryMapper.selectPath(e);
-                knowledgeApprovalNodeCategory.setPath(String.join(".", pathList));
+                //knowledgeApprovalNodeCategory.setPath(String.join(".", pathList));
                 knowledgeApprovalNodeCategoryMapper.insert(knowledgeApprovalNodeCategory);
             });
         }

+ 49 - 37
src/main/java/com/redxun/knowledge/service/KnowledgeApproveServiceImpl.java

@@ -104,6 +104,54 @@ public class KnowledgeApproveServiceImpl extends SuperServiceImpl<KnowledgeAppro
         Map<String, Object> params = PageHelper.constructParams(filter);
         //查询出全部记录
         List<KnowledgeApprovalListVo> allKnowledgeApprove = knowledgeApproveMapper.findAllKnowledgeApprove(filter.getParams(), params);
+        //数据处理
+        String userNo = userService.queryLoginUsername();
+        List<KnowledgeApprovalListVo> collectList = this.allApproveList(allKnowledgeApprove);
+        //查询知识管理员
+        List<String> knowledgeManager = knowledgeApproveMapper.findKnowledgeManager();
+        String user = userService.queryLoginUser();
+        //如果是知识管理员,展示全部 不是 查看自己能审核的记录
+        if(!knowledgeManager.contains(user) && !"admin".equals(userNo)){
+            //只查看当前登陆人能审核的记录(isAudit=0)
+            collectList = collectList.stream().filter(e -> e.getIsAudit() == 0 && (e.getApprovalStatus() == 1 || e.getApprovalStatus() == 3)).collect(Collectors.toList());
+            log.info("能审核的数量 -> {}",collectList.size());
+        }
+        //如果是admin,全部能审核
+        if ("admin".equals(userNo)){
+            collectList.forEach(e -> e.setIsAudit(0));
+        }
+        //数据分页
+        Page pages = PageListUtils.getPages(filter.getPage().getCurrent(), filter.getPage().getSize(), collectList);
+        List<KnowledgeApprovalListVo> collect = pages.getRecords();
+        //组织架构信息解析
+        collect.forEach(e -> {
+            String categoryId = e.getCategoryId();
+            KnowledgeCategoryAdminVo knowledgeCategoryAdminVo = knowledgeCategoryService.findAllParentByCategoryId(categoryId);
+            e.setKnowledgeCategoryAdminVo(knowledgeCategoryAdminVo);
+            if (StringUtils.isNotEmpty(e.getOrganizationId())){
+                OrganizationDto organizationDto = JSON.parseObject(e.getOrganizationId(), OrganizationDto.class);
+                e.setOrganizationIds(organizationDto);
+            }
+            //处理默认节点有两个领导的情况(默认节点默认在第一位,sort=1)
+            String[] split = e.getApproverId().split(",");
+            if (split.length > 1){
+                String approverNameTager = Arrays.stream(split).map(h -> userService.queryByUsername(h).getFullName()).collect(Collectors.joining(","));
+                e.setApproverName(approverNameTager);
+            }
+            // 判断是否有代理人,有,approverName赋值代理人
+            if (hasTager(e)){
+                e.setApproverName(userService.queryByUsername(e.getApproverId()).getFullName());
+            }
+        });
+        return pages;
+    }
+
+    /**
+     * 未分页前全部审核记录
+     * @param allKnowledgeApprove
+     * @return
+     */
+    public List<KnowledgeApprovalListVo> allApproveList(List<KnowledgeApprovalListVo> allKnowledgeApprove){
         // 根据知识Id进行数据分组
         Map<String, List<KnowledgeApprovalListVo>> result =
                 allKnowledgeApprove.stream().collect(Collectors.groupingBy(KnowledgeApprovalListVo::getKnowledgerId));
@@ -169,43 +217,7 @@ public class KnowledgeApproveServiceImpl extends SuperServiceImpl<KnowledgeAppro
                 e.setIsAudit(0);
             }
         });
-        //查询知识管理员
-        List<String> knowledgeManager = knowledgeApproveMapper.findKnowledgeManager();
-        String user = userService.queryLoginUser();
-        //如果是知识管理员,展示全部 不是 查看自己能审核的记录
-        if(!knowledgeManager.contains(user) && !"admin".equals(userNo)){
-            //只查看当前登陆人能审核的记录(isAudit=0)
-            collectList = collectList.stream().filter(e -> e.getIsAudit() == 0 && (e.getApprovalStatus() == 1 || e.getApprovalStatus() == 3)).collect(Collectors.toList());
-            log.info("能审核的数量 -> {}",collectList.size());
-        }
-        //如果是admin,全部能审核
-        if ("admin".equals(userNo)){
-            collectList.forEach(e -> e.setIsAudit(0));
-        }
-        //数据分页
-        Page pages = PageListUtils.getPages(filter.getPage().getCurrent(), filter.getPage().getSize(), collectList);
-        List<KnowledgeApprovalListVo> collect = pages.getRecords();
-        //组织架构信息解析
-        collect.forEach(e -> {
-            String categoryId = e.getCategoryId();
-            KnowledgeCategoryAdminVo knowledgeCategoryAdminVo = knowledgeCategoryService.findAllParentByCategoryId(categoryId);
-            e.setKnowledgeCategoryAdminVo(knowledgeCategoryAdminVo);
-            if (StringUtils.isNotEmpty(e.getOrganizationId())){
-                OrganizationDto organizationDto = JSON.parseObject(e.getOrganizationId(), OrganizationDto.class);
-                e.setOrganizationIds(organizationDto);
-            }
-            //处理默认节点有两个领导的情况(默认节点默认在第一位,sort=1)
-            String[] split = e.getApproverId().split(",");
-            if (split.length > 1){
-                String approverNameTager = Arrays.stream(split).map(h -> userService.queryByUsername(h).getFullName()).collect(Collectors.joining(","));
-                e.setApproverName(approverNameTager);
-            }
-            // 判断是否有代理人,有,approverName赋值代理人
-            if (hasTager(e)){
-                e.setApproverName(userService.queryByUsername(e.getApproverId()).getFullName());
-            }
-        });
-        return pages;
+        return collectList;
     }
 
 

+ 6 - 0
src/main/java/com/redxun/knowledge/service/KnowledgeCategoryServiceImpl.java

@@ -20,6 +20,8 @@ import com.redxun.knowledge.utils.PageListUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -70,6 +72,7 @@ public class KnowledgeCategoryServiceImpl extends SuperServiceImpl<KnowledgeCate
     }
 
     // 根据id查询其下级分类信息(非懒加载)
+    @Cacheable(value = "knowledgeCategory",key = "'categoryId_' + #categoryId")
     public KnowledgeCategoryAdminVo getAllByCategoryId(String categoryId) {
         QueryWrapper<KnowledgeCategory> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("PK_ID", categoryId);
@@ -161,6 +164,7 @@ public class KnowledgeCategoryServiceImpl extends SuperServiceImpl<KnowledgeCate
      * @return
      */
     @Override
+    @CacheEvict(value = "knowledgeCategory", allEntries=true)
     public int insert(KnowledgeCategory entity) {
         if (BeanUtil.isEmpty(entity.getPkId())) {
             entity.setPkId(IdGenerator.getIdStr());
@@ -189,6 +193,7 @@ public class KnowledgeCategoryServiceImpl extends SuperServiceImpl<KnowledgeCate
      * @return
      */
     @Override
+    @CacheEvict(value = "knowledgeCategory", allEntries=true)
     public int update(KnowledgeCategory entity) {
         KnowledgeCategory knowledgeCategory = this.get(entity.getPkId());
         if (knowledgeCategory.getIsSys() == 1) {
@@ -243,6 +248,7 @@ public class KnowledgeCategoryServiceImpl extends SuperServiceImpl<KnowledgeCate
      * @param knowledgeCategoryId
      */
     @Transactional(rollbackFor = Exception.class)
+    @CacheEvict(value = "knowledgeCategory", allEntries=true)
     public Integer deleteKnowledgeCategory(String knowledgeCategoryId) {
 
         // 查询该分类下是否还有知识

+ 57 - 1
src/main/java/com/redxun/knowledge/service/KnowledgeServiceImpl.java

@@ -181,6 +181,26 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             if (ObjectUtils.isNotEmpty(approvalVoList)) {
                 KnowledgeApprovalNodeVo node;
                 for (int index = 0; index < approvalVoList.size(); index++) {
+                    //自定义节点存在,加入到默认节点的下一个节点
+                    if (index == 1 && StringUtils.isNotEmpty(knowledgeDto.getCustomNodes())){
+                        KnowledgeApprove knowledgeApprove = new KnowledgeApprove();
+                        knowledgeApprove.setPkId(IdGenerator.getIdStr());
+                        knowledgeApprove.setName("自定义节点");
+                        knowledgeApprove.setKnowledgerId(knowledge.getPkId());
+                        knowledgeApprove.setApproverId(knowledgeDto.getCustomNodes());
+                        String approverName = Arrays.asList(knowledgeApprove.getApproverId().split(",")).parallelStream().map(e -> userService.queryByUsername(e).getFullName()).
+                                collect(Collectors.joining(","));
+                        knowledgeApprove.setApproverName(approverName);
+                        knowledgeApprove.setApprovalBatch(1);
+                        knowledgeApprove.setUpdateBy(users.getUserId());
+                        knowledgeApprove.setSort(2);
+                        knowledgeApprove.setIsFinal(0);
+                        knowledgeApprove.setCreateBy(userService.queryLoginUser());
+                        knowledgeApprove.setCreateTime(new Date());
+                        knowledgeApproveMapper.insert(knowledgeApprove);
+                        index--;
+                        continue;
+                    }
                     node = approvalVoList.get(index);
                     if (node != null) {
                         KnowledgeApprove knowledgeApprove = new KnowledgeApprove();
@@ -191,7 +211,11 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                         knowledgeApprove.setApproverName(node.getApproverName());
                         knowledgeApprove.setApprovalBatch(1);
                         knowledgeApprove.setUpdateBy(users.getUserId());
-                        knowledgeApprove.setSort(index + 1);
+                        if (index > 0 && StringUtils.isNotEmpty(knowledgeDto.getCustomNodes())){
+                            knowledgeApprove.setSort(index + 2);
+                        } else {
+                            knowledgeApprove.setSort(index + 1);
+                        }
                         knowledgeApprove.setIsFinal(node.getIsFinal());
                         knowledgeApprove.setCreateBy(userService.queryLoginUser());
                         knowledgeApprove.setCreateTime(new Date());
@@ -362,6 +386,18 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             if (e.getCreateBy().equals(userService.queryLoginUser())){
                 e.setIsOrganizationId(0);
             }
+            //如果知识还没有人进行审核,支持撤回(第一个节点审核结果为空,可撤回)(草稿无法撤回)
+            if (!filter.getParams().containsKey("isDraft")){
+                String knowledgeId = e.getPkId();
+                List<KnowledgeApprove> knowledgeApproveList = knowledgeApproveMapper.selectList(new QueryWrapper<KnowledgeApprove>().eq("KNOWLEDGER_ID", e.getPkId()));
+                if(knowledgeApproveList.get(0).getResult() == null){
+                    e.setIsWithdraw(0);
+                } else {
+                    e.setIsWithdraw(1);
+                }
+            } else {
+                e.setIsWithdraw(1);
+            }
         });
         return page;
     }
@@ -943,4 +979,24 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
         //转移
         knowledgeMapper.transferCategory(knowledgeIds,categoryId);
     }
+
+    /**
+     * 知识撤回
+     * @param knowledgeId
+     */
+    public void knowledgeWithdraw(String knowledgeId) {
+        //判断知识是否被审核过了
+        List<KnowledgeApprove> knowledgeApproveList = knowledgeApproveMapper.
+                selectList(new QueryWrapper<KnowledgeApprove>().eq("KNOWLEDGER_ID", knowledgeId));
+        if (knowledgeApproveList.stream().findFirst().get().getResult() != null){
+            throw new RuntimeException("知识被审核过了,无法撤回");
+        }
+        //撤回(知识审核状态修改为6且进入草稿,审核记录删除)
+        Knowledge knowledge = this.get(knowledgeId);
+        knowledge.setPkId(knowledgeId);
+        knowledge.setApprovalStatus(6);
+        knowledge.setIsDraft(0);
+        knowledgeMapper.updateById(knowledge);
+        knowledgeApproveMapper.deleteByKnowledgeId(knowledgeId);
+    }
 }

+ 27 - 0
src/main/java/com/redxun/knowledge/task/SendMessageDTO.java

@@ -0,0 +1,27 @@
+package com.redxun.knowledge.task;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 文件名: SendMessageDTO
+ * 作者: zizg
+ * 时间: 2023/7/26
+ * 描述:
+ * 修改人:
+ * 修改时间:
+ * 修改内容:
+ */
+@Data
+public class SendMessageDTO implements Serializable {
+
+    private String approverId;
+
+    private String titles;
+
+    private String userId;
+
+    private Date createTime;
+}

+ 86 - 0
src/main/java/com/redxun/knowledge/task/SendQYWXJobHandler.java

@@ -0,0 +1,86 @@
+package com.redxun.knowledge.task;
+
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
+import com.redxun.knowledge.common.MessageService;
+import com.redxun.knowledge.common.UserService;
+import com.redxun.knowledge.entity.vo.KnowledgeApprovalListVo;
+import com.redxun.knowledge.mapper.KnowledgeApproveMapper;
+import com.redxun.knowledge.qywexin.QYWechatUtils;
+import com.redxun.knowledge.service.KnowledgeApproveServiceImpl;
+import com.xxl.job.core.handler.IJobHandler;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 文件名: SendQYWXJobHandler
+ * 作者: zizg
+ * 时间: 2023/7/25
+ * 描述: 每天8点给未审核知识超过两天的人发企业微信
+ * 修改人:
+ * 修改时间:
+ * 修改内容:
+ */
+@Component
+@Slf4j
+public class SendQYWXJobHandler extends IJobHandler {
+
+    @Autowired
+    private KnowledgeApproveServiceImpl knowledgeApproveService;
+
+    @Autowired
+    private KnowledgeApproveMapper knowledgeApproveMapper;
+
+    @Autowired
+    private UserService userService;
+
+    @Value("${qywx.approvePage}")
+    private String qywxApprovePage;
+
+    @Override
+    @XxlJob("sendQYWX")
+    public void execute() throws Exception {
+        log.info("开始发送消息~");
+        List<KnowledgeApprovalListVo> allKnowledgeApprove = knowledgeApproveMapper.findAllKnowledgeApprove(new HashMap<>(), new HashMap<>());
+        List<KnowledgeApprovalListVo> result = knowledgeApproveService.allApproveList(allKnowledgeApprove);
+        //过滤出待审核记录和待最终审核记录
+        List<SendMessageDTO> collect = result.parallelStream().filter(e -> e.getApprovalStatus() == 1 || e.getApprovalStatus() == 3).map(e -> {
+            SendMessageDTO sendMessageDTO = new SendMessageDTO();
+            sendMessageDTO.setApproverId(e.getApproverId());
+            sendMessageDTO.setTitles(e.getTitles());
+            sendMessageDTO.setUserId(e.getCreateBy());
+            sendMessageDTO.setCreateTime(e.getCreateTime());
+            return sendMessageDTO;
+        }).collect(Collectors.toList());
+        log.info("待发送短信人数 -> {}",collect.size());
+        collect.forEach(e -> this.sendMessage(e.getApproverId(),e.getTitles(),e.getUserId(),e.getCreateTime()));
+        log.info("消息发送完成~");
+    }
+
+    /**
+     * 发送企业微信
+     * @param sender 待发送人
+     * @param titles 文章标题
+     * @param userId 文章作者
+     * @param date   创建日期
+     */
+    private void sendMessage(String sender, String titles, String userId, Date date){
+        String[] qyUser = new  String[]{sender};
+        // 发消息通过前来审核
+        QYWechatUtils.send(qyUser,"您有一条待审核任务,请尽快完成审核!" + "<br>" +
+                "审核类型:知识审核" + "<br>" +
+                "提交内容:" + titles + "<br>" +
+                "提交人:" + userService.queryUser(userId).getFullName() + "<br>" +
+                "提交时间:" + DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN)+ "<br>" +
+                "审批地址:" + "<a href=" + qywxApprovePage + ">查看</a>");
+    }
+}