liuyongxin 1 年之前
父節點
當前提交
c3e3101aab

+ 14 - 6
src/main/java/com/dingding/mid/listener/ProcessListener.java

@@ -47,26 +47,34 @@ public class ProcessListener implements ExecutionListener {
     @Override
     public void notify(DelegateExecution execution) {
         log.info("ProcessListener触发了");
-        execution.setVariable(PROCESS_STATUS,BUSINESS_STATUS_4);
+        execution.setVariable(PROCESS_STATUS, BUSINESS_STATUS_4);
         String processInstanceId = execution.getProcessInstanceId();
-        log.info("processInstanceId:{}",processInstanceId);
+        log.info("processInstanceId:{}", processInstanceId);
 
         // TODO: 2024/3/4 根据流程实例id 修改表单的数据 修改状态
         HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId)
                 .includeProcessVariables().singleResult();
         String processDefinitionKey = historicProcessInstance.getProcessDefinitionKey();
-        ProcessTemplates processTemplates = processTemplateService.getById(processDefinitionKey.replace(PROCESS_PREFIX,""));
+        ProcessTemplates processTemplates = processTemplateService.getById(processDefinitionKey.replace(PROCESS_PREFIX, ""));
         String tableConfigId = processTemplates.getTableConfigId();
-        if (Optional.ofNullable(tableConfigId).isPresent()){
+        log.info("tableConfigId:{}", tableConfigId);
+        if (tableConfigId != null) {
             //根据tableConfigId 查询需要修改的表单
             WorkflowConfig workflowConfig = workflowConfigService.getById(tableConfigId);
             //获取表名
             String tableName = workflowConfig.getTableName();
             //MQTT
-            WorkFlowMessage workFlowMessage = new WorkFlowMessage().setTableName(tableName).setProcessInstanceId(processInstanceId);
+            String command = "UPDATE-STATE";
+            WorkFlowMessage workFlowMessage = new WorkFlowMessage().setTableName(tableName).setProcessInstanceId(processInstanceId).setCommand(command);
             //发送表名和实例id
             String topic = "workflow";
-            sendMessageService.publish(topic,workFlowMessage);
+            boolean publish = sendMessageService.publish(topic, workFlowMessage);
+            if (publish) {
+                log.info("发送成功");
+            } else {
+                log.info("发送失败");
+            }
+
         }
     }
 }

+ 3 - 0
src/main/java/com/dingding/mid/mqtt/WorkFlowMessage.java

@@ -17,6 +17,9 @@ import java.io.Serializable;
 @ApiModel(value = "工作流消息")
 public class WorkFlowMessage implements Serializable {
 
+    //command
+    private String command;
+
     //表名
     private String tableName;
 

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

@@ -36,8 +36,7 @@ public class SendMessageService {
 
     public boolean publish(String topic, WorkFlowMessage workFlowMessage) {
         JSONObject jsonObject = JSONUtil.parseObj(workFlowMessage);
-        client.publish(topic, JSONUtil.toJsonStr(jsonObject).getBytes(StandardCharsets.UTF_8));
-        return true;
+        return client.publish(topic, JSONUtil.toJsonStr(jsonObject).getBytes(StandardCharsets.UTF_8));
     }
 
 //    public boolean publish(String topic, MqttMessage mqttMessage, MqttProperties mqttProperties) {