Gogs 4 лет назад
Родитель
Сommit
82caceb51d

+ 29 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/dto/FormDataDto.java

@@ -100,6 +100,11 @@ public class FormDataDto implements Serializable {
      */
     private String submitSource;
 
+    private String candidatorTableName;
+    
+    private Long moduleId;
+    private Long nodeId;
+
 
     public int getLimit() {
         try {
@@ -258,6 +263,30 @@ public class FormDataDto implements Serializable {
     public void setId(Long id) {
         this.id = id;
     }
+
+    public String getCandidatorTableName() {
+        return candidatorTableName;
+    }
+
+    public void setCandidatorTableName(String candidatorTableName) {
+        this.candidatorTableName = candidatorTableName;
+    }
+
+    public Long getModuleId() {
+        return moduleId;
+    }
+
+    public void setModuleId(Long moduleId) {
+        this.moduleId = moduleId;
+    }
+
+    public Long getNodeId() {
+        return nodeId;
+    }
+
+    public void setNodeId(Long nodeId) {
+        this.nodeId = nodeId;
+    }
 }
 
 

+ 7 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/dto/TaskDto.java

@@ -229,4 +229,11 @@ public class TaskDto extends BaseDto {
 
     /***/
     private String other;
+
+    /**
+     * 扩展节点审核人
+     */
+    private String candidatorId;
+
+    private String candidatorTableName;
 }

+ 63 - 0
boman-api/boman-domain/src/main/java/com/boman/domain/jflow/ProcessNodeCandidator.java

@@ -0,0 +1,63 @@
+package com.boman.domain.jflow;
+
+/**
+ * 节点审核人
+ *
+ * @author zhong.h
+ */
+public class ProcessNodeCandidator {
+
+    /**
+     * id
+     */
+    private Long id;
+
+    /** 业务数据id */
+    private Long businessCode;
+    /** 模板id */
+    private Long moduleId;
+    /** 节点id */
+    private Long nodeId;
+    /** 审核人id */
+    private String candidatorId;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getBusinessCode() {
+        return businessCode;
+    }
+
+    public void setBusinessCode(Long businessCode) {
+        this.businessCode = businessCode;
+    }
+
+    public Long getModuleId() {
+        return moduleId;
+    }
+
+    public void setModuleId(Long moduleId) {
+        this.moduleId = moduleId;
+    }
+
+    public Long getNodeId() {
+        return nodeId;
+    }
+
+    public void setNodeId(Long nodeId) {
+        this.nodeId = nodeId;
+    }
+
+    public String getCandidatorId() {
+        return candidatorId;
+    }
+
+    public void setCandidatorId(String candidatorId) {
+        this.candidatorId = candidatorId;
+    }
+}

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

@@ -2,6 +2,7 @@ package com.boman.web.core.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.TaskDto;
 import com.boman.web.core.service.jflow.JFlowTaskService;
 import io.swagger.annotations.ApiOperation;
@@ -57,4 +58,35 @@ public class JFlowTaskController {
     public AjaxResult pageDetail(@RequestBody TaskDto taskDto) {
         return jFlowTaskService.pageDetail(taskDto);
     }
+
+    /**
+     * 功能描述: 设置扩展审核人
+     *
+     * @param taskDto businessCodes=1,2 hardShut=true
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @ApiOperation(value = "设置下一个节点审核数据")
+    @PostMapping("/p/c/setCandiditors")
+    public AjaxResult setCandiditors(@RequestBody TaskDto taskDto) {
+        return jFlowTaskService.setCandiditors(taskDto);
+    }
+
+    /**
+     * 功能描述: 获取候选人数据
+     *
+     * eg:{
+     * "table": "sys_config",
+     * "fixedData": {
+     * "id": 20
+     * }
+     * }
+     *
+     * @param condition condition
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @ApiOperation(value = "获取候选人数据")
+    @PostMapping("/p/c/getBusinessCandidators")
+    public AjaxResult getBusinessCandidators(@RequestBody FormDataDto condition) {
+        return jFlowTaskService.getBusinessCandidators(condition);
+    }
 }

+ 0 - 19
boman-web-core/src/main/java/com/boman/web/core/controller/ObjController.java

@@ -125,25 +125,6 @@ public class ObjController {
         return tableServiceCmdService.getObjectAllColumns(condition);
     }
 
-    /**
-     * 功能描述: 获取候选人数据
-     *
-     * eg:{
-     * "table": "sys_config",
-     * "fixedData": {
-     * "id": 20
-     * }
-     * }
-     *
-     * @param condition condition
-     * @return com.boman.domain.dto.AjaxResult
-     */
-    @ApiOperation(value = "获取候选人数据")
-    @PostMapping("/getBusinessCandidators")
-    public AjaxResult getBusinessCandidators(@RequestBody FormDataDto condition) {
-        return tableServiceCmdService.getBusinessCandidators(condition);
-    }
-
     /**
      * 功能描述: 获取表单列表数据
      * eg:{

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

@@ -0,0 +1,152 @@
+package com.boman.web.core.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+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.apache.ibatis.jdbc.SQL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.escapeStr;
+import static com.boman.domain.constant.FormDataConstant.*;
+
+
+/**
+ * 流程针对业务数据层面接口
+ *
+ *
+ * @author zhong.h
+ */
+@Mapper
+@Component
+public interface JFTaskBusinessMapper {
+    Logger LOGGER = LoggerFactory.getLogger(JFTaskBusinessMapper.class);
+
+    @InsertProvider(type = StandardlyMapper.SqlProvider.class, method = "insert")
+    int insert(@Param("tableName") String tableName, @Param("model") JSONObject model);
+
+    @UpdateProvider(type = JFTaskBusinessMapper.SqlProvider.class, method = "update")
+    int updateByIdList(@Param("tableName") String tableName, @Param("pkName") String pkName
+            , @Param("idList") List<Long> idList, @Param("model") JSONObject models);
+
+
+    @Select("select id, business_code as businessCode,module_id as moduleId,node_id as nodeId,candidator_id as candidatorId from ${tableName} t where t.business_code = #{businessCode} and t.module_id = #{moduleId} and t.node_id = #{nodeId}")
+    ProcessNodeCandidator selectData(@Param("tableName") String tableName, @Param("businessCode") Long businessCode, @Param("moduleId") Long moduleId, @Param("nodeId") Long nodeId);
+
+    @Select("select check_user_id from ${tableName} t where t.id = #{businessCode}")
+    String selectBusinessCheckUserId(@Param("tableName") String tableName, @Param("businessCode") Long businessCode);
+
+    @Select("select candidator_id from ${tableName} t where t.business_code = #{businessCode} and module_id = #{moduleId} and node_id = #{nodeId}")
+    JSONObject selectNodeData(@Param("tableName") String tableName, @Param("businessCode") Long businessCode, @Param("moduleId") Long moduleId, @Param("nodeId") Long nodeId);
+
+    class SqlProvider {
+
+        private static boolean isNullOrEmpty(String str) {
+            return str == null || str.length() == 0 || str.trim().length() == 0;
+        }
+
+        private static boolean isNullOrEmpty(JSONObject json) {
+            return json == null || json.isEmpty();
+        }
+
+        public String insert(Map<String, Object> para) {
+            JSONObject model = (JSONObject) para.get("model");
+            String tableName = (String) para.get("tableName");
+            if (isNullOrEmpty(tableName)) {
+                throw new IllegalArgumentException("tableName 无效");
+            } else if (isNullOrEmpty(model)) {
+                throw new IllegalArgumentException("model 无效");
+            } else {
+                SQL sql = new SQL();
+                Set<String> keySet = model.keySet();
+                sql.INSERT_INTO(tableName);
+
+                for (int i = 0; i < model.size(); ++i) {
+                    String key = (String) keySet.toArray()[i];
+                    sql.VALUES(key, "#{model." + key + "}");
+                }
+
+                String sqlStr = sql.toString();
+                LOGGER.info("新增的sql语句为: {}, \r\n 新增的数据为: {}", sqlStr, model);
+                return sqlStr;
+            }
+        }
+
+        public String update(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            String pkName = (String) para.get("pkName");
+            List<Long> idList = (List<Long>) para.get("idList");
+            JSONObject models = (JSONObject) para.get("model");
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("update ").append(tableName).append(" set ");
+            for (Map.Entry<String, Object> entry : models.entrySet()) {
+                String key = entry.getKey();
+                Object value = entry.getValue();
+                wholeSql.append(key).append(convert(EQ, CHAR, key, value)).append(" , ");
+            }
+
+            wholeSql = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), ","));
+            wholeSql.append(" where ").append(pkName).append(" in ( ");
+
+            for (int i = 0; i < idList.size(); ++i) {
+                wholeSql.append(String.format("#{idList[%d]}", i));
+                wholeSql.append(",");
+            }
+
+            wholeSql.setCharAt(wholeSql.length() - 1, ')');
+            String sqlStr = wholeSql.toString();
+            LOGGER.info("批量更新的sql语句为: {} \r\n 更改的数据为: {} \r\n idList: {}", sqlStr, models, idList);
+            return sqlStr;
+        }
+
+        /**
+         * 功能描述: 仅此用来拼装查询条件,不做他用
+         *
+         * @param queryType  like > < =
+         * @param columnType varchar char textarea timestamp
+         * @param key        key
+         * @param valueObj   valueObj
+         * @return java.lang.String
+         */
+        private String convert(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) + ")";
+            }
+        }
+    }
+}

+ 0 - 60
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -437,66 +437,6 @@ public class TableServiceCmdService {
 
     }
 
-    /**
-     * 功能描述: 获取单表单所有数据
-     *
-     * @param dto condition
-     * @return com.boman.domain.dto.AjaxResult
-     */
-    public AjaxResult getBusinessCandidators(FormDataDto dto) {
-        String tableName = dto.getTableName();
-        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
-        List<GenTableColumn> columns = genTable.getColumns();
-        // 获取候选人字段
-        JSONObject jsonObject = selectService.selectById(tableName, IdUtils.getPkName(genTable.getColumns()), dto.getId(), dto.getOther());
-        String candidator = "";
-        String candidatorDepart = "";
-        for (GenTableColumn column : columns) {
-            String columnName = column.getColumnName();
-            if(columnName.equals("check_user_id")) {
-                candidator = jsonObject.getString(column.getColumnName());
-                break;
-            }
-            if(columnName.equals("check_group_id")) {
-                candidatorDepart = jsonObject.getString(column.getColumnName());
-                break;
-            }
-        }
-        if(StringUtils.isEmpty(candidator) && StringUtils.isEmpty(candidatorDepart)) {
-            return AjaxResult.error(-1, "没有候选人或者组!");
-        }
-        int type =  0;
-        List<Long> ids = new ArrayList<>();
-        // 候选人
-        if(StringUtils.isNotEmpty(candidator)) {
-            type = 1;
-            String[] idArrs = candidator.split(",");
-            for(String idArr : idArrs) {
-                ids.add(Long.valueOf(idArr));
-            }
-        }
-        // 候选组
-        if(StringUtils.isNotEmpty(candidatorDepart)) {
-            type = 2;
-            String[] idArrs = candidatorDepart.split(",");
-            for(String idArr : idArrs) {
-                ids.add(Long.valueOf(idArr));
-            }
-        }
-
-        List<JSONObject> jsonObjects = null;
-        if(type == 1) {
-            jsonObjects = selectService.selectCandidatorsById("sys_user", IdUtils.getPkName(genTable.getColumns()), ids, type);
-        }
-        JSONObject result = new JSONObject();
-        if( jsonObjects == null) {
-            return AjaxResult.error(-1, "没有候选人或组!");
-        }
-        result.put("approvers", jsonObjects);
-        return new AjaxResult(1, 0, "", result);
-
-    }
-
     /**
      * 判断hr字段里面是否有值
      *

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

@@ -2,6 +2,7 @@ package com.boman.web.core.service.jflow;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.TaskDto;
 
 public interface JFlowTaskService {
@@ -11,4 +12,6 @@ public interface JFlowTaskService {
     AjaxResult pageDeny(TaskDto taskDto);
     JSONObject approvalStatistics(TaskDto taskDto);
     AjaxResult pageDetail(TaskDto taskDto);
+    AjaxResult setCandiditors(TaskDto taskDto);
+    AjaxResult getBusinessCandidators(FormDataDto dto);
 }

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

@@ -1,18 +1,42 @@
 package com.boman.web.core.service.jflow.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.exception.CustomException;
+import com.boman.common.core.utils.StringUtils;
+import com.boman.common.redis.RedisKey;
+import com.boman.domain.GenTable;
+import com.boman.domain.GenTableColumn;
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.TaskDto;
+import com.boman.domain.jflow.ProcessNodeCandidator;
 import com.boman.jflow.api.RemoteJflowTaskService;
+import com.boman.web.core.domain.RowResult;
+import com.boman.web.core.mapper.JFTaskBusinessMapper;
+import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.service.jflow.JFlowTaskService;
+import com.boman.web.core.service.select.IBaseSelectService;
+import com.boman.web.core.utils.IdUtils;
+import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 @Service
 public class JFlowTaskServiceImpl implements JFlowTaskService {
 
     @Autowired
     private RemoteJflowTaskService remoteJflowTaskService;
+    @Autowired
+    private JFTaskBusinessMapper jfTaskBusinessMapper;
+    @Autowired
+    private TableServiceCmdService tableServiceCmdService;
+    @Resource
+    private IBaseSelectService selectService;
 
     @Override
     public AjaxResult historyLoad(TaskDto taskDto) {
@@ -43,4 +67,109 @@ public class JFlowTaskServiceImpl implements JFlowTaskService {
     public AjaxResult pageDetail(TaskDto taskDto) {
         return remoteJflowTaskService.pageDetail(taskDto);
     }
+
+    /**
+     * 设置审核人节点信息
+     *
+     * @param taskDto
+     * @return
+     */
+    @Override
+    public AjaxResult setCandiditors(TaskDto taskDto) {
+        String candidatorTableName = taskDto.getCandidatorTableName();
+        List<RowResult> result = Lists.newArrayListWithCapacity(1);
+        GenTable genTable = tableServiceCmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, candidatorTableName);
+        String pkName = IdUtils.getPkName(genTable.getColumns());
+        try {
+            String candidatorId = taskDto.getCandidatorId();
+            // 这个是如果没有设置审核人,先去主表数据中获取
+            if(StringUtils.isEmpty(candidatorId)) {
+                candidatorId = jfTaskBusinessMapper.selectBusinessCheckUserId(taskDto.getTableName(), taskDto.getBusinessCode());
+            }
+            if(StringUtils.isEmpty(candidatorId)) {
+                return AjaxResult.error("没有设置审核人", result);
+            }
+            // 先查看是否已经存在节点对应的数据审核数据
+            ProcessNodeCandidator candidator = jfTaskBusinessMapper.selectData(candidatorTableName, taskDto.getBusinessCode(), taskDto.getModuleId(), taskDto.getNodeId());
+            JSONObject model = new JSONObject();
+            if(candidator != null) {
+                model.put("candidator_id", candidatorId);
+                jfTaskBusinessMapper.updateByIdList(taskDto.getCandidatorTableName(), pkName, Arrays.asList(candidator.getId()), model);
+            }else {
+                model.put("id", IdUtils.getMaxId(candidatorTableName, pkName));
+                model.put("module_id", taskDto.getModuleId());
+                model.put("business_code", taskDto.getBusinessCode());
+                model.put("node_id", taskDto.getNodeId());
+                model.put("candidator_id", candidatorId);
+                jfTaskBusinessMapper.insert(taskDto.getCandidatorTableName(), model);
+            }
+        }catch (CustomException e) {
+            return AjaxResult.error("设置扩展节点审核人异常", result);
+        }
+
+        return AjaxResult.success(result);
+    }
+
+    /**
+     * 功能描述: 获取单表单所有数据
+     *
+     * @param dto condition
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    public AjaxResult getBusinessCandidators(FormDataDto dto) {
+        String tableName = dto.getCandidatorTableName();
+        GenTable genTable = tableServiceCmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
+        List<GenTableColumn> columns = genTable.getColumns();
+        // 获取候选人字段
+        JSONObject jsonObject = jfTaskBusinessMapper.selectNodeData(tableName, dto.getId(), dto.getModuleId(), dto.getNodeId());
+        if(jsonObject == null) {
+            return AjaxResult.error(-1, "没有候选人或者组!");
+        }
+        String candidator = "";
+        String candidatorDepart = "";
+        for (GenTableColumn column : columns) {
+            String columnName = column.getColumnName();
+            if(columnName.equals("candidator_id")) {
+                candidator = jsonObject.getString(column.getColumnName());
+                break;
+            }
+            if(columnName.equals("check_group_id")) {
+                candidatorDepart = jsonObject.getString(column.getColumnName());
+                break;
+            }
+        }
+        if(StringUtils.isEmpty(candidator) && StringUtils.isEmpty(candidatorDepart)) {
+            return AjaxResult.error(-1, "没有候选人或者组!");
+        }
+        int type =  0;
+        List<Long> ids = new ArrayList<>();
+        // 候选人
+        if(StringUtils.isNotEmpty(candidator)) {
+            type = 1;
+            String[] idArrs = candidator.split(",");
+            for(String idArr : idArrs) {
+                ids.add(Long.valueOf(idArr));
+            }
+        }
+        // 候选组
+        if(StringUtils.isNotEmpty(candidatorDepart)) {
+            type = 2;
+            String[] idArrs = candidatorDepart.split(",");
+            for(String idArr : idArrs) {
+                ids.add(Long.valueOf(idArr));
+            }
+        }
+
+        List<JSONObject> jsonObjects = null;
+        if(type == 1) {
+            jsonObjects = selectService.selectCandidatorsById("sys_user", IdUtils.getPkName(genTable.getColumns()), ids, type);
+        }
+        JSONObject result = new JSONObject();
+        if( jsonObjects == null) {
+            return AjaxResult.error(-1, "没有候选人或组!");
+        }
+        result.put("approvers", jsonObjects);
+        return new AjaxResult(1, 0, "", result);
+
+    }
 }