Pārlūkot izejas kodu

样本送检钉钉通知

陈长荣 2 mēneši atpakaļ
vecāks
revīzija
de2d678915

+ 10 - 4
jfcloud-gene-biz/src/main/java/com/github/jfcloud/gene/sample/enums/SampleTypeEnum.java

@@ -11,20 +11,23 @@ public enum SampleTypeEnum {
     /**
      * 病理
      */
-    PATHOLOGICAL("pathological"),
+    PATHOLOGICAL("pathological", "病理样本检测"),
     /**
      * 动物样本
      */
-    ANIMAL("animal"),
+    ANIMAL("animal", "动物样本检测"),
     /**
      * 动物影像
      */
-    ANIMAL_IMAGE("animalImage");
+    ANIMAL_IMAGE("animalImage", "动物影像检测");
 
     private final String type;
 
-    SampleTypeEnum(String type) {
+    private final String label;
+
+    SampleTypeEnum(String type, String label) {
         this.type = type;
+        this.label = label;
     }
 
     public static List<String> allType() {
@@ -44,4 +47,7 @@ public enum SampleTypeEnum {
         return type;
     }
 
+    public String getLabel() {
+        return label;
+    }
 }

+ 98 - 24
jfcloud-gene-biz/src/main/java/com/github/jfcloud/gene/sample/service/impl/SampleInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.github.jfcloud.gene.sample.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
@@ -9,6 +10,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.jfcloud.admin.api.sys.dto.message.MessageUserDTO;
 import com.github.jfcloud.common.core.util.R;
 import com.github.jfcloud.common.data.datascope.DataScope;
 import com.github.jfcloud.gene.cache.UserIdNameCache;
@@ -22,6 +24,7 @@ import com.github.jfcloud.gene.flow.entity.FlowAudit;
 import com.github.jfcloud.gene.flow.entity.FlowInfo;
 import com.github.jfcloud.gene.flow.service.FlowAuditService;
 import com.github.jfcloud.gene.flow.service.FlowFileVersionService;
+import com.github.jfcloud.gene.flow.service.NotifyService;
 import com.github.jfcloud.gene.flow.vo.SynProjectVo;
 import com.github.jfcloud.gene.sample.dto.SampleAuditDto;
 import com.github.jfcloud.gene.sample.dto.SampleDetailDto;
@@ -37,6 +40,7 @@ import com.github.jfcloud.gene.sample.service.biz.SamplePathologicalServiceImpl;
 import com.github.jfcloud.gene.sample.vo.SampleAuditVo;
 import com.github.jfcloud.gene.sample.vo.SamplePageVo;
 import com.github.jfcloud.gene.sample.vo.SampleSubmitVo;
+import com.github.jfcloud.gene.sys.service.DBSystemPropertiesService;
 import com.github.jfcloud.project.api.dto.LacmsProjectDTO;
 import com.github.jfcloud.project.api.dto.ProjectFeignDTO;
 import com.github.jfcloud.project.api.feign.RemoteProjectService;
@@ -60,6 +64,8 @@ public class SampleInfoServiceImpl extends ServiceImpl<SampleInfoMapper, SampleI
     private final FlowFileVersionService fileVersionService;
     private final UserIdNameCache userIdNameCache;
     private final FlowAuditService flowAuditService;
+    private final NotifyService notifyService;
+    private final DBSystemPropertiesService systemPropertiesService;
     private final RemoteProjectService remoteProjectService;
     private final SubProjectFeign subProjectFeign;
 
@@ -151,9 +157,7 @@ public class SampleInfoServiceImpl extends ServiceImpl<SampleInfoMapper, SampleI
                     .setCreateTime(new Date());
         }
         updateInfo.updateById();
-
-        // todo 提交钉钉消息推送
-//        notifyService.notify(id);
+        notify(id);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -270,7 +274,7 @@ public class SampleInfoServiceImpl extends ServiceImpl<SampleInfoMapper, SampleI
                     .updateById();
 
             generate(id);
-//            notifyService.notify(id);
+            notify(id);
             return;
         }
 
@@ -295,7 +299,7 @@ public class SampleInfoServiceImpl extends ServiceImpl<SampleInfoMapper, SampleI
                 .updateById();
 
         generate(id);
-//        notifyService.notify(id);
+        notify(id);
     }
 
     @Override
@@ -346,26 +350,96 @@ public class SampleInfoServiceImpl extends ServiceImpl<SampleInfoMapper, SampleI
         String leaderNickname = userIdNameCache.getNicknameByUserId(vo.getProjectLeader());
         projectFeignDTO.setLeaders(leaderNickname);
 
-        log.info("推送科研项目:flowId={}, param={}", id, JSON.toJSONString(projectFeignDTO));
-        R<Long> longR = remoteProjectService.initProject(projectFeignDTO);
-        if (!longR.isOk()) {
-            log.error("projectId={}推送科研失败,{}", id, longR);
+        Long kyId;
+        if (systemPropertiesService.getBooleanValue("sample.sync.ky")) {
+            log.info("推送科研项目:flowId={}, param={}", id, JSON.toJSONString(projectFeignDTO));
+            R<Long> longR = remoteProjectService.initProject(projectFeignDTO);
+            if (!longR.isOk()) {
+                log.error("projectId={}推送科研失败,{}", id, longR);
+            }
+            Assert.isTrue(longR.isOk(), "操作失败,科研" + longR);
+            kyId = longR.getData();
+            new FlowInfo().setId(id).setKyId(kyId).updateById();
+        } else {
+            log.warn("科研同步配置未开启,不进行同步");
+            return;
+        }
+
+        if (kyId != null && systemPropertiesService.getBooleanValue("sample.sync.animal")) {
+            //同步动物中心,生成动物中心项目信息
+            LacmsProjectDTO lacmsProjectDTO = new LacmsProjectDTO();
+            lacmsProjectDTO.setKyId(kyId);
+            lacmsProjectDTO.setProjectName(sampleInfo.getProjectName());
+            lacmsProjectDTO.setProjectLeader(vo.getProjectLeader());
+            lacmsProjectDTO.setPl(leaderNickname);
+            lacmsProjectDTO.setEthicsCode(sampleInfo.getProjectNo());
+            lacmsProjectDTO.setProjectType("样本送检");
+            lacmsProjectDTO.setProjectNum(projectNo);
+            log.info("推送动物中心:flowId={}, param={}", id, JSON.toJSONString(lacmsProjectDTO));
+            subProjectFeign.initProject(lacmsProjectDTO);
+        } else {
+            log.warn("动物中心同步配置未开启,不进行同步");
+        }
+    }
+
+    private void notify(Long sampleId) {
+        SampleInfo sampleInfo = getById(sampleId);
+        if (sampleInfo == null) {
+            return;
+        }
+
+        //查询流程前一个状态
+        List<FlowAudit> flowAudits = flowAuditService.auditList(sampleId, "sample." + sampleInfo.getType(), false);
+        FlowAudit previousAudit = null;
+        String previousStatus = "";
+        String previousUser = "";
+        if (CollUtil.isNotEmpty(flowAudits)) {
+            previousAudit = flowAudits.get(0);
+            GeneStatusEnum statusEnum = GeneStatusEnum.getByStatus(previousAudit.getFlowStatus());
+            previousStatus = statusEnum != null ? statusEnum.getDescription() : "";
+            previousUser = userIdNameCache.getNicknameByUserId(previousAudit.getCreateBy());
+        }
+
+        String projectType = "样本送检/" + Objects.requireNonNull(SampleTypeEnum.resolve(sampleInfo.getType())).getLabel();
+
+        Long userId;
+        String dingMsg;
+        GeneStatusEnum statusEnum = Objects.requireNonNull(GeneStatusEnum.getByStatus(sampleInfo.getStatus()));
+        switch (statusEnum) {
+            case REJECTED:
+                //驳回通知申请人
+                userId = Long.valueOf(sampleInfo.getCreateBy());
+                dingMsg = String.format("【%s】【%s/%s】不同意,请修正后再提交", projectType, previousStatus, previousUser);
+                break;
+            case DEPART_LEADER:
+                userId = sampleInfo.getDepartLeaderId();
+                dingMsg = String.format("【%s】【%s/%s】已同意,请进行审查", projectType, previousStatus, previousUser);
+                break;
+            case PROJECT_MANAGEMENT:
+                userId = sampleInfo.getProjectManageId();
+                dingMsg = String.format("【%s】【%s/%s】已同意,请进行审查", projectType, previousStatus, previousUser);
+                break;
+            case COMPLETED:
+                //执行
+                userId = Long.valueOf(sampleInfo.getCreateBy());
+                dingMsg = String.format("【%s】【%s/%s】已同意,请执行项目", projectType, previousStatus, previousUser);
+                break;
+            default:
+                log.error("流程项目 ({}) 状态异常 {}", sampleInfo.getProjectName(), statusEnum.getDescription());
+                return;
+        }
+
+        if (sampleInfo.getVersion() > 1) {
+            dingMsg += "(第" + sampleInfo.getVersion() + "次申请)";
+        }
+
+        //查询是否需要钉钉通知
+        String key = String.format("sample.%s.dingding.enable", sampleInfo.getStatus());
+        if (systemPropertiesService.getBooleanValue(key)) {
+            MessageUserDTO messageUserDTO = new MessageUserDTO();
+            messageUserDTO.setUserId(userId);
+            notifyService.sendDingding(dingMsg, Collections.singletonList(messageUserDTO));
         }
-        Assert.isTrue(longR.isOk(), "操作失败,科研" + longR);
-        Long kyId = longR.getData();
-        new FlowInfo().setId(id).setKyId(kyId).updateById();
-
-        //同步动物中心,生成动物中心项目信息
-        LacmsProjectDTO lacmsProjectDTO = new LacmsProjectDTO();
-        lacmsProjectDTO.setKyId(kyId);
-        lacmsProjectDTO.setProjectName(sampleInfo.getProjectName());
-        lacmsProjectDTO.setProjectLeader(vo.getProjectLeader());
-        lacmsProjectDTO.setPl(leaderNickname);
-        lacmsProjectDTO.setEthicsCode(sampleInfo.getProjectNo());
-        lacmsProjectDTO.setProjectType("样本送检");
-        lacmsProjectDTO.setProjectNum(projectNo);
-        log.info("推送动物中心:flowId={}, param={}", id, JSON.toJSONString(lacmsProjectDTO));
-        subProjectFeign.initProject(lacmsProjectDTO);
     }
 }
 

+ 17 - 0
jfcloud-gene-biz/src/main/resources/sql/ddl-20250321.sql

@@ -0,0 +1,17 @@
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('sample.-1.dingding.enable','true','样本送检驳回钉钉通知');
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('sample.25.dingding.enable','true','样本送检部门负责人审核钉钉通知');
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('sample.60.dingding.enable','true','样本送检项目管理部审核钉钉通知');
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('sample.100.dingding.enable','true','样本送检完成钉钉通知');
+
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('gene.sync.ky','true','基因定制科研同步');
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('gene.sync.animal','true','基因定制动物同步');
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('sample.sync.ky','true','样本送检科研同步');
+INSERT INTO jfcloud_gene.system_properties (prop_key,prop_value,remark) VALUES
+    ('sample.sync.animal','true','样本送检动物同步');