shiqian 4 жил өмнө
parent
commit
a434ba4661

+ 11 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/obj/ObjectUtils.java

@@ -219,6 +219,17 @@ public class ObjectUtils {
     }
 
 
+    public static <V> List<V> map(Map<String, V> input, Function<String, V> function) {
+        requireNonNull(input, "map is null");
+        List<V> result = new ArrayList<>(input.size());
+        for (Map.Entry<String, V> entry : input.entrySet()) {
+            result.add(entry.getValue());
+        }
+
+        return result;
+    }
+
+
     /**
      * 功能描述: 根据规则获取单个
      *

+ 45 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java

@@ -0,0 +1,45 @@
+package com.boman.web.core.controller;
+
+import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.web.core.domain.BaseTableDTO;
+import com.boman.web.core.service.common.ICommonService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * @author shiqian
+ * @date 2021年04月15日 16:25
+ **/
+@RestController
+@RequestMapping("common/")
+public class CommonController {
+
+    @Resource
+    private ICommonService commonService;
+
+    /**
+     * 功能描述: 根据表名和id查找
+     *
+     * @param tableName tableName
+     * @param id        id
+     * @return com.boman.common.core.web.domain.AjaxResult
+     */
+    @GetMapping("/tableName/{tableName}/id/{id}")
+    public AjaxResult getById(@PathVariable("tableName") String tableName, @PathVariable("id") Long id) {
+        return AjaxResult.success(commonService.getById(tableName, id));
+    }
+
+    /**
+     * 功能描述: 根据表名和自定义字段查找
+     *
+     * @param tableName tableName
+     * @param id        id
+     * @return com.boman.common.core.web.domain.AjaxResult
+     */
+    @PostMapping
+    public AjaxResult getByMap(@RequestBody BaseTableDTO dto) {
+        return AjaxResult.success(commonService.getByMap(dto.getTable(), dto.getFixedData()));
+    }
+
+}

+ 0 - 20
boman-web-core/src/main/java/com/boman/web/core/domain/BaseTableDTO.java

@@ -22,11 +22,6 @@ public class BaseTableDTO {
     @JSONField(name = "table")
     private String table;
 
-    @JSONField(name = "delMTable")
-    private Boolean delMTable;
-
-    @JSONField(name = "tabItem")
-    private JSONObject tabItem;
 
     public Long getObjId() {
         return objId;
@@ -52,19 +47,4 @@ public class BaseTableDTO {
         this.table = table;
     }
 
-    public Boolean getDelMTable() {
-        return delMTable;
-    }
-
-    public void setDelMTable(Boolean delMTable) {
-        this.delMTable = delMTable;
-    }
-
-    public JSONObject getTabItem() {
-        return tabItem;
-    }
-
-    public void setTabItem(JSONObject tabItem) {
-        this.tabItem = tabItem;
-    }
 }

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

@@ -165,13 +165,13 @@ public interface StandardlyMapper {
 
     /**
      * 功能描述: 根据tableName和map(属性名和属性值)进行查查
-     * {@link SqlProvider#selectByMap(java.util.Map)}
+     * {@link SqlProvider#getByMap(java.util.Map)}
      * @param tableName tableName
      * @param param     属性名和属性值
      * @return java.util.List<com.alibaba.fastjson.JSONObject>
      */
-    @SelectProvider(type = SqlProvider.class, method = "selectByMap")
-    List<JSONObject> selectByMap(@Param("tableName") String tableName, @Param("param") Map<String, Object> param);
+    @SelectProvider(type = SqlProvider.class, method = "getByMap")
+    List<JSONObject> getByMap(@Param("tableName") String tableName, @Param("param") JSONObject param);
 
 
     public static class SqlProvider {
@@ -538,8 +538,8 @@ public interface StandardlyMapper {
             return result;
         }
 
-        public String selectByMap(Map<String, Object> para) {
-            Map<String, Object> param = (Map<String, Object>) para.get("param");
+        public String getByMap(Map<String, Object> para) {
+            JSONObject param = (JSONObject) para.get("param");
             String tableName = (String) para.get("tableName");
 
             StringBuilder wholeSql = new StringBuilder();

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

@@ -299,9 +299,9 @@ public class TableServiceCmdService {
                     String fkTableName = fkGenTable.getTableName();
                     Object primaryTableFKvalue = json.get(selfColumnName);
                     // "DEPT_ID": {"value": 104, "name": "开发部"}
-                    Map<String, Object> param = Maps.newHashMap();
+                    JSONObject param = new JSONObject();
                     param.put(fkColumnName, primaryTableFKvalue);
-                    List<JSONObject> fkList = selectService.selectByMap(fkTableName, param);
+                    List<JSONObject> fkList = selectService.getByMap(fkTableName, param);
 
                     for (JSONObject object : fkList) {
                         Object value = object.get(dkColumnName);
@@ -741,7 +741,7 @@ public class TableServiceCmdService {
      * @param tableName      表名
      * @return com.boman.gen.domain.GenTable
      */
-    private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
+    public GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
         tableName = tableName.trim().toLowerCase();
         String key = requireNonNull(redisKeyPrefix) + requireNonNull(tableName);
         GenTable genTable = redisService.getCacheObject(key);

+ 6 - 4
boman-web-core/src/main/java/com/boman/web/core/service/select/BaseSelectServiceImpl.java

@@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
-import java.util.Map;
 
 import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
 
@@ -42,7 +41,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
     public List<JSONObject> selectByCondition(String tableName, JSONObject condition
             , JSONObject packCondition, JSONArray showData, String orderBy, Integer limit, Integer offset) {
         requireNonNull(tableName, "表名为空");
-        requireNonNull(showData, "数据库中此表: [" + tableName + "] , 没有列表展示的字段");
+        requireNonNull(showData, "表: [" + tableName + "] , 过滤了可展示字段,一个展示字段都没有,还查个鬼啊");
         requireNonNull(orderBy);
         return mapper.selectByCondition(tableName, condition, packCondition, showData, orderBy, limit, offset);
     }
@@ -55,9 +54,12 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
      * @return java.util.List<com.alibaba.fastjson.JSONObject>
      */
     @Override
-    public List<JSONObject> selectByMap(String tableName, Map<String, Object> param) {
+    public List<JSONObject> getByMap(String tableName, JSONObject param) {
         requireNonNull(tableName, "表名为空");
-        return mapper.selectByMap(tableName, param);
+
+        // 判断condition中列是否都在此table中
+
+        return mapper.getByMap(tableName, param);
     }
 
     /**

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

@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author shiqian
@@ -19,7 +18,7 @@ public interface IBaseSelectService {
      * @param param     属性名和属性值
      * @return java.util.List<com.alibaba.fastjson.JSONObject>
      */
-    List<JSONObject> selectByMap(String tableName, Map<String, Object> param);
+    List<JSONObject> getByMap(String tableName, JSONObject param);
 
     /**
      * 功能描述: 根据条件查询

+ 22 - 4
boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

@@ -9,10 +9,10 @@ import com.google.common.collect.Lists;
 
 import java.sql.Timestamp;
 import java.util.List;
+import java.util.Map;
 import java.util.function.Predicate;
 
-import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
-import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
 import static com.boman.web.core.constant.FormDataConstant.HR;
 
 /**
@@ -79,7 +79,7 @@ public class ColumnUtils {
     }
 
     /**
-     * 功能描述: 按照predicate的规则过滤allColumns中包含data并且符合过滤规则的数据
+     * 功能描述: 按照predicate的规则过滤allColumns中包含data并且符合过滤规则的数据, <p>过滤掉hr !!!</p>
      *
      * @param allColumns 所有的列
      * @param sort       同{@link ColumnUtils#filterData(java.util.List, int, java.util.function.Predicate)}
@@ -94,6 +94,10 @@ public class ColumnUtils {
         if (dataIsEmpty) {
             // data为空,拿出所有列中列表可见的
             for (GenTableColumn allColumn : allColumns) {
+                if (HR.equalsIgnoreCase(allColumn.getHtmlType())) {
+                    continue;
+                }
+
                 String columnName = allColumn.getColumnName();
 //                String columnName = allColumn.getColumnName().toUpperCase();
                 String[] maskArray = requireNonNull(allColumn.getMask(), "mask is empty").split("");
@@ -108,6 +112,9 @@ public class ColumnUtils {
             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("");
                     assert maskArray.length == 6;
@@ -127,4 +134,15 @@ public class ColumnUtils {
         return variables.replaceAll("\\$", "");
     }
 
-}
+
+    public <T> void checkColumn(Map<String, T> form, List<GenTableColumn> allColumns){
+        requireNonNull(form, "jsonObject is empty");
+        requireNonNull(allColumns, "allColumns is empty");
+
+
+        List<String> all = map(allColumns, GenTableColumn::getColumnName);
+//        map(form, );
+
+
+    }
+}