|
|
@@ -0,0 +1,451 @@
|
|
|
+package cn.iocoder.yudao.module.iscs.api.task;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.framework.common.biz.iscs.IscsInitApi;
|
|
|
+import cn.iocoder.yudao.framework.common.biz.iscs.dto.InitWorkDTO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.workdesign.workflowdesign.vo.WorkflowDesignSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.workdesign.workflowwork.vo.WorkflowWorkSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.isolationpoint.IsolationPointDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.isolationpoint.IsolationPointService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.workdesign.WorkflowDesignService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.workdesign.WorkflowWorkService;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class IscsInitApiImpl implements IscsInitApi {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IsolationPointService isolationPointService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WorkflowDesignService workflowDesignService;
|
|
|
+ @Resource
|
|
|
+ private WorkflowWorkService workflowWorkService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void workInit(InitWorkDTO dto) {
|
|
|
+ Long tenantId = dto.getTenantId();
|
|
|
+ Long lockPerson = dto.getLockPerson();
|
|
|
+ List<Long> coLockPersons = dto.getCoLockPersons();
|
|
|
+ Long workerUserId = dto.getWorkerUserId();
|
|
|
+ System.out.println("tenantId---------" + tenantId);
|
|
|
+
|
|
|
+
|
|
|
+ // 点位相关初始化
|
|
|
+ IsolationPointDO isolationPointDO1 = new IsolationPointDO();
|
|
|
+ isolationPointDO1.setPointName("UPS总闸");
|
|
|
+
|
|
|
+ IsolationPointDO isolationPointDO2 = new IsolationPointDO();
|
|
|
+ isolationPointDO2.setPointName("电机总开");
|
|
|
+
|
|
|
+ IsolationPointDO isolationPointDO3 = new IsolationPointDO();
|
|
|
+ isolationPointDO3.setPointName("电机总开");
|
|
|
+
|
|
|
+ List<IsolationPointDO> isolationPointDOS = new ArrayList<>();
|
|
|
+ isolationPointDOS.add(isolationPointDO1);
|
|
|
+ isolationPointDOS.add(isolationPointDO2);
|
|
|
+ isolationPointDOS.add(isolationPointDO3);
|
|
|
+ isolationPointService.saveBatch(isolationPointDOS);
|
|
|
+
|
|
|
+ List<Long> isolationPoints = new ArrayList<>();
|
|
|
+ isolationPoints.add(isolationPointDO1.getId());
|
|
|
+ isolationPoints.add(isolationPointDO2.getId());
|
|
|
+ isolationPoints.add(isolationPointDO3.getId());
|
|
|
+
|
|
|
+ // 流程模板初始化
|
|
|
+ WorkflowDesignSaveReqVO workflowDesignSaveReqVO = new WorkflowDesignSaveReqVO();
|
|
|
+ workflowDesignSaveReqVO.setName("作业流程实例");
|
|
|
+ workflowDesignSaveReqVO.setContent(getInitJson(isolationPoints, lockPerson, coLockPersons, workerUserId));
|
|
|
+ workflowDesignSaveReqVO.setDescription("初始化作业模板");
|
|
|
+ Long workflowDesign = workflowDesignService.createWorkflowDesign(workflowDesignSaveReqVO);
|
|
|
+
|
|
|
+ // 根据模板生成作业
|
|
|
+ WorkflowWorkSaveReqVO workflowWorkSaveReqVO = new WorkflowWorkSaveReqVO();
|
|
|
+ workflowWorkSaveReqVO.setName("标准维修作业" + new Random().nextInt(1000));
|
|
|
+ workflowWorkSaveReqVO.setType("1");
|
|
|
+ workflowWorkSaveReqVO.setUrgencyLevel("0");
|
|
|
+ workflowWorkSaveReqVO.setDesignId(workflowDesign);
|
|
|
+ workflowWorkService.createWorkflowWork(workflowWorkSaveReqVO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static String getInitJson(List<Long> isolationPoints, Long lockPerson, List<Long> coLockPersons, Long workerUserId) {
|
|
|
+ String originalJsonStr = "{\n" +
|
|
|
+ " \"nodeCount\" : 6,\n" +
|
|
|
+ " \"edgeCount\" : 5,\n" +
|
|
|
+ " \"adjacency\" : {\n" +
|
|
|
+ " \"createJob-1766650792290\" : {\n" +
|
|
|
+ " \"parentUuid\" : [ ],\n" +
|
|
|
+ " \"childrenUuid\" : [ \"review-1766650839450\" ]\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"confirm-1766650799337\" : {\n" +
|
|
|
+ " \"parentUuid\" : [ \"review-1766650839450\" ],\n" +
|
|
|
+ " \"childrenUuid\" : [ \"isolation-1766650858056\" ]\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"review-1766650839450\" : {\n" +
|
|
|
+ " \"parentUuid\" : [ \"createJob-1766650792290\" ],\n" +
|
|
|
+ " \"childrenUuid\" : [ \"confirm-1766650799337\" ]\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"isolation-1766650858056\" : {\n" +
|
|
|
+ " \"parentUuid\" : [ \"confirm-1766650799337\" ],\n" +
|
|
|
+ " \"childrenUuid\" : [ \"releaseIsolation-1766650866562\" ]\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"releaseIsolation-1766650866562\" : {\n" +
|
|
|
+ " \"parentUuid\" : [ \"isolation-1766650858056\" ],\n" +
|
|
|
+ " \"childrenUuid\" : [ \"complete-1766650878643\" ]\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"complete-1766650878643\" : {\n" +
|
|
|
+ " \"parentUuid\" : [ \"releaseIsolation-1766650866562\" ],\n" +
|
|
|
+ " \"childrenUuid\" : [ ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodes\" : [ {\n" +
|
|
|
+ " \"uuid\" : \"createJob-1766650792290\",\n" +
|
|
|
+ " \"type\" : \"createJob\",\n" +
|
|
|
+ " \"position\" : {\n" +
|
|
|
+ " \"x\" : 22.01707056367252,\n" +
|
|
|
+ " \"y\" : 50.73719707724561\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodeName\" : \"创建作业\",\n" +
|
|
|
+ " \"nodeIcon\" : \"2007.png\",\n" +
|
|
|
+ " \"smsTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"messageTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"emailTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"appTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"data\" : {\n" +
|
|
|
+ " \"label\" : \"创建作业\",\n" +
|
|
|
+ " \"type\" : \"createJob\",\n" +
|
|
|
+ " \"nodeId\" : \"001\",\n" +
|
|
|
+ " \"icon\" : \"2007.png\",\n" +
|
|
|
+ " \"workerUserId\" : 251,\n" +
|
|
|
+ " \"remark\" : \"\",\n" +
|
|
|
+ " \"formId\" : \"\",\n" +
|
|
|
+ " \"isolationType\" : \"\",\n" +
|
|
|
+ " \"isolationPoints\" : [ ],\n" +
|
|
|
+ " \"isolationNode\" : [ ],\n" +
|
|
|
+ " \"isolationNodeUuid\" : \"\",\n" +
|
|
|
+ " \"lockPerson\" : \"\",\n" +
|
|
|
+ " \"coLockPersons\" : [ ],\n" +
|
|
|
+ " \"notificationMethods\" : {\n" +
|
|
|
+ " \"sms\" : false,\n" +
|
|
|
+ " \"message\" : false,\n" +
|
|
|
+ " \"email\" : false,\n" +
|
|
|
+ " \"app\" : false\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"notificationPerson\" : \"\",\n" +
|
|
|
+ " \"notificationTime\" : \"\",\n" +
|
|
|
+ " \"selectedIsolationNodeId\" : \"\",\n" +
|
|
|
+ " \"submitForm\" : \"\",\n" +
|
|
|
+ " \"nodeName\" : \"创建作业\",\n" +
|
|
|
+ " \"nodeIcon\" : \"2007.png\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"uuid\" : \"confirm-1766650799337\",\n" +
|
|
|
+ " \"type\" : \"confirm\",\n" +
|
|
|
+ " \"position\" : {\n" +
|
|
|
+ " \"x\" : 351.78708474285037,\n" +
|
|
|
+ " \"y\" : 24.381477335664925\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodeName\" : \"现场勘察确认\",\n" +
|
|
|
+ " \"nodeIcon\" : \"4005.png\",\n" +
|
|
|
+ " \"smsTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"messageTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"emailTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"appTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"data\" : {\n" +
|
|
|
+ " \"label\" : \"现场勘察确认\",\n" +
|
|
|
+ " \"type\" : \"confirm\",\n" +
|
|
|
+ " \"nodeId\" : \"002\",\n" +
|
|
|
+ " \"icon\" : \"4005.png\",\n" +
|
|
|
+ " \"workerUserId\" : 251,\n" +
|
|
|
+ " \"remark\" : \"\",\n" +
|
|
|
+ " \"formId\" : \"53\",\n" +
|
|
|
+ " \"isolationType\" : \"\",\n" +
|
|
|
+ " \"isolationPoints\" : [ ],\n" +
|
|
|
+ " \"isolationNode\" : [ ],\n" +
|
|
|
+ " \"isolationNodeUuid\" : \"\",\n" +
|
|
|
+ " \"lockPerson\" : \"\",\n" +
|
|
|
+ " \"coLockPersons\" : [ ],\n" +
|
|
|
+ " \"notificationMethods\" : {\n" +
|
|
|
+ " \"sms\" : false,\n" +
|
|
|
+ " \"message\" : false,\n" +
|
|
|
+ " \"email\" : false,\n" +
|
|
|
+ " \"app\" : false\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"notificationPerson\" : \"\",\n" +
|
|
|
+ " \"notificationTime\" : \"\",\n" +
|
|
|
+ " \"selectedIsolationNodeId\" : \"\",\n" +
|
|
|
+ " \"submitForm\" : \"\",\n" +
|
|
|
+ " \"nodeName\" : \"现场勘察确认\",\n" +
|
|
|
+ " \"nodeIcon\" : \"4005.png\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"uuid\" : \"review-1766650839450\",\n" +
|
|
|
+ " \"type\" : \"review\",\n" +
|
|
|
+ " \"position\" : {\n" +
|
|
|
+ " \"x\" : 189.9974210811705,\n" +
|
|
|
+ " \"y\" : 50.68595889912385\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodeName\" : \"作业审核\",\n" +
|
|
|
+ " \"nodeIcon\" : \"1004.png\",\n" +
|
|
|
+ " \"smsTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"messageTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"emailTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"appTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"data\" : {\n" +
|
|
|
+ " \"label\" : \"作业审核\",\n" +
|
|
|
+ " \"type\" : \"review\",\n" +
|
|
|
+ " \"nodeId\" : \"003\",\n" +
|
|
|
+ " \"icon\" : \"1004.png\",\n" +
|
|
|
+ " \"workerUserId\" : 251,\n" +
|
|
|
+ " \"remark\" : \"\",\n" +
|
|
|
+ " \"formId\" : \"54\",\n" +
|
|
|
+ " \"isolationType\" : \"\",\n" +
|
|
|
+ " \"isolationPoints\" : [ ],\n" +
|
|
|
+ " \"isolationNode\" : [ ],\n" +
|
|
|
+ " \"isolationNodeUuid\" : \"\",\n" +
|
|
|
+ " \"lockPerson\" : \"\",\n" +
|
|
|
+ " \"coLockPersons\" : [ ],\n" +
|
|
|
+ " \"notificationMethods\" : {\n" +
|
|
|
+ " \"sms\" : false,\n" +
|
|
|
+ " \"message\" : false,\n" +
|
|
|
+ " \"email\" : false,\n" +
|
|
|
+ " \"app\" : false\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"notificationPerson\" : \"\",\n" +
|
|
|
+ " \"notificationTime\" : \"\",\n" +
|
|
|
+ " \"selectedIsolationNodeId\" : \"\",\n" +
|
|
|
+ " \"submitForm\" : \"\",\n" +
|
|
|
+ " \"nodeName\" : \"作业审核\",\n" +
|
|
|
+ " \"nodeIcon\" : \"1004.png\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"uuid\" : \"isolation-1766650858056\",\n" +
|
|
|
+ " \"type\" : \"isolation\",\n" +
|
|
|
+ " \"position\" : {\n" +
|
|
|
+ " \"x\" : 562.101351432562,\n" +
|
|
|
+ " \"y\" : 51.367615523177534\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodeName\" : \"能量隔离\",\n" +
|
|
|
+ " \"nodeIcon\" : \"6005.png\",\n" +
|
|
|
+ " \"smsTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"messageTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"emailTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"appTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"data\" : {\n" +
|
|
|
+ " \"label\" : \"能量隔离\",\n" +
|
|
|
+ " \"type\" : \"isolation\",\n" +
|
|
|
+ " \"nodeId\" : \"005\",\n" +
|
|
|
+ " \"icon\" : \"6005.png\",\n" +
|
|
|
+ " \"workerUserId\" : \"\",\n" +
|
|
|
+ " \"remark\" : \"\",\n" +
|
|
|
+ " \"formId\" : \"55\",\n" +
|
|
|
+ " \"isolationType\" : \"1\",\n" +
|
|
|
+ " \"isolationPoints\" : [ 130, 130, 130 ],\n" +
|
|
|
+ " \"isolationNode\" : [ ],\n" +
|
|
|
+ " \"isolationNodeUuid\" : \"\",\n" +
|
|
|
+ " \"lockPerson\" : 249,\n" +
|
|
|
+ " \"coLockPersons\" : [ 250 ],\n" +
|
|
|
+ " \"notificationMethods\" : {\n" +
|
|
|
+ " \"sms\" : false,\n" +
|
|
|
+ " \"message\" : false,\n" +
|
|
|
+ " \"email\" : false,\n" +
|
|
|
+ " \"app\" : false\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"notificationPerson\" : \"\",\n" +
|
|
|
+ " \"notificationTime\" : \"\",\n" +
|
|
|
+ " \"selectedIsolationNodeId\" : \"\",\n" +
|
|
|
+ " \"submitForm\" : \"\",\n" +
|
|
|
+ " \"nodeName\" : \"能量隔离\",\n" +
|
|
|
+ " \"nodeIcon\" : \"6005.png\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"uuid\" : \"releaseIsolation-1766650866562\",\n" +
|
|
|
+ " \"type\" : \"releaseIsolation\",\n" +
|
|
|
+ " \"position\" : {\n" +
|
|
|
+ " \"x\" : 764.9565268541271,\n" +
|
|
|
+ " \"y\" : 50.876612170258824\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodeName\" : \"解除隔离\",\n" +
|
|
|
+ " \"nodeIcon\" : \"7007.png\",\n" +
|
|
|
+ " \"smsTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"messageTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"emailTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"appTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"data\" : {\n" +
|
|
|
+ " \"label\" : \"解除隔离\",\n" +
|
|
|
+ " \"type\" : \"releaseIsolation\",\n" +
|
|
|
+ " \"nodeId\" : \"006\",\n" +
|
|
|
+ " \"icon\" : \"7007.png\",\n" +
|
|
|
+ " \"workerUserId\" : \"\",\n" +
|
|
|
+ " \"remark\" : \"\",\n" +
|
|
|
+ " \"formId\" : \"54\",\n" +
|
|
|
+ " \"isolationType\" : \"1\",\n" +
|
|
|
+ " \"isolationPoints\" : [ 130, 130, 130 ],\n" +
|
|
|
+ " \"isolationNode\" : [ ],\n" +
|
|
|
+ " \"isolationNodeUuid\" : \"isolation-1766650858056\",\n" +
|
|
|
+ " \"lockPerson\" : 249,\n" +
|
|
|
+ " \"coLockPersons\" : [ 250 ],\n" +
|
|
|
+ " \"notificationMethods\" : {\n" +
|
|
|
+ " \"sms\" : false,\n" +
|
|
|
+ " \"message\" : false,\n" +
|
|
|
+ " \"email\" : false,\n" +
|
|
|
+ " \"app\" : false\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"notificationPerson\" : \"\",\n" +
|
|
|
+ " \"notificationTime\" : \"\",\n" +
|
|
|
+ " \"selectedIsolationNodeId\" : \"isolation-1766650858056\",\n" +
|
|
|
+ " \"submitForm\" : \"\",\n" +
|
|
|
+ " \"nodeName\" : \"解除隔离\",\n" +
|
|
|
+ " \"nodeIcon\" : \"7007.png\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"uuid\" : \"complete-1766650878643\",\n" +
|
|
|
+ " \"type\" : \"complete\",\n" +
|
|
|
+ " \"position\" : {\n" +
|
|
|
+ " \"x\" : 961.8893632852687,\n" +
|
|
|
+ " \"y\" : 50.305803156917875\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"nodeName\" : \"完成/结束\",\n" +
|
|
|
+ " \"nodeIcon\" : \"5006.png\",\n" +
|
|
|
+ " \"smsTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"messageTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"emailTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"appTemplateCode\" : \"false\",\n" +
|
|
|
+ " \"data\" : {\n" +
|
|
|
+ " \"label\" : \"完成/结束\",\n" +
|
|
|
+ " \"type\" : \"complete\",\n" +
|
|
|
+ " \"nodeId\" : \"008\",\n" +
|
|
|
+ " \"icon\" : \"5006.png\",\n" +
|
|
|
+ " \"workerUserId\" : 251,\n" +
|
|
|
+ " \"remark\" : \"\",\n" +
|
|
|
+ " \"formId\" : \"58\",\n" +
|
|
|
+ " \"isolationType\" : \"\",\n" +
|
|
|
+ " \"isolationPoints\" : [ ],\n" +
|
|
|
+ " \"isolationNode\" : [ ],\n" +
|
|
|
+ " \"isolationNodeUuid\" : \"\",\n" +
|
|
|
+ " \"lockPerson\" : \"\",\n" +
|
|
|
+ " \"coLockPersons\" : [ ],\n" +
|
|
|
+ " \"notificationMethods\" : {\n" +
|
|
|
+ " \"sms\" : false,\n" +
|
|
|
+ " \"message\" : false,\n" +
|
|
|
+ " \"email\" : false,\n" +
|
|
|
+ " \"app\" : false\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"notificationPerson\" : \"\",\n" +
|
|
|
+ " \"notificationTime\" : \"\",\n" +
|
|
|
+ " \"selectedIsolationNodeId\" : \"\",\n" +
|
|
|
+ " \"submitForm\" : \"\",\n" +
|
|
|
+ " \"nodeName\" : \"完成/结束\",\n" +
|
|
|
+ " \"nodeIcon\" : \"5006.png\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " } ],\n" +
|
|
|
+ " \"edges\" : [ {\n" +
|
|
|
+ " \"id\" : \"edge-releaseIsolation-1766650866562-left-source-isolation-1766650858056-right-target-1766650870118\",\n" +
|
|
|
+ " \"source\" : \"releaseIsolation-1766650866562\",\n" +
|
|
|
+ " \"target\" : \"isolation-1766650858056\",\n" +
|
|
|
+ " \"sourceHandle\" : \"left-source\",\n" +
|
|
|
+ " \"targetHandle\" : \"right-target\",\n" +
|
|
|
+ " \"type\" : \"straight\"\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"id\" : \"edge-confirm-1766650799337-left-source-createJob-1766650792290-right-target-1766657015939\",\n" +
|
|
|
+ " \"source\" : \"review-1766650839450\",\n" +
|
|
|
+ " \"target\" : \"createJob-1766650792290\",\n" +
|
|
|
+ " \"sourceHandle\" : \"left-source\",\n" +
|
|
|
+ " \"targetHandle\" : \"right-target\",\n" +
|
|
|
+ " \"type\" : \"straight\"\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"id\" : \"edge-confirm-1766650799337-left-source-review-1766650839450-right-target-1767073828489\",\n" +
|
|
|
+ " \"source\" : \"confirm-1766650799337\",\n" +
|
|
|
+ " \"target\" : \"review-1766650839450\",\n" +
|
|
|
+ " \"sourceHandle\" : \"left-source\",\n" +
|
|
|
+ " \"targetHandle\" : \"right-target\",\n" +
|
|
|
+ " \"type\" : \"straight\"\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"id\" : \"edge-isolation-1766650858056-left-source-confirm-1766650799337-right-target-1767073842505\",\n" +
|
|
|
+ " \"source\" : \"isolation-1766650858056\",\n" +
|
|
|
+ " \"target\" : \"confirm-1766650799337\",\n" +
|
|
|
+ " \"sourceHandle\" : \"left-source\",\n" +
|
|
|
+ " \"targetHandle\" : \"right-target\",\n" +
|
|
|
+ " \"type\" : \"straight\"\n" +
|
|
|
+ " }, {\n" +
|
|
|
+ " \"id\" : \"edge-complete-1766650878643-left-source-releaseIsolation-1766650866562-right-target-1767074071353\",\n" +
|
|
|
+ " \"source\" : \"complete-1766650878643\",\n" +
|
|
|
+ " \"target\" : \"releaseIsolation-1766650866562\",\n" +
|
|
|
+ " \"sourceHandle\" : \"left-source\",\n" +
|
|
|
+ " \"targetHandle\" : \"right-target\",\n" +
|
|
|
+ " \"type\" : \"straight\"\n" +
|
|
|
+ " } ]\n" +
|
|
|
+ "}";
|
|
|
+
|
|
|
+ // 初始化ObjectMapper(建议声明为类的成员变量,避免重复创建)
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 将原始JSON字符串解析为可修改的ObjectNode
|
|
|
+ ObjectNode rootNode = (ObjectNode) objectMapper.readTree(originalJsonStr);
|
|
|
+
|
|
|
+ // 2. 获取nodes数组节点
|
|
|
+ ArrayNode nodesArray = (ArrayNode) rootNode.get("nodes");
|
|
|
+
|
|
|
+ // 3. 遍历nodes数组,找到type为isolation和releaseIsolation的节点并替换字段
|
|
|
+ for (JsonNode node : nodesArray) {
|
|
|
+ if (node instanceof ObjectNode nodeObj) {
|
|
|
+ String nodeType = nodeObj.get("type").asText();
|
|
|
+
|
|
|
+ // 只处理能量隔离和解除隔离节点
|
|
|
+ if ("isolation".equals(nodeType) || "releaseIsolation".equals(nodeType)) {
|
|
|
+ ObjectNode dataNode = (ObjectNode) nodeObj.get("data");
|
|
|
+
|
|
|
+ // 替换isolationPoints(隔离点列表)
|
|
|
+ ArrayNode isolationPointsArray = objectMapper.valueToTree(isolationPoints);
|
|
|
+ dataNode.set("isolationPoints", isolationPointsArray);
|
|
|
+
|
|
|
+ // 替换lockPerson(锁具负责人),处理null情况
|
|
|
+ if (lockPerson != null) {
|
|
|
+ dataNode.put("lockPerson", lockPerson);
|
|
|
+ } else {
|
|
|
+ dataNode.putNull("lockPerson"); // 若为null则设为JSON null
|
|
|
+ }
|
|
|
+
|
|
|
+ // 替换coLockPersons(协同锁具人员列表)
|
|
|
+ ArrayNode coLockPersonsArray = objectMapper.valueToTree(coLockPersons);
|
|
|
+ dataNode.set("coLockPersons", coLockPersonsArray);
|
|
|
+ } else {
|
|
|
+ ObjectNode dataNode = (ObjectNode) nodeObj.get("data");
|
|
|
+ // 替换节点负责人,处理null情况
|
|
|
+ if (workerUserId != null) {
|
|
|
+ dataNode.put("workerUserId", workerUserId);
|
|
|
+ } else {
|
|
|
+ dataNode.putNull("workerUserId"); // 若为null则设为JSON null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 将修改后的JSON节点转回格式化的字符串(保持可读性)
|
|
|
+ return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode);
|
|
|
+
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ // 异常处理:打印日志并返回原始字符串(或根据业务需求调整)
|
|
|
+ e.printStackTrace();
|
|
|
+ return originalJsonStr; // 解析失败时返回原始字符串,避免返回null
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|