Browse Source

feat:新增流程节点时创建数据表

xuezizhuo 1 year ago
parent
commit
c186f29751

+ 5 - 3
ruoyi-admin/src/main/resources/application.yml

@@ -87,13 +87,13 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: 192.168.110.15
+    host: localhost
     # 端口,默认为6379
     port: 6379
     # 数据库索引
     database: 0
     # 密码
-    password:
+    password: 123456
     # 连接超时时间
     timeout: 10s
     lettuce:
@@ -175,4 +175,6 @@ parameter:
     # form项目根据表单Fid查询详情接口
     FORM_GET_FORM_INFO_IP: http://localhost:8088/dragform/form/{fId}
     # from项目根据groupKey查询表格组信息
-    FORM_GET_GROUP_INFO_IP: http://localhost:8088/system/group/getInfoBySqlKey/{groupKey}
+    FORM_GET_GROUP_INFO_IP: http://localhost:8088/system/group/getInfoBySqlKey/{groupKey}
+    # CRM项目获取所有模板库数据表
+    CRM_QUERY_TEMPLATEBASE_TABLE: http://localhost:8080/system/templateBase/queryTemplateBaseTable

+ 12 - 1
ruoyi-common/src/main/java/com/ruoyi/common/config/bpm/BpmProperties.java

@@ -46,9 +46,12 @@ public class BpmProperties {
     //form项目根据表单Fid查询详情接口
     @Value("${parameter.ip.FORM_GET_FORM_INFO_IP}")
     public String formGetFormInfoIp;
-
+    //from项目根据groupKey查询表格组信息
     @Value("${parameter.ip.FORM_GET_GROUP_INFO_IP}")
     public String formGetGroupInfoIp;
+    //CRM项目获取所有模板库数据表信息
+    @Value("${parameter.ip.CRM_QUERY_TEMPLATEBASE_TABLE}")
+    public String crmQueryTemplateBaseTableIp;
 
 
     public String getGetTenantDictValIp() {
@@ -146,4 +149,12 @@ public class BpmProperties {
     public void setFormGetGroupInfoIp(String formGetGroupInfoIp) {
         this.formGetGroupInfoIp = formGetGroupInfoIp;
     }
+
+    public String getCrmQueryTemplateBaseTableIp() {
+        return crmQueryTemplateBaseTableIp;
+    }
+
+    public void setCrmQueryTemplateBaseTableIp(String crmQueryTemplateBaseTableIp) {
+        this.crmQueryTemplateBaseTableIp = crmQueryTemplateBaseTableIp;
+    }
 }

+ 19 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/Sending.java

@@ -190,4 +190,23 @@ public class Sending<T> {
     public ResponseEntity sendGetGroupInfo(T param) {
         return this.sendCommonGetParams(bpmProperties.getFormGetGroupInfoIp(),param);
     }
+
+    /**
+     * 获取模板库数据表信息接口
+     */
+    public ResponseEntity sendQueryTemplateBaseTable(){
+        // 得到当前用户的token  下发流程请求需要携带
+        String token = SecurityUtils.getLoginUser().getToken();
+        // 设置请求头
+        HttpHeaders headers = new HttpHeaders();
+        headers.set("Authorization", "XIAFA" + token);
+        HttpEntity request = new HttpEntity(headers);
+        ResponseEntity<AjaxResult> response = restTemplate.exchange(
+                bpmProperties.crmQueryTemplateBaseTableIp,
+                HttpMethod.GET,
+                request,
+                AjaxResult.class
+        );;
+        return response;
+    }
 }

+ 12 - 1
ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/NodeVo.java

@@ -17,9 +17,12 @@ public class NodeVo {
     private List<BpmNodeScriptRelevance> bpmNodeScriptRelevanceList;
     // 节点执行用户关系表
     private List<BpmNodeHandleUser> bpmNodeHandleUserList;
-    //  需要删除的节点id
+    // 需要删除的节点id
     private Long[] removeNodeIds;
 
+    // 所有节点绑定的数据表
+    private List<String> tableNameList;
+
     public Long[] getRemoveNodeIds() {
         return removeNodeIds;
     }
@@ -52,4 +55,12 @@ public class NodeVo {
     public void setBpmNodeHandleUserList(List<BpmNodeHandleUser> bpmNodeHandleUserList) {
         this.bpmNodeHandleUserList = bpmNodeHandleUserList;
     }
+
+    public List<String> getTableNameList() {
+        return tableNameList;
+    }
+
+    public void setTableNameList(List<String> tableNameList) {
+        this.tableNameList = tableNameList;
+    }
 }

+ 15 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/CommonMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.mapper;
 
 import com.ruoyi.system.entity.CommonEntity;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -60,4 +61,18 @@ public interface CommonMapper {
      */
     List<Map<String,Object>> selectDropDownListByDict(String dictType);
 
+    /**
+     * 查询模板库建表语句
+     * @param tableName 表名
+     * @return
+     */
+    Map<String, String> selectTableSql(@Param("tableName") String tableName);
+
+    /**
+     * 执行sql
+     * @param sql sql语句
+     * @return
+     */
+    void executeSql(String sql);
+
 }

+ 11 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java

@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
 
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.TableSql;
+import org.apache.ibatis.annotations.Param;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
@@ -50,4 +51,14 @@ public interface ICommonService {
      */
     List<CommonEntity> dragTablePreview(CommonEntity commonEntity);
 
+    /**
+     * 查询模板库建表语句
+     */
+    Map<String, String> selectTableSql(String tableName);
+
+    /**
+     * 执行sql
+     */
+    void executeSql(String sql);
+
 }

+ 46 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BpmProcessConfigurationServiceImpl.java

@@ -4,15 +4,19 @@ import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.http.Sending;
 import com.ruoyi.system.entity.BpmNodeHandleUser;
 import com.ruoyi.system.entity.BpmNodeScriptRelevance;
 import com.ruoyi.system.entity.vo.NodeVo;
 import com.ruoyi.system.service.IBpmNodeHandleUserService;
 import com.ruoyi.system.service.IBpmNodeScriptRelevanceService;
+import com.ruoyi.system.service.ICommonService;
 import org.apache.ibatis.session.SqlSession;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.BpmProcessConfigurationMapper;
@@ -36,6 +40,12 @@ public class BpmProcessConfigurationServiceImpl implements IBpmProcessConfigurat
     @Autowired  // 节点执行脚本
     private IBpmNodeScriptRelevanceService iBpmNodeScriptRelevanceService;
 
+    @Autowired
+    private ICommonService commonService;
+
+    @Autowired
+    private Sending sending;
+
     /**
      * 查询流程配置
      *
@@ -106,6 +116,24 @@ public class BpmProcessConfigurationServiceImpl implements IBpmProcessConfigurat
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int insertBpmProcessNodeConfig(NodeVo nodeVo) {
+        // 下发获取当前所有数据表
+        ResponseEntity<AjaxResult> responseEntity = sending.sendQueryTemplateBaseTable();
+        if(responseEntity.getStatusCodeValue() != 200){
+            return 0;
+        }
+        AjaxResult ajaxResult = responseEntity.getBody();
+        List<String> tableNameList = (List<String>) ajaxResult.get("data");
+        nodeVo.getTableNameList().stream().filter(tableName -> !tableNameList.contains(tableName)).collect(Collectors.toList());
+        // 新建流程节点所需数据表
+        for (String tableName : nodeVo.getTableNameList()){
+            String createTableSql = commonService.selectTableSql(tableName).get("create table");
+            createTableSql = createTableSql.replace("CREATE TABLE","CREATE TABLE IF NOT EXISTS {DBNAME}.");
+            try {
+                commonService.executeSql(createTableSql);
+            }catch (Exception e){
+                return 0;
+            }
+        }
         // 新增节点配置
         if (nodeVo.getBpmProcessConfigurationList().size() != 0)
             nodeVo.getBpmProcessConfigurationList().stream().forEach(e -> {
@@ -126,6 +154,24 @@ public class BpmProcessConfigurationServiceImpl implements IBpmProcessConfigurat
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int updateBpmProcessNodeConfig(NodeVo nodeVo) {
+        // 下发获取当前所有数据表
+        ResponseEntity<AjaxResult> responseEntity = sending.sendQueryTemplateBaseTable();
+        if(responseEntity.getStatusCodeValue() != 200){
+            return 0;
+        }
+        AjaxResult ajaxResult = responseEntity.getBody();
+        List<String> tableNameList = (List<String>) ajaxResult.get("data");
+        nodeVo.getTableNameList().stream().filter(tableName -> !tableNameList.contains(tableName)).collect(Collectors.toList());
+        // 新建流程节点所需数据表
+        for (String tableName : nodeVo.getTableNameList()){
+            String createTableSql = commonService.selectTableSql(tableName).get("create table");
+            createTableSql = createTableSql.replace("CREATE TABLE","CREATE TABLE IF NOT EXISTS {DBNAME}.");
+            try {
+                commonService.executeSql(createTableSql);
+            }catch (Exception e){
+                return 0;
+            }
+        }
         // 修改节点配置
         if (nodeVo.getBpmProcessConfigurationList().size() != 0) {
             // 定义存储修改操作中新增节点,根据id为null来判断是否新增数据条

+ 10 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -243,6 +243,16 @@ public class CommonServiceImpl implements ICommonService {
         return commonMapper.queryTableList(sql);
     }
 
+    @Override
+    public Map<String, String> selectTableSql(String tableName) {
+        return commonMapper.selectTableSql(tableName);
+    }
+
+    @Override
+    public void executeSql(String sql) {
+        commonMapper.executeSql(sql);
+    }
+
     public static String extractSubstring(String input, String identifier) {
         int startIndex = input.indexOf(identifier);
         if (startIndex == -1) {

+ 8 - 0
ruoyi-system/src/main/resources/mapper/common/CommonMapper.xml

@@ -96,4 +96,12 @@
         select dict_value as fieldKey,dict_label as fieldName from sys_dict_data where dict_type = #{dictType} and status = '0'
     </select>
 
+    <select id="selectTableSql" resultType="map">
+        SHOW CREATE TABLE `zkqy-template`.`${tableName}`
+    </select>
+
+    <select id="executeSql">
+        ${sql}
+    </select>
+
 </mapper>