shiqian преди 4 години
родител
ревизия
489807a038

+ 4 - 0
boman-web-core/src/main/java/com/boman/web/core/constant/FormDataConstant.java

@@ -96,6 +96,10 @@ public class FormDataConstant {
     public static final String PAGE_ROWS = "rows";
 
 
+    /**  暂时是用作新增时,成功的记录数 */
+    public static final String SUCCESS_CNT = "successCnt";
+
+
     /**  数据库字段创建人*/
     public static final String UPDATE_BY = "UPDATE_BY";
 

+ 5 - 25
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -17,7 +17,6 @@ import com.boman.gen.domain.GenTable;
 import com.boman.gen.domain.GenTableColumn;
 import com.boman.gen.domain.GenTableRelation;
 import com.boman.system.api.RemoteDictDataService;
-import com.boman.web.core.constant.DictConstant;
 import com.boman.web.core.constant.FormDataConstant;
 import com.boman.web.core.constant.SubmitConstant;
 import com.boman.web.core.domain.*;
@@ -68,7 +67,7 @@ public class TableServiceCmdService {
     @Resource
     private  RestTemplate restTemplate;
     @Resource
-    private RemoteDictDataService dictTypeService;
+    private RemoteDictDataService remoteDictDataService;
     @Resource
     private RemoteGenTableService remoteGenTableService;
 
@@ -91,15 +90,10 @@ public class TableServiceCmdService {
         String pkName = IdUtils.getPkName(columns);
         requireNonNull(pkName, "主键名称为空");
 
-        //
-        List<String> allColumnNameList = columns.stream()
-                .map(GenTableColumn::getColumnName)
-                .collect(Collectors.toList());
-
         // 新增
         if (ObjectUtils.ltZero(baseTableDTO.getObjId())) {
             Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
-            RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0), allColumnNameList);
+            RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0), columns);
             if (RowResult.checkSuccess(rowResult)) {
                 LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
             } else {
@@ -318,7 +312,7 @@ public class TableServiceCmdService {
             if (GenTableColumn.IS_QUERY.equalsIgnoreCase(column.getIsQuery())) {
                 String dictType = column.getDictType();
                 if (ObjectUtils.isNotEmpty(dictType)) {
-                    List<SysDictData> sysDictData1 = dictTypeService.listByType(dictType);
+                    List<SysDictData> sysDictData1 = remoteDictDataService.listByType(dictType);
                     column.setSysDictData(sysDictData1);
                 }
 
@@ -517,7 +511,7 @@ public class TableServiceCmdService {
         GenTable genTable = redisService.getCacheObject(key);
         if (ObjectUtils.isEmpty(genTable)) {
             genTable = remoteGenTableService.getByTableName(tableName);
-            requireNonNull(genTable, "未找到表对应的信息");
+            requireNonNull(genTable, "数据库中,未找到表对应的信息");
             // {@link com.boman.gen.controller.MyController.packTableAndInsertToRedis} 失效时间
             redisService.setCacheObject(key, genTable, 12L, TimeUnit.DAYS);
         }
@@ -542,7 +536,7 @@ public class TableServiceCmdService {
         for (GenTableColumn column : columns) {
             String dictType = column.getDictType();
             if (ObjectUtils.isNotEmpty(dictType)) {
-                List<SysDictData> sysDictData1 = dictTypeService.listByType(dictType);
+                List<SysDictData> sysDictData1 = remoteDictDataService.listByType(dictType);
                 column.setSysDictData(sysDictData1);
             }
         }
@@ -550,19 +544,5 @@ public class TableServiceCmdService {
         return AjaxResult.success(genTable);
     }
 
-    public List<JSONObject> coverSysDictDataToJSONObject(List<SysDictData> sysDictData) {
-        List<JSONObject> result = Lists.newArrayListWithCapacity(sysDictData.size());
-        for (SysDictData data : sysDictData) {
-            JSONObject jsonObject = new JSONObject();
-            String dictLabel = data.getDictLabel();
-            String dictValue = data.getDictValue();
-            jsonObject.put(DictConstant.DICT_LABEL, dictLabel);
-            jsonObject.put(DictConstant.DICT_VALUE, dictValue);
-            result.add(jsonObject);
-        }
-
-        return result;
-
-    }
 }
 

+ 24 - 16
boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java

@@ -2,6 +2,7 @@ package com.boman.web.core.service.save;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.SecurityUtils;
+import com.boman.gen.domain.GenTableColumn;
 import com.boman.web.core.constant.FormDataConstant;
 import com.boman.web.core.domain.MainTableRecord;
 import com.boman.web.core.domain.RowResult;
@@ -30,36 +31,43 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
     /**
      * 功能描述: 保存一行
      *
-     * @param tableName         tableName
-     * @param pkName            主键名称
-     * @param maxId             最大的SEQ
-     * @param row               要保存的数据
-     * @param allColumnNameList 这是此表的所有字段属性名称,用来判断是否所有UPDATE_BY和UPDATE_TIME
+     * @param tableName tableName
+     * @param pkName    主键名称
+     * @param maxId     最大的SEQ
+     * @param row       要保存的数据
+     * @param columns   这是此表的所有字段属性名称,用来判断是否所有UPDATE_BY和UPDATE_TIME,和时间类型
      * @return com.boman.system.common.RowResult
      */
     @Override
-    public RowResult insertRow(String tableName, String pkName, Long maxId, MainTableRecord row, List<String> allColumnNameList) {
+    public RowResult insertRow(String tableName, String pkName, Long maxId, MainTableRecord row, List<GenTableColumn> columns) {
         JSONObject commitData = row.getMainData().getCommitData();
         Timestamp currentTime = new Timestamp(System.currentTimeMillis());
-        if (allColumnNameList.contains(FormDataConstant.UPDATE_BY)
-                || allColumnNameList.contains(FormDataConstant.UPDATE_BY.toLowerCase())) {
-            commitData.put(FormDataConstant.UPDATE_BY, SecurityUtils.getUserId());
-        }
-        if (allColumnNameList.contains(FormDataConstant.UPDATE_TIME)
-                || allColumnNameList.contains(FormDataConstant.UPDATE_TIME.toLowerCase())) {
-            commitData.put(FormDataConstant.UPDATE_TIME, currentTime);
+        for (GenTableColumn column : columns) {
+            // 判断是否有修改人、修改时间
+            if (column.getColumnName().equalsIgnoreCase(FormDataConstant.UPDATE_BY)) {
+                commitData.put(FormDataConstant.UPDATE_BY, SecurityUtils.getUserId());
+            }
+            if (column.getColumnName().equalsIgnoreCase(FormDataConstant.UPDATE_TIME)) {
+                commitData.put(FormDataConstant.UPDATE_TIME, currentTime);
+            }
+
+            // 如果某一列是datetime类型,需要把类型转成datetime,否则数据库会报错
+            if (FormDataConstant.DATETIME.equalsIgnoreCase(column.getColumnType())) {
+                String columnName = column.getColumnName().toUpperCase();
+                commitData.put(columnName, commitData.getTimestamp(columnName));
+            }
         }
 
         // 新增
         if (row.getId() > 0) {
-            commitData.put("CREATE_TIME", currentTime);
-            commitData.put("CREATE_BY", SecurityUtils.getUserId());
+            commitData.put(FormDataConstant.UPDATE_TIME, currentTime);
+            commitData.put(FormDataConstant.UPDATE_BY, SecurityUtils.getUserId());
         }
 
         commitData.put(pkName.toUpperCase(), maxId);
         int ret = mapper.insert(tableName, commitData);
         if (ret > 0) {
-            commitData.put("successCnt", ret);
+            commitData.put(FormDataConstant.SUCCESS_CNT, ret);
             return RowResult.ok("保存成功", commitData);
         }
 

+ 7 - 6
boman-web-core/src/main/java/com/boman/web/core/service/save/IBaseSaveService.java

@@ -1,6 +1,7 @@
 package com.boman.web.core.service.save;
 
 
+import com.boman.gen.domain.GenTableColumn;
 import com.boman.web.core.domain.MainTableRecord;
 import com.boman.web.core.domain.RowResult;
 
@@ -17,13 +18,13 @@ public interface IBaseSaveService {
     /**
      * 功能描述: 保存一行
      *
-     * @param tableName         tableName
-     * @param pkName            主键名称
-     * @param maxId             最大的SEQ
-     * @param row               要保存的数据
-     * @param allColumnNameList 这是此表的所有字段属性名称,用来判断是否所有UPDATE_BY和UPDATE_TIME
+     * @param tableName tableName
+     * @param pkName    主键名称
+     * @param maxId     最大的SEQ
+     * @param row       要保存的数据
+     * @param columns   这是此表的所有字段属性名称,用来判断是否所有UPDATE_BY和UPDATE_TIME,和时间类型
      * @return com.boman.system.common.RowResult
      */
-    RowResult insertRow(String tableName, String pkName, Long maxId, MainTableRecord row, List<String> allColumnNameList);
+    RowResult insertRow(String tableName, String pkName, Long maxId, MainTableRecord row, List<GenTableColumn> columns);
 
 }