Explorar el Código

新增sop表单编辑

wangliang hace 1 año
padre
commit
8bd2c1ecca

+ 67 - 2
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -67,6 +67,9 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
     @Resource
     TSJobRemindService tsJobRemindService;
 
+    @Resource
+    TFFlowApproveService tfFlowApproveService;
+
     /**
      * 查询动态sop表名是否存在
      *
@@ -582,7 +585,32 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
         TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, tbSopInfo.getSopNo()));
         Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
 
-        return JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
+        TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().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("已结束的流程不允许修改");
+        }
+
+        FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
+        LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
+        FlowTaskResult flowTaskResult = null;
+        String key = null;
+        for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
+            if (entry.getValue().getSetup().intValue() == 1) {
+                flowTaskResult = entry.getValue();
+                key = entry.getKey();
+                break;
+            }
+        }
+        List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResult.getFormProperty();
+        for (FlowFormWidgetResult f : flowFormWidgetResultList) {
+            f.setReadable(true);
+            f.setWritable(false);
+        }
+        setupMap.put(key, flowTaskResult);
+        flowResult.setSetupMap(setupMap);
+        return flowResult;
     }
 
     /**
@@ -600,9 +628,46 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
         TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, tbSopInfo.getSopNo()));
         Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
 
+        TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().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());
+
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        FlowResult flowResultParam = JSONObject.parseObject(sopSaveParam.getFormProperties(), FlowResult.class);
+        LinkedHashMap<String, FlowTaskResult> setupParamMap = flowResultParam.getSetupMap();
+        String removeKey = null;
+        for (Map.Entry<String, FlowTaskResult> entry : setupParamMap.entrySet()) {
+            if (entry.getValue().getSetup().intValue() == 1) {
+                removeKey = entry.getKey();
+                break;
+            }
+        }
+        if (Objects.nonNull(removeKey)) {
+            setupParamMap.remove(removeKey);
+        }
+
+        FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
+        LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
+        FlowTaskResult flowTaskResult = null;
+        for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
+            if (entry.getValue().getSetup().intValue() == 1) {
+                flowTaskResult = entry.getValue();
+                //更新动态表单字段和处理时限
+                tbSopInfoService.saveDynamicSop(tfCustomFlow, tfCustomFlowEntity.getCode(), tfCustomFlowEntity.getFlowId(), entry.getValue());
+            }
+        }
+        if (Objects.nonNull(flowTaskResult)) {
+            setupParamMap.put(removeKey, flowTaskResult);
+        }
+        flowResultParam.setSetupMap(setupParamMap);
         tfCustomFlowEntity.updateInfo(sysUser.getId());
-        tfCustomFlowEntity.setFlowProcessVar(sopSaveParam.getFormProperties());
+        tfCustomFlowEntity.setFlowProcessVar(JacksonUtil.parseJson(flowResultParam));
         return tfCustomFlowEntityService.updateById(tfCustomFlowEntity);
     }