Browse Source

Merge remote-tracking branch 'origin/master'

liuyongxin 1 year ago
parent
commit
c3db0fc6c4

+ 1 - 0
src/main/java/com/dingding/mid/common/CommonConstants.java

@@ -17,5 +17,6 @@ public interface CommonConstants {
 	String BUSINESS_STATUS_2="2";//撤销
 	String BUSINESS_STATUS_3="3";//驳回
 	String BUSINESS_STATUS_4="4";//已结束
+	String EXTEND_DATA = "extendData";
 
 }

+ 12 - 0
src/main/java/com/dingding/mid/controller/WorkspaceProcessController.java

@@ -18,6 +18,7 @@ import com.dingding.mid.entity.Users;
 import com.dingding.mid.entity.WorkflowConfig;
 import com.dingding.mid.enums.RefuseEnums;
 import com.dingding.mid.exception.WorkFlowException;
+import com.dingding.mid.mqtt.CloudMessage;
 import com.dingding.mid.mqtt.WorkFlowMessage;
 import com.dingding.mid.service.*;
 import com.dingding.mid.utils.MinioUploadUtil;
@@ -140,6 +141,7 @@ public class WorkspaceProcessController {
             processVariables.put(PROCESS_STATUS,BUSINESS_STATUS_1);
             processVariables.put(START_USER_INFO,JSONObject.toJSONString(startUserInfo));
             processVariables.put(INITIATOR_ID,startUserInfo.getId());
+            processVariables.put(EXTEND_DATA,startProcessInstanceDTO.getExtendData());
             ArrayList<UserInfo> userInfos = CollUtil.newArrayList(startUserInfo);
             processVariables.put("root",JSONObject.toJSONString(userInfos));
             Map<String, List<UserInfo>> processUsers = startProcessInstanceDTO.getProcessUsers();
@@ -498,6 +500,10 @@ public class WorkspaceProcessController {
 
 
         taskService.complete(task.getId());
+        // 消息处理
+        CloudMessage cloudMessage = new CloudMessage();
+        cloudMessage.setTaskId(taskId);
+        sendMessageService.publish("message/deal/workflow",cloudMessage);
         return Result.OK();
     }
 
@@ -631,6 +637,7 @@ public class WorkspaceProcessController {
         ProcessTemplates processTemplates = processTemplateService.getById(processDefinitionKey.replace(PROCESS_PREFIX, ""));
         String tableConfigId = processTemplates.getTableConfigId();
         log.info("tableConfigId:{}", tableConfigId);
+        log.info("ProcessVariables:{}",historicProcessInstance.getProcessVariables());
         if (tableConfigId != null) {
             //根据tableConfigId 查询需要修改的表单
             WorkflowConfig workflowConfig = workflowConfigService.getById(tableConfigId);
@@ -647,7 +654,12 @@ public class WorkspaceProcessController {
             } else {
                 log.info("发送失败");
             }
+            // TODO: 2024/3/8 给发起人发送拒绝信息
         }
+        // 消息处理
+        CloudMessage cloudMessage = new CloudMessage();
+        cloudMessage.setTaskId(taskId);
+        sendMessageService.publish("message/deal/workflow",cloudMessage);
 
         return Result.OK();
     }

+ 2 - 0
src/main/java/com/dingding/mid/dto/StartProcessInstanceDTO.java

@@ -24,4 +24,6 @@ public class StartProcessInstanceDTO {
     private Map<String, List<UserInfo>> processUsers;
     @ApiModelProperty("当前人用户信息,(因为本项目没有做登录功能,所以就是直接传递用户信息就行 简单起见)")
     private UserInfo startUserInfo;
+    @ApiModelProperty("扩展信息,包含回源的数据来源和数据id,其他信息根据情况而定,dataFrom:数据来源,dataId:数据id")
+    private JSONObject extendData;
 }

+ 8 - 2
src/main/java/com/dingding/mid/listener/CounterSignListener.java

@@ -10,9 +10,12 @@ import com.dingding.mid.dto.json.UserInfo;
 import com.dingding.mid.entity.Users;
 import com.dingding.mid.enums.AssigneeTypeEnums;
 import com.dingding.mid.exception.WorkFlowException;
+import com.dingding.mid.mqtt.CloudMessage;
+import com.dingding.mid.service.SendMessageService;
 import com.dingding.mid.service.UserService;
 import com.dingding.mid.utils.SpringContextHolder;
 import lombok.extern.slf4j.Slf4j;
+import org.checkerframework.checker.units.qual.C;
 import org.flowable.bpmn.model.Process;
 import org.flowable.bpmn.model.UserTask;
 import org.flowable.engine.RepositoryService;
@@ -21,6 +24,7 @@ import org.flowable.engine.delegate.ExecutionListener;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -41,6 +45,10 @@ public class CounterSignListener implements ExecutionListener {
     private RepositoryService repositoryService;
     @Resource
     private UserService userService;
+
+    @Resource
+    private SendMessageService sendMessageService;
+
     @Override
     public void notify(DelegateExecution execution) {
 
@@ -183,7 +191,5 @@ public class CounterSignListener implements ExecutionListener {
                 execution.setVariable(variable,assigneeList);
             }
         }
-        else{
-        }
     }
 }

+ 2 - 1
src/main/java/com/dingding/mid/listener/ProcessListener.java

@@ -56,6 +56,7 @@ public class ProcessListener implements ExecutionListener {
         ProcessTemplates processTemplates = processTemplateService.getById(processDefinitionKey.replace(PROCESS_PREFIX, ""));
         String tableConfigId = processTemplates.getTableConfigId();
         log.info("tableConfigId:{}", tableConfigId);
+        log.info("ProcessVariables:{}",historicProcessInstance.getProcessVariables());
         if (tableConfigId != null) {
             //根据tableConfigId 查询需要修改的表单
             WorkflowConfig workflowConfig = workflowConfigService.getById(tableConfigId);
@@ -72,7 +73,7 @@ public class ProcessListener implements ExecutionListener {
             } else {
                 log.info("发送失败");
             }
-
+            // TODO: 2024/3/8 给发起人发送审核完成消息
         }
     }
 }

+ 63 - 2
src/main/java/com/dingding/mid/listener/TaskCreatedListener.java

@@ -1,6 +1,12 @@
 package com.dingding.mid.listener;
 
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.dingding.mid.mqtt.CloudMessage;
+import com.dingding.mid.service.SendMessageService;
 import com.dingding.mid.utils.SpringContextHolder;
+import liquibase.pro.packaged.R;
 import lombok.extern.slf4j.Slf4j;
 import org.flowable.engine.RuntimeService;
 import org.flowable.engine.TaskService;
@@ -10,6 +16,9 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 
+import java.time.LocalDateTime;
+
+import static com.dingding.mid.common.CommonConstants.EXTEND_DATA;
 import static com.dingding.mid.common.WorkFlowConstants.*;
 
 /**
@@ -22,20 +31,72 @@ import static com.dingding.mid.common.WorkFlowConstants.*;
 public class TaskCreatedListener implements TaskListener {
     @Resource
     private TaskService taskService;
+
+    @Resource
+    private SendMessageService sendMessageService;
+
     @Override
     public void notify(DelegateTask delegateTask) {
         log.info("TaskCreatedListener触发了"+delegateTask.toString());
+            log.info(" 操作人:{}",delegateTask.getAssignee());
+            log.info(" 执行id:{}",delegateTask.getExecutionId());
+            log.info(" 实例id:{}",delegateTask.getProcessInstanceId());
+            log.info(" 任务类别:{}",delegateTask.getCategory());
+            log.info(" 变量信息:{}",delegateTask.getVariables());
+            log.info(" 任务描述:{}",delegateTask.getDescription());
+            log.info(" 事件名称:{}",delegateTask.getEventName());
+            log.info(" 任务优先级:{}",delegateTask.getPriority());
+            log.info(" 任务名称:{}",delegateTask.getName());
+            log.info(" 当前任务事件的名称:{}",delegateTask.getEventName());
+            log.info(" 扩展信息:{}",delegateTask.getVariable(EXTEND_DATA));
+
             if(DEFAULT_NULL_ASSIGNEE.equals(delegateTask.getAssignee())){
                 Object autoRefuse = delegateTask.getVariable(AUTO_REFUSE_STR);
+                log.info("autoRefuse :{} 审批人为空",autoRefuse);
                 if(autoRefuse==null){
                     taskService.addComment(delegateTask.getId(),delegateTask.getProcessInstanceId(),OPINION_COMMENT,"审批人为空,自动通过");
                     taskService.complete(delegateTask.getId());
-                }
-                else{
+                } else{
                     taskService.addComment(delegateTask.getId(),delegateTask.getProcessInstanceId(),OPINION_COMMENT,"审批人为空,自动驳回");
                     RuntimeService runtimeService = SpringContextHolder.getBean(RuntimeService.class);
                     runtimeService.deleteProcessInstance(delegateTask.getProcessInstanceId(),"审批人为空,自动驳回");
                 }
+            } else {
+                if ("审批人".equals(delegateTask.getName()) || "办理人".equals(delegateTask.getName()) || "审批人".equals(delegateTask.getName())) {
+                    if ("create".equals(delegateTask.getEventName())) {
+                        Object extendData = delegateTask.getVariable(EXTEND_DATA);
+                        if (JSONUtil.isTypeJSON(extendData == null ? "" : extendData.toString())) {
+                            log.info("EXTEND_DATA is json");
+                            // 获取
+                            JSONObject jsonObject = JSONUtil.parseObj(extendData);
+                            String dataFrom = jsonObject.getStr("dataFrom");
+                            String dataId = jsonObject.getStr("dataId");
+                            if (StrUtil.isAllNotBlank(dataFrom,dataId)) {
+                                // 发送消息
+                                CloudMessage cloudMessage = new CloudMessage();
+                                cloudMessage.setContent(String.format("您有新的%s待处理",delegateTask.getName()));
+                                cloudMessage.setReceiveBy(delegateTask.getAssignee())
+                                        .setCreateTime(LocalDateTime.now())
+                                        .setTypeCode(dataFrom)
+                                        .setOutId(delegateTask.getProcessInstanceId())
+                                        .setExtend(extendData.toString())
+                                        .setMessageLevel(1)
+                                        .setDealStatus(0)
+                                        .setMessageStatus(0)
+                                        .setMessageTypeId(4)
+                                        .setTypeName(dataFrom)
+                                        .setTaskId(delegateTask.getId())
+                                        .setTitle(delegateTask.getName() + "消息");
+                                log.info(" 操作人:{}",delegateTask.getAssignee());
+                                sendMessageService.publish("message/sys/workflow",cloudMessage);
+                            } else {
+                                log.info("EXTEND_DATA is not json");
+                            }
+                        }
+
+                    }
+                }
             }
+
     }
 }

+ 17 - 1
src/main/java/com/dingding/mid/mqtt/CloudMessage.java

@@ -18,6 +18,13 @@ public class CloudMessage implements Serializable{
      *
      */
 //    @ApiModelProperty(value="消息命令")
+//    private String command;
+
+    /**
+     * SINGLE_MESSAGE 一对一   ROLE_GROUP_MESSAGE  根据角色群发
+     *
+     */
+//    @ApiModelProperty(value="消息命令")
 //    private String command;
 
     /**
@@ -37,7 +44,7 @@ public class CloudMessage implements Serializable{
      * 收件人uid
      */
     @ApiModelProperty(value="收件人uid")
-    private Integer receiveBy;
+    private String receiveBy;
 
     /**
      * 发送时间
@@ -87,6 +94,9 @@ public class CloudMessage implements Serializable{
     @ApiModelProperty(value="模块")
     private String module;
 
+    @ApiModelProperty(value="类型id")
+    private Integer messageTypeId;
+
     /**
      * 类型
      */
@@ -99,4 +109,10 @@ public class CloudMessage implements Serializable{
     @ApiModelProperty(value="扩展信息")
     private String extend;
 
+    /**
+     * 任务id
+     */
+    @ApiModelProperty(value="任务id")
+    private String taskId;
+
 }

+ 4 - 4
src/main/java/com/dingding/mid/service/SendMessageService.java

@@ -22,15 +22,15 @@ public class SendMessageService {
     @Autowired
     private MqttClientTemplate client;
 
-    public boolean publish(String topic, MqttMessage mqttMessage) {
+    public boolean publish(String topic,JSONObject mqttMessage) {
         JSONObject jsonObject = JSONUtil.parseObj(mqttMessage);
-        //client.publish(topic, JSONUtil.toJsonStr(jsonObject).getBytes(StandardCharsets.UTF_8));
+        client.publish(topic, JSONUtil.toJsonStr(jsonObject).getBytes(StandardCharsets.UTF_8));
         return true;
     }
 
     public boolean publish(String topic,CloudMessage cloudMessage) {
         JSONObject jsonObject = JSONUtil.parseObj(cloudMessage);
-       // client.publish(topic, JSONUtil.toJsonStr(jsonObject).getBytes(StandardCharsets.UTF_8));
+        client.publish(topic, JSONUtil.toJsonStr(jsonObject).getBytes(StandardCharsets.UTF_8));
         return true;
     }
 
@@ -69,7 +69,7 @@ public class SendMessageService {
     }
 
     public static CloudMessage fomatNormalMessage(String title, String content
-            , String typeName, Integer messageLevel, Integer toUser, String toUserName, String outId) {
+            , String typeName, Integer messageLevel, String toUser, String toUserName, String outId) {
         CloudMessage cloudMessage = new CloudMessage();
         cloudMessage.setCreateTime(LocalDateTime.now());
         cloudMessage.setTitle(title);

+ 147 - 0
src/main/resources/application-test.yml

@@ -0,0 +1,147 @@
+# 应用服务器
+server:
+  tomcat:
+    uri-encoding: UTF-8 #tomcat编码
+  port: 9998 #tomcat端口
+
+  #===================== 数据源配置 =====================
+spring:
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    username: ${MYSQL_USER:root}
+    password: ${MYSQL_PWD:ozyebgwec@*wegh}
+    url: jdbc:mysql://${MYSQL_HOST:192.168.31.68}:${MYSQL_PORT:3306}/${MYSQL_DB:chemicals_scene}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&queryTimeout=2400&nullCatalogMeansCurrent=true
+  #===================== Redis配置 =====================
+  redis:
+    database: 1 #缓存库编号
+    host: 192.168.31.68
+    port: 6379
+    password:
+    timeout: 3000 #超时时间(单位:秒)
+    lettuce: #Lettuce为Redis的Java驱动包
+      pool:
+        max-active: 8 # 连接池最大连接数
+        max-wait: -1ms  # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        min-idle: 0 # 连接池中的最小空闲连接
+        max-idle: 8 # 连接池中的最大空闲连接
+
+  mail:
+    host: smtp.qq.com #邮件服务器的host
+    password: sb #邮件服务器的发件人密码
+    username: 6666@qq.com #邮件服务器的发件人
+    port: 25 #smtp默认端口
+    protocol: smtp #使用smtp协议
+    default-encoding: UTF-8 #邮件使用的字符集
+    properties:
+      mail:
+        debug: true #启调试模式(发送邮件的细节都能看出来) 默认值为fasle
+        debug.auth: true
+        smtp:
+          auth: true #如果为true ,则尝试使用auth命令对用户进行身份验证 默认为false
+          connectiontimeout: 20000 #套接字连接超时值(毫秒)。默认值为无限超时。
+          sendpartial: true #如果为true 并且邮件有一些有效和无效的地址 并使用SendFailException 报告部分失败, 如果设置为false(默认值) 如果存在无效的收件人地址, 则不会将邮件发送给任何收件人
+          starttls:
+            #如果为true,则在发出任何登录命令之前,启用starttl命令(如果服务器支持) 将连接切换到受TLS保护的连接,请注意,必须配置适当的信任存储,以便客户端信任服务器的证书,默认为false
+            enable: true
+            # 如果为true,则需要使用 starttl命令,如果服务器不支持此命令,或者该命令失败,connect()将失败,默认为false 如果此设置为true james邮件服务器会报错 STARTTLS is required but host does not support STARTTLS
+            required: false
+          timeout: 20000 #I/O超时值(ms) 默认为无限超时
+          userset: true #如果设置为true,则在isConnected()中使用RSET命令而不是NOOP命令 在某些情况下,sendmail在执行许多NOOP命令后响应缓存,使用RSET可以避免这个sendMail问题,默认为false
+
+
+flowable:
+  dmn:
+    enabled: false
+  cmmn:
+    enabled: false
+  idm:
+    enabled: false
+  async-history-executor-activate: false
+  async-executor-activate: false
+  check-process-definitions: false
+  content:
+    enabled: false
+  app:
+    enabled: false
+  eventregistry:
+    enabled: false
+
+config:
+  minio:
+    endpoint: http://192.168.0.147:9000/ #服务端地址
+    accessKey: admin #账号
+    secretKey: test. #密码
+    fileHost: http://192.168.0.147:9000/ #地址
+
+
+
+knife4j:
+  enable: true
+  openapi:
+    title: 仿钉钉
+    description: "`仿钉钉流程设计器兼容,Activiti-Flowable-Camunda`"
+    email: 2471089198@qq.com
+    concat: ProcessEngine
+    url: https://baidu.com
+    version: v4.0
+    license: Apache 2.0
+    license-url: https://stackoverflow.com/
+    terms-of-service-url: https://stackoverflow.com/
+    group:
+      test1:
+        group-name: Vue2版本接口
+        api-rule: package
+        api-rule-resources:
+          - com.dingding.mid.controller
+
+##################################################################################重要--避免为了在ActivitiConfig中写死############################################################################################
+##### db-Type  只有如下可选值,flowable源码并未对这里进行忽略大小写判断,所以我们新增一个配置项来进行配置,防止有人写大写的情况
+workflow:
+#  public static final String DATABASE_TYPE_H2 = "h2";
+#  public static final String DATABASE_TYPE_HSQL = "hsql";
+#  public static final String DATABASE_TYPE_MYSQL = "mysql";
+#  public static final String DATABASE_TYPE_ORACLE = "oracle";
+#  public static final String DATABASE_TYPE_POSTGRES = "postgres";
+#  public static final String DATABASE_TYPE_MSSQL = "mssql";
+#  public static final String DATABASE_TYPE_DB2 = "db2";
+#  public static final String DATABASE_TYPE_COCKROACHDB = "cockroachdb";
+  db-type: mysql
+  email-host: xxx.qq.com
+  email-password: xxxx
+  email-addr: xxx.qq.com
+  email-port: 25
+
+mqtt:
+  client:
+    enabled: true               # 是否开启客户端,默认:true
+    ip: 192.168.31.68              # 连接的服务端 ip ,默认:127.0.0.1
+    port: 1883                  # 端口:默认:1883
+    name: accident-Mqtt-Client      # 名称,默认:Mica-Mqtt-Client
+    clientId: accident000001            # 客户端Id(非常重要,一般为设备 sn,不可重复)
+    user-name: accidentadmin             # 认证的用户名
+    password: accidentadmin            # 认证的密码
+    timeout: 5                  # 超时时间,单位:秒,默认:5秒
+    reconnect: true             # 是否重连,默认:true
+    re-interval: 5000           # 重连时间,默认 5000 毫秒
+    version: mqtt_3_1_1         # mqtt 协议版本,可选 MQTT_3_1、mqtt_3_1_1、mqtt_5,默认:mqtt_3_1_1
+    read-buffer-size: 8KB       # 接收数据的 buffer size,默认:8k
+    max-bytes-in-message: 10MB  # 消息解析最大 bytes 长度,默认:10M
+    buffer-allocator: heap      # 堆内存和堆外内存,默认:堆内存
+    keep-alive-secs: 60         # keep-alive 时间,单位:秒
+    clean-session: true         # mqtt clean session,默认:true
+    ssl:
+      enabled: false            # 是否开启 ssl 认证,2.1.0 开始支持双向认证
+      keystore-path:            # 可选参数:ssl 双向认证 keystore 目录,支持 classpath:/ 路径。
+      keystore-pass:            # 可选参数:ssl 双向认证 keystore 密码
+      truststore-path:          # 可选参数:ssl 双向认证 truststore 目录,支持 classpath:/ 路径。
+      truststore-pass:          # 可选参数:ssl 双向认证 truststore 密码
+usermqtt:
+  host: 192.168.31.68
+  port: 1883
+  endpoint:
+  username:
+  password:
+
+
+