ye-zhaojia пре 2 недеља
родитељ
комит
a1d9aa6c68

+ 57 - 0
src/main/java/com/qqflow/engine/domain/flow/service/impl/ProcessInstanceServiceImpl.java

@@ -622,9 +622,66 @@ public class ProcessInstanceServiceImpl implements ProcessInstanceService {
             }
         }
         if (!hasPermission) throw new BusinessException("只有当前节点处理人可补充材料");
+        String changeDesc = this.diffFormData(instance.getFormData(), formData);
         this.processInstanceMapper.update(null, Wrappers.<ProcessInstance>lambdaUpdate()
                 .eq(ProcessInstance::getId, instanceId)
                 .set(ProcessInstance::getFormData, formData));
+        // 记录"修改表单数据"的审批记录,便于在流程进度中查看进行了哪些操作
+        if (changeDesc != null) {
+            ApprovalTask task = pendingTasks.isEmpty() ? null : pendingTasks.get(0);
+            ApprovalRecord record = new ApprovalRecord();
+            record.setTaskId(task != null ? task.getId() : null);
+            record.setInstanceId(instanceId);
+            record.setNodeId(currentNodeId);
+            record.setNodeName(task != null ? task.getNodeName() : null);
+            record.setOperatorId(operatorId);
+            record.setOperatorName(loginUser != null ? loginUser.getRealName() : null);
+            record.setActionType("EDIT_FORM");
+            record.setActionResult("EDIT");
+            record.setComment(changeDesc);
+            record.setCreateTime(LocalDateTime.now());
+            this.approvalRecordMapper.insert(record);
+        }
+    }
+
+    /** 对比新旧表单数据,返回变更说明;无变化返回 null */
+    private String diffFormData(String oldJson, String newJson) {
+        if (newJson == null || newJson.isBlank()) {
+            return null;
+        }
+        Map<String, Object> oldMap = this.parseFormDataMap(oldJson);
+        Map<String, Object> newMap = this.parseFormDataMap(newJson);
+        if (oldMap == null || oldMap.isEmpty()) {
+            return "补充表单数据";
+        }
+        List<String> changed = new ArrayList<>();
+        for (Map.Entry<String, Object> e : newMap.entrySet()) {
+            Object oldVal = oldMap.get(e.getKey());
+            Object newVal = e.getValue();
+            if (!Objects.equals(oldVal, newVal)) {
+                changed.add(e.getKey());
+            }
+        }
+        for (String k : oldMap.keySet()) {
+            if (!newMap.containsKey(k)) {
+                changed.add(k + "(删除)");
+            }
+        }
+        if (changed.isEmpty()) {
+            return null;
+        }
+        return "修改表单数据:" + String.join("、", changed);
+    }
+
+    private Map<String, Object> parseFormDataMap(String json) {
+        if (json == null || json.isBlank()) {
+            return Collections.emptyMap();
+        }
+        try {
+            return this.objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
+        } catch (Exception e) {
+            return Collections.emptyMap();
+        }
     }
 
     private boolean canOperateTask(ApprovalTask task, Long operatorId, String userType) {