Jelajahi Sumber

作废、sop编辑修改

wangliang 1 tahun lalu
induk
melakukan
cd5319827a

+ 255 - 179
sop-business/src/main/java/com/qmth/sop/business/activiti/service/impl/ActivitiServiceImpl.java

@@ -60,6 +60,7 @@ import java.util.zip.ZipInputStream;
  */
 @Service
 public class ActivitiServiceImpl implements ActivitiService {
+
     private final static Logger log = LoggerFactory.getLogger(ActivitiServiceImpl.class);
 
     @Resource
@@ -122,6 +123,9 @@ public class ActivitiServiceImpl implements ActivitiService {
     @Resource
     TSJobRemindService tsJobRemindService;
 
+    @Resource
+    TBDeviceDeliveryService tbDeviceDeliveryService;
+
     /**
      * 根据deploymentId查找processDefinitionId
      *
@@ -161,7 +165,8 @@ public class ActivitiServiceImpl implements ActivitiService {
     public Map<String, Object> createDeployment(List<TFCustomTypeEnum> tfCustomTypeEnumList) throws Exception {
         Map<String, Object> map = new HashMap<>();
         for (TFCustomTypeEnum tfCustomTypeEnum : tfCustomTypeEnumList) {
-            List<TFCustomFlow> tfCustomFlowList = tfCustomFlowService.list(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getType, tfCustomTypeEnum));
+            List<TFCustomFlow> tfCustomFlowList = tfCustomFlowService.list(
+                    new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getType, tfCustomTypeEnum));
             if (CollectionUtils.isEmpty(tfCustomFlowList)) {
                 DeploymentBuilder builder = repositoryService.createDeployment();
                 ClassPathResource resource = new ClassPathResource(tfCustomTypeEnum.getFileName());
@@ -170,7 +175,8 @@ public class ActivitiServiceImpl implements ActivitiService {
                 Map<String, Object> mapData = formPropertiesGet(builder.deploy().getId(), null, null, true, null);
                 map.put(tfCustomTypeEnum.name(), mapData);
             } else {
-                Map<String, Object> mapData = formPropertiesGet(tfCustomFlowList.get(0).getFlowDeploymentId(), null, null, true, null);
+                Map<String, Object> mapData = formPropertiesGet(tfCustomFlowList.get(0).getFlowDeploymentId(), null,
+                        null, true, null);
                 map.put(tfCustomTypeEnum.name(), mapData);
             }
         }
@@ -194,7 +200,8 @@ public class ActivitiServiceImpl implements ActivitiService {
         TFCustomFlowEntity tfCustomFlowEntity = (TFCustomFlowEntity) map.get(SystemConstant.FLOW_ENTITY);
         Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
 
-        if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW) {
+        if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW) {
             int count = tfFlowApproveService.findFlowPassageSopByCrmNo(tfCustomFlowEntity.getCrmNo());
             if (count == 0) {
                 tbCrmService.updateCrmStatus(tfCustomFlowEntity.getCrmNo(), CrmStatusEnum.FINISH);
@@ -215,7 +222,9 @@ public class ActivitiServiceImpl implements ActivitiService {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         Map<String, Object> map = new HashMap<>();
         List<String> approveUserIds = flowApproveParam.getApproveUserIds();
-        if (CollectionUtils.isEmpty(approveUserIds) && (flowApproveParam.getApprove() == FlowApprovePassEnum.START || flowApproveParam.getApprove() == FlowApprovePassEnum.DRAFT || flowApproveParam.getApprove() == FlowApprovePassEnum.PASS)) {
+        if (CollectionUtils.isEmpty(approveUserIds) && (flowApproveParam.getApprove() == FlowApprovePassEnum.START
+                || flowApproveParam.getApprove() == FlowApprovePassEnum.DRAFT
+                || flowApproveParam.getApprove() == FlowApprovePassEnum.PASS)) {
             approveUserIds = new ArrayList<>();
             approveUserIds.add(String.valueOf(sysUser.getId()));//否则是当前登录用户
         }
@@ -226,34 +235,44 @@ public class ActivitiServiceImpl implements ActivitiService {
         FlowResult flowResult = null;
         TFCustomFlow tfCustomFlow = null;
         if (Objects.nonNull(flowApproveParam.getFlowDeploymentId()) && Objects.isNull(flowApproveParam.getTaskId())) {
-            Optional.ofNullable(flowApproveParam.getCrmNo()).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
+            Optional.ofNullable(flowApproveParam.getCrmNo())
+                    .orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
 
-            tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getFlowDeploymentId, flowApproveParam.getFlowDeploymentId()));
+            tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda()
+                    .eq(TFCustomFlow::getFlowDeploymentId, flowApproveParam.getFlowDeploymentId()));
             Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_CUSTOM_NO_DATA.exception());
-            Optional.ofNullable(tfCustomFlow.getFlowProcessVar()).orElseThrow(() -> ExceptionResultEnum.FLOW_PROCESS_VAR_NO_DATA.exception());
+            Optional.ofNullable(tfCustomFlow.getFlowProcessVar())
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_PROCESS_VAR_NO_DATA.exception());
 
             TFCustomFlow maxTfCustomFlow = tfCustomFlowService.findMaxVersion(null, null, tfCustomFlow.getType());
             if (maxTfCustomFlow.getVersion().intValue() != tfCustomFlow.getVersion().intValue()) {//说明版本发生变化
                 BeanUtils.copyProperties(maxTfCustomFlow, tfCustomFlow);
             }
             Optional.ofNullable(maxTfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_CUSTOM_NO_DATA.exception());
-            Optional.ofNullable(maxTfCustomFlow.getFlowProcessVar()).orElseThrow(() -> ExceptionResultEnum.FLOW_PROCESS_VAR_NO_DATA.exception());
+            Optional.ofNullable(maxTfCustomFlow.getFlowProcessVar())
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_PROCESS_VAR_NO_DATA.exception());
 
             map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + 1, approveUserIds);
-            ProcessInstance processInstance = runtimeService.startProcessInstanceById(tfCustomFlow.getFlowDefinitionId(), map);
+            ProcessInstance processInstance = runtimeService.startProcessInstanceById(
+                    tfCustomFlow.getFlowDefinitionId(), map);
             processFlowId = processInstance.getId();
 
             String code = sequenceService.createFlowCode(tfCustomFlow.getType());
-            tfCustomFlowEntity = new TFCustomFlowEntity(tfCustomFlow.getId(), sysUser.getId(), code, flowApproveParam.getCrmNo());
-            tfFlowApprove = new TFFlowApprove(sysUser.getOrgId(), Long.parseLong(approveUserIds.get(approveUserIds.size() - 1)), FlowStatusEnum.valueOf(flowApproveParam.getApprove().name()), sysUser.getId());
+            tfCustomFlowEntity = new TFCustomFlowEntity(tfCustomFlow.getId(), sysUser.getId(), code,
+                    flowApproveParam.getCrmNo());
+            tfFlowApprove = new TFFlowApprove(sysUser.getOrgId(),
+                    Long.parseLong(approveUserIds.get(approveUserIds.size() - 1)),
+                    FlowStatusEnum.valueOf(flowApproveParam.getApprove().name()), sysUser.getId());
             flowResult = JSONObject.parseObject(tfCustomFlow.getFlowProcessVar(), FlowResult.class);
         } else if (Objects.nonNull(flowApproveParam.getTaskId())) {
-            taskTemp = taskService.createTaskQuery().taskId(String.valueOf(flowApproveParam.getTaskId())).singleResult();
+            taskTemp = taskService.createTaskQuery().taskId(String.valueOf(flowApproveParam.getTaskId()))
+                    .singleResult();
             Optional.ofNullable(taskTemp).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_NO_DATA.exception());
             processFlowId = taskTemp.getProcessInstanceId();
         }
 
-        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_TASK_PREFIX + processFlowId, processFlowId, SystemConstant.LOCK_FLOW_TIME_OUT);
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_TASK_PREFIX + processFlowId, processFlowId,
+                SystemConstant.LOCK_FLOW_TIME_OUT);
         if (!lock) {
             throw ExceptionResultEnum.ERROR.exception("正在审批中,请稍候再试!");
         }
@@ -262,14 +281,18 @@ public class ActivitiServiceImpl implements ActivitiService {
             if (Objects.isNull(taskTemp)) {
                 taskList = taskService.createTaskQuery().processInstanceId(processFlowId).list();
             } else {
-                tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, Long.parseLong(processFlowId)));
-                Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+                tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda()
+                        .eq(TFCustomFlowEntity::getFlowId, Long.parseLong(processFlowId)));
+                Optional.ofNullable(tfCustomFlowEntity)
+                        .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
                 flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
 
                 tfCustomFlow = tfCustomFlowService.getById(tfCustomFlowEntity.gettFCustomFlowId());
 
-                tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, Long.parseLong(processFlowId)));
-                Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
+                tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda()
+                        .eq(TFFlowApprove::getFlowId, Long.parseLong(processFlowId)));
+                Optional.ofNullable(tfFlowApprove)
+                        .orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
                 taskList.add(taskTemp);
             }
             List<TFFlowLog> tfFlowLogList = new ArrayList<>();
@@ -286,14 +309,17 @@ public class ActivitiServiceImpl implements ActivitiService {
                 boolean multiInstance = false;
                 if (currFlow instanceof UserTask) {
                     if (currFlow.getBehavior() instanceof MultiInstanceActivityBehavior) {
-                        nrOfCompletedInstances = (Integer) taskService.getVariable(task.getId(), SystemConstant.NR_OF_COMPLETED_INSTANCES);
+                        nrOfCompletedInstances = (Integer) taskService.getVariable(task.getId(),
+                                SystemConstant.NR_OF_COMPLETED_INSTANCES);
                         nrOfCompletedInstances++;
                         nrOfInstances = (Integer) taskService.getVariable(task.getId(), SystemConstant.NR_OF_INSTANCES);
                         multiInstance = true;
                     }
-                    currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
+                    currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())),
+                            FlowTaskResult.class);
                     if (Objects.nonNull(flowApproveParam.getFormProperties())) {
-                        formDataFlowTaskResult = JSONObject.parseObject(flowApproveParam.getFormProperties(), FlowTaskResult.class);
+                        formDataFlowTaskResult = JSONObject.parseObject(flowApproveParam.getFormProperties(),
+                                FlowTaskResult.class);
                     }
                     int currSetup = currFlowTaskResult.getSetup().intValue();
                     if (currSetup != 1 && flowApproveParam.getApprove() == FlowApprovePassEnum.START) {
@@ -304,14 +330,19 @@ public class ActivitiServiceImpl implements ActivitiService {
                     }
                     //流程流水日志
                     TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getOrgId(), sysUser.getId(), sysUser.getId(),
-                            currFlowTaskResult.getSetup(), Long.parseLong(processFlowId),
-                            Long.parseLong(task.getId()), tfCustomFlowEntity.getId(), StringUtils.join(approveUserIds, SystemConstant.LIST_JOIN_SPLIT));
-                    if (flowApproveParam.getApprove() == FlowApprovePassEnum.PASS || flowApproveParam.getApprove() == FlowApprovePassEnum.DRAFT || flowApproveParam.getApprove() == FlowApprovePassEnum.START) {
+                            currFlowTaskResult.getSetup(), Long.parseLong(processFlowId), Long.parseLong(task.getId()),
+                            tfCustomFlowEntity.getId(),
+                            StringUtils.join(approveUserIds, SystemConstant.LIST_JOIN_SPLIT));
+                    if (flowApproveParam.getApprove() == FlowApprovePassEnum.PASS
+                            || flowApproveParam.getApprove() == FlowApprovePassEnum.DRAFT
+                            || flowApproveParam.getApprove() == FlowApprovePassEnum.START) {
                         boolean dingExceptionNoPass = false;
                         if (Objects.nonNull(flowApproveParam.getSetup())) {
                             currSetup = flowApproveParam.getSetup();
                         } else {
-                            if (tfCustomFlow.getType() == TFCustomTypeEnum.DING_EXCEPTION_FLOW && currSetup == 2 && Objects.nonNull(flowApproveParam.getApproveRemark()) && Objects.equals(DingExceptionApproveEnum.NO_PASS.getTitle(), flowApproveParam.getApproveRemark())) {
+                            if (tfCustomFlow.getType() == TFCustomTypeEnum.DING_EXCEPTION_FLOW && currSetup == 2
+                                    && Objects.nonNull(flowApproveParam.getApproveRemark()) && Objects.equals(
+                                    DingExceptionApproveEnum.NO_PASS.getTitle(), flowApproveParam.getApproveRemark())) {
                                 currSetup = 0;
                                 nrOfCompletedInstances = nrOfInstances;
                                 dingExceptionNoPass = true;
@@ -319,77 +350,65 @@ public class ActivitiServiceImpl implements ActivitiService {
                                 currSetup = currSetup == setupMap.size() - 1 ? 0 : currSetup + 1;
                             }
                         }
-                        nextFlowTaskResult = this.getNextFlowTaskResult(nrOfCompletedInstances,
-                                nrOfInstances,
-                                currFlowTaskResult,
-                                nextFlowTaskResult,
-                                currSetup,
-                                setupMap,
+                        nextFlowTaskResult = this.getNextFlowTaskResult(nrOfCompletedInstances, nrOfInstances,
+                                currFlowTaskResult, nextFlowTaskResult, currSetup, setupMap,
                                 flowApproveParam.getApprove());
 
-                        this.approvePass(currFlowTaskResult,
-                                setupMap,
-                                multiInstance,
-                                nrOfCompletedInstances,
-                                nrOfInstances,
-                                tfFlowApprove,
-                                tfFlowLog,
-                                nextFlowTaskResult,
-                                map,
-                                flowApproveParam.getApprove(),
-                                flowApproveParam.getApproveRemark());
+                        this.approvePass(currFlowTaskResult, setupMap, multiInstance, nrOfCompletedInstances,
+                                nrOfInstances, tfFlowApprove, tfFlowLog, nextFlowTaskResult, map,
+                                flowApproveParam.getApprove(), flowApproveParam.getApproveRemark());
                         if (dingExceptionNoPass) {
                             map.put(FlowApproveOperationEnum.REJECT.getId() + currFlowTaskResult.getSetup(), 1);
                         }
                         map.put(SystemConstant.ASSIGNEE + nextFlowTaskResult.getSetup(), approveUserIds);
                         map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + nextFlowTaskResult.getSetup(), approveUserIds);
-                    } else if (flowApproveParam.getApprove() == FlowApprovePassEnum.REJECT || flowApproveParam.getApprove() == FlowApprovePassEnum.CANCEL) {
+                    } else if (flowApproveParam.getApprove() == FlowApprovePassEnum.REJECT
+                            || flowApproveParam.getApprove() == FlowApprovePassEnum.CANCEL) {
                         if (Objects.nonNull(flowApproveParam.getSetup())) {
                             currSetup = flowApproveParam.getSetup();
                         } else {
                             currSetup = currSetup - 1;
                         }
 
-                        nextFlowTaskResult = this.getNextFlowTaskResult(nrOfCompletedInstances,
-                                nrOfInstances,
-                                currFlowTaskResult,
-                                nextFlowTaskResult,
-                                currSetup,
-                                setupMap,
+                        nextFlowTaskResult = this.getNextFlowTaskResult(nrOfCompletedInstances, nrOfInstances,
+                                currFlowTaskResult, nextFlowTaskResult, currSetup, setupMap,
                                 flowApproveParam.getApprove());
 
-                        this.approveReject(multiInstance,
-                                map,
-                                currFlowTaskResult,
-                                nextFlowTaskResult,
-                                tfFlowApprove,
-                                tfFlowLog,
-                                flowApproveParam.getApprove(),
-                                flowApproveParam.getApproveRemark());
+                        this.approveReject(multiInstance, map, currFlowTaskResult, nextFlowTaskResult, tfFlowApprove,
+                                tfFlowLog, flowApproveParam.getApprove(), flowApproveParam.getApproveRemark());
                     }
                     map.put(SystemConstant.APPROVE, nextFlowTaskResult.getTaskKey());
-                    if (Objects.nonNull(formDataFlowTaskResult) && Objects.equals(task.getTaskDefinitionKey(), formDataFlowTaskResult.getTaskKey())) {
+                    if (Objects.nonNull(formDataFlowTaskResult) && Objects.equals(task.getTaskDefinitionKey(),
+                            formDataFlowTaskResult.getTaskKey())) {
                         setupMap.put(task.getTaskDefinitionKey(), formDataFlowTaskResult);
-                        if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW) {
-                            tbSopInfoService.saveDynamicSop(tfCustomFlow, tfCustomFlowEntity.getCode(), Long.parseLong(processFlowId), formDataFlowTaskResult);
+                        if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                                || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW) {
+                            tbSopInfoService.saveDynamicSop(tfCustomFlow, tfCustomFlowEntity.getCode(),
+                                    Long.parseLong(processFlowId), formDataFlowTaskResult);
                         }
                     }
                     flowResult.setSetupMap(setupMap);
                     tfCustomFlowEntity.setFlowProcessVar(JacksonUtil.parseJson(flowResult));
-                    if (flowApproveParam.getApprove() == FlowApprovePassEnum.START || flowApproveParam.getApprove() == FlowApprovePassEnum.PASS
-                            || flowApproveParam.getApprove() == FlowApprovePassEnum.CANCEL || flowApproveParam.getApprove() == FlowApprovePassEnum.REJECT) {
-                        if (flowApproveParam.getApprove() == FlowApprovePassEnum.CANCEL || flowApproveParam.getApprove() == FlowApprovePassEnum.REJECT) {
+                    if (flowApproveParam.getApprove() == FlowApprovePassEnum.START
+                            || flowApproveParam.getApprove() == FlowApprovePassEnum.PASS
+                            || flowApproveParam.getApprove() == FlowApprovePassEnum.CANCEL
+                            || flowApproveParam.getApprove() == FlowApprovePassEnum.REJECT) {
+                        if (flowApproveParam.getApprove() == FlowApprovePassEnum.CANCEL
+                                || flowApproveParam.getApprove() == FlowApprovePassEnum.REJECT) {
                             List<HistoricTaskInstance> historicTaskInstanceList = historyService.createHistoricTaskInstanceQuery()
-                                    .processInstanceId(task.getProcessInstanceId()).orderByHistoricTaskInstanceEndTime().desc().list();
+                                    .processInstanceId(task.getProcessInstanceId()).orderByHistoricTaskInstanceEndTime()
+                                    .desc().list();
                             if (!CollectionUtils.isEmpty(historicTaskInstanceList)) {
                                 Set<String> approveIdSet = new LinkedHashSet<>();
                                 for (int i = historicTaskInstanceList.size() - 1; i >= 0; i--) {
                                     HistoricTaskInstance historicTaskInstance = historicTaskInstanceList.get(i);
-                                    if (Objects.equals(historicTaskInstance.getTaskDefinitionKey(), nextFlowTaskResult.getTaskKey())) {
+                                    if (Objects.equals(historicTaskInstance.getTaskDefinitionKey(),
+                                            nextFlowTaskResult.getTaskKey())) {
                                         if (Objects.nonNull(historicTaskInstance.getAssignee())) {
                                             approveIdSet.add(historicTaskInstance.getAssignee());
                                         } else {
-                                            List<HistoricIdentityLink> historicIdentityLinkList = historyService.getHistoricIdentityLinksForTask(historicTaskInstance.getId());
+                                            List<HistoricIdentityLink> historicIdentityLinkList = historyService.getHistoricIdentityLinksForTask(
+                                                    historicTaskInstance.getId());
                                             if (!CollectionUtils.isEmpty(historicIdentityLinkList)) {
                                                 for (HistoricIdentityLink h : historicIdentityLinkList) {
                                                     approveIdSet.add(h.getUserId());
@@ -398,9 +417,13 @@ public class ActivitiServiceImpl implements ActivitiService {
                                         }
                                     }
                                 }
-                                tfFlowLog.setPendApproveId(approveIdSet.toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(", ", ","));
-                                map.put(SystemConstant.ASSIGNEE + nextFlowTaskResult.getSetup(), new ArrayList<>(approveIdSet));
-                                map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + nextFlowTaskResult.getSetup(), new ArrayList<>(approveIdSet));
+                                tfFlowLog.setPendApproveId(
+                                        approveIdSet.toString().replaceAll("\\[", "").replaceAll("\\]", "")
+                                                .replaceAll(", ", ","));
+                                map.put(SystemConstant.ASSIGNEE + nextFlowTaskResult.getSetup(),
+                                        new ArrayList<>(approveIdSet));
+                                map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + nextFlowTaskResult.getSetup(),
+                                        new ArrayList<>(approveIdSet));
                             }
                         }
                         taskService.setVariable(task.getId(), SystemConstant.FLOW_CUSTOM, tfCustomFlow);
@@ -408,15 +431,17 @@ public class ActivitiServiceImpl implements ActivitiService {
                         taskService.setVariable(task.getId(), SystemConstant.FLOW_ENTITY, tfCustomFlowEntity);
                         taskService.setVariable(task.getId(), SystemConstant.FLOW_APPROVE_LOG, tfFlowLog);
                         taskService.setVariable(task.getId(), SystemConstant.FLOW_SYS_USER, sysUser);
-//                        taskService.setVariable(task.getId(), SystemConstant.APPROVE_MAP_VAR, flowApproveParam.getVar());
+                        //                        taskService.setVariable(task.getId(), SystemConstant.APPROVE_MAP_VAR, flowApproveParam.getVar());
                         taskService.complete(task.getId(), map);
-                        if (flowApproveParam.getApprove() == FlowApprovePassEnum.START || flowApproveParam.getApprove() == FlowApprovePassEnum.PASS) {
+                        if (flowApproveParam.getApprove() == FlowApprovePassEnum.START
+                                || flowApproveParam.getApprove() == FlowApprovePassEnum.PASS) {
                             List<Task> tasks = taskService.createTaskQuery().processInstanceId(processFlowId).list();
                             if (!CollectionUtils.isEmpty(tasks)) {
                                 Set<String> approveIdSet = new LinkedHashSet<>();
                                 for (Task t : tasks) {
                                     if (Objects.isNull(t.getAssignee())) {
-                                        List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(t.getId());
+                                        List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(
+                                                t.getId());
                                         if (!CollectionUtils.isEmpty(identityLinkList)) {
                                             for (IdentityLink i : identityLinkList) {
                                                 approveIdSet.add(i.getUserId());
@@ -426,7 +451,9 @@ public class ActivitiServiceImpl implements ActivitiService {
                                         approveIdSet.add(t.getAssignee());
                                     }
                                 }
-                                tfFlowLog.setPendApproveId(approveIdSet.toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(", ", ","));
+                                tfFlowLog.setPendApproveId(
+                                        approveIdSet.toString().replaceAll("\\[", "").replaceAll("\\]", "")
+                                                .replaceAll(", ", ","));
                             } else {
                                 tfFlowLog.setPendApproveId(null);
                             }
@@ -442,7 +469,7 @@ public class ActivitiServiceImpl implements ActivitiService {
             map.put(SystemConstant.FLOW_CUSTOM, tfCustomFlow);
             map.put(SystemConstant.FLOW_APPROVE, tfFlowApprove);
             map.put(SystemConstant.FLOW_ENTITY, tfCustomFlowEntity);
-//            map.put(SystemConstant.APPROVE_MAP_VAR, flowApproveParam.getVar());
+            //            map.put(SystemConstant.APPROVE_MAP_VAR, flowApproveParam.getVar());
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {
@@ -468,54 +495,68 @@ public class ActivitiServiceImpl implements ActivitiService {
      */
     @Override
     @Transactional
-    public Map<String, Object> formPropertiesGet(String flowDeploymentId,
-                                                 Long flowId,
-                                                 Long taskId,
-                                                 Boolean dynamicTable,
-                                                 String crmNo) throws Exception {
+    public Map<String, Object> formPropertiesGet(String flowDeploymentId, Long flowId, Long taskId,
+            Boolean dynamicTable, String crmNo) throws Exception {
         Map<String, Object> map = new HashMap<>();
         FlowResult flowResult = null;
         TFCustomFlow tfCustomFlow = null;
         List<Task> taskList = null;
         if (Objects.nonNull(flowDeploymentId)) {
-            tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getFlowDeploymentId, flowDeploymentId));
-            Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_DEPLOYMENT_NO_DATA.exception());
+            tfCustomFlow = tfCustomFlowService.getOne(
+                    new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getFlowDeploymentId, flowDeploymentId));
+            Optional.ofNullable(tfCustomFlow)
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_DEPLOYMENT_NO_DATA.exception());
             if (Objects.isNull(tfCustomFlow.getFlowDefinitionId())) {
                 String processDefinitionId = this.findProcessDefinitionIdByDeploymentId(flowDeploymentId);
                 tfCustomFlow.setFlowDefinitionId(processDefinitionId);
                 tfCustomFlowService.updateById(tfCustomFlow);
             }
             flowResult = JSONObject.parseObject(tfCustomFlow.getFlowProcessVar(), FlowResult.class);
-            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW) {
+            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                    || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
+                    || tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW) {
                 map = this.getFlowFormPropertie(flowResult, map, 1);
-                if ((Objects.nonNull(dynamicTable) && dynamicTable) && (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)) {
+                if ((Objects.nonNull(dynamicTable) && dynamicTable) && (
+                        tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                                || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)) {
                     Map<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
                     Set<TDFormWidgetMetadata> tdFormWidgetMetadataSet = new LinkedHashSet<>();
                     for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
-                        FlowTaskResult flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()), FlowTaskResult.class);
+                        FlowTaskResult flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()),
+                                FlowTaskResult.class);
                         List<FlowFormWidgetResult> formWidgetResultList = flowTaskResultTemp.getFormProperty();
                         if (!CollectionUtils.isEmpty(formWidgetResultList)) {
                             for (FlowFormWidgetResult f : formWidgetResultList) {
-                                if (f.getCode() != WidgetCodeEnum.FORM_GROUP_TITLE && f.getCode() != WidgetCodeEnum.ONLY_TITLE
+                                if (f.getCode() != WidgetCodeEnum.FORM_GROUP_TITLE
+                                        && f.getCode() != WidgetCodeEnum.ONLY_TITLE
                                         && f.getCode() != WidgetCodeEnum.BUTTON && f.getCode() != WidgetCodeEnum.IMG
                                         && f.getCode() != WidgetCodeEnum.LABEL && f.getCode() != WidgetCodeEnum.SIGN
                                         && f.getCode() != WidgetCodeEnum.OTHER) {
-                                    tdFormWidgetMetadataSet.add(new TDFormWidgetMetadata(tfCustomFlow.getType(), tfCustomFlow.getFlowDeploymentId(), tfCustomFlow.getVersion(), flowTaskResultTemp.getSetup(), f.getCode(), f.getFormId(), f.getFormName(), f.getTitle()));
+                                    tdFormWidgetMetadataSet.add(new TDFormWidgetMetadata(tfCustomFlow.getType(),
+                                            tfCustomFlow.getFlowDeploymentId(), tfCustomFlow.getVersion(),
+                                            flowTaskResultTemp.getSetup(), f.getCode(), f.getFormId(), f.getFormName(),
+                                            f.getTitle()));
                                 }
                             }
                         }
                     }
-                    tdFormWidgetMetadataService.selectMetadataExist(tfCustomFlow.getType(), tfCustomFlow.getVersion(), tdFormWidgetMetadataSet);
-                    mySQLExec.execCreateSopDynamicTable(SystemConstant.SOP_DYNAMIC_TABLE_FILE_NAME, tfCustomFlow.getType(), tfCustomFlow.getVersion());
+                    tdFormWidgetMetadataService.selectMetadataExist(tfCustomFlow.getType(), tfCustomFlow.getVersion(),
+                            tdFormWidgetMetadataSet);
+                    mySQLExec.execCreateSopDynamicTable(SystemConstant.SOP_DYNAMIC_TABLE_FILE_NAME,
+                            tfCustomFlow.getType(), tfCustomFlow.getVersion());
                 }
             }
         } else if (Objects.nonNull(flowId)) {
-            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW) {
+            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                    || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
+                    || tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW) {
                 taskList = taskService.createTaskQuery().processInstanceId(String.valueOf(flowId)).list();
                 map = this.getFlowFormPropertie(map, taskList, flowResult, tfCustomFlow);
             }
         } else {
-            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW) {
+            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                    || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
+                    || tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW) {
                 taskList = taskService.createTaskQuery().taskId(String.valueOf(taskId)).list();
                 map = this.getFlowFormPropertie(map, taskList, flowResult, tfCustomFlow);
             }
@@ -544,11 +585,13 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @return
      */
     @Override
-    public IPage<WorkTaskResult> getFlowTaskList(IPage<Map> iPage, Long userId, TFCustomTypeEnum type, Long serviceId, String customName, FlowTaskTypeEnum flowTaskTypeEnum, String crmNo) {
+    public IPage<WorkTaskResult> getFlowTaskList(IPage<Map> iPage, Long userId, TFCustomTypeEnum type, Long serviceId,
+            String customName, FlowTaskTypeEnum flowTaskTypeEnum, String crmNo) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         userId = Objects.nonNull(sysUser) ? sysUser.getId() : userId;
         Map<String, Object> map = new HashMap<>();
-        IPage<WorkTaskResult> workTaskResultIPage = sysUserService.getFlowTaskList(iPage, userId, type, serviceId, customName, flowTaskTypeEnum, crmNo);
+        IPage<WorkTaskResult> workTaskResultIPage = sysUserService.getFlowTaskList(iPage, userId, type, serviceId,
+                customName, flowTaskTypeEnum, crmNo);
         if (Objects.nonNull(workTaskResultIPage) && !CollectionUtils.isEmpty(workTaskResultIPage.getRecords())) {
             Set<String> sopNoSet = new HashSet<>(workTaskResultIPage.getRecords().size());
             Map<String, WorkTaskResult> workTaskMap = new LinkedHashMap<>();
@@ -560,14 +603,16 @@ public class ActivitiServiceImpl implements ActivitiService {
                     for (Task t : taskList) {
                         FlowResult flowResult = JSONObject.parseObject(w.getFlowProcessVar(), FlowResult.class);
                         LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
-                        FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(t.getTaskDefinitionKey())), FlowTaskResult.class);
+                        FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(
+                                GsonUtil.toJson(setupMap.get(t.getTaskDefinitionKey())), FlowTaskResult.class);
                         map = this.getFlowFormPropertie(flowResult, map, currFlowTaskResult.getSetup());
                         w.setFlowProcessVar(null);
                         w.setSetupMap((FlowTaskResult) map.get(SystemConstant.FORM_PROPERTIES));
                     }
                 }
             }
-            List<WorkTaskResult> workTaskResultList = tsJobRemindService.getJobRemindProcessHour(sysUser.getId(), sopNoSet);
+            List<WorkTaskResult> workTaskResultList = tsJobRemindService.getJobRemindProcessHour(sysUser.getId(),
+                    sopNoSet);
             if (!CollectionUtils.isEmpty(workTaskResultList)) {
                 for (WorkTaskResult w : workTaskResultList) {
                     if (Objects.nonNull(workTaskMap.get(w.getCode())) && Objects.nonNull(w.getProcessHour())) {
@@ -591,7 +636,8 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @return
      */
     @Override
-    public int getFlowTaskListCount(Long userId, TFCustomTypeEnum type, Long serviceId, String customName, FlowTaskTypeEnum flowTaskTypeEnum, String crmNo) {
+    public int getFlowTaskListCount(Long userId, TFCustomTypeEnum type, Long serviceId, String customName,
+            FlowTaskTypeEnum flowTaskTypeEnum, String crmNo) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         userId = Objects.nonNull(sysUser) ? sysUser.getId() : userId;
         return sysUserService.getFlowTaskListCount(userId, type, serviceId, customName, flowTaskTypeEnum, crmNo);
@@ -612,7 +658,8 @@ public class ActivitiServiceImpl implements ActivitiService {
             throw ExceptionResultEnum.ERROR.exception("不能转给自己!");
         }
 
-        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_EXCHANGE_PREFIX + taskId, taskId, SystemConstant.LOCK_FLOW_TIME_OUT);
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_EXCHANGE_PREFIX + taskId, taskId,
+                SystemConstant.LOCK_FLOW_TIME_OUT);
         if (!lock) {
             throw ExceptionResultEnum.ERROR.exception("正在转审中,请稍候再试!");
         }
@@ -626,7 +673,8 @@ public class ActivitiServiceImpl implements ActivitiService {
             if (currFlow.getBehavior() instanceof MultiInstanceActivityBehavior) {//会签
                 multiInstance = true;
 
-                List<Task> taskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
+                List<Task> taskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId())
+                        .list();
                 List<String> taskApproveList = new ArrayList<>();
                 for (Task t : taskList) {
                     if (Objects.equals(String.valueOf(t.getAssignee()), String.valueOf(userId))) {
@@ -638,7 +686,8 @@ public class ActivitiServiceImpl implements ActivitiService {
                     throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限,无需流转");
                 }
             } else {//或签
-                Task taskUser = taskService.createTaskQuery().taskId(String.valueOf(taskId)).taskCandidateOrAssigned(String.valueOf(userId)).singleResult();
+                Task taskUser = taskService.createTaskQuery().taskId(String.valueOf(taskId))
+                        .taskCandidateOrAssigned(String.valueOf(userId)).singleResult();
                 if (Objects.nonNull(taskUser)) {
                     throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限,无需流转");
                 }
@@ -651,12 +700,16 @@ public class ActivitiServiceImpl implements ActivitiService {
                 taskService.setAssignee(String.valueOf(taskId), String.valueOf(userId));
             }
 
-            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, Long.parseLong(task.getProcessInstanceId())));
-            Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                    new QueryWrapper<TFCustomFlowEntity>().lambda()
+                            .eq(TFCustomFlowEntity::getFlowId, Long.parseLong(task.getProcessInstanceId())));
+            Optional.ofNullable(tfCustomFlowEntity)
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
 
             FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
             LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
-            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
+            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(
+                    GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
             TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getOrgId(), sysUser.getId(), sysUser.getId(),
                     currFlowTaskResult.getSetup(), Long.parseLong(task.getProcessInstanceId()),
                     Long.parseLong(task.getId()), tfCustomFlowEntity.getId(), String.valueOf(userId));
@@ -668,7 +721,9 @@ public class ActivitiServiceImpl implements ActivitiService {
             SysOrg exchangeOrg = commonCacheService.orgCache(exchangeUser.getOrgId());
             String orgName = Objects.nonNull(sysOrg) ? sysOrg.getName() : "无机构";
             String exchangeOrgName = Objects.nonNull(exchangeOrg) ? exchangeOrg.getName() : "无机构";
-            tfFlowLog.setApproveRemark(sysUser.getRealName() + "(" + orgName + ")转" + exchangeUser.getRealName() + "(" + exchangeOrgName + ")审批");
+            tfFlowLog.setApproveRemark(
+                    sysUser.getRealName() + "(" + orgName + ")转" + exchangeUser.getRealName() + "(" + exchangeOrgName
+                            + ")审批");
             tfFlowLogService.save(tfFlowLog);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
@@ -694,12 +749,14 @@ public class ActivitiServiceImpl implements ActivitiService {
     public Boolean flowEnd(Long flowId) {
         Optional.ofNullable(flowId).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程id不能为空"));
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_END_PREFIX + flowId, flowId, SystemConstant.LOCK_FLOW_TIME_OUT);
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_END_PREFIX + flowId, flowId,
+                SystemConstant.LOCK_FLOW_TIME_OUT);
         if (!lock) {
             throw ExceptionResultEnum.ERROR.exception("正在终止中,请稍候再试!");
         }
         try {
-            TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, flowId));
+            TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(
+                    new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, flowId));
             Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
 
             if (tfFlowApprove.getStatus() == FlowStatusEnum.FINISH) {
@@ -708,8 +765,25 @@ public class ActivitiServiceImpl implements ActivitiService {
                 throw ExceptionResultEnum.ERROR.exception("该流程已作废");
             }
 
-            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
-            Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                    new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
+            Optional.ofNullable(tfCustomFlowEntity)
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+
+            TFCustomFlow tfCustomFlow = tfCustomFlowService.getById(tfCustomFlowEntity.gettFCustomFlowId());
+            Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_CUSTOM_NO_DATA.exception());
+
+            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW && tfFlowApprove.getSetup().intValue() >= 4
+                    && tfFlowApprove.getSetup().intValue() < 8) {
+                FlowTaskResult flowTaskResultDeviceOut = tbSopInfoService.getFormProperties(tfCustomFlowEntity, 4);
+                tbDeviceDeliveryService.updateDeviceRelated(flowTaskResultDeviceOut, tfCustomFlowEntity.getCrmNo(),
+                        tfCustomFlowEntity.getCode(), null, sysUser.getId(), false);
+            } else if (tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
+                    && tfFlowApprove.getSetup().intValue() >= 4) {
+                FlowTaskResult flowTaskResultDeviceOut = tbSopInfoService.getFormProperties(tfCustomFlowEntity, 4);
+                tbDeviceDeliveryService.updateDeviceRelated(flowTaskResultDeviceOut, tfCustomFlowEntity.getCrmNo(),
+                        tfCustomFlowEntity.getCode(), DeviceDeliveryStatusEnum.RECEIVE, sysUser.getId(), true);
+            }
 
             FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
             LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
@@ -717,11 +791,12 @@ public class ActivitiServiceImpl implements ActivitiService {
             if (CollectionUtils.isEmpty(taskList)) {
                 throw ExceptionResultEnum.FLOW_TASK_NO_DATA.exception();
             }
-            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(taskList.get(0).getTaskDefinitionKey())), FlowTaskResult.class);
+            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(
+                    GsonUtil.toJson(setupMap.get(taskList.get(0).getTaskDefinitionKey())), FlowTaskResult.class);
 
             TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getOrgId(), sysUser.getId(), sysUser.getId(),
-                    currFlowTaskResult.getSetup(), flowId,
-                    Long.parseLong(taskList.get(0).getId()), tfCustomFlowEntity.getId(), null);
+                    currFlowTaskResult.getSetup(), flowId, Long.parseLong(taskList.get(0).getId()),
+                    tfCustomFlowEntity.getId(), null);
             tfFlowLog.setApproveOperation(FlowApproveOperationEnum.END);
             tfFlowLog.setApproveRemark(sysUser.getRealName() + "终止流程");
             tfFlowLogService.save(tfFlowLog);
@@ -795,9 +870,11 @@ public class ActivitiServiceImpl implements ActivitiService {
         }
         TFCustomFlowEntity tfCustomFlowEntity = null;
         if (Objects.nonNull(flowId)) {
-            tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
+            tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                    new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
         } else {
-            tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, code));
+            tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                    new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, code));
         }
         Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
         flowId = Objects.isNull(flowId) ? tfCustomFlowEntity.getFlowId() : flowId;
@@ -806,7 +883,8 @@ public class ActivitiServiceImpl implements ActivitiService {
         Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_CUSTOM_NO_DATA.exception());
 
         //获取当前流程节点
-        TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, flowId));
+        TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(
+                new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, flowId));
         Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
 
         FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
@@ -824,13 +902,16 @@ public class ActivitiServiceImpl implements ActivitiService {
         //获取流程审批历史
         List<TFFlowLogResult> tfFlowLogResultList = tfFlowLogService.findByObjectId(tfCustomFlowEntity.getId());
         if (!CollectionUtils.isEmpty(tfFlowLogResultList)) {
-            flowApproveHistoryList = GsonUtil.fromJson(GsonUtil.toJson(tfFlowLogResultList), new TypeToken<List<TFFlowViewLogResult>>() {
-            }.getType());
+            flowApproveHistoryList = GsonUtil.fromJson(GsonUtil.toJson(tfFlowLogResultList),
+                    new TypeToken<List<TFFlowViewLogResult>>() {
+
+                    }.getType());
             for (TFFlowViewLogResult t : flowApproveHistoryList) {
                 t.setMessageType(FlowMsgTypeEnum.STANDARD);
                 approveSetupMap.put(t.getApproveSetup(), t.getApproveSetup());
-                if (Objects.nonNull(t.getApproveRemark()) && t.getApproveRemark().contains(";") && tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW
-                        && (t.getApproveSetup().intValue() == 3 || t.getApproveSetup().intValue() == 4)) {
+                if (Objects.nonNull(t.getApproveRemark()) && t.getApproveRemark().contains(";")
+                        && tfCustomFlow.getType() == TFCustomTypeEnum.QUALITY_PROBLEM_FLOW && (
+                        t.getApproveSetup().intValue() == 3 || t.getApproveSetup().intValue() == 4)) {
                     String[] strs = t.getApproveRemark().split(";");
                     StringJoiner stringJoiner = new StringJoiner("");
                     for (int i = 1; i < strs.length; i++) {
@@ -838,13 +919,15 @@ public class ActivitiServiceImpl implements ActivitiService {
                     }
                     t.setApproveFormSuggestion(stringJoiner.toString());
                     if (t.getApproveSetup().intValue() == 3) {
-                        flowFormSuggestionJiaResultList.add(new FlowFormSuggestionJiaResult(t.getCreateTime(), t.getApproveUserName(),
-                                t.getApproveOperation() == FlowApproveOperationEnum.APPROVE ? "同意" : "不同意", t.getApproveFormSuggestion(),
-                                strs[0]));
+                        flowFormSuggestionJiaResultList.add(
+                                new FlowFormSuggestionJiaResult(t.getCreateTime(), t.getApproveUserName(),
+                                        t.getApproveOperation() == FlowApproveOperationEnum.APPROVE ? "同意" : "不同意",
+                                        t.getApproveFormSuggestion(), strs[0]));
                     } else {
-                        flowFormSuggestionYiResultList.add(new FlowFormSuggestionYiResult(t.getCreateTime(), t.getApproveUserName(),
-                                t.getApproveOperation() == FlowApproveOperationEnum.APPROVE ? "同意" : "不同意", t.getApproveFormSuggestion(),
-                                strs[0]));
+                        flowFormSuggestionYiResultList.add(
+                                new FlowFormSuggestionYiResult(t.getCreateTime(), t.getApproveUserName(),
+                                        t.getApproveOperation() == FlowApproveOperationEnum.APPROVE ? "同意" : "不同意",
+                                        t.getApproveFormSuggestion(), strs[0]));
                     }
                 }
                 if (Objects.nonNull(t.getApproveOperation())) {
@@ -863,21 +946,25 @@ public class ActivitiServiceImpl implements ActivitiService {
             FlowTaskResult flowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()), FlowTaskResult.class);
             if (flowTaskResult.getSetup().intValue() > 0) {
                 //正在审批的表单
-                if (Objects.nonNull(tfFlowApprove.getSetup()) && flowTaskResult.getSetup().intValue() == tfFlowApprove.getSetup().intValue()) {
+                if (Objects.nonNull(tfFlowApprove.getSetup())
+                        && flowTaskResult.getSetup().intValue() == tfFlowApprove.getSetup().intValue()) {
                     currFlowTaskResult = flowTaskResult;
-                    List<Task> taskList = taskService.createTaskQuery().processInstanceId(String.valueOf(flowId)).list();
+                    List<Task> taskList = taskService.createTaskQuery().processInstanceId(String.valueOf(flowId))
+                            .list();
                     if (!CollectionUtils.isEmpty(taskList)) {
                         taskIdList = taskList.stream().map(s -> Long.parseLong(s.getId())).collect(Collectors.toList());
                     }
                 } else if (approveSetupMap.containsKey(flowTaskResult.getSetup())) {//已经审批过的表单
-                    flowTaskHistoryList = CollectionUtils.isEmpty(flowTaskHistoryList) ? new ArrayList<>(approveSetupMap.size()) : flowTaskHistoryList;
+                    flowTaskHistoryList = CollectionUtils.isEmpty(flowTaskHistoryList) ?
+                            new ArrayList<>(approveSetupMap.size()) :
+                            flowTaskHistoryList;
                     flowTaskHistoryList.add(flowTaskResult);
                 }
             }
         }
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        if ((tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW ||
-                tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)) {
+        if ((tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)) {
             if (Objects.nonNull(currFlowTaskResult) && currFlowTaskResult.getSetup().intValue() == 3) {
                 List<Task> taskList = taskService.createTaskQuery().processInstanceId(String.valueOf(flowId)).list();
                 List<FlowFormWidgetResult> flowFormWidgetResultListNew = new ArrayList<>();
@@ -903,14 +990,15 @@ public class ActivitiServiceImpl implements ActivitiService {
                     List<FlowFormWidgetResult> flowFormWidgetResultList = currFlowTaskResult.getFormProperty();
                     for (FlowFormWidgetResult f : flowFormWidgetResultList) {
                         if (Objects.nonNull(sysRole)) {
-                            if (f.getRoleType() == sysRole.getType() &&
-                                    (sysRole.getType() == RoleTypeEnum.REGION_MANAGER || sysRole.getType() == RoleTypeEnum.EFFECT_ENGINEER)) {
+                            if (f.getRoleType() == sysRole.getType() && (
+                                    sysRole.getType() == RoleTypeEnum.REGION_MANAGER
+                                            || sysRole.getType() == RoleTypeEnum.EFFECT_ENGINEER)) {
                                 flowFormWidgetResultListNew.add(f);
                             }
                         } else {
-                            if (f.getFormId().contains(SystemConstant.APPROVE_RADIO_REGION) ||
-                                    f.getFormId().contains(SystemConstant.APPROVE_REMARK_REGION) ||
-                                    f.getFormId().contains(SystemConstant.SIGN_REGION)) {
+                            if (f.getFormId().contains(SystemConstant.APPROVE_RADIO_REGION) || f.getFormId()
+                                    .contains(SystemConstant.APPROVE_REMARK_REGION) || f.getFormId()
+                                    .contains(SystemConstant.SIGN_REGION)) {
                                 flowFormWidgetResultListNew.add(f);
                             }
                         }
@@ -941,9 +1029,9 @@ public class ActivitiServiceImpl implements ActivitiService {
                             f.setReadable(true);
                             f.setWritable(false);
                         } else {
-                            if (f.getFormId().contains(SystemConstant.APPROVE_RADIO_REGION) ||
-                                    f.getFormId().contains(SystemConstant.APPROVE_REMARK_REGION) ||
-                                    f.getFormId().contains(SystemConstant.SIGN_REGION)) {
+                            if (f.getFormId().contains(SystemConstant.APPROVE_RADIO_REGION) || f.getFormId()
+                                    .contains(SystemConstant.APPROVE_REMARK_REGION) || f.getFormId()
+                                    .contains(SystemConstant.SIGN_REGION)) {
                                 flowFormWidgetResultListNew.add(f);
                             }
                         }
@@ -957,9 +1045,12 @@ public class ActivitiServiceImpl implements ActivitiService {
 
         CrmProjectResult crmProjectResult = null;
         if (Objects.nonNull(tfCustomFlowEntity.getCrmNo())) {
-            crmProjectResult = tbCrmService.findCrmProjectBySopNoOrCrmNo(tfCustomFlowEntity.getCode(), tfCustomFlowEntity.getCrmNo());
+            crmProjectResult = tbCrmService.findCrmProjectBySopNoOrCrmNo(tfCustomFlowEntity.getCode(),
+                    tfCustomFlowEntity.getCrmNo());
         }
-        return new FlowViewResult(flowId, tfFlowApprove.getStatus(), tfCustomFlowEntity.getCode(), taskIdList, flowTaskHistoryList, currFlowTaskResult, flowApproveHistoryList, crmProjectResult, flowFormSuggestionJiaResultList, flowFormSuggestionYiResultList);
+        return new FlowViewResult(flowId, tfFlowApprove.getStatus(), tfCustomFlowEntity.getCode(), taskIdList,
+                flowTaskHistoryList, currFlowTaskResult, flowApproveHistoryList, crmProjectResult,
+                flowFormSuggestionJiaResultList, flowFormSuggestionYiResultList);
     }
 
     /**
@@ -993,15 +1084,14 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param tfCustomFlow
      * @return
      */
-    protected Map<String, Object> getFlowFormPropertie(Map<String, Object> map,
-                                                       List<Task> taskList,
-                                                       FlowResult flowResult,
-                                                       TFCustomFlow tfCustomFlow) {
+    protected Map<String, Object> getFlowFormPropertie(Map<String, Object> map, List<Task> taskList,
+            FlowResult flowResult, TFCustomFlow tfCustomFlow) {
         if (CollectionUtils.isEmpty(taskList)) {
             throw ExceptionResultEnum.ERROR.exception("流程任务数据为空!");
         }
         Long flowId = Long.parseLong(taskList.get(0).getProcessInstanceId());
-        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
+        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
         Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
         tfCustomFlow = tfCustomFlowService.getById(tfCustomFlowEntity.gettFCustomFlowId());
         Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_DEPLOYMENT_NO_DATA.exception());
@@ -1009,7 +1099,8 @@ public class ActivitiServiceImpl implements ActivitiService {
         flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
         LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
         for (Task task : taskList) {
-            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
+            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(
+                    GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
             map = this.getFlowFormPropertie(flowResult, map, currFlowTaskResult.getSetup());
         }
         map.put(SystemConstant.FLOW_DEPLOYMENT_ID, tfCustomFlow.getFlowDeploymentId());
@@ -1028,7 +1119,8 @@ public class ActivitiServiceImpl implements ActivitiService {
     protected Map<String, Object> getFlowFormPropertie(FlowResult flowResult, Map<String, Object> map, int setup) {
         Map<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
         for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
-            FlowTaskResult flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()), FlowTaskResult.class);
+            FlowTaskResult flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()),
+                    FlowTaskResult.class);
             if (flowTaskResultTemp.getSetup().intValue() == setup) {
                 map.put(SystemConstant.FORM_PROPERTIES, flowTaskResultTemp);
                 break;
@@ -1049,17 +1141,14 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param approvePass
      * @return
      */
-    protected FlowTaskResult getNextFlowTaskResult(Integer nrOfCompletedInstances,
-                                                   Integer nrOfInstances,
-                                                   FlowTaskResult currFlowTaskResult,
-                                                   FlowTaskResult nextFlowTaskResult,
-                                                   int currSetup,
-                                                   Map<String, FlowTaskResult> setupMap,
-                                                   FlowApprovePassEnum approvePass) {
-        if (approvePass == FlowApprovePassEnum.PASS || approvePass == FlowApprovePassEnum.START || approvePass == FlowApprovePassEnum.DRAFT) {
-            if (Objects.nonNull(nrOfCompletedInstances)
-                    && Objects.nonNull(nrOfInstances)
-                    && nrOfCompletedInstances.intValue() != nrOfInstances.intValue() || approvePass == FlowApprovePassEnum.DRAFT) {
+    protected FlowTaskResult getNextFlowTaskResult(Integer nrOfCompletedInstances, Integer nrOfInstances,
+            FlowTaskResult currFlowTaskResult, FlowTaskResult nextFlowTaskResult, int currSetup,
+            Map<String, FlowTaskResult> setupMap, FlowApprovePassEnum approvePass) {
+        if (approvePass == FlowApprovePassEnum.PASS || approvePass == FlowApprovePassEnum.START
+                || approvePass == FlowApprovePassEnum.DRAFT) {
+            if (Objects.nonNull(nrOfCompletedInstances) && Objects.nonNull(nrOfInstances)
+                    && nrOfCompletedInstances.intValue() != nrOfInstances.intValue()
+                    || approvePass == FlowApprovePassEnum.DRAFT) {
                 nextFlowTaskResult = currFlowTaskResult;
             } else {
                 nextFlowTaskResult = this.getNextFlowTaskResult(setupMap, currSetup, nextFlowTaskResult);
@@ -1079,11 +1168,11 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param nextFlowTaskResult
      * @return
      */
-    protected FlowTaskResult getNextFlowTaskResult(Map<String, FlowTaskResult> setupMap,
-                                                   int currSetup,
-                                                   FlowTaskResult nextFlowTaskResult) {
+    protected FlowTaskResult getNextFlowTaskResult(Map<String, FlowTaskResult> setupMap, int currSetup,
+            FlowTaskResult nextFlowTaskResult) {
         for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
-            FlowTaskResult flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()), FlowTaskResult.class);
+            FlowTaskResult flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()),
+                    FlowTaskResult.class);
             if (flowTaskResultTemp.getSetup().intValue() == currSetup) {
                 nextFlowTaskResult = flowTaskResultTemp;
                 break;
@@ -1107,17 +1196,10 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param approvePass
      * @param approveRemark
      */
-    public void approvePass(FlowTaskResult currFlowTaskResult,
-                            Map<String, FlowTaskResult> setupMap,
-                            boolean multiInstance,
-                            Integer nrOfCompletedInstances,
-                            Integer nrOfInstances,
-                            TFFlowApprove tfFlowApprove,
-                            TFFlowLog tfFlowLog,
-                            FlowTaskResult nextFlowTaskResult,
-                            Map<String, Object> map,
-                            FlowApprovePassEnum approvePass,
-                            String approveRemark) {
+    public void approvePass(FlowTaskResult currFlowTaskResult, Map<String, FlowTaskResult> setupMap,
+            boolean multiInstance, Integer nrOfCompletedInstances, Integer nrOfInstances, TFFlowApprove tfFlowApprove,
+            TFFlowLog tfFlowLog, FlowTaskResult nextFlowTaskResult, Map<String, Object> map,
+            FlowApprovePassEnum approvePass, String approveRemark) {
         if (multiInstance) {
             map.computeIfAbsent(FlowApproveOperationEnum.REJECT.getId() + currFlowTaskResult.getSetup(), v -> 0);
         }
@@ -1125,8 +1207,7 @@ public class ActivitiServiceImpl implements ActivitiService {
             if (approvePass == FlowApprovePassEnum.DRAFT) {
                 tfFlowApprove.setStatus(FlowStatusEnum.valueOf(approvePass.name()));
             } else {
-                if (multiInstance && Objects.nonNull(nrOfCompletedInstances)
-                        && Objects.nonNull(nrOfInstances)
+                if (multiInstance && Objects.nonNull(nrOfCompletedInstances) && Objects.nonNull(nrOfInstances)
                         && nrOfCompletedInstances.intValue() == nrOfInstances.intValue()) {
                     tfFlowApprove.setStatus(FlowStatusEnum.FINISH);
                     tfFlowApprove.setSetup(FlowApproveSetupEnum.FINISH.getSetup());
@@ -1174,14 +1255,9 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param approvePass
      * @param approveRemark
      */
-    protected void approveReject(boolean multiInstance,
-                                 Map<String, Object> map,
-                                 FlowTaskResult currFlowTaskResult,
-                                 FlowTaskResult nextFlowTaskResult,
-                                 TFFlowApprove tfFlowApprove,
-                                 TFFlowLog tfFlowLog,
-                                 FlowApprovePassEnum approvePass,
-                                 String approveRemark) {
+    protected void approveReject(boolean multiInstance, Map<String, Object> map, FlowTaskResult currFlowTaskResult,
+            FlowTaskResult nextFlowTaskResult, TFFlowApprove tfFlowApprove, TFFlowLog tfFlowLog,
+            FlowApprovePassEnum approvePass, String approveRemark) {
         if (multiInstance) {
             map.computeIfAbsent(FlowApproveOperationEnum.REJECT.getId() + currFlowTaskResult.getSetup(), v -> 1);
         }

+ 22 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/params/DeviceInOutForm.java

@@ -40,6 +40,28 @@ public class DeviceInOutForm implements Serializable {
     @ApiModelProperty("快递单拍照")
     private String basePhotoPath;
 
+    @ApiModelProperty("是否默认设备")
+    private Boolean defaultData;
+
+    @ApiModelProperty("快递单号")
+    private String expressNo;
+
+    public String getExpressNo() {
+        return expressNo;
+    }
+
+    public void setExpressNo(String expressNo) {
+        this.expressNo = expressNo;
+    }
+
+    public Boolean getDefaultData() {
+        return defaultData;
+    }
+
+    public void setDefaultData(Boolean defaultData) {
+        this.defaultData = defaultData;
+    }
+
     public String getSerialNo() {
         return serialNo;
     }

+ 36 - 4
sop-business/src/main/java/com/qmth/sop/business/service/TBDeviceDeliveryService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
 import com.qmth.sop.business.bean.params.DeviceInOutForm;
+import com.qmth.sop.business.bean.result.FlowTaskResult;
 import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.entity.TBDeviceDelivery;
@@ -24,6 +25,7 @@ import java.util.Map;
  * @since 2023-11-28
  */
 public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
+
     /**
      * 设备发货导入
      *
@@ -39,7 +41,6 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      */
     void editDeviceDelivery(DeviceDeliveryParam deviceDeliveryParam);
 
-
     /**
      * 设备发货管理查询
      *
@@ -58,7 +59,10 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @param receiveEndTime    验收结束时间
      * @return 分页结果
      */
-    IPage<TBDeviceDeliveryResult> page(IPage<Map> iPage, Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
+    IPage<TBDeviceDeliveryResult> page(IPage<Map> iPage, Long serviceId, DeviceUsageTypeEnum usageType, String crmNo,
+            DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime,
+            String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime)
+            throws Exception;
 
     /**
      * 设备发货管理列表
@@ -77,7 +81,10 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @param receiveEndTime    验收结束时间
      * @return 分页结果
      */
-    List<TBDeviceDeliveryResult> list(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
+    List<TBDeviceDeliveryResult> list(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo,
+            DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime,
+            String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime)
+            throws Exception;
 
     /**
      * 设备发货管理导出
@@ -95,7 +102,9 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @param receiveStartTime  验收开始时间
      * @param receiveEndTime    验收结束时间分页结果
      */
-    void dataExport(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
+    void dataExport(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status,
+            Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo,
+            Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception;
 
     /**
      * 新增设备发货入库记录
@@ -126,4 +135,27 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @return 发货人集合
      */
     List<SysUser> findDeliveryUserList();
+
+    /**
+     * 根据sop表单信息更新状态
+     *
+     * @param flowTaskResult
+     * @param crmNo
+     * @param status
+     * @param userId
+     */
+    void updateStatusBySop(FlowTaskResult flowTaskResult, String crmNo, DeviceDeliveryStatusEnum status, Long userId);
+
+    /**
+     * 更新设备相关
+     *
+     * @param flowTaskResult
+     * @param crmNo
+     * @param sopNo
+     * @param status
+     * @param userId
+     * @param deviceDeliveryUpdate
+     */
+    void updateDeviceRelated(FlowTaskResult flowTaskResult, String crmNo, String sopNo, DeviceDeliveryStatusEnum status,
+            Long userId, Boolean deviceDeliveryUpdate);
 }

+ 15 - 3
sop-business/src/main/java/com/qmth/sop/business/service/TBSopInfoService.java

@@ -95,7 +95,8 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * @return
      * @throws InterruptedException
      */
-    public Boolean sopApplyOrPublish(String sopNo, String crmNo, String flowDeploymentId, FlowApprovePassEnum approve, String formProperties) throws InterruptedException;
+    public Boolean sopApplyOrPublish(String sopNo, String crmNo, String flowDeploymentId, FlowApprovePassEnum approve,
+            String formProperties) throws InterruptedException;
 
     /**
      * 根据crmNo查询在途的sop信息
@@ -122,7 +123,8 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * @param tbSopInfoDetail
      * @param crmNo
      */
-    public void sopSystemApprove(TFCustomFlow tfCustomFlow, TFCustomFlowEntity tfCustomFlowEntity, TFFlowApprove tfFlowApprove, TBSopInfoDetail tbSopInfoDetail, String crmNo) throws InterruptedException;
+    public void sopSystemApprove(TFCustomFlow tfCustomFlow, TFCustomFlowEntity tfCustomFlowEntity,
+            TFFlowApprove tfFlowApprove, TBSopInfoDetail tbSopInfoDetail, String crmNo) throws InterruptedException;
 
     /**
      * 保存提醒/延时任务
@@ -140,7 +142,8 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * @param userId
      * @throws InterruptedException
      */
-    public void saveSopPlanDate(FlowTaskResult flowTaskResult, Long sopId, Long flowId, Long userId) throws InterruptedException;
+    public void saveSopPlanDate(FlowTaskResult flowTaskResult, Long sopId, Long flowId, Long userId)
+            throws InterruptedException;
 
     /**
      * sop保存设备信息
@@ -176,4 +179,13 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * @return
      */
     List<Map<String, Object>> findSopPassage(Long serviceId);
+
+    /**
+     * 获取表单内容
+     *
+     * @param tfCustomFlowEntity
+     * @param setup
+     * @return
+     */
+    public FlowTaskResult getFormProperties(TFCustomFlowEntity tfCustomFlowEntity, Integer setup);
 }

+ 230 - 107
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDeviceDeliveryServiceImpl.java

@@ -1,6 +1,8 @@
 package com.qmth.sop.business.service.impl;
 
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -10,6 +12,8 @@ import com.qmth.sop.business.bean.dto.DeviceDeliveryImportDto;
 import com.qmth.sop.business.bean.dto.DeviceInfoDto;
 import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
 import com.qmth.sop.business.bean.params.DeviceInOutForm;
+import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
+import com.qmth.sop.business.bean.result.FlowTaskResult;
 import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.TBDeviceDeliveryMapper;
@@ -18,6 +22,7 @@ import com.qmth.sop.business.util.excel.BasicExcelListener;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
 import com.qmth.sop.common.util.FileUtil;
+import com.qmth.sop.common.util.GsonUtil;
 import com.qmth.sop.common.util.ServletUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
@@ -43,19 +48,27 @@ import java.util.stream.Collectors;
  * @since 2023-11-28
  */
 @Service
-public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMapper, TBDeviceDelivery> implements TBDeviceDeliveryService {
+public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMapper, TBDeviceDelivery>
+        implements TBDeviceDeliveryService {
 
     @Resource
     private SysDeviceService sysDeviceService;
+
     @Resource
     private SysDeviceModelService sysDeviceModelService;
+
     @Resource
     private SysSupplierService sysSupplierService;
+
     @Resource
     private SysUserService sysUserService;
+
     @Resource
     private TBCrmService tbCrmService;
 
+    @Resource
+    TBDeviceInOutService tbDeviceInOutService;
+
     @Transactional
     @Override
     public void deviceDeliveryImport(MultipartFile file) throws IOException {
@@ -65,28 +78,28 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
 
         StringJoiner errorData = new StringJoiner("");
         EasyExcel.read(inputStream, DeviceDeliveryImportDto.class, new BasicExcelListener<DeviceDeliveryImportDto>() {
+
             @Override
-            public void handle(LinkedMultiValueMap<String, DeviceDeliveryImportDto> dataList, StringJoiner errorDataSj, Exception exception) {
+            public void handle(LinkedMultiValueMap<String, DeviceDeliveryImportDto> dataList, StringJoiner errorDataSj,
+                    Exception exception) {
                 deviceDeliveryImportDtoLinkedMultiValueMap.addAll(dataList);
                 errorData.add(errorDataSj.toString());
             }
         }).headRowNumber(2).sheet(0).doRead();
 
-        List<DeviceDeliveryImportDto> deviceDeliveryImportDtoList = deviceDeliveryImportDtoLinkedMultiValueMap.get(BasicExcelListener.SUCCESS);
+        List<DeviceDeliveryImportDto> deviceDeliveryImportDtoList = deviceDeliveryImportDtoLinkedMultiValueMap.get(
+                BasicExcelListener.SUCCESS);
 
         // 派单序列号集合
-        List<String> crmNoList = tbCrmService.list(new QueryWrapper<TBCrm>()
-                        .lambda()
-                        .eq(TBCrm::getEnable, true))
-                .stream()
-                .map(TBCrm::getCrmNo)
-                .distinct()
-                .collect(Collectors.toList());
+        List<String> crmNoList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getEnable, true))
+                .stream().map(TBCrm::getCrmNo).distinct().collect(Collectors.toList());
 
         if (CollectionUtils.isNotEmpty(deviceDeliveryImportDtoList)) {
-            List<SysSupplier> sysSupplierList = sysSupplierService.list(new QueryWrapper<SysSupplier>().lambda().eq(SysSupplier::getType, SupplierTypeEnum.DEVICE));
+            List<SysSupplier> sysSupplierList = sysSupplierService.list(
+                    new QueryWrapper<SysSupplier>().lambda().eq(SysSupplier::getType, SupplierTypeEnum.DEVICE));
             // 供应商map
-            Map<String, Long> supplierMap = sysSupplierList.stream().collect(Collectors.toMap(SysSupplier::getName, SysSupplier::getId));
+            Map<String, Long> supplierMap = sysSupplierList.stream()
+                    .collect(Collectors.toMap(SysSupplier::getName, SysSupplier::getId));
 
             // serialNo - obj
             Map<String, DeviceInfoDto> deviceMap = new HashMap<>();
@@ -115,7 +128,8 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                     throw ExceptionResultEnum.ERROR.exception(String.format("excel中存在系统中不存在的供应商名称[%s]", supplierName));
                 }
                 DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-                if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness() && !dpr.getHasRegionManager()) {
+                if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness()
+                        && !dpr.getHasRegionManager()) {
                     // 设备管理员权限
                     Long userSupplierId = requestUser.getSupplierId();
                     if (userSupplierId == null || userSupplierId == 0) {
@@ -126,17 +140,15 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                     }
                 }
 
-
                 String mailingAddress = deviceDeliveryImportDto.getMailingAddress();
                 String consignee = deviceDeliveryImportDto.getConsignee();
                 String consigneePhone = deviceDeliveryImportDto.getConsigneePhone();
                 String expressNo = deviceDeliveryImportDto.getExpressNo();
 
                 // 查询设备表是否有该设备
-                SysDevice sysDevice = sysDeviceService.getOne(new QueryWrapper<SysDevice>()
-                        .lambda()
-                        .eq(SysDevice::getSerialNo, serialNo)
-                        .last(SystemConstant.LIMIT1));
+                SysDevice sysDevice = sysDeviceService.getOne(
+                        new QueryWrapper<SysDevice>().lambda().eq(SysDevice::getSerialNo, serialNo)
+                                .last(SystemConstant.LIMIT1));
 
                 if (Objects.isNull(sysDevice)) {
                     // 设备表不存在该设备 -> 新增设备
@@ -156,19 +168,19 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                     sysDeviceService.save(willAddSysDevice);
                 } else {
                     if (InOutTypeEnum.OUT.equals(sysDevice.getBound())) {
-                        throw ExceptionResultEnum.ERROR.exception(String.format("序列号为[%s]的设备在设备管理中已存在且状态为'出库',不能导入", sysDevice.getSerialNo()));
+                        throw ExceptionResultEnum.ERROR.exception(
+                                String.format("序列号为[%s]的设备在设备管理中已存在且状态为'出库',不能导入", sysDevice.getSerialNo()));
                     }
                 }
 
                 // 查询是否有处于发货过程中设备
-                TBDeviceDelivery dbDeviceDelivery = this.getOne(new QueryWrapper<TBDeviceDelivery>()
-                        .lambda()
-                        .eq(TBDeviceDelivery::getSerialNo, serialNo)
-                        .eq(TBDeviceDelivery::getEffect, true)
-                        .last(SystemConstant.LIMIT1));
+                TBDeviceDelivery dbDeviceDelivery = this.getOne(
+                        new QueryWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getSerialNo, serialNo)
+                                .eq(TBDeviceDelivery::getEffect, true).last(SystemConstant.LIMIT1));
 
                 if (Objects.nonNull(dbDeviceDelivery)) {
-                    throw ExceptionResultEnum.EXCEPTION_ERROR.exception(String.format("excel中存在已发货过程中的设备(序列号)[%s]", serialNo));
+                    throw ExceptionResultEnum.EXCEPTION_ERROR.exception(
+                            String.format("excel中存在已发货过程中的设备(序列号)[%s]", serialNo));
                 }
 
                 TBDeviceDelivery tbDeviceDelivery = new TBDeviceDelivery();
@@ -206,16 +218,17 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         String consignee = deviceDeliveryParam.getConsignee();
         String consigneePhone = deviceDeliveryParam.getConsigneePhone();
         String expressNo = deviceDeliveryParam.getExpressNo();
-        this.update(new UpdateWrapper<TBDeviceDelivery>().lambda()
-                .eq(TBDeviceDelivery::getId, id)
-                .set(TBDeviceDelivery::getMailingAddress, mailingAddress)
-                .set(TBDeviceDelivery::getConsignee, consignee)
+        this.update(new UpdateWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getId, id)
+                .set(TBDeviceDelivery::getMailingAddress, mailingAddress).set(TBDeviceDelivery::getConsignee, consignee)
                 .set(TBDeviceDelivery::getConsigneePhone, consigneePhone)
                 .set(TBDeviceDelivery::getExpressNo, expressNo));
     }
 
     @Override
-    public IPage<TBDeviceDeliveryResult> page(IPage<Map> iPage, Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception {
+    public IPage<TBDeviceDeliveryResult> page(IPage<Map> iPage, Long serviceId, DeviceUsageTypeEnum usageType,
+            String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime,
+            Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime,
+            Long receiveEndTime) throws Exception {
         if (crmNo != null && crmNo.length() > 0) {
             crmNo = SystemConstant.translateSpecificSign(crmNo);
         }
@@ -227,7 +240,8 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         }
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness() && !dpr.getHasRegionManager()) {
+        if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness()
+                && !dpr.getHasRegionManager()) {
             // 是设备管理员
             Long userSupplierId = requestUser.getSupplierId();
             if (userSupplierId == null || userSupplierId == 0) {
@@ -235,7 +249,9 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
             }
             supplierId = userSupplierId;
         }
-        IPage<TBDeviceDeliveryResult> page = this.baseMapper.page(iPage, serviceId, usageType, crmNo, status, deliverUserId, deliveryStartTime, deliveryEndTime, serialNo, deviceNo, supplierId, receiveStartTime, receiveEndTime);
+        IPage<TBDeviceDeliveryResult> page = this.baseMapper.page(iPage, serviceId, usageType, crmNo, status,
+                deliverUserId, deliveryStartTime, deliveryEndTime, serialNo, deviceNo, supplierId, receiveStartTime,
+                receiveEndTime);
         for (TBDeviceDeliveryResult e : page.getRecords()) {
             this.fillResultInfo(e);
         }
@@ -243,7 +259,10 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     }
 
     @Override
-    public List<TBDeviceDeliveryResult> list(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception {
+    public List<TBDeviceDeliveryResult> list(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo,
+            DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime,
+            String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime)
+            throws Exception {
         if (crmNo != null && crmNo.length() > 0) {
             crmNo = SystemConstant.translateSpecificSign(crmNo);
         }
@@ -255,7 +274,8 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         }
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness() && !dpr.getHasRegionManager()) {
+        if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness()
+                && !dpr.getHasRegionManager()) {
             // 设备
             Long userSupplierId = requestUser.getSupplierId();
             if (userSupplierId == null || userSupplierId == 0) {
@@ -263,7 +283,8 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
             }
             supplierId = userSupplierId;
         }
-        List<TBDeviceDeliveryResult> result = this.baseMapper.list(serviceId, usageType, crmNo, status, deliverUserId, deliveryStartTime, deliveryEndTime, serialNo, deviceNo, supplierId, receiveStartTime, receiveEndTime);
+        List<TBDeviceDeliveryResult> result = this.baseMapper.list(serviceId, usageType, crmNo, status, deliverUserId,
+                deliveryStartTime, deliveryEndTime, serialNo, deviceNo, supplierId, receiveStartTime, receiveEndTime);
         for (TBDeviceDeliveryResult e : result) {
             this.fillResultInfo(e);
         }
@@ -271,8 +292,11 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     }
 
     @Override
-    public void dataExport(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception {
-        List<TBDeviceDeliveryResult> datasource = this.list(serviceId, usageType, crmNo, status, deliverUserId, deliveryStartTime, deliveryEndTime, serialNo, deviceNo, supplierId, receiveStartTime, receiveEndTime);
+    public void dataExport(Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status,
+            Long deliverUserId, Long deliveryStartTime, Long deliveryEndTime, String serialNo, String deviceNo,
+            Long supplierId, Long receiveStartTime, Long receiveEndTime) throws Exception {
+        List<TBDeviceDeliveryResult> datasource = this.list(serviceId, usageType, crmNo, status, deliverUserId,
+                deliveryStartTime, deliveryEndTime, serialNo, deviceNo, supplierId, receiveStartTime, receiveEndTime);
         File fileTemp = null;
         try {
             fileTemp = SystemConstant.getFileTempVar(SystemConstant.XLSX_PREFIX);
@@ -292,11 +316,9 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         for (DeviceInOutForm deviceInOutForm : deviceInOutFormList) {
             String serialNo = deviceInOutForm.getSerialNo();
-            List<TBDeviceDelivery> outList = this.list(new QueryWrapper<TBDeviceDelivery>()
-                    .lambda()
+            List<TBDeviceDelivery> outList = this.list(new QueryWrapper<TBDeviceDelivery>().lambda()
                     .eq(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.RECEIVE)
-                    .eq(TBDeviceDelivery::getEffect, true)
-                    .eq(TBDeviceDelivery::getSerialNo, serialNo)
+                    .eq(TBDeviceDelivery::getEffect, true).eq(TBDeviceDelivery::getSerialNo, serialNo)
                     .eq(TBDeviceDelivery::getDeliveryType, InOutTypeEnum.OUT));
 
             if (CollectionUtils.isNotEmpty(outList)) {
@@ -338,11 +360,9 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     public void updateOutRecord(List<DeviceInOutForm> deviceInOutFormList) {
         for (DeviceInOutForm deviceInOutForm : deviceInOutFormList) {
             String serialNo = deviceInOutForm.getSerialNo();
-            List<TBDeviceDelivery> outList = this.list(new QueryWrapper<TBDeviceDelivery>()
-                    .lambda()
+            List<TBDeviceDelivery> outList = this.list(new QueryWrapper<TBDeviceDelivery>().lambda()
                     .eq(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.DELIVER)
-                    .eq(TBDeviceDelivery::getEffect, true)
-                    .eq(TBDeviceDelivery::getSerialNo, serialNo)
+                    .eq(TBDeviceDelivery::getEffect, true).eq(TBDeviceDelivery::getSerialNo, serialNo)
                     .eq(TBDeviceDelivery::getDeliveryType, InOutTypeEnum.OUT));
 
             if (CollectionUtils.isNotEmpty(outList)) {
@@ -361,60 +381,68 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     public void updateStatus(List<Long> deviceDeliveryIdList, DeviceDeliveryStatusEnum status, Long requestUserId) {
         if (CollectionUtils.isNotEmpty(deviceDeliveryIdList)) {
             // 只有在生命周期的才能被操作
-            List<TBDeviceDelivery> tbDeviceDeliveryList = this.list(new QueryWrapper<TBDeviceDelivery>()
-                    .lambda()
-                    .in(TBDeviceDelivery::getId, deviceDeliveryIdList));
+            List<TBDeviceDelivery> tbDeviceDeliveryList = this.list(
+                    new QueryWrapper<TBDeviceDelivery>().lambda().in(TBDeviceDelivery::getId, deviceDeliveryIdList));
 
             switch (status) {
-                case DELIVER:
-                    // 变更为已发货状态(供应商点击批量发货时触发 UN_DELIVER -> DELIVER(或sop入库新增记录触发))
-                    if (tbDeviceDeliveryList.stream().anyMatch(e -> !DeviceDeliveryStatusEnum.UN_DELIVER.equals(e.getStatus()) || !e.getEffect())) {
-                        throw ExceptionResultEnum.ERROR.exception(String.format("只有[出入库过程中]且[%s]的记录才能[%s]", DeviceDeliveryStatusEnum.UN_DELIVER.getTitle(), "发货"));
-                    }
-                    tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
-                        Long currenTime = System.currentTimeMillis();
-                        e.setDeliverUserId(requestUserId);
-                        e.setUpdateId(requestUserId);
-                        e.setDeliverTime(currenTime);
-                        e.setUpdateTime(currenTime);
-                        e.setStatus(DeviceDeliveryStatusEnum.DELIVER);
-                    }).collect(Collectors.toList());
-                    this.updateBatchById(tbDeviceDeliveryList);
-                    break;
-                case RECEIVE:
-                    // 变更为已签收状态(设备发货列表点击签收触发||sop现场测试签收 -> DELIVER -> RECEIVE)
-                    // 入库签收终止该入库记录的生命周期(出库签收不终止,设备发货出库生命周期的终止是在设备出库提交,生成设备发货入库记录时触发)
-                    if (tbDeviceDeliveryList.stream().anyMatch(e -> !DeviceDeliveryStatusEnum.DELIVER.equals(e.getStatus()) || !e.getEffect())) {
-                        throw ExceptionResultEnum.ERROR.exception(String.format("只有[出入库过程中]且[%s]的发货记录才能[%s]", DeviceDeliveryStatusEnum.DELIVER.getTitle(), "签收"));
-                    }
-                    tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
-                        Long currenTime = System.currentTimeMillis();
-                        e.setReceiveUserId(requestUserId);
-                        e.setUpdateId(requestUserId);
-                        e.setReceiveTime(currenTime);
-                        e.setUpdateTime(currenTime);
-                        e.setStatus(DeviceDeliveryStatusEnum.RECEIVE);
-                        if (InOutTypeEnum.IN.equals(e.getDeliveryType())) {
-                            e.setEffect(false);
-                        }
-                    }).collect(Collectors.toList());
-                    this.updateBatchById(tbDeviceDeliveryList);
-                    break;
-                case CANCEL:
-                    // 变更为已作废状态(只有带发货状态能被作废)
-                    // 作废触发时该出库生命周期终止
-                    if (tbDeviceDeliveryList.stream().anyMatch(e -> !DeviceDeliveryStatusEnum.UN_DELIVER.equals(e.getStatus()) || !e.getEffect())) {
-                        throw ExceptionResultEnum.ERROR.exception(String.format("只有[出入库过程中]且[%s]的发货记录才能[%s]", DeviceDeliveryStatusEnum.UN_DELIVER.getTitle(), "作废"));
-                    }
-                    tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
-                        e.setUpdateId(requestUserId);
-                        e.setUpdateTime(System.currentTimeMillis());
-                        e.setStatus(DeviceDeliveryStatusEnum.CANCEL);
-                        e.setEnable(false);
+            case DELIVER:
+                // 变更为已发货状态(供应商点击批量发货时触发 UN_DELIVER -> DELIVER(或sop入库新增记录触发))
+                if (tbDeviceDeliveryList.stream()
+                        .anyMatch(e -> !DeviceDeliveryStatusEnum.UN_DELIVER.equals(e.getStatus()) || !e.getEffect())) {
+                    throw ExceptionResultEnum.ERROR.exception(
+                            String.format("只有[出入库过程中]且[%s]的记录才能[%s]", DeviceDeliveryStatusEnum.UN_DELIVER.getTitle(),
+                                    "发货"));
+                }
+                tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
+                    Long currenTime = System.currentTimeMillis();
+                    e.setDeliverUserId(requestUserId);
+                    e.setUpdateId(requestUserId);
+                    e.setDeliverTime(currenTime);
+                    e.setUpdateTime(currenTime);
+                    e.setStatus(DeviceDeliveryStatusEnum.DELIVER);
+                }).collect(Collectors.toList());
+                this.updateBatchById(tbDeviceDeliveryList);
+                break;
+            case RECEIVE:
+                // 变更为已签收状态(设备发货列表点击签收触发||sop现场测试签收 -> DELIVER -> RECEIVE)
+                // 入库签收终止该入库记录的生命周期(出库签收不终止,设备发货出库生命周期的终止是在设备出库提交,生成设备发货入库记录时触发)
+                if (tbDeviceDeliveryList.stream()
+                        .anyMatch(e -> !DeviceDeliveryStatusEnum.DELIVER.equals(e.getStatus()) || !e.getEffect())) {
+                    throw ExceptionResultEnum.ERROR.exception(
+                            String.format("只有[出入库过程中]且[%s]的发货记录才能[%s]", DeviceDeliveryStatusEnum.DELIVER.getTitle(),
+                                    "签收"));
+                }
+                tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
+                    Long currenTime = System.currentTimeMillis();
+                    e.setReceiveUserId(requestUserId);
+                    e.setUpdateId(requestUserId);
+                    e.setReceiveTime(currenTime);
+                    e.setUpdateTime(currenTime);
+                    e.setStatus(DeviceDeliveryStatusEnum.RECEIVE);
+                    if (InOutTypeEnum.IN.equals(e.getDeliveryType())) {
                         e.setEffect(false);
-                    }).collect(Collectors.toList());
-                    this.updateBatchById(tbDeviceDeliveryList);
-                    break;
+                    }
+                }).collect(Collectors.toList());
+                this.updateBatchById(tbDeviceDeliveryList);
+                break;
+            case CANCEL:
+                // 变更为已作废状态(只有带发货状态能被作废)
+                // 作废触发时该出库生命周期终止
+                if (tbDeviceDeliveryList.stream()
+                        .anyMatch(e -> !DeviceDeliveryStatusEnum.UN_DELIVER.equals(e.getStatus()) || !e.getEffect())) {
+                    throw ExceptionResultEnum.ERROR.exception(
+                            String.format("只有[出入库过程中]且[%s]的发货记录才能[%s]", DeviceDeliveryStatusEnum.UN_DELIVER.getTitle(),
+                                    "作废"));
+                }
+                tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
+                    e.setUpdateId(requestUserId);
+                    e.setUpdateTime(System.currentTimeMillis());
+                    e.setStatus(DeviceDeliveryStatusEnum.CANCEL);
+                    e.setEnable(false);
+                    e.setEffect(false);
+                }).collect(Collectors.toList());
+                this.updateBatchById(tbDeviceDeliveryList);
+                break;
             }
         }
     }
@@ -424,12 +452,11 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
         QueryWrapper<TBDeviceDelivery> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda()
-                .select(TBDeviceDelivery::getDeliverUserId)
-                .eq(TBDeviceDelivery::getEnable, true)
+        queryWrapper.lambda().select(TBDeviceDelivery::getDeliverUserId).eq(TBDeviceDelivery::getEnable, true)
                 .ne(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.CANCEL);
 
-        if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness() && !dpr.getHasRegionManager()) {
+        if (dpr.getHasDeviceDelivery() && !dpr.getHasAdmin() && !dpr.getHasPmo() && !dpr.getHasBusiness()
+                && !dpr.getHasRegionManager()) {
             // 设备
             Long userSupplierId = requestUser.getSupplierId();
             if (userSupplierId == null || userSupplierId == 0) {
@@ -437,12 +464,9 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
             }
             queryWrapper.lambda().eq(TBDeviceDelivery::getSupplierId, userSupplierId);
         }
-        List<Long> deliveryUserIdList = this.list(queryWrapper)
-                .stream()
+        List<Long> deliveryUserIdList = this.list(queryWrapper).stream()
                 .filter(e -> e != null && e.getDeliverUserId() != null && e.getDeliverUserId() > 0)
-                .map(TBDeviceDelivery::getDeliverUserId)
-                .distinct()
-                .collect(Collectors.toList());
+                .map(TBDeviceDelivery::getDeliverUserId).distinct().collect(Collectors.toList());
         List<SysUser> result = new ArrayList<>();
         if (CollectionUtils.isNotEmpty(deliveryUserIdList)) {
             result = sysUserService.listByIds(deliveryUserIdList);
@@ -450,6 +474,101 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         return result;
     }
 
+    /**
+     * 根据sop表单信息更新状态
+     *
+     * @param flowTaskResult
+     * @param crmNo
+     * @param status
+     * @param userId
+     */
+    @Override
+    @Transactional
+    public void updateStatusBySop(FlowTaskResult flowTaskResult, String crmNo, DeviceDeliveryStatusEnum status,
+            Long userId) {
+        List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResult.getFormProperty();
+        List<String> deviceSerialNoList = new ArrayList<>();
+        for (FlowFormWidgetResult t : flowFormWidgetResultList) {
+            if (t.getFormId().contains(SystemConstant.DEVICE_OUT_TABLE)) {
+                JSONObject jsonObject = JSONObject.parseObject(t.getValue());
+                JSONArray jsonArray = jsonObject.getJSONArray(SystemConstant.VALUE);
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    DeviceInOutForm deviceInOutForm = GsonUtil.fromJson(GsonUtil.toJson(jsonArray.getJSONObject(i)),
+                            DeviceInOutForm.class);
+                    deviceSerialNoList.add(deviceInOutForm.getSerialNo());
+                }
+            }
+        }
+        List<TBDeviceDelivery> tbDeviceDeliveryList = this.list(
+                new QueryWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getCrmNo, crmNo)
+                        .eq(TBDeviceDelivery::getEffect, true).in(TBDeviceDelivery::getSerialNo, deviceSerialNoList));
+        if (!org.springframework.util.CollectionUtils.isEmpty(tbDeviceDeliveryList)) {
+            for (TBDeviceDelivery t : tbDeviceDeliveryList) {
+                t.setStatus(status);
+                t.setReceiveTime(System.currentTimeMillis());
+                t.setReceiveUserId(userId);
+                t.updateInfo(userId);
+            }
+            this.updateBatchById(tbDeviceDeliveryList);
+        }
+    }
+
+    /**
+     * 更新设备相关
+     *
+     * @param flowTaskResult
+     * @param crmNo
+     * @param sopNo
+     * @param status
+     * @param userId
+     * @param deviceDeliveryUpdate
+     */
+    @Override
+    @Transactional
+    public void updateDeviceRelated(FlowTaskResult flowTaskResult, String crmNo, String sopNo,
+            DeviceDeliveryStatusEnum status, Long userId, Boolean deviceDeliveryUpdate) {
+        List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResult.getFormProperty();
+        List<String> deviceSerialNoList = new ArrayList<>();
+        for (FlowFormWidgetResult t : flowFormWidgetResultList) {
+            if (t.getFormId().contains(SystemConstant.DEVICE_OUT_TABLE)) {
+                JSONObject jsonObject = JSONObject.parseObject(t.getValue());
+                JSONArray jsonArray = jsonObject.getJSONArray(SystemConstant.VALUE);
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    DeviceInOutForm deviceInOutForm = GsonUtil.fromJson(GsonUtil.toJson(jsonArray.getJSONObject(i)),
+                            DeviceInOutForm.class);
+                    deviceSerialNoList.add(deviceInOutForm.getSerialNo());
+
+                    TBDeviceInOut tbDeviceInOut = tbDeviceInOutService.getOne(
+                            new QueryWrapper<TBDeviceInOut>().lambda().eq(TBDeviceInOut::getSopNo, sopNo)
+                                    .eq(TBDeviceInOut::getType, InOutTypeEnum.OUT)
+                                    .eq(TBDeviceInOut::getSerialNo, deviceInOutForm.getSerialNo()));
+                    SysDevice sysDevice = sysDeviceService.getOne(new QueryWrapper<SysDevice>().lambda()
+                            .eq(SysDevice::getSerialNo, deviceInOutForm.getSerialNo()));
+                    sysDevice.setLocation(tbDeviceInOut.getLocation());
+                    sysDevice.setLocationArr(tbDeviceInOut.getAddressArr());
+                    sysDevice.updateInfo(userId);
+
+                    tbDeviceInOutService.removeById(tbDeviceInOut.getId());
+                    sysDeviceService.updateById(sysDevice);
+                }
+            }
+        }
+        if (deviceDeliveryUpdate) {
+            List<TBDeviceDelivery> tbDeviceDeliveryList = this.list(
+                    new QueryWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getCrmNo, crmNo)
+                            .eq(TBDeviceDelivery::getEffect, true)
+                            .in(TBDeviceDelivery::getSerialNo, deviceSerialNoList));
+            if (!org.springframework.util.CollectionUtils.isEmpty(tbDeviceDeliveryList)) {
+                for (TBDeviceDelivery t : tbDeviceDeliveryList) {
+                    t.setStatus(status);
+                    t.setReceiveTime(System.currentTimeMillis());
+                    t.setReceiveUserId(userId);
+                    t.updateInfo(userId);
+                }
+                this.updateBatchById(tbDeviceDeliveryList);
+            }
+        }
+    }
 
     /**
      * 补充结果信息
@@ -467,10 +586,14 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         e.setStatusStr(Objects.nonNull(dbStatus) ? dbStatus.getTitle() : "");
 
         Long dbDeliveryTime = e.getDeliverTime();
-        e.setDeliverTimeStr(dbDeliveryTime != null && dbDeliveryTime > 0 ? DateFormatUtils.format(dbDeliveryTime, SystemConstant.DEFAULT_DATE_PATTERN) : "--");
+        e.setDeliverTimeStr(dbDeliveryTime != null && dbDeliveryTime > 0 ?
+                DateFormatUtils.format(dbDeliveryTime, SystemConstant.DEFAULT_DATE_PATTERN) :
+                "--");
 
         Long dbReceiveTime = e.getReceiveTime();
-        e.setReceiveTimeStr(dbReceiveTime != null && dbReceiveTime > 0 ? DateFormatUtils.format(dbReceiveTime, SystemConstant.DEFAULT_DATE_PATTERN) : "--");
+        e.setReceiveTimeStr(dbReceiveTime != null && dbReceiveTime > 0 ?
+                DateFormatUtils.format(dbReceiveTime, SystemConstant.DEFAULT_DATE_PATTERN) :
+                "--");
 
         String path = e.getExpressPhotoPath();
         if (path != null && path.length() > 0) {

+ 18 - 31
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -1011,33 +1011,8 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
 
                     //现场环境测试后,设备发货管理里的设备通过序列号匹配更新为签收
                     FlowTaskResult flowTaskResultDeviceOut = this.getFormProperties(tfCustomFlowEntity, 4);
-                    List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResultDeviceOut.getFormProperty();
-                    List<String> deviceSerialNoList = new ArrayList<>();
-                    for (FlowFormWidgetResult t : flowFormWidgetResultList) {
-                        if (t.getFormId().contains(SystemConstant.DEVICE_OUT_TABLE)) {
-                            JSONObject jsonObject = JSONObject.parseObject(t.getValue());
-                            JSONArray jsonArray = jsonObject.getJSONArray(SystemConstant.VALUE);
-                            for (int i = 0; i < jsonArray.size(); i++) {
-                                DeviceInOutForm deviceInOutForm = GsonUtil.fromJson(
-                                        GsonUtil.toJson(jsonArray.getJSONObject(i)), DeviceInOutForm.class);
-                                deviceSerialNoList.add(deviceInOutForm.getSerialNo());
-                            }
-                        }
-                    }
-                    List<TBDeviceDelivery> tbDeviceDeliveryList = tbDeviceDeliveryService.list(
-                            new QueryWrapper<TBDeviceDelivery>().lambda()
-                                    .eq(TBDeviceDelivery::getCrmNo, tfCustomFlowEntity.getCrmNo())
-                                    .eq(TBDeviceDelivery::getEffect, true)
-                                    .in(TBDeviceDelivery::getSerialNo, deviceSerialNoList));
-                    if (!CollectionUtils.isEmpty(tbDeviceDeliveryList)) {
-                        for (TBDeviceDelivery t : tbDeviceDeliveryList) {
-                            t.setStatus(DeviceDeliveryStatusEnum.RECEIVE);
-                            t.setReceiveTime(System.currentTimeMillis());
-                            t.setReceiveUserId(sysUser.getId());
-                            t.updateInfo(sysUser.getId());
-                        }
-                        tbDeviceDeliveryService.updateBatchById(tbDeviceDeliveryList);
-                    }
+                    tbDeviceDeliveryService.updateStatusBySop(flowTaskResultDeviceOut, tfCustomFlowEntity.getCrmNo(),
+                            DeviceDeliveryStatusEnum.RECEIVE, sysUser.getId());
                 } else if (tfFlowApprove.getSetup().intValue() == 7) {//校验收尾
                     FlowTaskResult flowTaskResult = this.getFormProperties(tfCustomFlowEntity, 2);
                     processLimitedTime = this.getProcessLimitedTime(flowTaskResult,
@@ -1227,10 +1202,6 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
                 .eq(TFFlowApprove::getFlowId, tfCustomFlowEntity.getFlowId()));
         Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
 
-        //        if (tfFlowApprove.getStatus() == FlowStatusEnum.FINISH || tfFlowApprove.getStatus() == FlowStatusEnum.END) {
-        //            throw ExceptionResultEnum.ERROR.exception("已结束的流程不允许修改");
-        //        }
-
         TFCustomFlow tfCustomFlow = tfCustomFlowService.getById(tfCustomFlowEntity.gettFCustomFlowId());
         Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_CUSTOM_NO_DATA.exception());
 
@@ -1273,6 +1244,21 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
             map.put(SystemConstant.SOURCE, "save");
             tbSopInfoService.saveJobRemind(map);
 
+            if (tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
+                    && tfFlowApprove.getSetup().intValue() == 4) {
+                tbSopInfoService.sopDeviceInOutSave(map, 4);
+            }
+
+            if (tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
+                    && tfFlowApprove.getSetup().intValue() > 4) {
+                FlowTaskResult flowTaskResultDeviceOut = this.getFormProperties(tfCustomFlowEntity, 4);
+                tbDeviceDeliveryService.updateStatusBySop(flowTaskResultDeviceOut, tfCustomFlowEntity.getCrmNo(),
+                        DeviceDeliveryStatusEnum.RECEIVE, sysUser.getId());
+            } else if (tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
+                    && tfFlowApprove.getSetup().intValue() == 4) {
+                tbSopInfoService.sopDeviceInOutSave(map, 4);
+            }
+
             FlowTaskResult flowTaskResult = this.getFormProperties(tfCustomFlowEntity, 1);
             tbSopInfoService.saveSopPlanDate(flowTaskResult, tbSopInfo.getId(), tfCustomFlowEntity.getFlowId(),
                     sysUser.getId());
@@ -1303,6 +1289,7 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
      * @param setup
      * @return
      */
+    @Override
     public FlowTaskResult getFormProperties(TFCustomFlowEntity tfCustomFlowEntity, Integer setup) {
         FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
         LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();