Browse Source

动态增加sop增删改

wangliang 1 year ago
parent
commit
70bdc0b75e

+ 3 - 0
sop-business/src/main/java/com/qmth/sop/business/activiti/service/impl/ActivitiServiceImpl.java

@@ -318,6 +318,9 @@ public class ActivitiServiceImpl implements ActivitiService {
                     map.put(SystemConstant.APPROVE, nextFlowTaskResult.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, Long.parseLong(processFlowId), formDataFlowTaskResult);
+                        }
                     }
                     flowResult.setSetupMap(setupMap);
                     tfCustomFlowEntity.setFlowProcessVar(JacksonUtil.parseJson(flowResult));

+ 0 - 12
sop-business/src/main/java/com/qmth/sop/business/bean/result/FlowFormWidgetResult.java

@@ -28,10 +28,6 @@ public class FlowFormWidgetResult implements Serializable {
     @TableId(value = "id")
     private Long id;
 
-    @ApiModelProperty(value = "父id")
-    @JsonSerialize(using = ToStringSerializer.class)
-    private Long parentId;
-
     @ApiModelProperty(value = "编码,TEXT:文本,TEXTAREA:文本域,SELECT:下拉框,RADIO:单选框,CHECKBOX:复选框,DATE:日期,BUTTON:按钮,IMG:图片,VIDEO:视频,AUDIO:音频,FILE:文件,POP_SELECT:弹出选择框,LABEL:标签,TABLE:表格,OTHER:其它")
     private WidgetCodeEnum code;
 
@@ -166,14 +162,6 @@ public class FlowFormWidgetResult implements Serializable {
         this.id = id;
     }
 
-    public Long getParentId() {
-        return parentId;
-    }
-
-    public void setParentId(Long parentId) {
-        this.parentId = parentId;
-    }
-
     public WidgetCodeEnum getCode() {
         return code;
     }

+ 1 - 1
sop-business/src/main/java/com/qmth/sop/business/mapper/TBSopInfoMapper.java

@@ -58,5 +58,5 @@ public interface TBSopInfoMapper extends BaseMapper<TBSopInfo> {
      * @param fieldName
      * @return
      */
-    int selectDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId, String fieldName);
+    List<Map> selectDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId, @Param("fieldName") String fieldName);
 }

+ 7 - 4
sop-business/src/main/java/com/qmth/sop/business/service/TBSopInfoService.java

@@ -3,7 +3,10 @@ package com.qmth.sop.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.result.FlowTaskResult;
 import com.qmth.sop.business.entity.TBSopInfo;
-import com.qmth.sop.common.enums.TFCustomTypeEnum;
+import com.qmth.sop.business.entity.TFCustomFlow;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -27,12 +30,12 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
     /**
      * 保存动态sop信息
      *
-     * @param type
+     * @param tfCustomFlow
      * @param flowId
      * @param flowTaskResult
      * @return
      */
-    Boolean saveDynamicSop(TFCustomTypeEnum type, Long flowId, FlowTaskResult flowTaskResult);
+    Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, Long flowId, FlowTaskResult flowTaskResult);
 
     /**
      * 查询动态sop数据
@@ -43,5 +46,5 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * @param fieldName
      * @return
      */
-    int selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName);
+    List<Map> selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName);
 }

+ 26 - 17
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -1,6 +1,5 @@
 package com.qmth.sop.business.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
 import com.qmth.sop.business.bean.result.FlowTaskResult;
@@ -8,10 +7,10 @@ import com.qmth.sop.business.entity.TBSopInfo;
 import com.qmth.sop.business.entity.TFCustomFlow;
 import com.qmth.sop.business.mapper.TBSopInfoMapper;
 import com.qmth.sop.business.service.TBSopInfoService;
-import com.qmth.sop.business.service.TFCustomFlowService;
-import com.qmth.sop.common.enums.ExceptionResultEnum;
-import com.qmth.sop.common.enums.TFCustomTypeEnum;
+import com.qmth.sop.common.enums.WidgetCodeEnum;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -28,7 +27,7 @@ import java.util.*;
 public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo> implements TBSopInfoService {
 
     @Resource
-    TFCustomFlowService tfCustomFlowService;
+    TBSopInfoMapper tbSopInfoMapper;
 
     /**
      * 查询动态sop表名是否存在
@@ -45,26 +44,36 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
     /**
      * 保存动态sop信息
      *
-     * @param type
+     * @param tfCustomFlow
      * @param flowId
      * @param flowTaskResult
      * @return
      */
     @Override
-    public Boolean saveDynamicSop(TFCustomTypeEnum type, Long flowId, FlowTaskResult flowTaskResult) {
-        TFCustomFlow tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getType, type));
-        Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.FLOW_CUSTOM_NO_DATA.exception());
-
-        String tableName = type.getTableName() + "_" + tfCustomFlow.getVersion();
+    @Transactional
+    public Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, Long flowId, FlowTaskResult flowTaskResult) {
+        String tableName = tfCustomFlow.getType().getTableName() + "_" + tfCustomFlow.getVersion();
         List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResult.getFormProperty();
         List<Map<String, String>> fieldValue = new ArrayList<>(flowFormWidgetResultList.size());
+        StringJoiner stringJoiner = new StringJoiner(",");
         for (FlowFormWidgetResult f : flowFormWidgetResultList) {
-            Map<String, String> map = new LinkedHashMap<>();
-            map.put(f.getFormId(), f.getValue());
-            fieldValue.add(map);
+            if (f.getCode() != WidgetCodeEnum.FORM_GROUP_TITLE && f.getCode() != WidgetCodeEnum.ONLE_TITLE
+                    && f.getCode() != WidgetCodeEnum.BUTTON && f.getCode() != WidgetCodeEnum.IMG
+                    && f.getCode() != WidgetCodeEnum.LABEL && f.getCode() != WidgetCodeEnum.SIGN
+                    && f.getCode() != WidgetCodeEnum.OTHER) {
+                Map<String, String> map = new LinkedHashMap<>();
+                map.put(f.getFormId(), f.getValue());
+                fieldValue.add(map);
+                stringJoiner.add(f.getFormId());
+            }
         }
-
         //首先查询动态表里是否有当前表单的数据,没有插入,有则更新
+        List<Map> list = this.selectDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId, stringJoiner.toString());
+        if (CollectionUtils.isEmpty(list)) {//插入操作
+//            tbSopInfoMapper.saveDynamicSop();
+        } else {//否则更新
+//            tbSopInfoMapper.updateDynamicSop();
+        }
         return null;
     }
 
@@ -78,7 +87,7 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
      * @return
      */
     @Override
-    public int selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName) {
-        return 0;
+    public List<Map> selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName) {
+        return this.baseMapper.selectDynamicSop(tableName, flowDeploymentId, flowId, fieldName);
     }
 }

+ 2 - 2
sop-business/src/main/resources/mapper/TBSopInfoMapper.xml

@@ -14,8 +14,8 @@
 
     </update>
 
-    <select id="selectDynamicSop" resultType="java.lang.Integer">
-        select #{fieldName} from #{tableName}
+    <select id="selectDynamicSop" resultType="java.util.Map">
+        select ${fieldName} from ${tableName}
         <where> 1 = 1
             <if test="flowDeploymentId != null and flowDeploymentId != ''">
                 and flow_deployment_id = #{flowDeploymentId}