Explorar o código

添加回调接口,流程审核后需要调用业务接口
微信模块添加功能

zh %!s(int64=4) %!d(string=hai) anos
pai
achega
a0cc2c528b

+ 12 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/JFlowTaskController.java

@@ -3,6 +3,7 @@ package com.boman.web.core.controller;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.TaskDto;
+import com.boman.domain.dto.UpdateDto;
 import com.boman.web.core.service.jflow.JFlowTaskService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -57,4 +58,15 @@ public class JFlowTaskController {
     public AjaxResult pageDetail(@RequestBody TaskDto taskDto) {
         return jFlowTaskService.pageDetail(taskDto);
     }
+
+    /**
+     * 功能描述: 根据表名更改commitData, 条件condition
+     *
+     * @param dto dto tableName commitData condition
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @PostMapping("/updateBusinessData")
+    public AjaxResult updateBusinessData(@RequestBody UpdateDto dto) {
+        return AjaxResult.success(jFlowTaskService.updateBusinessData(dto));
+    }
 }

+ 104 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/JFTaskBusinessMapper.java

@@ -2,7 +2,10 @@ package com.boman.web.core.mapper;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.domain.dto.UpdateDto;
 import com.boman.domain.jflow.ProcessNodeCandidator;
+import com.boman.web.core.utils.ColumnUtils;
+import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.*;
 import org.slf4j.Logger;
@@ -12,6 +15,9 @@ import org.springframework.stereotype.Component;
 import java.util.List;
 import java.util.Map;
 
+import static com.boman.common.core.utils.obj.ObjectUtils.escapeStr;
+import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
+import static com.boman.domain.constant.FormDataConstant.*;
 import static com.mysql.cj.util.StringUtils.isNullOrEmpty;
 
 /**
@@ -36,6 +42,10 @@ public interface JFTaskBusinessMapper {
     @Select("select * from process_node_candidators t where t.business_code = #{businessCode} and t.module_id = #{moduleId} and t.node_id = #{nodeId}")
     ProcessNodeCandidator selectData(@Param("businessCode") Long businessCode, @Param("moduleId") Long moduleId, @Param("nodeId") Long nodeId);
 
+    @UpdateProvider(type = SqlProvider.class, method = "updateBusinessData")
+    int updateBusinessData(@Param("tableName") String tableName, @Param("packCommitData") JSONObject packCommitData
+            , @Param("packColCondition") JSONObject packColCondition);
+
     class SqlProvider {
 
         public String insertList(Map<String, Object> para) {
@@ -98,5 +108,99 @@ public interface JFTaskBusinessMapper {
             LOGGER.info("批量更新的sql语句为: {} \r\n 更改的数据为: {} \r\n idList: {}", sqlStr, models, idList);
             return sqlStr;
         }
+
+        public String updateBusinessData(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            JSONObject packCommitData = (JSONObject) para.get("packCommitData");
+            JSONObject packColCondition = (JSONObject) para.get("packColCondition");
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("update ").append(tableName).append(" set ");
+
+            for (Map.Entry<String, Object> entry : packCommitData.entrySet()) {
+                String key = entry.getKey();
+                Object valueObj = entry.getValue();
+                List<String> types = ((List<String>) valueObj);
+                /** {@link com.boman.web.core.utils.ColumnUtils.packColCondition} 这里是拼参数的地方 **/
+                Object value = types.get(0);
+                String queryType = types.get(1);
+                String columnType = types.get(2);
+                wholeSql.append(key).append(covert(queryType, columnType, key, value)).append(" , ");
+            }
+
+            wholeSql = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), " , "));
+            packCondition(packColCondition, wholeSql);
+
+            String sqlStr = wholeSql.toString();
+            LOGGER.info("通用的更新sql语句为: {} \r\n 提交的数据为: {} \r\n 条件为: {}", sqlStr, packCommitData, packColCondition);
+            return sqlStr;
+        }
+
+        /**
+         * 功能描述: 判断传过来的值是否需要转义
+         *
+         * @param packCondition 封装的条件
+         * @param wholeSql      sql
+         */
+        private void packCondition(JSONObject packCondition, StringBuilder wholeSql) {
+            if (isEmpty(packCondition)) {
+                return;
+            }
+
+            wholeSql.append(" where ");
+            StringBuilder conditionSql = new StringBuilder();
+            for (Map.Entry<String, Object> entry : packCondition.entrySet()) {
+                String key = entry.getKey();
+                Object valueObj = entry.getValue();
+                List<String> types = ((List<String>) valueObj);
+                /** {@link com.boman.web.core.utils.ColumnUtils.packColCondition} 这里是拼参数的地方 **/
+                Object value = types.get(0);
+
+                conditionSql.append(key).append(covert(EQ, "NUMBER", key, value)).append(" and ");
+            }
+
+            wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
+        }
+
+        /**
+         * 功能描述: 仅此用来拼装查询条件,不做他用
+         *
+         * @param queryType  like > < =
+         * @param columnType varchar char textarea timestamp
+         * @param key        key
+         * @param valueObj   valueObj
+         * @return java.lang.String
+         */
+        private String covert(String queryType, String columnType, String key, Object valueObj) {
+            // false 不需要转义
+            boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR) || columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
+            Object value;
+            switch (queryType) {
+                case EQ:
+                    value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                    return " = " + value;
+                case LIKE:
+                    return " like concat('%', #{condition." + key + "}, '%')";
+                case NE:
+                    value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                    return " != " + value;
+                case GT:
+                    value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                    return " > " + value;
+                case GTE:
+                    value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                    return " >= " + value;
+                case LT:
+                    value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                    return " < " + value;
+                case LTE:
+                    value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                    return " <= " + value;
+                default:
+                    // in
+                    List<Object> list = valueObj instanceof List ? ((List<Object>) valueObj) : Lists.newArrayList(valueObj);
+                    return " in (" + ColumnUtils.joinList(list) + ")";
+            }
+        }
     }
 }

+ 2 - 0
boman-web-core/src/main/java/com/boman/web/core/service/jflow/JFlowTaskService.java

@@ -3,6 +3,7 @@ package com.boman.web.core.service.jflow;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.TaskDto;
+import com.boman.domain.dto.UpdateDto;
 
 public interface JFlowTaskService {
     AjaxResult historyLoad(TaskDto taskDto);
@@ -11,4 +12,5 @@ public interface JFlowTaskService {
     AjaxResult pageDeny(TaskDto taskDto);
     JSONObject approvalStatistics(TaskDto taskDto);
     AjaxResult pageDetail(TaskDto taskDto);
+    int updateBusinessData(UpdateDto dto);
 }

+ 16 - 0
boman-web-core/src/main/java/com/boman/web/core/service/jflow/impl/JFlowTaskServiceImpl.java

@@ -3,16 +3,23 @@ package com.boman.web.core.service.jflow.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.TaskDto;
+import com.boman.domain.dto.UpdateDto;
 import com.boman.jflow.api.RemoteJflowTaskService;
+import com.boman.web.core.mapper.JFTaskBusinessMapper;
 import com.boman.web.core.service.jflow.JFlowTaskService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+
 @Service
 public class JFlowTaskServiceImpl implements JFlowTaskService {
 
     @Autowired
     private RemoteJflowTaskService remoteJflowTaskService;
+    @Autowired
+    private JFTaskBusinessMapper jfTaskBusinessMapper;
+
 
     @Override
     public AjaxResult historyLoad(TaskDto taskDto) {
@@ -43,4 +50,13 @@ public class JFlowTaskServiceImpl implements JFlowTaskService {
     public AjaxResult pageDetail(TaskDto taskDto) {
         return remoteJflowTaskService.pageDetail(taskDto);
     }
+
+    @Override
+    public int updateBusinessData(UpdateDto dto) {
+        String tableName = requireNonNull(dto.getTableName(), "tableName is empty");
+        JSONObject condition = requireNonNull(dto.getCondition(), "condition is empty, 条件为空不允许调用修改接口,防止误操作");
+        JSONObject commitData = requireNonNull(dto.getCommitData(), "commitData is empty");
+
+        return jfTaskBusinessMapper.updateBusinessData(tableName, commitData, condition);
+    }
 }

+ 17 - 0
boman-wechat/pom.xml

@@ -102,4 +102,21 @@
             <version>2.5.0-SNAPSHOT</version>
         </dependency>
     </dependencies>
+
+    <build>
+        <finalName>${project.artifactId}</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>

+ 2 - 2
boman-wechat/src/main/resources/bootstrap-prod.yml

@@ -1,7 +1,7 @@
 server:
-  port: 7000
+  port: 8093
 
-spring: 
+spring:
   application:
     name: boman-wechat
   profiles:

+ 1 - 1
boman-wechat/src/main/resources/logback.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <configuration scan="true" scanPeriod="60 seconds" debug="false">
     <!-- 日志存放路径 -->
-	<property name="log.path" value="logs/boman-web-core" />
+	<property name="log.path" value="logs/boman-wechat" />
    <!-- 日志输出格式 -->
 	<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />