Quellcode durchsuchen

sop动态表增删改

wangliang vor 1 Jahr
Ursprung
Commit
cdb587391e

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 2
sop-business/src/main/java/com/qmth/sop/business/activiti/listener/ProcessEventListener.java


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

@@ -319,7 +319,7 @@ public class ActivitiServiceImpl implements ActivitiService {
                     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);
+                            tbSopInfoService.saveDynamicSop(tfCustomFlow, tfCustomFlowEntity.getCode(), Long.parseLong(processFlowId), formDataFlowTaskResult);
                         }
                     }
                     flowResult.setSetupMap(setupMap);

+ 2 - 2
sop-business/src/main/java/com/qmth/sop/business/exec/MySQLExec.java

@@ -93,11 +93,11 @@ public class MySQLExec {
                     if (t.getCode() == WidgetCodeEnum.TABLE) {
                         stringJoiner.add("`" + t.getFieldId() + "`" + " mediumtext CHARACTER SET utf8mb4 COMMENT '" + t.getFieldTitle() + "'");
                     } else if (t.getCode() == WidgetCodeEnum.TEXTAREA) {
-                        stringJoiner.add("`" + t.getFieldId() + "`" + " varchar(500) NOT NULL COMMENT '" + t.getFieldTitle() + "'");
+                        stringJoiner.add("`" + t.getFieldId() + "`" + " varchar(500) DEFAULT NULL COMMENT '" + t.getFieldTitle() + "'");
                     } else if (t.getCode() == WidgetCodeEnum.NUMBER) {
                         stringJoiner.add("`" + t.getFieldId() + "`" + " int DEFAULT NULL COMMENT '" + t.getFieldTitle() + "'");
                     } else {
-                        stringJoiner.add("`" + t.getFieldId() + "`" + " varchar(100) NOT NULL COMMENT '" + t.getFieldTitle() + "'");
+                        stringJoiner.add("`" + t.getFieldId() + "`" + " varchar(100) DEFAULT NULL COMMENT '" + t.getFieldTitle() + "'");
                     }
                 }
                 string = string.replaceAll("\\#\\{dynamicTable\\}", "`" + tableName + "`");

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

@@ -30,24 +30,22 @@ public interface TBSopInfoMapper extends BaseMapper<TBSopInfo> {
      * 保存动态sop信息
      *
      * @param tableName
-     * @param flowDeploymentId
-     * @param flowId
      * @param fieldName
      * @param fieldValue
      * @return
      */
-    Boolean saveDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId, @Param("fieldName") String fieldName, @Param("fieldValue") List<Map> fieldValue);
+    Boolean saveDynamicSop(@Param("tableName") String tableName, @Param("fieldName") String fieldName, @Param("fieldValue") String fieldValue);
 
     /**
      * 更新动态sop信息
      *
      * @param tableName
+     * @param flowDeploymentId
      * @param flowId
-     * @param fieldName
      * @param fieldValue
      * @return
      */
-    Boolean updateDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId, @Param("fieldName") String fieldName, @Param("fieldValue") List<Map> fieldValue);
+    Boolean updateDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId, @Param("fieldValue") String fieldValue);
 
     /**
      * 查询动态sop数据
@@ -55,8 +53,15 @@ public interface TBSopInfoMapper extends BaseMapper<TBSopInfo> {
      * @param tableName
      * @param flowDeploymentId
      * @param flowId
-     * @param fieldName
      * @return
      */
-    List<Map> selectDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId, @Param("fieldName") String fieldName);
+    int selectDynamicSop(@Param("tableName") String tableName, @Param("flowDeploymentId") String flowDeploymentId, @Param("flowId") Long flowId);
+
+    /**
+     * 查询所有列
+     *
+     * @param tableName
+     * @return
+     */
+    List<Map<String, String>> selectDynamicSopAll(@Param("tableName") String tableName);
 }

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

@@ -5,9 +5,6 @@ import com.qmth.sop.business.bean.result.FlowTaskResult;
 import com.qmth.sop.business.entity.TBSopInfo;
 import com.qmth.sop.business.entity.TFCustomFlow;
 
-import java.util.List;
-import java.util.Map;
-
 /**
  * <p>
  * sop表 服务类
@@ -31,11 +28,12 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * 保存动态sop信息
      *
      * @param tfCustomFlow
+     * @param code
      * @param flowId
      * @param flowTaskResult
      * @return
      */
-    Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, Long flowId, FlowTaskResult flowTaskResult);
+    Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, String code, Long flowId, FlowTaskResult flowTaskResult);
 
     /**
      * 查询动态sop数据
@@ -43,8 +41,7 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      * @param tableName
      * @param flowDeploymentId
      * @param flowId
-     * @param fieldName
      * @return
      */
-    List<Map> selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName);
+    int selectDynamicSop(String tableName, String flowDeploymentId, Long flowId);
 }

+ 62 - 15
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -7,7 +7,9 @@ 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.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.WidgetCodeEnum;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -45,36 +47,82 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
      * 保存动态sop信息
      *
      * @param tfCustomFlow
+     * @param code
      * @param flowId
      * @param flowTaskResult
      * @return
      */
     @Override
     @Transactional
-    public Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, Long flowId, FlowTaskResult flowTaskResult) {
+    public Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, String code, 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(",");
+        Map<String, String> formFieldMap = new HashMap<>(flowFormWidgetResultList.size());
         for (FlowFormWidgetResult f : flowFormWidgetResultList) {
             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());
+                if (Objects.nonNull(f.getValue()) && f.getValue().startsWith("[") && f.getValue().endsWith("]")) {
+                    f.setValue(f.getValue().replaceAll("\\[", "").replaceAll("\\]", ""));
+                    formFieldMap.put(f.getFormId(), StringUtils.join(Arrays.asList(f.getValue()), SystemConstant.LIST_JOIN_SPLIT));
+                } else {
+                    formFieldMap.put(f.getFormId(), f.getValue());
+                }
+                formFieldMap.put(f.getFormId(), f.getValue());
             }
         }
         //首先查询动态表里是否有当前表单的数据,没有插入,有则更新
-        List<Map> list = this.selectDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId, stringJoiner.toString());
-        if (CollectionUtils.isEmpty(list)) {//插入操作
-//            tbSopInfoMapper.saveDynamicSop();
+        int count = this.selectDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId);
+        if (count == 0) {//插入操作
+            //查询所有列
+            List<Map<String, String>> dynamicFieldList = this.baseMapper.selectDynamicSopAll(tableName);
+            Map<String, Object> map = new LinkedHashMap<>();
+            if (!CollectionUtils.isEmpty(dynamicFieldList)) {
+                StringJoiner stringJoinerFieldName = new StringJoiner(",");
+                StringJoiner stringJoinerFieldValue = new StringJoiner(",");
+                for (Map<String, String> m : dynamicFieldList) {
+                    for (Map.Entry<String, String> entry : m.entrySet()) {
+                        switch (entry.getValue()) {
+                            case SystemConstant.TYPE:
+                                map.put(entry.getValue(), tfCustomFlow.getType());
+                                break;
+                            case SystemConstant.FLOW_DEPLOYMENT_ID_FIELD:
+                                map.put(entry.getValue(), tfCustomFlow.getFlowDeploymentId());
+                                break;
+                            case SystemConstant.VERSION:
+                                map.put(entry.getValue(), tfCustomFlow.getVersion());
+                                break;
+                            case SystemConstant.CODE:
+                                map.put(entry.getValue(), code);
+                                break;
+                            case SystemConstant.FLOW_ID:
+                                map.put(entry.getValue(), flowId);
+                                break;
+                            default:
+                                if (formFieldMap.containsKey(entry.getValue())) {
+                                    map.put(entry.getValue(), formFieldMap.get(entry.getValue()));
+                                } else {
+                                    map.put(entry.getValue(), null);
+                                }
+                                break;
+                        }
+                    }
+                }
+                for (Map.Entry<String, Object> entry : map.entrySet()) {
+                    stringJoinerFieldName.add(entry.getKey());
+                    stringJoinerFieldValue.add(Objects.nonNull(entry.getValue()) ? "'" + entry.getValue().toString() + "'" : null);
+                }
+                tbSopInfoMapper.saveDynamicSop(tableName, stringJoinerFieldName.toString(), stringJoinerFieldValue.toString());
+            }
         } else {//否则更新
-//            tbSopInfoMapper.updateDynamicSop();
+            StringJoiner stringJoinerFieldValue = new StringJoiner(",");
+            for (Map.Entry<String, String> entry : formFieldMap.entrySet()) {
+                stringJoinerFieldValue.add(entry.getKey() + "='" + entry.getValue() + "'");
+            }
+            tbSopInfoMapper.updateDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId, stringJoinerFieldValue.toString());
         }
-        return null;
+        return true;
     }
 
     /**
@@ -83,11 +131,10 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
      * @param tableName
      * @param flowDeploymentId
      * @param flowId
-     * @param fieldName
      * @return
      */
     @Override
-    public List<Map> selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName) {
-        return this.baseMapper.selectDynamicSop(tableName, flowDeploymentId, flowId, fieldName);
+    public int selectDynamicSop(String tableName, String flowDeploymentId, Long flowId) {
+        return this.baseMapper.selectDynamicSop(tableName, flowDeploymentId, flowId);
     }
 }

+ 1 - 0
sop-business/src/main/resources/db/dynamic_create_sop_table.sql

@@ -4,6 +4,7 @@ DROP TABLE IF EXISTS #{dynamicTable};
 CREATE TABLE #{dynamicTable} (
          `type` varchar(20) NOT NULL COMMENT '流程类型,OFFICE_SOP_FLOW:教务处SOP,CLOUD_MARK_SOP_FLOW:研究生SOP,DING_EXCEPTION_FLOW:考勤异常审核流程,PROJECT_EXCHANGE_FLOW:项目计划变更流程,QUALITY_PROBLEM_FLOW:质量问题反馈流程',
          `flow_deployment_id` VARCHAR(50) NOT NULL COMMENT '流程部署id',
+         `version` int NOT NULL DEFAULT '1' COMMENT '版本号',
          `code` VARCHAR(30) DEFAULT NULL COMMENT '流程编号',
          `flow_id` bigint DEFAULT NULL COMMENT '流程id',
          #{dynamicFields}

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

@@ -7,15 +7,26 @@
     </select>
 
     <insert id="saveDynamicSop">
-
+        INSERT INTO ${tableName}
+        (${fieldName})
+        VALUES(${fieldValue})
     </insert>
 
     <update id="updateDynamicSop">
-
+        update ${tableName}
+        set ${fieldValue}
+        <where> 1 = 1
+            <if test="flowDeploymentId != null and flowDeploymentId != ''">
+                and flow_deployment_id = #{flowDeploymentId}
+            </if>
+            <if test="flowId != null and flowId != ''">
+                and flow_id = #{flowId}
+            </if>
+        </where>
     </update>
 
-    <select id="selectDynamicSop" resultType="java.util.Map">
-        select ${fieldName} from ${tableName}
+    <select id="selectDynamicSop" resultType="java.lang.Integer">
+        select count(1) from ${tableName}
         <where> 1 = 1
             <if test="flowDeploymentId != null and flowDeploymentId != ''">
                 and flow_deployment_id = #{flowDeploymentId}
@@ -25,4 +36,8 @@
             </if>
         </where>
     </select>
+
+    <select id="selectDynamicSopAll" resultType="java.util.Map">
+        SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=#{tableName}
+    </select>
 </mapper>

+ 4 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -99,6 +99,10 @@ public class SystemConstant {
     public static final String LIST_JOIN_SPLIT = ",";
     public static final String JOB_DATA = "jobData";
     public static final String SOP_DYNAMIC_TABLE_FILE_NAME = "db/dynamic_create_sop_table.sql";
+    public static final String FLOW_DEPLOYMENT_ID_FIELD = "flow_deployment_id";
+    public static final String VERSION = "version";
+    public static final String CODE = "code";
+    public static final String FLOW_ID = "flow_id";
 
     /**
      * 表达式

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.