Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

Administrator 4 lat temu
rodzic
commit
5ef435fac7
18 zmienionych plików z 336 dodań i 14 usunięć
  1. 9 0
      boman-api/boman-api-jflow/src/main/java/com/boman/jflow/api/RemoteJflowProcessService.java
  2. 13 0
      boman-api/boman-domain/src/main/java/com.boman.domain/dto/FormDataDto.java
  3. 22 0
      boman-api/boman-domain/src/main/java/com.boman.domain/dto/InsertListDto.java
  4. 13 0
      boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java
  5. 13 4
      boman-web-core/src/main/java/com/boman/web/core/controller/JFlowProcessController.java
  6. 24 0
      boman-web-core/src/main/java/com/boman/web/core/controller/ObjController.java
  7. 71 0
      boman-web-core/src/main/java/com/boman/web/core/mapper/StandardlyMapper.java
  8. 59 9
      boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java
  9. 18 0
      boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java
  10. 9 0
      boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java
  11. 9 0
      boman-web-core/src/main/java/com/boman/web/core/service/jflow/JFlowProcessService.java
  12. 12 0
      boman-web-core/src/main/java/com/boman/web/core/service/jflow/impl/JFlowProcessServiceImpl.java
  13. 27 1
      boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java
  14. 4 0
      boman-web-core/src/main/java/com/boman/web/core/service/save/IBaseSaveService.java
  15. 6 0
      boman-web-core/src/main/java/com/boman/web/core/service/submit/BaseSubmitServiceImpl.java
  16. 10 0
      boman-web-core/src/main/java/com/boman/web/core/service/submit/IBaseSubmitService.java
  17. 11 0
      boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java
  18. 6 0
      boman-web-core/src/main/java/com/boman/web/core/utils/IdUtils.java

+ 9 - 0
boman-api/boman-api-jflow/src/main/java/com/boman/jflow/api/RemoteJflowProcessService.java

@@ -19,4 +19,13 @@ public interface RemoteJflowProcessService {
 
     @PostMapping("/jflow/p/c/process/launch")
     AjaxResult launch(@RequestBody ProcessDto processDto);
+
+    /**
+     * 功能描述: 强制关闭流程
+     *
+     * @param processDto businessCodes=1,2 hardShut=true
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @PostMapping("/jflow/p/c/process/batch/shut")
+    AjaxResult shut(@RequestBody ProcessDto processDto);
 }

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

@@ -93,6 +93,11 @@ public class FormDataDto implements Serializable {
      */
     private String submitSource;
 
+    /**
+     * 逻辑删除时,是否调用jflow接口
+     */
+    private Boolean stopProcess;
+
 
     public int getLimit() {
         try {
@@ -112,6 +117,14 @@ public class FormDataDto implements Serializable {
         }
     }
 
+    public Boolean getStopProcess() {
+        return stopProcess;
+    }
+
+    public void setStopProcess(Boolean stopProcess) {
+        this.stopProcess = stopProcess;
+    }
+
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }

+ 22 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/dto/InsertListDto.java

@@ -0,0 +1,22 @@
+package com.boman.domain.dto;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/**
+ * @author shiqian
+ * @date 2021年06月30日 16:42
+ **/
+@Data
+public class InsertListDto {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(InsertListDto.class);
+
+    private String tableName;
+
+    private List<JSONObject> dataList;
+}

+ 13 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.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.FormDataDto;
+import com.boman.domain.dto.InsertListDto;
 import com.boman.web.core.service.common.ICommonService;
 import org.springframework.web.bind.annotation.*;
 
@@ -87,4 +88,16 @@ public class CommonController {
         return commonService.getNewest(tableName);
     }
 
+
+    /**
+     * 功能描述: 批量插入数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @PostMapping("insertList")
+    public int insertList(@RequestBody InsertListDto dto) {
+        return commonService.insertList(dto);
+    }
+
 }

+ 13 - 4
boman-web-core/src/main/java/com/boman/web/core/controller/JFlowProcessController.java

@@ -7,10 +7,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  *  流程中心控制器
@@ -37,4 +34,16 @@ public class JFlowProcessController {
     public AjaxResult launch(@RequestBody ProcessDto processDto) {
         return jFlowProcessService.launch(processDto);
     }
+
+    /**
+     * 功能描述: 强制关闭流程
+     *
+     * @param processDto businessCodes=1,2 hardShut=true
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @ApiOperation(value = "发起工作流流程")
+    @PostMapping("/batch/shut")
+    public AjaxResult shut(@RequestBody ProcessDto processDto) {
+        return jFlowProcessService.shut(processDto);
+    }
 }

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

@@ -257,6 +257,30 @@ public class ObjController {
         return tableServiceCmdService.objectSubmit(condition, true);
     }
 
+    /**
+     * 功能描述: 根据外键修改信息
+     *
+     * {
+     *     "table":"boman_message_receive",
+     *     "commitData":[
+     *         {
+     *             "foreignKeyName":"message_id",
+     *             "foreignKey": 3,
+     *             "updateData":{
+     *                 "visible": "Y"
+     *             }
+     *         }
+     *     ]
+     * }
+     *
+     * @param condition condition
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @ApiOperation(value = "根据外键修改数据接口")
+    @PostMapping("/updateDataByForeignKey")
+    public AjaxResult genReceiverMsg(@RequestBody FormDataDto condition) {
+        return tableServiceCmdService.genReceiverMsg(condition);
+    }
 
     /**
      * 功能描述: 反提交接口, 更改的字段类型和字段值都是一致的

+ 71 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardlyMapper.java

@@ -1,6 +1,7 @@
 package com.boman.web.core.mapper;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.web.core.utils.ColumnUtils;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
@@ -62,6 +63,10 @@ public interface StandardlyMapper {
     )
     int insert(@Param("tableName") String var1, @Param("model") JSONObject var2);
 
+    /** {@link SqlProvider#insertList(Map)} */
+    @InsertProvider(type = SqlProvider.class,method = "insertList")
+    int insertList(@Param("tableName") String tableName, @Param("dataList") List<JSONObject> dataList);
+
     @InsertProvider(
             type = SqlProvider.class,
             method = "inserts"
@@ -88,6 +93,10 @@ public interface StandardlyMapper {
     int updateByIdList(@Param("tableName") String tableName, @Param("pkName") String pkName
             , @Param("idList") List<Long> idList, @Param("model") JSONObject models);
 
+    @UpdateProvider(type = SqlProvider.class, method = "updateByForeignKey")
+    int updateByForeignKey(@Param("tableName") String tableName, @Param("foreignKeyName") String foreignKeyName
+            , @Param("foreignKeyList") List<Long> foreignKeyList, @Param("model") JSONObject models);
+
     @Select("select id from ${tableName} where ${akColumnName} = #{akColumnValue}")
     Long selectIdByAkColumn(@Param("tableName") String tableName, @Param("akColumnName") String akColumnName, @Param("akColumnValue") String akColumnValue);
 
@@ -341,6 +350,39 @@ public interface StandardlyMapper {
             }
         }
 
+        public String insertList(Map<String, Object> para) {
+            List<JSONObject> dataList = (List<JSONObject>) para.get("dataList");
+            String tableName = (String) para.get("tableName");
+            if (isNullOrEmpty(tableName)) {
+                throw new IllegalArgumentException("tableName 无效");
+            }
+
+            if (ObjectUtils.isEmpty(dataList)) {
+                throw new IllegalArgumentException("需要插入的数据为空");
+            }
+
+            StringBuilder stringBuilder = new StringBuilder();
+            stringBuilder.append("insert into ").append(tableName).append(" ( ");
+            JSONObject keySet = dataList.get(0);
+            stringBuilder.append(String.join(", ", keySet.keySet()));
+            stringBuilder.append(" ) ").append("values ");
+
+            for (JSONObject data : dataList) {
+                StringBuilder values = new StringBuilder();
+                values.append(" ( ");
+                for (Map.Entry<String, Object> entry : data.entrySet()) {
+                    values.append("#{model.").append(entry.getKey()).append("}, ");
+                }
+
+                String beforeLast = StringUtils.substringBeforeLast(values.toString(), ", ");
+                stringBuilder.append(beforeLast).append(" ) ");
+            }
+
+            String sqlStr = stringBuilder.toString();
+            LOGGER.info("批量新增的sql语句为: {}, \r\n 新增的数据为: {}", sqlStr, dataList);
+            return sqlStr;
+        }
+
 
         public String updateByIdList(Map<String, Object> para) {
             String tableName = (String) para.get("tableName");
@@ -371,6 +413,35 @@ public interface StandardlyMapper {
 
         }
 
+        public String updateByForeignKey(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            String foreignKeyName = (String) para.get("foreignKeyName");
+            List<Long> foreignKeyList = (List<Long>) para.get("foreignKeyList");
+            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(covert(EQ, CHAR, key, value)).append(" , ");
+            }
+
+            wholeSql = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), ","));
+            wholeSql.append(" where ").append(foreignKeyName).append(" in ( ");
+
+            for (Long id : foreignKeyList) {
+                wholeSql.append(id);
+                wholeSql.append(",");
+            }
+
+            wholeSql.setCharAt(wholeSql.length() - 1, ')');
+            String sqlStr = wholeSql.toString();
+            LOGGER.info("批量更新的sql语句为: {}, \r\n 更改的数据为: {}, \r\n foreignKeyList: {}", sqlStr, models, foreignKeyList);
+            return sqlStr;
+
+        }
+
         public String delete(Map<String, Object> para) {
             Long[] ids = (Long[]) para.get("ids");
             String tableName = (String) para.get("tableName");

+ 59 - 9
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -17,10 +17,12 @@ import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
 import com.boman.domain.SysDictData;
 import com.boman.domain.constant.*;
+import com.boman.domain.dto.ProcessDto;
 import com.boman.domain.dto.RoleMenuDto;
 import com.boman.domain.exception.NoSuchFunctionException;
 import com.boman.gen.api.RemoteGenTableColumnService;
 import com.boman.gen.api.RemoteGenTableService;
+import com.boman.jflow.api.RemoteJflowProcessService;
 import com.boman.jflow.api.RemoteJflowTaskService;
 import com.boman.system.api.RemoteMenuService;
 import com.boman.domain.SysMenu;
@@ -92,7 +94,7 @@ public class TableServiceCmdService {
     @Resource
     private RemoteMenuService remoteMenuService;
     @Resource
-    private RemoteJflowTaskService remoteJflowTaskService;
+    private RemoteJflowProcessService remoteJflowProcessService;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
 
@@ -210,15 +212,26 @@ public class TableServiceCmdService {
         RowResult rowResult;
         for (Long id : idArr) {
             // 校验权限
-            if (BooleanUtils.isTrue(checkAuthObjectDelete(genTable, id, pkName))) {
-                rowResult = deleteService.objectLogicDelete(new Long[]{id}, dto.getTable(), pkName, jsonObject);
-                if (rowResult.isOk()) {
-                    LOGGER.info("逻辑删除成功, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
-                    continue;
-                }
-                LOGGER.info("逻辑删除失败, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
-            } else {
+            if (BooleanUtils.isFalse(checkAuthObjectDelete(genTable, id, pkName))) {
                 rowResult = RowResult.create(RowResult.FAIL, "无操作权限");
+                result.add(rowResult);
+                continue;
+            }
+
+            rowResult = deleteService.objectLogicDelete(new Long[]{id}, dto.getTable(), pkName, jsonObject);
+            if (!rowResult.isOk()) {
+                LOGGER.info("逻辑删除失败, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
+                result.add(rowResult);
+                continue;
+            }
+
+            LOGGER.info("逻辑删除成功, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
+            Boolean stopProcess = dto.getStopProcess();
+            if (BooleanUtils.isTrue(stopProcess)) {
+                ProcessDto processDto = new ProcessDto();
+                processDto.setBusinessCode(id);
+                processDto.setHardShut(Boolean.TRUE);
+                remoteJflowProcessService.shut(processDto);
             }
 
             result.add(rowResult);
@@ -680,6 +693,43 @@ public class TableServiceCmdService {
         return AjaxResult.success(commitData);
     }
 
+    /**
+     * 功能描述: 修改数据
+     *
+     * @param condition condition
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    public AjaxResult genReceiverMsg(FormDataDto condition) {
+        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
+        String tableName = requireNonNull(genTable.getTableName(), "tableName = [" + genTable.getTableName() + "] 此表不存在");
+
+        List<JSONObject> commitData = condition.getCommitData();
+        for(JSONObject commitDatum : commitData) {
+            Long foreignKey = Long.valueOf(commitDatum.get("foreignKey").toString());
+            String foreignKeyName = (String) commitDatum.get("foreignKeyName");
+            this.executeData(tableName, foreignKeyName, foreignKey, (Map<String, Object>) commitDatum.get("updateData"));
+        }
+
+        return AjaxResult.success(commitData);
+    }
+
+    /**
+     * 功能描述: 修改数据
+     *
+     * @param tableName   tableName
+     * @param foreignKeyName 外键名
+     * @param foreignKey  外键值
+     * @param commitDatum 返回给前台的数据
+     */
+    private void executeData(String tableName, String foreignKeyName, Long foreignKey, Map<String, Object> commitDatum) {
+        int effective = submitService.executeData(tableName, foreignKeyName, foreignKey, new JSONObject(commitDatum));
+        if (effective > 0) {
+            commitDatum.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.SUCCESS);
+        } else {
+            commitDatum.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.FAIL);
+        }
+    }
+
     /**
      * 功能描述: 处理提交和反提交
      *

+ 18 - 0
boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java

@@ -5,7 +5,9 @@ import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
 import com.boman.domain.GenTable;
 import com.boman.domain.dto.FormDataDto;
+import com.boman.domain.dto.InsertListDto;
 import com.boman.web.core.service.TableServiceCmdService;
+import com.boman.web.core.service.save.IBaseSaveService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import com.boman.web.core.utils.IdUtils;
 import org.springframework.stereotype.Service;
@@ -29,6 +31,8 @@ public class CommonServiceImpl implements ICommonService {
     private RedisService redisService;
     @Resource
     private TableServiceCmdService cmdService;
+    @Resource
+    private IBaseSaveService saveService;
 
     /**
      * 功能描述: 根据表名和id查找
@@ -105,4 +109,18 @@ public class CommonServiceImpl implements ICommonService {
         requireNonNull(tableName, "tableName is empty");
         return selectService.getNewest(tableName);
     }
+
+    /**
+     * 功能描述: 批量插入数据 默认插入的是多对多的关联表,因此未处理create_by等字段
+     *
+     * @param dto dto
+     * @return int
+     */
+    @Override
+    public int insertList(InsertListDto dto) {
+        String tableName = requireNonNull(dto.getTableName(), "tableName is empty");
+        List<JSONObject> dataList = requireNonNull(dto.getDataList(), "dataList is empty");
+
+        return saveService.insertList(tableName, dataList);
+    }
 }

+ 9 - 0
boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java

@@ -2,6 +2,7 @@ package com.boman.web.core.service.common;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.FormDataDto;
+import com.boman.domain.dto.InsertListDto;
 
 import java.util.List;
 
@@ -56,4 +57,12 @@ public interface ICommonService {
      * @return com.alibaba.fastjson.JSONObject
      */
     JSONObject getNewest(String tableName);
+
+    /**
+     * 功能描述: 批量插入数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    int insertList(InsertListDto dto);
 }

+ 9 - 0
boman-web-core/src/main/java/com/boman/web/core/service/jflow/JFlowProcessService.java

@@ -4,5 +4,14 @@ import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.ProcessDto;
 
 public interface JFlowProcessService {
+
     AjaxResult launch(ProcessDto processDto);
+
+    /**
+     * 功能描述: 强制关闭流程
+     *
+     * @param processDto businessCodes=1,2 hardShut=true
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    AjaxResult shut(ProcessDto processDto);
 }

+ 12 - 0
boman-web-core/src/main/java/com/boman/web/core/service/jflow/impl/JFlowProcessServiceImpl.java

@@ -18,4 +18,16 @@ public class JFlowProcessServiceImpl implements JFlowProcessService {
     public AjaxResult launch(ProcessDto processDto) {
         return remoteJflowProcessService.launch(processDto);
     }
+
+
+    /**
+     * 功能描述: 强制关闭流程
+     *
+     * @param processDto businessCodes=1,2 hardShut=true
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @Override
+    public AjaxResult shut(ProcessDto processDto) {
+        return remoteJflowProcessService.shut(processDto);
+    }
 }

+ 27 - 1
boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java

@@ -1,15 +1,25 @@
 package com.boman.web.core.service.save;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.common.redis.RedisKey;
+import com.boman.common.redis.service.RedisService;
+import com.boman.domain.GenTable;
+import com.boman.domain.GenTableColumn;
 import com.boman.domain.constant.FormDataConstant;
+import com.boman.domain.constant.TableNameConst;
 import com.boman.web.core.domain.RowResult;
-import com.boman.web.core.domain.TableContext;
 import com.boman.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.utils.IdUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+import java.util.List;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
+
 /**
  * @author shiqian
  * @description
@@ -22,6 +32,8 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
 
     @Autowired
     private StandardlyMapper mapper;
+    @Resource
+    private RedisService redisService;
     /**
      * 功能描述: 保存一行
      *
@@ -41,4 +53,18 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
         return RowResult.error("失败");
     }
 
+    @Override
+    public int insertList(String tableName, List<JSONObject> datList) {
+        requireNonNull(tableName, "insertList tableName is empty");
+        requireNonNull(datList, "insertList datList is empty");
+
+        String pkName = IdUtils.getPkName(tableName);
+
+        for (JSONObject data : datList) {
+            Long maxId = IdUtils.getMaxId(tableName, pkName);
+            data.put(TableNameConst.ID, maxId);
+        }
+
+        return mapper.insertList(tableName, datList);
+    }
 }

+ 4 - 0
boman-web-core/src/main/java/com/boman/web/core/service/save/IBaseSaveService.java

@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.boman.web.core.domain.RowResult;
 import com.boman.web.core.domain.TableContext;
 
+import java.util.List;
+
 /**
  * @author shiqian
  * @description
@@ -22,4 +24,6 @@ public interface IBaseSaveService {
      */
     RowResult insertRow(String tableName, JSONObject commitData);
 
+    int insertList(String tableName, List<JSONObject> datList);
+
 }

+ 6 - 0
boman-web-core/src/main/java/com/boman/web/core/service/submit/BaseSubmitServiceImpl.java

@@ -37,4 +37,10 @@ public class BaseSubmitServiceImpl implements IBaseSubmitService {
         requireNonNull(model, "提交的数据为空");
         return mapper.updateByIdList(tableName, pkName, Lists.newArrayList(id), model);
     }
+
+    @Override
+    public int executeData(String tableName, String foreignKeyName, Long foreignKey, JSONObject model) {
+        requireNonNull(model, "提交的数据为空");
+        return mapper.updateByForeignKey(tableName, foreignKeyName, Lists.newArrayList(foreignKey), model);
+    }
 }

+ 10 - 0
boman-web-core/src/main/java/com/boman/web/core/service/submit/IBaseSubmitService.java

@@ -18,4 +18,14 @@ public interface IBaseSubmitService {
      * @return int
      */
     int handlerSubmit(String tableName, String pkName, JSONObject model, Long id);
+
+    /**
+     * 根据外键修改数据
+     * @param tableName
+     * @param foreignKeyName
+     * @param foreignKey
+     * @param model
+     * @return
+     */
+    int executeData(String tableName, String foreignKeyName, Long foreignKey, JSONObject model);
 }

+ 11 - 0
boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

@@ -9,6 +9,9 @@ import com.boman.common.core.utils.StringUtils;
 import com.boman.common.core.utils.array.ArrayUtils;
 import com.boman.common.core.utils.collection.CollectionUtils;
 import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.common.redis.RedisKey;
+import com.boman.common.redis.service.RedisService;
+import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
 import com.boman.domain.constant.MysqlDataTypeConst;
 import com.boman.domain.exception.UnknownColumnException;
@@ -447,4 +450,12 @@ public class ColumnUtils {
         }
         context.setCommitData(commitData);
     }
+
+    public static List<GenTableColumn> getColumnList(String tableName){
+        requireNonNull(tableName, "getPkName tableName is empty");
+        RedisService redisService = SpringUtils.getBean(RedisService.class);
+        GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName.trim());
+        requireNonNull(genTable, String.format("表名为: %s 的表不存在缓存中", tableName));
+        return genTable.getColumns();
+    }
 }

+ 6 - 0
boman-web-core/src/main/java/com/boman/web/core/utils/IdUtils.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.boman.common.core.utils.SpringUtils;
 import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
+import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
 import com.boman.web.core.mapper.StandardlyMapper;
 import org.apache.commons.collections.CollectionUtils;
@@ -57,6 +58,11 @@ public class IdUtils {
         throw new IllegalArgumentException("获取主键失败");
     }
 
+
+    public static String getPkName(String tableName) {
+        return getPkName(ColumnUtils.getColumnList(tableName));
+    }
+
     public static void putIfNotContains(JSONArray jsonArray, String input) {
         if (isEmpty(jsonArray)) {
             jsonArray = new JSONArray();