Explorar o código

删除冗余代码

shiqian %!s(int64=4) %!d(string=hai) anos
pai
achega
033074b204

+ 28 - 0
boman-api/boman-api-system/src/main/java/com/boman/system/api/domain/SysFile.java

@@ -20,6 +20,16 @@ public class SysFile
      */
     private String url;
 
+    /**
+     * vue上传组件带的 为了取的时候不要来回去转,直接用此接受
+     */
+    private String status;
+
+    /**
+     * vue上传组件带的
+     */
+    private String uid;
+
     public String getName()
     {
         return name;
@@ -40,11 +50,29 @@ public class SysFile
         this.url = url;
     }
 
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
             .append("name", getName())
             .append("url", getUrl())
+            .append("uid", getUid())
+            .append("status", getStatus())
             .toString();
     }
 }

+ 20 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/exception/UnknownColumnException.java

@@ -0,0 +1,20 @@
+package com.boman.domain.exception;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author shiqian
+ * @date 2021年04月21日 15:44
+ **/
+public class UnknownColumnException extends RuntimeException{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(UnknownColumnException.class);
+
+    public UnknownColumnException(){}
+
+    public UnknownColumnException(String errorMsg){
+        super(errorMsg);
+    }
+
+}

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

@@ -170,24 +170,24 @@ public class ObjController {
         return tableServiceCmdService.getQueryParam(condition);
     }
 
-
-    /**
-     * 功能描述: 获取表单表头
-     * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
-     * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
-     *
-     *                    eg:{
-     *                          "table": "sys_config"
-     *                        }
-     *
-     * @param condition condition
-     * @return com.boman.common.core.web.domain.AjaxResult
-     */
-    @ApiOperation(value = "获取表单表头")
-    @PostMapping("/getTableHead")
-    public AjaxResult getTableHead(@RequestBody FormDataDto condition) {
-        return tableServiceCmdService.getTableHead(condition);
-    }
+//
+//    /**
+//     * 功能描述: 获取表单表头
+//     * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
+//     * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
+//     *
+//     *                    eg:{
+//     *                          "table": "sys_config"
+//     *                        }
+//     *
+//     * @param condition condition
+//     * @return com.boman.common.core.web.domain.AjaxResult
+//     */
+//    @ApiOperation(value = "获取表单表头")
+//    @PostMapping("/getTableHead")
+//    public AjaxResult getTableHead(@RequestBody FormDataDto condition) {
+//        return tableServiceCmdService.getTableHead(condition);
+//    }
 
     /**
      * 功能描述: 获取表单按钮

+ 3 - 4
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardlyMapper.java

@@ -124,7 +124,7 @@ public interface StandardlyMapper {
     @SelectProvider(type = SqlProvider.class, method = "selectByIdList")
     List<JSONObject> selectByIdList(@Param("tableName") String tableName
             , @Param("pkName") String pkName, @Param("idList") List<Long> idList
-            , @Param("showData") JSONArray showData);
+            , @Param("showData") List<String> showData);
 
     /**
      * 功能描述: 自定义查询,需要查询的字段和value都在condition中
@@ -557,15 +557,14 @@ public interface StandardlyMapper {
             String tableName = (String) para.get("tableName");
             String pkName = (String) para.get("pkName");
             List<Long> idList = (List<Long>) para.get(ID_LIST);
-            JSONArray showData = (JSONArray) para.get("showData");
+            List<String> showData = (List<String>) para.get("showData");
 
             StringBuilder wholeSql = new StringBuilder();
             wholeSql.append("select ");
             // showData
             StringBuilder showDataSql = new StringBuilder();
             if (ObjectUtils.isNotEmpty(showData)) {
-                for (Object columnObj : showData) {
-                    String columnName = (String) columnObj;
+                for (String columnName : showData) {
                     showDataSql.append(columnName).append(", ");
                 }
                 wholeSql.append(StringUtils.substringBeforeLast(showDataSql.toString(), ","));

+ 30 - 151
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -3,6 +3,7 @@ package com.boman.web.core.service;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.boman.common.core.constant.GenConstants;
 import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.SecurityUtils;
@@ -33,7 +34,6 @@ import com.boman.web.core.service.update.IBaseUpdateService;
 import com.boman.web.core.utils.IdUtils;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
-import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.BooleanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,12 +45,10 @@ import java.sql.Timestamp;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
-import java.util.stream.Collectors;
 
 import static com.boman.common.core.utils.obj.ObjectUtils.*;
 import static com.boman.web.core.constant.FormDataConstant.*;
 import static com.boman.web.core.utils.ColumnUtils.*;
-import static com.boman.web.core.utils.ColumnUtils.handlerBlobWithJSONObject;
 
 /**
  * @author shiqian
@@ -196,21 +194,21 @@ public class TableServiceCmdService {
     public AjaxResult queryList(FormDataDto dto) {
         requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
 
-        // 拿到每个字段对应的查询类型,=、 like、 >、 <
         GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
-        JSONObject fixedData = dto.getFixedData();
-        fixedData = ifNullSetEmpty(fixedData);
+        JSONObject fixedData = ifNullSetEmpty(dto.getFixedData());
+        List<GenTableColumn> columns = genTable.getColumns();
 
         // 查询条件
         JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
-        checkColumn(condition, genTable.getColumns());
-        List<GenTableColumn> columns = genTable.getColumns();
+        // 检查列
+        checkColumn(condition, columns);
         // 封装好以后的查询条件
         JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
-        JSONArray jsonArray = fixedData.getJSONArray(SHOW_DATA);
-        checkColumn(jsonArray, genTable.getColumns());
+        JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
+        // 检查列
+        checkColumn(showData, genTable.getColumns());
         // 需要返回到前台的列, 需要判断是否是列表展示, 4为判断列表是否可见
-        JSONArray showData = filterData(columns, 4, jsonArray, MaskConstant.LIST_VISIBLE::equals);
+        showData = filterData(columns, 4, showData, MaskConstant.LIST_VISIBLE::equals);
 
         JSONObject rows = new JSONObject();
         int total = selectService.countByCondition(genTable.getTableName(), condition, packCondition);
@@ -223,7 +221,9 @@ public class TableServiceCmdService {
 
         List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
                 , showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
+        // 处理blob
         handlerBlobWithJSONObject(genTable.getIsContainsBlob(), result);
+        // 处理日期、外键、字典值
         handler(result =  filter(result, ObjectUtils::isNotEmpty), columns);
         // 定制接口
         result = isCustomized(dto.getTable(),result,"trigger_retrieve");
@@ -304,7 +304,10 @@ public class TableServiceCmdService {
         for (JSONObject jsonObject : result) {
             for (GenTableColumn column : columns) {
                 if (jsonObject.containsKey(column.getColumnName()) && NEED_CONVERT_DATE_LIST.contains(column.getColumnType())) {
-                    getStrByTimeStamp(jsonObject, column.getColumnName());
+                    Date date = jsonObject.getTimestamp(column.getColumnName());
+                    if (null != date) {
+                        jsonObject.put(column.getColumnName(), DateUtils.dateTime(date));
+                    }
                 }
             }
         }
@@ -325,17 +328,8 @@ public class TableServiceCmdService {
             for (GenTableColumn column : columns) {
                 if (jsonObject.containsKey(column.getColumnName())) {
                     String value = jsonObject.getString(column.getColumnName());
-                    JSONArray fileList = JSON.parseArray(value);
-                    ArrayList<SysFile> files = Lists.newArrayListWithCapacity(fileList.size());
-                    for (Object obj : fileList) {
-                        JSONObject fileItem = (JSONObject) obj;
-                        SysFile file = new SysFile();
-                        file.setName(fileItem.getString(SINGLE_OBJ_NAME));
-                        file.setUrl(fileItem.getString(URL));
-                        files.add(file);
-                    }
-
-                    jsonObject.put(column.getColumnName(), files);
+                    List<SysFile> fileList = JSON.parseObject(value, new TypeReference<List<SysFile>>(){}.getType());
+                    jsonObject.put(column.getColumnName(), fileList);
                 }
             }
         }
@@ -367,20 +361,6 @@ public class TableServiceCmdService {
         }
     }
 
-    /**
-     * 功能描述: 把jsonObject中时间类型转为string,再放到jsonObject中,类型为: yyyy-mm-dd
-     *
-     * @param jsonObject jsonObject
-     * @param columnType create_time update_time...
-     */
-    private void getStrByTimeStamp(JSONObject jsonObject, String columnType) {
-        Date date = jsonObject.getTimestamp(columnType);
-        if (null != date) {
-            jsonObject.put(columnType, DateUtils.dateTime(date));
-        }
-    }
-
-
     /**
      * 功能描述: 获取单表单数据
      *
@@ -389,14 +369,11 @@ public class TableServiceCmdService {
      */
     public AjaxResult getObject(FormDataDto dto) {
         String tableName = requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
-
-        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
-        String pkName = IdUtils.getPkName(genTable.getColumns());
-        JSONObject fixedData = dto.getFixedData();
-        Long id = fixedData.getLong(FormDataConstant.ID);
-        requireNonNull(id, "如果是回显,则传参为此行记录的id, 如为新增,则传-1,传null可不行");
         Boolean isUi = requireNonNull(dto.getIsUi(), "未传isUi这个参数");
+        Long id = dto.getFixedData().getLong(FormDataConstant.ID);
+        requireNonNull(id, "如果是回显,则传参为此行记录的id, 如为新增,则传-1,传null可不行");
 
+        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
         List<GenTableColumn> columns = genTable.getColumns();
         // id = -1时,查询该表单对应的字段名称
         if (ltZero(id)) {
@@ -404,8 +381,10 @@ public class TableServiceCmdService {
         }
 
         // 默认查所有字段,不支持自定义
+        String pkName = IdUtils.getPkName(genTable.getColumns());
         JSONObject json = selectService.selectById(tableName, pkName, id);
         requireNonNull(json, "id 为[" + id + "]的数据不存在, 表名为[" + tableName + "]");
+        // 处理blob
         handlerBlobWithJSONObject(genTable.getIsContainsBlob(), Collections.singletonList(json));
         List<GenTableColumn> parentColumns = filterHrAndSort(columns);
 
@@ -434,51 +413,11 @@ public class TableServiceCmdService {
         }
 
         JSONObject result = new JSONObject();
-//        result.put(SHOW_DATA, packSingleObj(json, columns));
         result.put(SHOW_DATA, parentColumns);
         result.put(BUTTON_LIST, getButton(tableName));
         return AjaxResult.success(result);
     }
 
-    /**
-     * 功能描述: 单对象查询,封装成此类型返给前台:name=username, value=zhangsan, type=input, types=[{},{}]
-     *
-     * @param jsonObject 数据库查出的字段名称对应字段值
-     * @param columns    该表对应的所有的字段的信息
-     * @return java.util.List<com.alibaba.fastjson.JSONObject>
-     */
-    private List<JSONObject> packSingleObj(JSONObject jsonObject, List<GenTableColumn> columns) {
-        if (MapUtils.isEmpty(jsonObject)) {
-            return Collections.emptyList();
-        }
-
-        List<JSONObject> result = Lists.newArrayListWithCapacity(jsonObject.size());
-
-            for (GenTableColumn column : columns) {
-                JSONObject map = new JSONObject();
-                for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
-                    if (column.getColumnName().equalsIgnoreCase(entry.getKey())) {
-                        map.put(SINGLE_OBJ_NAME, column.getColumnName());
-                        map.put(SINGLE_OBJ_VALUE, entry.getValue());
-                        String htmlType = column.getHtmlType();
-                        map.put(SINGLE_OBJ_TYPE, htmlType);
-                        if (NEED_QUERY_DICT_LIST.contains(htmlType)) {
-                            String dictType = column.getDictType();
-                            try {
-                                map.put(SINGLE_OBJ_TYPES, remoteDictDataService.listByType(dictType));
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                            }
-                        }
-
-                        result.add(map);
-                    }
-                }
-            }
-
-        return result;
-    }
-
     /**
      * 功能描述: 封装成查询条件 key: 列名,  value:查询条件_查询类别
      * eg: [{"config_name": ["系统配置", "EQ", "varchar(100)"]}]
@@ -544,7 +483,7 @@ public class TableServiceCmdService {
         // genTable.getMenuRole() 暂时数据库没有数据,
         jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
 
-         jsonObject.put(ViewConst.VIEW_TYPE, genTable.getTplCategory());
+         jsonObject.put(ViewConst.VIEW_TYPE, Strings.nullToEmpty(genTable.getTplCategory()));
         return AjaxResult.success(jsonObject);
     }
 
@@ -578,23 +517,6 @@ public class TableServiceCmdService {
         return AjaxResult.success(queryList);
     }
 
-    /**
-     * 功能描述: 获取表单表头
-     * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
-     * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
-     *
-     *                    eg:{
-     *                          "table": "sys_config"
-     *                        }
-     *
-     * @param condition condition
-     * @return com.boman.common.core.web.domain.AjaxResult
-     */
-    public AjaxResult getTableHead(FormDataDto condition) {
-        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
-        return AjaxResult.success(getTableHeadList(genTable));
-    }
-
     /**
      * 功能描述:  单独获取按钮
      * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
@@ -638,27 +560,6 @@ public class TableServiceCmdService {
         return AjaxResult.success(jsonObject);
     }
 
-    public String getChildColumnNameByParentTableName(GenTable parentGenTable, Long childTableTableId){
-        requireNonNull(parentGenTable.getTableName(), "主表名称为空");
-//        GenTable primaryTable = redisService.getCacheObject(RedisKey.TABLE_INFO + genTable.getTableName());
-        Long parentTableId = parentGenTable.getTableId();
-        List<GenTableRelation> relations = redisService.getCacheObject(RedisKey.RELATION_INFO);
-        relations = relations.stream()
-                .filter(relation -> relation.getRelationParentId().equals(parentTableId))
-                .collect(Collectors.toList());
-
-        for (GenTableRelation relation : relations) {
-            if (relation.getRelationChildId().equals(6L)) {
-               // tableColumnService.selectGenTableColumnListByTableId(childTableTableId);
-//                return
-            }
-        }
-
-
-        return "";
-
-    }
-
     /**
      * 功能描述: 表单提交接口
      *
@@ -675,12 +576,9 @@ public class TableServiceCmdService {
         String pkName = IdUtils.getPkName(genTable.getColumns());
 
         // 先去查出之前的状态
-        List<Long> idList = commitData.stream().map(jsonObject -> jsonObject.getLong(FormDataConstant.ID))
-                .collect(Collectors.toList());
-        JSONArray showData = new JSONArray();
-        showData.add(FormDataConstant.STATUS);
-        showData.add(pkName);
-        List<JSONObject> beforeList = selectService.selectByIdList(tableName, pkName, idList, showData);
+        List<Long> idList = map(commitData, jsonObject -> jsonObject.getLong(FormDataConstant.ID));
+
+        List<JSONObject> beforeList = selectService.selectByIdList(tableName, pkName, idList, Lists.newArrayList(pkName, STATUS));
         requireNonNull(beforeList);
 
         for (JSONObject commitDatum : commitData) {
@@ -800,32 +698,13 @@ public class TableServiceCmdService {
     }
 
     /**
-     * 功能描述: 根据表名获取表信息、表字段和表字段对应的字典值
-     *                {
-     *                    "table": "sys_config",
-     *                }
+     * 功能描述: 根据表名封装列的对应关系, 同时封装好字典值
      *
-     *
-     * @param condition condition
+     * @param tableName  tableName
+     * @param allColumns allColumns
+     * @param isUi       带折叠true, 不带折叠false
      * @return com.boman.common.core.web.domain.AjaxResult
      */
-//    public AjaxResult getByTableName(BaseTableSaveDTO condition) {
-//        requireNonNull(condition.getTable(), "tableName = [" + condition.getTable() + "] 此表不存在");
-//        requireNonNull(condition.getIsUi(), "根据表名获取表字段,未传 isUi 这个字段");
-//        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
-//        List<GenTableColumn> allColumns = genTable.getColumns();
-//        // 把新增可见的列过滤出来
-////        List<GenTableColumn> returnData = ColumnUtils.filterNeedShowData(allColumns, 0, INSERT_VISIBLE::equals);
-//        // 普通的展示,不带折叠的
-//        if (BooleanUtils.isFalse(condition.getIsUi())) {
-//            packDictDataToColumns(allColumns, ObjectUtils::isNotEmpty);
-//            return AjaxResult.success(genTable);
-//        } else {
-//            // 带折叠的展示
-//            return getByTableName(genTable.getTableName(), allColumns, true);
-//        }
-//    }
-
     public AjaxResult getByTableName(String tableName, List<GenTableColumn> allColumns, Boolean isUi) {
         List<GenTableColumn> resultCols;
         List<GenTableColumn> parentColumns = filterHrAndSort(allColumns);

+ 1 - 2
boman-web-core/src/main/java/com/boman/web/core/service/select/BaseSelectServiceImpl.java

@@ -109,8 +109,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
      * @return com.alibaba.fastjson.JSONObject
      */
     @Override
-    public List<JSONObject> selectByIdList(String tableName, String pkName
-            , List<Long> idList, JSONArray showData) {
+    public List<JSONObject> selectByIdList(String tableName, String pkName, List<Long> idList, List<String> showData) {
         requireNonNull(tableName, "表名为空");
         requireNonNull(pkName, "主键名称为空");;
         requireNonNull(idList);

+ 1 - 1
boman-web-core/src/main/java/com/boman/web/core/service/select/IBaseSelectService.java

@@ -64,5 +64,5 @@ public interface IBaseSelectService {
      * @param showData  需要展示的列,若为空,查所有
      * @return com.alibaba.fastjson.JSONObject
      */
-    List<JSONObject> selectByIdList(String tableName, String pkName, List<Long> idList, JSONArray showData);
+    List<JSONObject> selectByIdList(String tableName, String pkName, List<Long> idList, List<String> showData);
 }

+ 7 - 6
boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.SecurityUtils;
 import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.gen.domain.GenTableColumn;
+import com.boman.domain.exception.UnknownColumnException;
 import com.google.common.collect.Lists;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.ArrayUtils;
@@ -125,8 +126,8 @@ public class ColumnUtils {
                 }
 
                 String columnName = allColumn.getColumnName();
-//                String columnName = allColumn.getColumnName().toUpperCase();
-                String[] maskArray = requireNonNull(allColumn.getMask(), "mask is empty").split("");
+                String mask = requireNonNull(allColumn.getMask(), "mask is empty, columnName = [" + allColumn.getColumnName() + "]");
+                String[] maskArray = mask.split("");
                 assert maskArray.length == 6;
                 String maskValue = maskArray[sort];
                 if (predicate.test(maskValue)) {
@@ -137,12 +138,12 @@ public class ColumnUtils {
             // data不为空,拿出前端传过来的列中可见的
             for (GenTableColumn allColumn : allColumns) {
                 String columnName = allColumn.getColumnName();
-//                String columnName = allColumn.getColumnName().toUpperCase();
                 if (HR.equalsIgnoreCase(allColumn.getHtmlType())) {
                     continue;
                 }
                 if (data.contains(columnName.toUpperCase()) || data.contains(columnName.toLowerCase())) {
-                    String[] maskArray = requireNonNull(allColumn.getMask(), "mask is empty").split("");
+                    String mask = requireNonNull(allColumn.getMask(), "mask is empty, columnName = [" + allColumn.getColumnName() + "]");
+                    String[] maskArray = mask.split("");
                     assert maskArray.length == 6;
                     String maskValue = maskArray[sort];
                     if (predicate.test(maskValue)) {
@@ -176,7 +177,7 @@ public class ColumnUtils {
         for (Map.Entry<String, Object> entry : target.entrySet()) {
             String columnName = entry.getKey();
             if (!all.contains(columnName.toLowerCase())) {
-                throw new IllegalArgumentException("此表 [" + tableName + "]中没有 [" + columnName + "] 字段");
+                throw new UnknownColumnException("此表 [" + tableName + "]中没有 [" + columnName + "] 字段");
             }
         }
     }
@@ -197,7 +198,7 @@ public class ColumnUtils {
         for (Object obj : target) {
             String columnName = (String) obj;
             if (!all.contains(columnName.toLowerCase()) || !all.contains(columnName.toUpperCase())) {
-                throw new IllegalArgumentException("此表 [" + tableName + "]中没有 [" + columnName + "] 字段");
+                throw new UnknownColumnException("此表 [" + tableName + "]中没有 [" + columnName + "] 字段");
             }
         }
     }