浏览代码

通用连表查询接口

shiqian 4 年之前
父节点
当前提交
147deda85a
共有 22 个文件被更改,包括 710 次插入116 次删除
  1. 7 0
      boman-api/boman-domain/src/main/java/com.boman.domain/constant/SqlConstant.java
  2. 3 3
      boman-api/boman-domain/src/main/java/com.boman.domain/dto/FormDataDto.java
  3. 250 0
      boman-api/boman-domain/src/main/java/com.boman.domain/dto/QueryBySqlDto.java
  4. 1 1
      boman-modules/boman-file/src/main/java/com/boman/file/controller/SysFileController.java
  5. 12 0
      boman-web-core/src/main/java/com/boman/web/core/controller/BomanMessageReceiveController.java
  6. 17 4
      boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java
  7. 13 2
      boman-web-core/src/main/java/com/boman/web/core/controller/MessageController.java
  8. 69 0
      boman-web-core/src/main/java/com/boman/web/core/mapper/StandardMapper.java
  9. 71 48
      boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java
  10. 2 1
      boman-web-core/src/main/java/com/boman/web/core/service/attendance/AttendanceServiceImpl.java
  11. 39 0
      boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/BomanMessageReceiveServiceImpl.java
  12. 8 0
      boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/IBomanMessageReceiveService.java
  13. 18 2
      boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java
  14. 10 1
      boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java
  15. 11 0
      boman-web-core/src/main/java/com/boman/web/core/service/message/MessageService.java
  16. 16 3
      boman-web-core/src/main/java/com/boman/web/core/service/message/MessageServiceImpl.java
  17. 41 5
      boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java
  18. 9 1
      boman-web-core/src/main/java/com/boman/web/core/service/save/IBaseSaveService.java
  19. 28 35
      boman-web-core/src/main/java/com/boman/web/core/service/select/BaseSelectServiceImpl.java
  20. 12 6
      boman-web-core/src/main/java/com/boman/web/core/service/select/IBaseSelectService.java
  21. 2 2
      boman-web-core/src/main/java/com/boman/web/core/service/update/BaseUpdateServiceImpl.java
  22. 71 2
      boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

+ 7 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/constant/SqlConstant.java

@@ -7,6 +7,8 @@ package com.boman.domain.constant;
  **/
 public class SqlConstant {
 
+    public static final String EMPTY = "";
+    public static final String SPACE = " ";
     public static final String SELECT = " select ";
     public static final String UPDATE = " update ";
     public static final String DELETE = " delete ";
@@ -16,6 +18,7 @@ public class SqlConstant {
     public static final String SET = " set ";
     public static final String FROM = " from ";
     public static final String COMMA = " , ";
+    public static final String POINT = " . ";
     public static final String LIMIT = " limit ";
     public static final String OFFSET = " offset ";
     public static final String ORDER_BY = " orderBy ";
@@ -43,4 +46,8 @@ public class SqlConstant {
     public static final String BIG_RIGHT = " } ";
 
 
+    public static final String LEFT_JOIN = " left join ";
+    public static final String ON = " on ";
+
+
 }

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

@@ -109,9 +109,9 @@ public class FormDataDto implements Serializable {
     private Boolean stopProcess;
 
     /******************************* 几个常量 **************************************/
-    private static final int MAX_PAGE_SIZE = 200;
-    private static final int DEFAULT_PAGE_SIZE = 10;
-    private static final int DEFAULT_PAGE_NO = 1;
+    public static final int MAX_PAGE_SIZE = 200;
+    public static final int DEFAULT_PAGE_SIZE = 10;
+    public static final int DEFAULT_PAGE_NO = 1;
 
 
     public int getLimit() {

+ 250 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/dto/QueryBySqlDto.java

@@ -0,0 +1,250 @@
+package com.boman.domain.dto;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.domain.GenTableColumn;
+import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+
+import static com.boman.domain.dto.FormDataDto.DEFAULT_PAGE_NO;
+import static com.boman.domain.dto.FormDataDto.MAX_PAGE_SIZE;
+import static com.boman.domain.dto.FormDataDto.DEFAULT_PAGE_SIZE;
+import static com.boman.domain.constant.SqlConstant.*;
+
+/**
+ * @author shiqian
+ * @date 2021年07月13日 11:25
+ **/
+@Data
+public class QueryBySqlDto {
+
+
+    private static final String LEFT_JOIN = "left_join";
+    private static final String COUNT_1 = " count(1) ";
+
+    /** 主表表名 **/
+    private String primaryTableName;
+    /** 子表表名 **/
+    private String deputyTableName;
+    /** 主表和子表 关联字段名称 **/
+    private String primaryTableNameRelKey;
+    /** 子表和主表 关联字段名称 **/
+    private String deputyTableNameRelKey;
+    /** 需要展示的列 **/
+    private List<String> showData;
+    /** 条件 <表名.字段名称, value> **/
+    private JSONObject condition;
+
+    private Integer pageNo;
+
+    private Integer pageSize;
+
+    private String orderBy;
+
+    public int getLimit() {
+        try {
+            return pageNo == 0 ? 0 : (pageNo - 1) * pageSize;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return DEFAULT_PAGE_NO;
+        }
+    }
+
+    public int getOffset(){
+        try {
+            int pageSize = this.pageSize == 0 ? DEFAULT_PAGE_SIZE : this.pageSize;
+            return Math.min(pageSize, MAX_PAGE_SIZE);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return DEFAULT_PAGE_SIZE;
+        }
+    }
+
+    /**
+     * 功能描述: 构建sql语句,暂且只查主表中的数据 todo
+     *
+     * @param pShowData  主表的showData
+     * @param queryBySql 前台传过来的dto
+     * @return java.lang.String
+     */
+    public static String buildDataSql(List<String> pShowData, QueryBySqlDto queryBySql) {
+        String primaryTableName = queryBySql.getPrimaryTableName();
+        String deputyTableName = queryBySql.getDeputyTableName();
+        return SELECT + buildShowData(pShowData, primaryTableName)
+//                + buildShowData(dShowData, queryBySql.getDeputyTableName())
+                + FROM + primaryTableName + LEFT_JOIN + deputyTableName + buildOn(queryBySql);
+    }
+
+    /**
+     * 功能描述: 构建sql语句,暂且只查主表中的条数 todo
+     *
+     * @param queryBySql 前台传过来的dto
+     * @return java.lang.String
+     */
+    public static String buildCountSql(QueryBySqlDto queryBySql) {
+        return SELECT + COUNT_1
+//                + buildShowData(dShowData, queryBySql.getDeputyTableName())
+                + FROM +  queryBySql.getPrimaryTableName() + LEFT_JOIN + queryBySql.getDeputyTableName() + buildOn(queryBySql);
+    }
+
+    /**
+     * 功能描述: 拼接sql语句 showData
+     *
+     * @param showData  showData
+     * @param tableName tableName
+     * @return java.lang.String
+     */
+    public static String buildShowData(List<String> showData, String tableName) {
+        StringBuilder sql = new StringBuilder(ALL);
+        if (!CollectionUtils.isEmpty(showData)) {
+            sql = new StringBuilder(EMPTY);
+            for (String showDatum : showData) {
+                String str = tableName + POINT + showDatum + ", ";
+                sql.append(str);
+            }
+
+            return StringUtils.substringBeforeLast(sql.toString(), ", ");
+        }
+
+        return sql.toString();
+    }
+
+    /**
+     * 功能描述: 连表查的 on 条件
+     *
+     * @param queryBySql queryBySql
+     * @return java.lang.String
+     */
+    public static String buildOn(QueryBySqlDto queryBySql) {
+        return ON + queryBySql.getPrimaryTableName() + POINT + queryBySql.getPrimaryTableNameRelKey()
+                + EQ + queryBySql.getDeputyTableName() + POINT + queryBySql.getDeputyTableNameRelKey();
+    }
+
+    /**
+     * 功能描述: 传到mapper层,判断是否需要转义
+     *
+     * @param columns   columns
+     * @param condition condition
+     * @return com.alibaba.fastjson.JSONObject
+     */
+    public static JSONObject packLeftJoinCondition(List<GenTableColumn> columns, JSONObject condition) {
+        if (isEmpty(condition)) {
+            return condition;
+        }
+
+        JSONObject result = new JSONObject(columns.size());
+        for (Map.Entry<String, Object> entry : condition.entrySet()) {
+            String key = entry.getKey();
+            String[] split = key.split("\\.");
+            // split[0] 表名, split[1] 属性名
+            key = split[1].trim();
+            Object value = entry.getValue();
+            for (GenTableColumn column : columns) {
+                if (!column.getColumnName().equalsIgnoreCase(key)) {
+                    continue;
+                }
+
+                // long string collection 暂时只作此三种类型判断
+                if (!isEmpty(value)) {
+                    // columnType 作为判断需不需要转义的一个标准,防止索引失效
+                    List<Object> objects = new ArrayList<>(3);
+                    objects.add(value);
+                    objects.add(column.getQueryType());
+                    objects.add(column.getColumnType());
+                    result.put(key, objects);
+                    break;
+                }
+            }
+        }
+
+        return result;
+    }
+
+    public static boolean isEmpty(Object input) {
+        if (input instanceof String) {
+            return StringUtils.isEmpty((String) input);
+        } else if (input instanceof Collection) {
+            return CollectionUtils.isEmpty(((Collection<?>) input));
+        } else {
+            return Objects.isNull(input);
+        }
+    }
+
+
+    /******************************************************** get set ********************************************************/
+
+    public String getPrimaryTableName() {
+        return primaryTableName;
+    }
+
+    public void setPrimaryTableName(String primaryTableName) {
+        this.primaryTableName = primaryTableName;
+    }
+
+    public String getDeputyTableName() {
+        return deputyTableName;
+    }
+
+    public void setDeputyTableName(String deputyTableName) {
+        this.deputyTableName = deputyTableName;
+    }
+
+    public String getPrimaryTableNameRelKey() {
+        return primaryTableNameRelKey;
+    }
+
+    public void setPrimaryTableNameRelKey(String primaryTableNameRelKey) {
+        this.primaryTableNameRelKey = primaryTableNameRelKey;
+    }
+
+    public String getDeputyTableNameRelKey() {
+        return deputyTableNameRelKey;
+    }
+
+    public void setDeputyTableNameRelKey(String deputyTableNameRelKey) {
+        this.deputyTableNameRelKey = deputyTableNameRelKey;
+    }
+
+    public List<String> getShowData() {
+        return showData;
+    }
+
+    public void setShowData(List<String> showData) {
+        this.showData = showData;
+    }
+
+    public JSONObject getCondition() {
+        return condition;
+    }
+
+    public void setCondition(JSONObject condition) {
+        this.condition = condition;
+    }
+
+    public Integer getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public String getOrderBy() {
+        return orderBy;
+    }
+
+    public void setOrderBy(String orderBy) {
+        this.orderBy = orderBy;
+    }
+}

+ 1 - 1
boman-modules/boman-file/src/main/java/com/boman/file/controller/SysFileController.java

@@ -46,7 +46,7 @@ public class SysFileController
             String staticPath = urlList.get(0);
             String absolutePath = urlList.get(1);
             String originalName = urlList.get(2);
-            sysFile.setName(FileUtils.getName(staticPath));
+            sysFile.setName(originalName);
             sysFile.setUrl(staticPath);
             sysFile.setAbsolutePath(absolutePath);
             sysFile.setOriginalName(originalName);

+ 12 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/BomanMessageReceiveController.java

@@ -40,4 +40,16 @@ public class BomanMessageReceiveController {
         return indexInfo;
     }
 
+   /**
+    * 功能描述: 读取发文和未读取发文的人数统计
+    *
+    * @param messageId messageId
+    * @return com.boman.domain.dto.AjaxResult
+    */
+    @GetMapping("/recieve/statistic/{messageId}")
+    public AjaxResult statisticRecieve(@PathVariable("messageId") Long messageId) {
+        return bomanMessageReceiveService.statisticRecieve(messageId);
+    }
+
+
 }

+ 17 - 4
boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java

@@ -2,10 +2,12 @@ package com.boman.web.core.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.domain.dto.*;
+import com.boman.web.core.domain.RowResult;
 import com.boman.web.core.service.common.ICommonService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * @author shiqian
@@ -88,14 +90,14 @@ public class CommonController {
 
 
     /**
-     * 功能描述: 批量插入数据
+     * 功能描述: 批量插入数据 仅此是关联表的批量插入,不处理多余的字段
      *
      * @param dto dto
      * @return int
      */
-    @PostMapping("/insertList")
-    public int insertList(@RequestBody InsertListDto dto) {
-        return commonService.insertList(dto);
+    @PostMapping("/insertRelList")
+    public int insertRelList(@RequestBody InsertListDto dto) {
+        return commonService.insertRelList(dto);
     }
 
     /**
@@ -121,4 +123,15 @@ public class CommonController {
         return commonService.update(dto);
     }
 
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @PostMapping("insertList")
+    public List<RowResult> insertList(@RequestBody InsertListDto dto) {
+        return commonService.insertList(dto);
+    }
+
 }

+ 13 - 2
boman-web-core/src/main/java/com/boman/web/core/controller/MessageController.java

@@ -1,9 +1,8 @@
 package com.boman.web.core.controller;
 
 import com.boman.domain.dto.AjaxResult;
-import com.boman.web.core.service.bomanMessageReceive.IBomanMessageReceiveService;
+import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.web.core.service.message.MessageService;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -42,4 +41,16 @@ public class MessageController {
         boolean withdraw = service.canDownload(id);
         return withdraw ? AjaxResult.success("可以下载") : AjaxResult.error("无法下载");
     }
+
+    /**
+     * 功能描述: 未完成的发文,对应菜单(申请中)
+     *
+     * @param queryBySql queryBySql
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @GetMapping("/notFinishMessages")
+    public AjaxResult notFinishMessages(@RequestBody QueryBySqlDto queryBySql) {
+        return AjaxResult.success(service.notFinishMessages(queryBySql));
+    }
+
 }

+ 69 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardMapper.java

@@ -2,6 +2,7 @@ package com.boman.web.core.mapper;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.web.core.utils.ColumnUtils;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
@@ -135,6 +136,26 @@ public interface StandardMapper {
                                        , @Param("limit") int limit
                                        , @Param("offset") int offset);
 
+    /**
+     * 功能描述: 自定义查询,需要查询的字段和value都在condition中
+     * {@link SqlProvider#selectByLeftJoinCondition(Map)}
+     *
+     * @param queryBySql    queryBySql
+     * @param packCondition 封装好的查询条件
+     * @param showData      需要查询的列
+     * @param orderBy       orderBy
+     * @param limit         分页
+     * @param offset        分页, 可以为null
+     * @return java.util.List<com.alibaba.fastjson.JSONObject>
+     */
+    @SelectProvider(type = SqlProvider.class, method = "selectByLeftJoinCondition")
+    List<JSONObject> selectByLeftJoinCondition(@Param("queryBySql") QueryBySqlDto queryBySql
+                                       , @Param("packCondition") JSONObject packCondition
+                                       , @Param("showData") List<String> showData
+                                       , @Param("orderBy") String orderBy
+                                       , @Param("limit") int limit
+                                       , @Param("offset") int offset);
+
 
     /**
      * 功能描述: 自定义查询,需要查询的字段和value都在condition中
@@ -147,6 +168,17 @@ public interface StandardMapper {
     @SelectProvider(type = SqlProvider.class, method = "countByCondition")
     int countByCondition(@Param("tableName") String tableName, @Param("packCondition") JSONObject packCondition);
 
+    /**
+     * 功能描述: 连表查询
+     * {@link SqlProvider#countByLeftJoinCondition(Map)}
+     *
+     * @param queryBySql    dto
+     * @param packCondition packCondition
+     * @return int
+     */
+    @SelectProvider(type = SqlProvider.class, method = "countByLeftJoinCondition")
+    int countByLeftJoinCondition(@Param("packCondition") JSONObject packCondition, @Param("queryBySql") QueryBySqlDto queryBySql);
+
     /**
      * 功能描述: 根据tableName和map(属性名和属性值)进行查查
      * {@link SqlProvider#getByMap(java.util.Map)}
@@ -392,6 +424,29 @@ public interface StandardMapper {
             return result;
         }
 
+        public String selectByLeftJoinCondition(Map<String, Object> para) {
+            QueryBySqlDto queryBySql = (QueryBySqlDto) para.get("queryBySql");
+            JSONObject packCondition = (JSONObject) para.get("packCondition");
+            String orderBy = (String) para.get("orderBy");
+            int limit = (int) para.get("limit");
+            int offset = (int) para.get("offset");
+            List<String> showData = (List<String>) para.get("showData");
+
+            String beforeSql = QueryBySqlDto.buildDataSql(showData, queryBySql);
+            StringBuilder wholeSql = new StringBuilder(beforeSql);
+
+            // 条件
+            packCondition(packCondition, wholeSql);
+            wholeSql.append(" order by ").append(orderBy).append(" limit ").append(limit);
+            if (isNotEmpty(offset)) {
+                wholeSql.append(", ").append(offset);
+            }
+
+            String result = wholeSql.toString();
+            LOGGER.info("selectByLeftJoinCondition的sql语句为:{} \r\n 查询条件: {}", result, packCondition);
+            return result;
+        }
+
         public String getByMap(Map<String, Object> para) {
             JSONObject packCondition = (JSONObject) para.get("packCondition");
             String tableName = (String) para.get("tableName");
@@ -460,6 +515,20 @@ public interface StandardMapper {
             return result;
         }
 
+        public String countByLeftJoinCondition(Map<String, Object> para) {
+            QueryBySqlDto queryBySql = (QueryBySqlDto) para.get("queryBySql");
+            JSONObject packCondition = (JSONObject) para.get("packCondition");
+
+            String beforeSql = QueryBySqlDto.buildCountSql(queryBySql);
+            StringBuilder wholeSql = new StringBuilder(beforeSql);
+            // 条件
+            packCondition(packCondition, wholeSql);
+
+            String result = wholeSql.toString();
+            LOGGER.info("查询countByLeftJoinCondition拼出的sql语句为: {} \r\n 查询条件: {}", result, packCondition);
+            return result;
+        }
+
         public String selectById(Map<String, Object> params) {
             String tableName = (String) params.get("tableName");
             String pkName = (String) params.get("pkName");

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

@@ -10,7 +10,6 @@ import com.boman.common.core.utils.number.NumberUtils;
 import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
-import com.boman.common.security.service.TokenService;
 import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
 import com.boman.domain.SysDictData;
@@ -22,7 +21,6 @@ import com.boman.gen.api.RemoteGenTableColumnService;
 import com.boman.gen.api.RemoteGenTableService;
 import com.boman.jflow.api.RemoteJflowProcessService;
 import com.boman.system.api.RemoteMenuService;
-import com.boman.system.api.model.LoginUser;
 import com.boman.web.core.domain.ActionType;
 import com.boman.web.core.domain.RowResult;
 import com.boman.web.core.domain.TableContext;
@@ -31,7 +29,6 @@ import com.boman.web.core.service.save.IBaseSaveService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import com.boman.web.core.service.submit.IBaseSubmitService;
 import com.boman.web.core.service.update.IBaseUpdateService;
-import com.boman.web.core.utils.BillRuleUtils;
 import com.boman.web.core.utils.ColumnUtils;
 import com.boman.web.core.utils.IdUtils;
 import com.google.common.base.Strings;
@@ -292,7 +289,7 @@ public class TableServiceCmdService {
         // 检查列
         checkColumn(condition, columns);
         // 封装好以后的查询条件
-        JSONObject packCondition = ifNullSetEmpty(selectService.packColCondition(columns, condition));
+        JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
         List<String> showData = dto.getShowData();
         // 检查列
         checkColumn(showData, genTable.getColumns());
@@ -330,6 +327,74 @@ public class TableServiceCmdService {
         return AjaxResult.success(rows);
     }
 
+
+    /**
+     * 功能描述: 获取单表单数据
+     *
+     * @param queryBySql queryBySql
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    public AjaxResult queryListBySql(QueryBySqlDto queryBySql) {
+        String primaryTableName = queryBySql.getPrimaryTableName();
+        String deputyTableName = queryBySql.getDeputyTableName();
+        String primaryTableNameRelKey = queryBySql.getPrimaryTableNameRelKey();
+        String deputyTableNameRelKey = queryBySql.getDeputyTableNameRelKey();
+        requireNonNull(primaryTableName, String.format("tableName = [%s] , 此表不存在", primaryTableName));
+        requireNonNull(deputyTableName, String.format("tableName = [%s] , 此表不存在", deputyTableName));
+        requireNonNull(primaryTableNameRelKey, String.format("主表和子表 关联字段名称不存在, name = [%s]", primaryTableNameRelKey));
+        requireNonNull(deputyTableNameRelKey, String.format("子表和主表 关联字段名称不存在, name = [%s]", deputyTableNameRelKey));
+
+        GenTable primaryGenTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, primaryTableName);
+        List<GenTableColumn> columns = primaryGenTable.getColumns();
+        GenTable deputyGenTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, deputyTableName);
+        List<GenTableColumn> deputyColumns = deputyGenTable.getColumns();
+        columns.addAll(deputyColumns);
+        // 查询条件
+        JSONObject condition = queryBySql.getCondition();
+        // 权限
+        checkAuthQueryList(primaryGenTable, condition);
+        // 检查列
+        checkLeftJoinColumn(condition.keySet(), columns);
+        // 封装好以后的查询条件
+        JSONObject packCondition = ifNullSetEmpty(ColumnUtils.packColCondition(columns, condition));
+
+        JSONObject rows = new JSONObject();
+        int total = selectService.countByLeftJoinCondition(packCondition, queryBySql);
+        rows.put(FormDataConstant.PAGE_TOTAL, total);
+        rows.put(TABLE_HEAD_LIST, getTableHeadList(primaryGenTable));
+        if (total <= 0) {
+            rows.put(FormDataConstant.PAGE_ROWS, new ArrayList<>());
+            return AjaxResult.success(rows);
+        }
+
+        List<String> showData = queryBySql.getShowData();
+        // 检查列
+        checkColumn(showData, columns);
+        // 需要返回到前台的列, 需要判断是否是列表展示, 4为判断列表是否可见
+        showData = filterData(columns, 4, showData, MaskConstant.LIST_VISIBLE::equals);
+        // 表的id单独处理,不管mask,都查出来返给前台
+        IdUtils.putIfNotContains(showData, IdUtils.getPkName(columns));
+        List<JSONObject> result = selectService.selectByLeftJoinCondition(queryBySql, packCondition, showData);
+//        result = filter(result, ObjectUtils::isNotEmpty);
+//
+//        // 查询时为null的列不显示的处理
+//        handleNullColumnValue(result, showData);
+//
+//        // 处理blob
+//        handleBlob(result, genTable.getIsContainsBlob());
+//        // 处理日期、外键、字典值
+//        handleDictForQueryList(result, columns);
+//        handleDateTimeForQueryList(result, columns);
+//        handleFkForQueryList(result, columns);
+//
+//        // 定制接口
+//        result = isCustomized(dto.getTable(), result, "trigger_retrieve");
+//
+//        rows.put(PAGE_ROWS, result);
+//        return AjaxResult.success(rows);
+        return AjaxResult.success();
+    }
+
     /**
      * 功能描述: 获取单表单数据
      *
@@ -670,7 +735,8 @@ public class TableServiceCmdService {
         List<String> permses = map(menus, SysMenu::getPerms);
         List<String> btns = Lists.newArrayListWithCapacity(permses.size());
         for (String perms : permses) {
-            if (perms.contains(tableName)) {
+            String[] split = perms.split(":");
+            if (split[0].equals(tableName)) {
                 btns.add(RoleMenuDto.getBtnFromPerms(perms));
             }
         }
@@ -1056,49 +1122,6 @@ public class TableServiceCmdService {
         return ajaxResult;
     }
 
-    /**P
-     * 功能描述: 新增的时候处理默认值, 从redis中拿到存在token中的userEnv对象,根据数据库中存的默认值的key,和userEnv中的key做比对,
-     * 从中取出作为字段的默认值,redis中存userEnv的位置:{@link TokenService#packUserEnv(com.boman.system.api.model.LoginUser))}
-     *
-     * @param commitData commitData
-     * @param columns 所有的列
-     */
-    private void handlerDefaultValue(JSONObject commitData, List<GenTableColumn> columns) {
-        String token = SecurityUtils.getToken();
-        LoginUser loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
-        JSONObject userEnv = loginUser.getUserEnv();
-        for (GenTableColumn column : columns) {
-            // 有默认值的列, 并且前台传过来的key中不包含
-            if (isNotEmpty(column.getDefaultValue()) && !commitData.containsKey(column.getColumnName())) {
-                String dbDefaultValue = column.getDefaultValue();
-                String defaultValue = ColumnUtils.parseVariables(dbDefaultValue);
-                String variables = dbDefaultValue.equalsIgnoreCase(defaultValue) ? dbDefaultValue : userEnv.getString(defaultValue);
-                commitData.put(column.getColumnName(), variables);
-            }
-        }
-    }
-
-    /*
-     * 功能描述: 单据规则
-     *
-     * @param commitData commitData
-     * @param allColumns allColumns
-     * @return void
-     */
-    private void buildBillRule(String tableName, JSONObject commitData, List<GenTableColumn> allColumns) {
-        requireNonNull(tableName, "tableName is empty");
-        for (GenTableColumn column : allColumns) {
-            String columnName = column.getColumnName();
-            String seqName = column.getSeqName();
-            if (isEmpty(seqName)) {
-                continue;
-            }
-
-            String rule = BillRuleUtils.getRules(tableName, seqName, columnName);
-            commitData.put(columnName, rule);
-        }
-    }
-
     private void addOtherColumn(List<GenTableColumn> columns, String other) {
         if(StringUtils.isEmpty(other)) {
             return;

+ 2 - 1
boman-web-core/src/main/java/com/boman/web/core/service/attendance/AttendanceServiceImpl.java

@@ -16,6 +16,7 @@ import com.boman.web.core.service.attendance.rules.AttendanceRulesService;
 import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import com.boman.web.core.utils.AuthUtils;
+import com.boman.web.core.utils.ColumnUtils;
 import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -138,7 +139,7 @@ public class AttendanceServiceImpl implements AttendanceService {
         String tableName = dto.getTable();
         GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
         List<GenTableColumn> columns = genTable.getColumns();
-        JSONObject packCondition = ifNullSetEmpty(selectService.packColCondition(columns, condition));
+        JSONObject packCondition = ifNullSetEmpty(ColumnUtils.packColCondition(columns, condition));
         int total = selectService.countByCondition(tableName, packCondition);
         JSONObject result = new JSONObject();
         result.put(FormDataConstant.PAGE_TOTAL, total);

+ 39 - 0
boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/BomanMessageReceiveServiceImpl.java

@@ -1,5 +1,6 @@
 package com.boman.web.core.service.bomanMessageReceive;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.StringUtils;
@@ -7,6 +8,7 @@ import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.UpdateDto;
 import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.service.select.IBaseSelectService;
+import com.sun.org.apache.regexp.internal.RE;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -25,8 +27,13 @@ public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveServi
 
     private static final String BOMAN_MESSAGE_RECEIVE = "boman_message_receive";
     private static final String STATUS = "status";
+    private static final String STATUS_N = "N";
+    private static final String STATUS_Y = "Y";
     private static final String MESSAGE_ID = "message_id";
     private static final String DELETED = "D";
+    private static final String TOTAL = "total";
+    private static final String NOT_READ = "notRead";
+    private static final String READ = "read";
 
     @Autowired
     private IBaseSelectService selectService;
@@ -123,4 +130,36 @@ public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveServi
         dto.setCondition(condition);
         return commonService.update(dto);
     }
+
+    /**
+     * 功能描述: 读取发文和未读取发文的人数统计
+     *
+     * @param messageId messageId
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @Override
+    public AjaxResult statisticRecieve(Long messageId) {
+        requireNonNull(messageId, "statisticRecieve, 发文id为空");
+
+        JSONObject condition = new JSONObject();
+        condition.put(MESSAGE_ID, messageId);
+        List<JSONObject> recieves = commonService.getByMap(BOMAN_MESSAGE_RECEIVE, condition);
+        requireNonNull(recieves, String.format("根据发文id: [%s], 未找到对应的收文列表", messageId));
+
+        int notRead = 0, read = 0;
+        for (JSONObject recieve : recieves) {
+            String status = recieve.getString(STATUS);
+            if (STATUS_N.equals(status)) {
+                notRead++;
+            } else if (STATUS_Y.equals(status)) {
+                read++;
+            }
+        }
+
+        JSONObject result = new JSONObject();
+        result.put(TOTAL, result.size());
+        result.put(NOT_READ, notRead);
+        result.put(READ, read);
+        return AjaxResult.success(result);
+    }
 }

+ 8 - 0
boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/IBomanMessageReceiveService.java

@@ -29,4 +29,12 @@ public interface IBomanMessageReceiveService {
      * @return int
      */
     int withdrawByMessageId(Long messageId);
+
+    /**
+     * 功能描述: 读取发文和未读取发文的人数统计
+     *
+     * @param messageId messageId
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    AjaxResult statisticRecieve(Long messageId);
 }

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

@@ -8,11 +8,13 @@ import com.boman.domain.dto.DeleteDto;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.InsertListDto;
 import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.domain.RowResult;
 import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.service.delete.IBaseDeleteService;
 import com.boman.web.core.service.save.IBaseSaveService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import com.boman.web.core.service.update.IBaseUpdateService;
+import com.boman.web.core.utils.ColumnUtils;
 import com.boman.web.core.utils.IdUtils;
 import org.springframework.stereotype.Service;
 
@@ -102,7 +104,7 @@ public class CommonServiceImpl implements ICommonService {
         String tableName = dto.getTable();
         requireNonNull(tableName, "tableName is empty");
         GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
-        JSONObject packCondition = selectService.packColCondition(genTable.getColumns(), condition);
+        JSONObject packCondition = ColumnUtils.packColCondition(genTable.getColumns(), condition);
         return selectService.countByCondition(tableName, packCondition);
     }
 
@@ -125,7 +127,21 @@ public class CommonServiceImpl implements ICommonService {
      * @return int
      */
     @Override
-    public int insertList(InsertListDto dto) {
+    public int insertRelList(InsertListDto dto) {
+        String tableName = requireNonNull(dto.getTableName(), "tableName is empty");
+        List<JSONObject> dataList = requireNonNull(dto.getDataList(), "dataList is empty");
+
+        return saveService.insertRelList(tableName, dataList);
+    }
+
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @Override
+    public List<RowResult> insertList(InsertListDto dto) {
         String tableName = requireNonNull(dto.getTableName(), "tableName is empty");
         List<JSONObject> dataList = requireNonNull(dto.getDataList(), "dataList is empty");
 

+ 10 - 1
boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java

@@ -5,6 +5,7 @@ import com.boman.domain.dto.DeleteDto;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.InsertListDto;
 import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.domain.RowResult;
 
 import java.util.List;
 
@@ -66,7 +67,7 @@ public interface ICommonService {
      * @param dto dto
      * @return int
      */
-    int insertList(InsertListDto dto);
+    int insertRelList(InsertListDto dto);
 
     /**
      * 功能描述: 通用删除数据
@@ -83,4 +84,12 @@ public interface ICommonService {
      * @return int
      */
     int update(UpdateDto dto);
+
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    List<RowResult> insertList(InsertListDto dto);
 }

+ 11 - 0
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageService.java

@@ -1,5 +1,8 @@
 package com.boman.web.core.service.message;
 
+import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.QueryBySqlDto;
+
 /**
  * @author shiqian
  * @date 2021年07月08日 13:56
@@ -21,4 +24,12 @@ public interface MessageService {
      * @return boolean
      */
     boolean canDownload(Long id);
+
+    /**
+     * 功能描述: 未完成的发文,对应菜单(申请中)
+     *
+     * @param queryBySql queryBySql
+     * @return List<JSONObject>
+     */
+    AjaxResult notFinishMessages(QueryBySqlDto queryBySql);
 }

+ 16 - 3
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageServiceImpl.java

@@ -1,8 +1,10 @@
 package com.boman.web.core.service.message;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.domain.dto.UpdateDto;
-import com.boman.web.core.service.bomanMessageReceive.BomanMessageReceiveServiceImpl;
+import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.service.bomanMessageReceive.IBomanMessageReceiveService;
 import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.utils.AuthUtils;
@@ -14,8 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 
-import java.sql.Timestamp;
-
 import static com.boman.common.core.utils.number.NumberUtils.eqZero;
 import static com.boman.common.core.utils.number.NumberUtils.gtZero;
 import static com.boman.common.core.utils.obj.ObjectUtils.*;
@@ -43,6 +43,8 @@ public class MessageServiceImpl implements MessageService {
     private ICommonService commonService;
     @Resource
     private IBomanMessageReceiveService receiveService;
+    @Resource
+    private TableServiceCmdService cmdService;
 
     /**
      * 功能描述: 撤回
@@ -101,4 +103,15 @@ public class MessageServiceImpl implements MessageService {
         long current = System.currentTimeMillis();
         return ((current - before) / 1000 / 60) > DEFAULT_TIME_OUT;
     }
+
+    /**
+     * 功能描述: 未完成的发文,对应菜单(申请中)
+     *
+     * @param queryBySql queryBySql
+     * @return List<JSONObject>
+     */
+    @Override
+    public AjaxResult notFinishMessages(QueryBySqlDto queryBySql) {
+        return cmdService.queryListBySql(queryBySql);
+    }
 }

+ 41 - 5
boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java

@@ -2,10 +2,12 @@ package com.boman.web.core.service.save;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.redis.service.RedisService;
+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.mapper.StandardMapper;
+import com.boman.web.core.utils.ColumnUtils;
 import com.boman.web.core.utils.IdUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -13,9 +15,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.List;
 
 import static com.boman.common.core.utils.obj.ObjectUtils.*;
+import static com.boman.web.core.utils.ColumnUtils.*;
 
 /**
  * @author shiqian
@@ -51,17 +56,48 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
     }
 
     @Override
-    public int insertList(String tableName, List<JSONObject> datList) {
-        requireNonNull(tableName, "insertList tableName is empty");
-        requireNonNull(datList, "insertList datList is empty");
+    public int insertRelList(String tableName, List<JSONObject> dataList) {
+        requireNonNull(tableName, "insertRelList tableName is empty");
+        requireNonNull(dataList, "insertRelList dataList is empty");
 
         String pkName = IdUtils.getPkName(tableName);
 
-        for (JSONObject data : datList) {
+        for (JSONObject data : dataList) {
             Long maxId = IdUtils.getMaxId(tableName, pkName);
             data.put(TableNameConst.ID, maxId);
         }
 
-        return mapper.insertList(tableName, datList);
+        return mapper.insertList(tableName, dataList);
+    }
+
+    /**
+     * 功能描述: 通用insertList
+     *
+     * @param tableName tableName
+     * @param dataList  dataList
+     * @return int
+     */
+    @Override
+    public List<RowResult> insertList(String tableName, List<JSONObject> dataList) {
+        requireNonNull(tableName, "insertList tableName is empty");
+        requireNonNull(dataList, "insertList datList is empty");
+
+        List<RowResult> rowResults = new ArrayList<>(dataList.size());
+        List<GenTableColumn> columns = ColumnUtils.getColumnList(tableName);
+        String pkName = IdUtils.getPkName(columns);
+        for (JSONObject commitData : dataList) {
+            Long maxId = IdUtils.getMaxId(tableName, pkName);
+            packUpdateByAndTime(columns, commitData, new Timestamp(System.currentTimeMillis()), true);
+            // 处理默认值
+            handlerDefaultValue(commitData, columns);
+            // 如果有单据、按照单据编号规则
+            buildBillRule(tableName, commitData, columns);
+            commitData.put(pkName, maxId);
+            rowResults.add(insertRow(tableName, commitData));
+        }
+
+        return rowResults;
     }
+
+
 }

+ 9 - 1
boman-web-core/src/main/java/com/boman/web/core/service/save/IBaseSaveService.java

@@ -24,6 +24,14 @@ public interface IBaseSaveService {
      */
     RowResult insertRow(String tableName, JSONObject commitData);
 
-    int insertList(String tableName, List<JSONObject> datList);
+    int insertRelList(String tableName, List<JSONObject> datList);
 
+    /**
+     * 功能描述: 通用insertList
+     *
+     * @param tableName tableName
+     * @param dataList  dataList
+     * @return int
+     */
+    List<RowResult> insertList(String tableName, List<JSONObject> dataList);
 }

+ 28 - 35
boman-web-core/src/main/java/com/boman/web/core/service/select/BaseSelectServiceImpl.java

@@ -1,22 +1,19 @@
 package com.boman.web.core.service.select;
 
 import com.alibaba.fastjson.JSONObject;
-import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.common.redis.RedisKey;
 import com.boman.domain.GenTable;
-import com.boman.domain.GenTableColumn;
 import com.boman.domain.dto.FormDataDto;
+import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.web.core.mapper.StandardMapper;
 import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.utils.ColumnUtils;
-import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 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.isEmpty;
 import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
@@ -50,11 +47,25 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
     @Override
     public List<JSONObject> selectByCondition(String tableName, JSONObject condition, JSONObject packCondition, List<String> showData, FormDataDto dto) {
         requireNonNull(tableName, "表名为空");
-        requireNonNull(showData, "表: [" + tableName + "] , 过滤了可展示字段,一个展示字段都没有,还查个鬼啊");
+        requireNonNull(showData, String.format("此表 = [%s], 无列表可展示字段", tableName));
         String orderBy = requireNonNull(dto.getOrderBy(), "order by is empty");
         return mapper.selectByCondition(tableName, packCondition, showData, orderBy, dto.getLimit(), dto.getOffset());
     }
 
+    @Override
+    public List<JSONObject> selectByLeftJoinCondition(QueryBySqlDto queryBySql, JSONObject packCondition, List<String> showData) {
+        String primaryTableName = queryBySql.getPrimaryTableName() ,deputyTableName = queryBySql.getDeputyTableName();
+        String primaryTableNameRelKey = queryBySql.getPrimaryTableNameRelKey(), deputyTableNameRelKey = queryBySql.getDeputyTableNameRelKey();
+        requireNonNull(primaryTableName, String.format("tableName = [%s] , 此表不存在", primaryTableName));
+        requireNonNull(deputyTableName, String.format("tableName = [%s] , 此表不存在", deputyTableName));
+        requireNonNull(primaryTableNameRelKey, String.format("主表和子表 关联字段名称不存在, name = [%s]", primaryTableNameRelKey));
+        requireNonNull(deputyTableNameRelKey, String.format("子表和主表 关联字段名称不存在, name = [%s]", deputyTableNameRelKey));
+        requireNonNull(showData, String.format("子表和主表 关联字段名称不存在, name = [%s]", deputyTableNameRelKey));
+        String orderBy = requireNonNull(queryBySql.getOrderBy(), "order by is empty");
+
+        return mapper.selectByLeftJoinCondition(queryBySql, packCondition, showData, orderBy, queryBySql.getLimit(), queryBySql.getOffset());
+    }
+
     /**
      * 功能描述: 根据tableName和map(属性名和属性值)进行查查
      *
@@ -120,6 +131,18 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
         return mapper.countByCondition(tableName, packCondition);
     }
 
+    /**
+     * 功能描述: 根据条件查询
+     *
+     * @param queryBySql    dto
+     * @param packCondition packCondition
+     * @return int
+     */
+    @Override
+    public int countByLeftJoinCondition(JSONObject packCondition, QueryBySqlDto queryBySql) {
+        return mapper.countByLeftJoinCondition(packCondition, queryBySql);
+    }
+
     /**
      * 功能描述: 根据id查所有,不支持自定义查询列
      *
@@ -154,36 +177,6 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
         return mapper.selectByIdList(tableName, pkName, idList, showData);
     }
 
-    /**
-     * 功能描述: 封装成查询条件 key: 列名,  value:查询条件_查询类别
-     * eg: [{"config_name": ["系统配置", "EQ", "varchar(100)"]}]
-     *
-     * @param columns columns
-     * @return com.alibaba.fastjson.JSONObject
-     */
-    @Override
-    public JSONObject packColCondition(List<GenTableColumn> columns, JSONObject condition) {
-        if (isEmpty(condition)) {
-            return condition;
-        }
-
-        JSONObject result = new JSONObject(columns.size());
-        for (Map.Entry<String, Object> entry : condition.entrySet()) {
-            String key = entry.getKey();
-            Object value = entry.getValue();
-            for (GenTableColumn column : columns) {
-                // long string collection 暂时只作此三种类型判断
-                if (column.getColumnName().equalsIgnoreCase(key) && ObjectUtils.isNotEmpty(value)) {
-                    // columnType 作为判断需不需要转义的一个标准,防止索引失效
-                    result.put(key, Lists.newArrayList(value, column.getQueryType(), column.getColumnType()));
-                    break;
-                }
-            }
-        }
-
-        return result;
-    }
-
     /**
      * 功能描述: 获取最新的一条数据 create desc
      *

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

@@ -1,9 +1,8 @@
 package com.boman.web.core.service.select;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.boman.domain.GenTableColumn;
 import com.boman.domain.dto.FormDataDto;
+import com.boman.domain.dto.QueryBySqlDto;
 
 import java.util.List;
 
@@ -43,16 +42,26 @@ public interface IBaseSelectService {
      */
     List<JSONObject> selectByCondition(String tableName, JSONObject condition, JSONObject packCondition, List<String> showData, FormDataDto dto);
 
+    List<JSONObject> selectByLeftJoinCondition(QueryBySqlDto queryBySql, JSONObject packCondition, List<String> showData);
+
     /**
      * 功能描述: 根据条件查询
      *
      * @param tableName     tableName
-     * @param condition     原始查询条件
      * @param packCondition 封装的查询条件
      * @return int
      */
     int countByCondition(String tableName, JSONObject packCondition);
 
+    /**
+     * 功能描述: 根据条件查询
+     *
+     * @param queryBySql    dto
+     * @param packCondition packCondition
+     * @return int
+     */
+    int countByLeftJoinCondition(JSONObject packCondition, QueryBySqlDto queryBySql);
+
     /**
      * 功能描述: 根据id查所有,不支持自定义查询列
      *
@@ -75,9 +84,6 @@ public interface IBaseSelectService {
      */
     List<JSONObject> selectByIdList(String tableName, String pkName, List<Long> idList, List<String> showData);
 
-
-    JSONObject packColCondition(List<GenTableColumn> columns, JSONObject condition);
-
     /**
      * 功能描述: 获取最新的一条数据 create desc
      *

+ 2 - 2
boman-web-core/src/main/java/com/boman/web/core/service/update/BaseUpdateServiceImpl.java

@@ -81,8 +81,8 @@ public class BaseUpdateServiceImpl implements IBaseUpdateService {
 
         ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime, false);
 
-        JSONObject packColCondition = selectService.packColCondition(columns, condition);
-        JSONObject packCommitData = selectService.packColCondition(columns, commitData);
+        JSONObject packColCondition = ColumnUtils.packColCondition(columns, condition);
+        JSONObject packCommitData = ColumnUtils.packColCondition(columns, commitData);
 
         return mapper.update(tableName, packCommitData, packColCondition);
     }

+ 71 - 2
boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

@@ -1,20 +1,23 @@
 package com.boman.web.core.utils;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.utils.collection.CollectionUtils;
 import com.alibaba.fastjson.util.TypeUtils;
 import com.boman.common.core.utils.SecurityUtils;
 import com.boman.common.core.utils.SpringUtils;
 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.common.security.service.TokenService;
 import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
+import com.boman.domain.constant.CacheConstants;
 import com.boman.domain.constant.MysqlDataTypeConst;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.exception.UnknownColumnException;
+import com.boman.system.api.model.LoginUser;
 import com.boman.web.core.domain.TableContext;
 import com.boman.web.core.service.TableServiceCmdService;
 import com.google.common.base.Joiner;
@@ -23,7 +26,6 @@ import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.web.client.RestTemplate;
 
-import javax.validation.constraints.NotNull;
 import java.sql.Timestamp;
 import java.util.*;
 import java.util.function.Predicate;
@@ -243,6 +245,26 @@ public class ColumnUtils {
         }
     }
 
+    /**
+     * 功能描述: 前台传过来的列是否都在表中
+     *
+     * @param strings 前台传过来的列名
+     * @param origin  此表对应的所有的列
+     */
+    public static void checkLeftJoinColumn(Set<String> strings, List<GenTableColumn> origin) {
+        if (org.apache.commons.collections4.CollectionUtils.isEmpty(strings) || ObjectUtils.isEmpty(origin)) {
+            return;
+        }
+
+        String tableName = origin.get(0).getTableName();
+        List<String> allColumnNames = map(origin, GenTableColumn::getColumnName);
+        for (String columnName : strings) {
+            if (!allColumnNames.contains(columnName.toLowerCase())) {
+                throw new UnknownColumnException("此表 [" + tableName + "]中没有 [" + columnName + "] 字段");
+            }
+        }
+    }
+
     /**
      * 功能描述: 前台传过来的列是否都在表中, List中的泛型必须为String
      *
@@ -529,4 +551,51 @@ public class ColumnUtils {
         }
     }
 
+
+    /**P
+     * 功能描述: 新增的时候处理默认值, 从redis中拿到存在token中的userEnv对象,根据数据库中存的默认值的key,和userEnv中的key做比对,
+     * 从中取出作为字段的默认值,redis中存userEnv的位置:{@link TokenService#packUserEnv(com.boman.system.api.model.LoginUser))}
+     *
+     * @param commitData commitData
+     * @param columns 所有的列
+     */
+    public static void handlerDefaultValue(JSONObject commitData, List<GenTableColumn> columns) {
+        String token = SecurityUtils.getToken();
+        RedisService redisService = SpringUtils.getBean(RedisService.class);
+        LoginUser loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
+        JSONObject userEnv = loginUser.getUserEnv();
+        for (GenTableColumn column : columns) {
+            // 有默认值的列, 并且前台传过来的key中不包含
+            if (isNotEmpty(column.getDefaultValue()) && !commitData.containsKey(column.getColumnName())) {
+                String dbDefaultValue = column.getDefaultValue();
+                String defaultValue = ColumnUtils.parseVariables(dbDefaultValue);
+                String variables = dbDefaultValue.equalsIgnoreCase(defaultValue) ? dbDefaultValue : userEnv.getString(defaultValue);
+                commitData.put(column.getColumnName(), variables);
+            }
+        }
+    }
+
+    /*
+     * 功能描述: 单据规则
+     *
+     * @param commitData commitData
+     * @param allColumns allColumns
+     * @return void
+     */
+    public static void buildBillRule(String tableName, JSONObject commitData, List<GenTableColumn> allColumns) {
+        requireNonNull(tableName, "tableName is empty");
+        for (GenTableColumn column : allColumns) {
+            String columnName = column.getColumnName();
+            String seqName = column.getSeqName();
+            if (isEmpty(seqName)) {
+                continue;
+            }
+
+            String rule = BillRuleUtils.getRules(tableName, seqName, columnName);
+            commitData.put(columnName, rule);
+        }
+    }
+
+
+
 }