Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

Administrator 4 жил өмнө
parent
commit
fc07912900
17 өөрчлөгдсөн 410 нэмэгдсэн , 404 устгасан
  1. 22 0
      boman-api/boman-domain/src/main/java/com.boman.domain/dto/DeleteDto.java
  2. 21 0
      boman-api/boman-domain/src/main/java/com.boman.domain/dto/UpdateDto.java
  3. 24 3
      boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java
  4. 174 361
      boman-web-core/src/main/java/com/boman/web/core/mapper/StandardMapper.java
  5. 1 1
      boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java
  6. 1 1
      boman-web-core/src/main/java/com/boman/web/core/service/attendance/AttendanceServiceImpl.java
  7. 38 1
      boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java
  8. 18 0
      boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java
  9. 37 6
      boman-web-core/src/main/java/com/boman/web/core/service/delete/BaseDeleteServiceImpl.java
  10. 8 1
      boman-web-core/src/main/java/com/boman/web/core/service/delete/IBaseDeleteService.java
  11. 2 5
      boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java
  12. 7 10
      boman-web-core/src/main/java/com/boman/web/core/service/select/BaseSelectServiceImpl.java
  13. 1 1
      boman-web-core/src/main/java/com/boman/web/core/service/select/IBaseSelectService.java
  14. 2 5
      boman-web-core/src/main/java/com/boman/web/core/service/submit/BaseSubmitServiceImpl.java
  15. 41 5
      boman-web-core/src/main/java/com/boman/web/core/service/update/BaseUpdateServiceImpl.java
  16. 11 0
      boman-web-core/src/main/java/com/boman/web/core/service/update/IBaseUpdateService.java
  17. 2 4
      boman-web-core/src/main/java/com/boman/web/core/utils/IdUtils.java

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

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

+ 21 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/dto/UpdateDto.java

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

+ 24 - 3
boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java

@@ -1,9 +1,7 @@
 package com.boman.web.core.controller;
 
 import com.alibaba.fastjson.JSONObject;
-import com.boman.domain.dto.AjaxResult;
-import com.boman.domain.dto.FormDataDto;
-import com.boman.domain.dto.InsertListDto;
+import com.boman.domain.dto.*;
 import com.boman.web.core.service.common.ICommonService;
 import org.springframework.web.bind.annotation.*;
 
@@ -100,4 +98,27 @@ public class CommonController {
         return commonService.insertList(dto);
     }
 
+    /**
+     * 功能描述: 通用删除数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @PostMapping("delete")
+    public int delete(@RequestBody DeleteDto dto) {
+        return commonService.delete(dto);
+    }
+
+
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @PostMapping("update")
+    public int update(@RequestBody UpdateDto dto) {
+        return commonService.update(dto);
+    }
+
 }

+ 174 - 361
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardlyMapper.java → boman-web-core/src/main/java/com/boman/web/core/mapper/StandardMapper.java

@@ -20,101 +20,84 @@ import static com.boman.domain.constant.FormDataConstant.*;
 
 /**
  * @author shiqian
- * @description
+ * @description 通用的mapper
  * @date 2021年03月22日 11:36
  **/
 @Mapper
 @Component
-public interface StandardlyMapper {
+public interface StandardMapper {
 
-    Logger LOGGER = LoggerFactory.getLogger(StandardlyMapper.class);
+    Logger LOGGER = LoggerFactory.getLogger(StandardMapper.class);
 
 
-    /** {@link SqlProvider#update(java.util.Map)} */
-    @UpdateProvider(type = SqlProvider.class, method = "update")
-    int updateById(@Param("tableName") String var1, @Param("model") JSONObject var2
-            , @Param("pkName") String pkName, @Param("ids") Long[] ids);
-
-    @UpdateProvider(
-            type = SqlProvider.class,
-            method = "update"
-    )
-    int newUpdateById(@Param("tableName") String var1, @Param("model") long var2);
-
-
-    @DeleteProvider(
-            type = SqlProvider.class,
-            method = "delete"
-    )
-    int deleteByIds(@Param("tableName") String var1, @Param("ids") Long[] var2, @Param("pkName") String pkName);
-
-    @Delete({"DELETE FROM ${tableName} where ID = #{id}"})
-    int deleteById(@Param("tableName") String tableName, @Param("pkName") String pkName, @Param("id") long var2);
-
-    @Select({"select * FROM ${tableName} where ID = #{id}"})
-    JSONObject getById(@Param("tableName") String var1, @Param("id") long var2);
-
-    @Select({"select ${columns} FROM ${tableName} where ID = #{id}"})
-    JSONObject getColumnsById(@Param("tableName") String var1, @Param("columns") String var2, @Param("id") long var3);
-
-    @InsertProvider(
-            type = SqlProvider.class,
-            method = "insert"
-    )
+    /* ***************************************************** insert ******************************************************/
+    /** {@link SqlProvider#insert(Map)} */
+    @InsertProvider(type = SqlProvider.class, method = "insert")
     int insert(@Param("tableName") String var1, @Param("model") JSONObject var2);
 
     /** {@link SqlProvider#insertList(Map)} */
-    @InsertProvider(type = SqlProvider.class,method = "insertList")
+    @InsertProvider(type = SqlProvider.class, method = "insertList")
     int insertList(@Param("tableName") String tableName, @Param("dataList") List<JSONObject> dataList);
 
-    @InsertProvider(
-            type = SqlProvider.class,
-            method = "inserts"
-    )
-    int inserts(@Param("tableName") String var1, @Param("models") JSONObject[] var2, @Param("processor") Consumer<JSONObject> var3);
 
-    @Select({"select count(1) FROM ${tableName} where ${column} = #{value} limit 1"})
-    boolean exists(@Param("tableName") String var1, @Param("column") String var2, @Param("value") Object var3);
+    /* ***************************************************** delete ******************************************************/
+    /** {@link SqlProvider#deleteByIdList(java.util.Map)} */
+    @DeleteProvider(type = SqlProvider.class, method = "deleteByIdList")
+    int deleteByIdList(@Param("tableName") String var1, @Param("idList") List<Long> idList, @Param("pkName") String pkName);
 
-    @Select({"select count(1) FROM ${tableName} where ID = #{id} limit 1"})
-    boolean existsById(@Param("tableName") String var1, @Param("id") long var2);
-
-    @Select({"select count(1) FROM ${tableName} where id <> #{id} and ${column} = #{value} limit 1"})
-    boolean existsWithoutId(@Param("tableName") String var1, @Param("id") long var2, @Param("column") String var4, @Param("value") Object var5);
+    /**
+     * 功能描述: 通用删除数据  {@link SqlProvider#delete(java.util.Map)}
+     *
+     * @param tableName        tableName
+     * @param condition        condition
+     * @param packColCondition packColCondition
+     * @return int
+     */
+    @SelectProvider(type = SqlProvider.class, method = "delete")
+    Integer delete(@Param("tableName") String tableName, @Param("condition") JSONObject condition
+            , @Param("packColCondition") JSONObject packColCondition);
 
-    @UpdateProvider(
-            type = SqlProvider.class,
-            method = "updates"
-    )
-    int updates(@Param("tableName") String var1, @Param("models") Collection<Object> var2, @Param("processor") Consumer<JSONObject> var3);
 
-    /** {@link SqlProvider#updateByIdList(Map)} */
+    /* ***************************************************** update ******************************************************/
+    /**  {@link SqlProvider#updateByIdList(Map)} */
     @UpdateProvider(type = SqlProvider.class, method = "updateByIdList")
     int updateByIdList(@Param("tableName") String tableName, @Param("pkName") String pkName
             , @Param("idList") List<Long> idList, @Param("model") JSONObject models);
 
+    /**  {@link SqlProvider#updateByForeignKey(Map)} */
     @UpdateProvider(type = SqlProvider.class, method = "updateByForeignKey")
     int updateByForeignKey(@Param("tableName") String tableName, @Param("foreignKeyName") String foreignKeyName
             , @Param("foreignKeyList") List<Long> foreignKeyList, @Param("model") JSONObject models);
 
-    @Select("select id from ${tableName} where ${akColumnName} = #{akColumnValue}")
-    Long selectIdByAkColumn(@Param("tableName") String tableName, @Param("akColumnName") String akColumnName, @Param("akColumnValue") String akColumnValue);
+    /**
+     * 功能描述: 通用修改  {@link SqlProvider#update(java.util.Map)}
+     *
+     * @param tableName        tableName
+     * @param packCommitData   packCommitData
+     * @param packColCondition packColCondition
+     * @return int
+     */
+    @SelectProvider(type = SqlProvider.class, method = "delete")
+    int update(@Param("tableName") String tableName, @Param("packCommitData") JSONObject packCommitData
+            , @Param("packColCondition") JSONObject packColCondition);
 
-    @Select("select ifnull(max(${pkName}),0) from ${tableName}")
+
+    /* ***************************************************** select ******************************************************/
+    @Select("select max(${pkName} from ${tableName}")
     int selectMaxId(@Param("tableName") String tableName, @Param("pkName") String pkName);
 
     /**
      * 功能描述: 根据id查所有
+     * {@link SqlProvider#selectById(Map)}
      *
      * @param tableName 表名
      * @param pkName    主键名称
      * @param id        主键值
+     * @param other     other is empty => select * from table where id = #{id}
      * @return com.alibaba.fastjson.JSONObject
      */
-//    @Select("select * from ${tableName} where ${pkName} = #{id} limit 1")
     @SelectProvider(type = SqlProvider.class, method = "selectById")
-    JSONObject selectById(@Param("tableName") String tableName
-            , @Param("pkName") String pkName, @Param("id") Long id,  @Param("other") String other);
+    JSONObject selectById(@Param("tableName") String tableName, @Param("pkName") String pkName, @Param("id") Long id, @Param("other") String other);
 
     /**
      * 功能描述: 根据id查所有
@@ -128,15 +111,15 @@ 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") List<String> showData);
+                                    , @Param("pkName") String pkName
+                                    , @Param("idList") List<Long> idList
+                                    , @Param("showData") List<String> showData);
 
     /**
      * 功能描述: 自定义查询,需要查询的字段和value都在condition中
      * {@link SqlProvider#selectByCondition(Map)}
      *
      * @param tableName     tableName
-     * @param condition     condition
      * @param packCondition 封装好的查询条件
      * @param showData      需要查询的列
      * @param orderBy       orderBy
@@ -146,12 +129,11 @@ public interface StandardlyMapper {
      */
     @SelectProvider(type = SqlProvider.class, method = "selectByCondition")
     List<JSONObject> selectByCondition(@Param("tableName") String tableName
-            , @Param("condition") JSONObject condition
-            , @Param("packCondition") JSONObject packCondition
-            , @Param("showData") List<String> showData
-            , @Param("orderBy") String orderBy
-            , @Param("limit") int limit
-            , @Param("offset") int offset);
+                                       , @Param("packCondition") JSONObject packCondition
+                                       , @Param("showData") List<String> showData
+                                       , @Param("orderBy") String orderBy
+                                       , @Param("limit") int limit
+                                       , @Param("offset") int offset);
 
 
     /**
@@ -159,174 +141,40 @@ public interface StandardlyMapper {
      * {@link SqlProvider#countByCondition(Map)}
      *
      * @param tableName     tableName
-     * @param condition     condition
      * @param packCondition 封装好的查询条件
      * @return int
      */
     @SelectProvider(type = SqlProvider.class, method = "countByCondition")
-    int countByCondition(@Param("tableName") String tableName
-            , @Param("condition") JSONObject condition
-            , @Param("packCondition") JSONObject packCondition);
+    int countByCondition(@Param("tableName") String tableName, @Param("packCondition") JSONObject packCondition);
 
     /**
      * 功能描述: 根据tableName和map(属性名和属性值)进行查查
      * {@link SqlProvider#getByMap(java.util.Map)}
      *
      * @param tableName     tableName
-     * @param condition     属性名和属性值
      * @param packCondition 属性名和属性值 条件
      * @param limitOne      true sql加上limit 1,   false 则不加
      * @return java.util.List<com.alibaba.fastjson.JSONObject>
      */
     @SelectProvider(type = SqlProvider.class, method = "getByMap")
-    List<JSONObject> getByMap(@Param("tableName") String tableName
-            , @Param("condition") JSONObject condition
-            , @Param("packCondition") JSONObject packCondition
+    List<JSONObject> getByMap(@Param("tableName") String tableName, @Param("packCondition") JSONObject packCondition
             , @Param("limitOne") boolean limitOne);
 
     /**
      * 功能描述: 获取最新的一条数据 create desc
      *
      * @param tableName tableName
-     * @return jcom.alibaba.fastjson.JSONObject
+     * @return com.alibaba.fastjson.JSONObject
      */
     @Select("select * from ${tableName} order by create_time desc limit 1")
     JSONObject getNewest(@Param("tableName") String tableName);
 
+
+    /* ***************************************************** SqlProvider ******************************************************/
     @SuppressWarnings("unchecked")
     class SqlProvider {
-        static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
-
-        public SqlProvider() {
-        }
-
-        private static boolean isReadOnly(String column) {
-            String[] var1 = READONLY_COLUMNS;
-            int var2 = var1.length;
-
-            for (int var3 = 0; var3 < var2; ++var3) {
-                String readonlyColumn = var1[var3];
-                if (readonlyColumn.equals(column)) {
-                    return true;
-                }
-            }
-
-            return false;
-        }
-
-        private static boolean isNullOrEmpty(String str) {
-            return str == null || str.length() == 0 || str.trim().length() == 0;
-        }
-
-        private static boolean isNullOrEmpty(JSONObject json) {
-            return json == null || json.isEmpty();
-        }
-
-        private static void keyToUpper(JSONObject json) {
-            String[] keys = new String[json.size()];
-            json.keySet().toArray(keys);
-            String[] var2 = keys;
-            int var3 = keys.length;
-
-            for (int var4 = 0; var4 < var3; ++var4) {
-                String key = var2[var4];
-                if (!key.equals(key.toUpperCase())) {
-                    json.put(key.toUpperCase(), json.get(key));
-                    json.remove(key);
-                }
-            }
-
-        }
-
-        public String update(Map<String, Object> para) {
-            String tableName = (String) para.get("tableName");
-            JSONObject model = (JSONObject) para.get("model");
-            String pkName = (String) para.get("pkName");
-            Long[] ids = (Long[]) para.get("ids");
-            if (StringUtils.isBlank(tableName)) {
-                throw new IllegalArgumentException("tableName 无效");
-            } else if (!model.isEmpty()) {
-                keyToUpper(model);
-                SQL sql = new SQL();
-                sql.UPDATE(tableName);
-
-                // 拼装set
-                model.forEach((key, value)->{
-                    if (!isReadOnly(key)) {
-                        // 此处需要对value加一个""
-                        sql.SET(key + " = \"" + value + "\"");
-                    }
-                });
-
-                // 拼装in
-                StringBuilder inSql = new StringBuilder();
-                for (int i = 0; i < ids.length; ++i) {
-                    inSql.append(String.format("#{ids[%d]}", i));
-                    inSql.append(",");
-                }
-
-                sql.WHERE(pkName + " in (" + inSql.toString());
-                String wholeSql = StringUtils.substringBeforeLast(sql.toString(), ",") + "))";
-                LOGGER.info("更改的sql语句为: {} \r\n 更改的数据为: {}", wholeSql, model);
-                return wholeSql;
-            } else {
-                throw new IllegalArgumentException("model 无效");
-            }
-        }
-
-        public String inserts(Map<String, Object> para) {
-            String tableName = (String) para.get("tableName");
-            JSONObject[] models = (JSONObject[]) ((JSONObject[]) para.get("models"));
-            Consumer<JSONObject> processor = (Consumer) para.get("processor");
-            if (isNullOrEmpty(tableName)) {
-                throw new IllegalArgumentException("tableName 无效");
-            } else if (models != null && models.length != 0) {
-                Set<String> columns = new HashSet();
-
-                for (int i = 0; i < models.length; ++i) {
-                    JSONObject model = models[i];
-                    if (model == null) {
-                        models[i] = model = new JSONObject();
-                    }
-
-                    if (processor != null) {
-                        processor.accept(model);
-                    }
-
-                    keyToUpper(model);
-                    columns.addAll(model.keySet());
-                }
-
-                StringBuffer sql = new StringBuffer();
-                sql.append("INSERT INTO ");
-                sql.append(tableName);
-                sql.append("(");
-                sql.append(String.join(",", columns));
-                sql.append(") VALUES");
-
-                for (int i = 0; i < models.length; ++i) {
-                    sql.append("(");
-
-                    for (Iterator var8 = columns.iterator(); var8.hasNext(); sql.append(",")) {
-                        String column = (String) var8.next();
-                        if (models[i].containsKey(column)) {
-                            sql.append(String.format("#{models[%d].%s}", i, column));
-                        } else {
-                            sql.append("default");
-                        }
-                    }
-
-                    sql.setCharAt(sql.length() - 1, ')');
-                    sql.append(",");
-                }
-
-                sql.deleteCharAt(sql.length() - 1);
-                return sql.toString();
-            } else {
-                throw new IllegalArgumentException("model 无效");
-            }
-        }
 
+        /* ***************************************************** insert ******************************************************/
         public String insert(Map<String, Object> para) {
             JSONObject model = (JSONObject) para.get("model");
             String tableName = (String) para.get("tableName");
@@ -384,6 +232,46 @@ public interface StandardlyMapper {
         }
 
 
+
+        /* ***************************************************** delete ******************************************************/
+        public String delete(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            JSONObject condition = (JSONObject) para.get("condition");
+            JSONObject packColCondition = (JSONObject) para.get("packColCondition");
+
+            StringBuilder sql = new StringBuilder();
+            sql.append("DELETE FROM ");
+            sql.append(tableName);
+            packCondition(packColCondition, sql);
+
+            String sqlStr = sql.toString();
+            LOGGER.info("通用删除的sql语句为: {} \r\n condition: {}", sqlStr, condition);
+            return sqlStr;
+        }
+
+        public String deleteByIdList(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            String pkName = (String) para.get("pkName");
+            List<Long> idList = (List<Long>) para.get(ID_LIST);
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("delete ").append(" from ").append(tableName).append(" where ").append(pkName).append(" in ( ");
+
+            for (int i = 0; i < idList.size(); ++i) {
+                wholeSql.append(String.format("#{idList[%d]}", i));
+                wholeSql.append(",");
+            }
+
+            wholeSql.setCharAt(wholeSql.length() - 1, ')');
+            String sqlStr = wholeSql.toString();
+            LOGGER.info("通用删除的sql语句为:{} \r\n deleteByIds idList: {}", sqlStr, idList);
+            return sqlStr;
+        }
+
+
+
+        /* ***************************************************** update ******************************************************/
+
         public String updateByIdList(Map<String, Object> para) {
             String tableName = (String) para.get("tableName");
             String pkName = (String) para.get("pkName");
@@ -410,7 +298,33 @@ public interface StandardlyMapper {
             String sqlStr = wholeSql.toString();
             LOGGER.info("批量更新的sql语句为: {} \r\n 更改的数据为: {} \r\n idList: {}", sqlStr, models, idList);
             return sqlStr;
+        }
+
+        public String update(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            JSONObject packCommitData = (JSONObject) para.get("packCommitData");
+            JSONObject packColCondition = (JSONObject) para.get("packColCondition");
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("update ").append(tableName).append(" set ");
+
+            for (Map.Entry<String, Object> entry : packCommitData.entrySet()) {
+                String key = entry.getKey();
+                Object valueObj = entry.getValue();
+                List<String> types = ((List<String>) valueObj);
+                /** {@link com.boman.web.core.utils.ColumnUtils.packColCondition} 这里是拼参数的地方 **/
+                Object value = types.get(0);
+                String queryType = types.get(1);
+                String columnType = types.get(2);
+                wholeSql.append(key).append(covert(queryType, columnType, key, value)).append(" , ");
+            }
 
+            wholeSql.append(StringUtils.substringBeforeLast(wholeSql.toString(), " , "));
+            packCondition(packColCondition, wholeSql);
+
+            String sqlStr = wholeSql.toString();
+            LOGGER.info("通用的更新sql语句为: {} \r\n 提交的数据为: {} \r\n 条件为: {}", sqlStr, packCommitData, packColCondition);
+            return sqlStr;
         }
 
         public String updateByForeignKey(Map<String, Object> para) {
@@ -442,151 +356,11 @@ public interface StandardlyMapper {
 
         }
 
-        public String delete(Map<String, Object> para) {
-            Long[] ids = (Long[]) para.get("ids");
-            String tableName = (String) para.get("tableName");
-            String pkName = (String) para.get("pkName");
-            if (isNullOrEmpty(tableName)) {
-                throw new IllegalArgumentException("tableName 无效");
-            } else if (ids == null) {
-                throw new IllegalArgumentException("ids 无效");
-            } else if (ids.length == 0) {
-                return "";
-            } else if (ids.length == 1) {
-                return "DELETE FROM " + tableName + " where " + pkName + " = #{ids[0]}";
-            } else {
-                StringBuffer sql = new StringBuffer();
-                sql.append("DELETE FROM ");
-                sql.append(tableName);
-                sql.append(" WHERE ");
-                sql.append(pkName + " in (");
-
-                for (int i = 0; i < ids.length; ++i) {
-                    sql.append(String.format("#{ids[%d]}", i));
-                    sql.append(",");
-                }
-
-                sql.setCharAt(sql.length() - 1, ')');
-                String sqlStr = sql.toString();
-                LOGGER.info("删除的sql语句为: {} \r\n idList: {}", sqlStr, ids);
-                return sqlStr;
-            }
-        }
 
-        public String updates(Map<String, Object> para) {
-            String tableName = (String) para.get("tableName");
-            Collection<Object> models = (Collection) para.get("models");
-            Consumer<JSONObject> processor = (Consumer) para.get("processor");
-            Boolean first = true;
-            if (isNullOrEmpty(tableName)) {
-                throw new IllegalArgumentException("tableName 无效");
-            } else if (models != null && models.size() != 0) {
-                JSONObject columnall = new JSONObject(true);
-                Iterator var7 = models.iterator();
-
-                while (var7.hasNext()) {
-                    Object obj = var7.next();
-                    JSONObject columnpart = (JSONObject) obj;
-                    if (columnpart == null) {
-                        columnpart = new JSONObject(true);
-                    }
-
-                    if (processor != null) {
-                        processor.accept(columnpart);
-                    }
-
-                    keyToUpper(columnpart);
-                    columnall.putAll(columnpart);
-                }
-
-                JSONObject clonekeyobj = (JSONObject) columnall.clone();
-                Set<String> keys = columnall.keySet();
-                Iterator var19 = keys.iterator();
 
-                while (var19.hasNext()) {
-                    String column = (String) var19.next();
-                    if (isReadOnly(column)) {
-                        clonekeyobj.remove(column);
-                    }
-                }
-
-                Set<String> firstkeys = clonekeyobj.keySet();
-                StringBuffer sql = new StringBuffer("");
-                sql.append("UPDATE ").append(tableName).append(" a");
-                sql.append(" right join (");
-                int i = -1;
-                Iterator var12 = models.iterator();
-
-                while (true) {
-                    while (var12.hasNext()) {
-                        Object obj = var12.next();
-                        ++i;
-                        JSONObject model = (JSONObject) obj;
-                        Iterator var15;
-                        String key;
-                        if (first.booleanValue()) {
-                            sql.append(" SELECT #{models[0].ID} `ID`,");
-                            var15 = firstkeys.iterator();
-
-                            while (var15.hasNext()) {
-                                key = (String) var15.next();
-                                if (model.get(key) == null) {
-                                    model.put(key, (Object) null);
-                                }
-
-                                sql.append(String.format("#{models[%d].%s} ", i, key));
-                                sql.append("`").append(key).append("`").append(",");
-                            }
-
-                            sql.deleteCharAt(sql.length() - 1);
-                            if (models.size() > 0) {
-                                sql.append(" union all");
-                            }
-
-                            first = false;
-                        } else {
-                            sql.append(" SELECT ");
-                            sql.append(String.format("#{models[%d].%s} ", i, "ID")).append(",");
-                            var15 = firstkeys.iterator();
-
-                            while (var15.hasNext()) {
-                                key = (String) var15.next();
-                                if (model.get(key) == null) {
-                                    model.put(key, (Object) null);
-                                }
-
-                                sql.append(String.format("#{models[%d].%s} ", i, key));
-                                sql.append(",");
-                            }
-
-                            sql.deleteCharAt(sql.length() - 1);
-                            if (i < models.size() - 1) {
-                                sql.append(" union all");
-                            }
-                        }
-                    }
-
-                    sql.append(") b on a.ID=b.ID ");
-                    sql.append(" SET ");
-                    var12 = firstkeys.iterator();
-
-                    while (var12.hasNext()) {
-                        String value = (String) var12.next();
-                        sql.append(" a.").append(value).append("=").append("IFNULL(b.").append(value).append(",").append("a.").append(value).append(")").append(",");
-                    }
-
-                    sql.deleteCharAt(sql.length() - 1);
-                    String sqlStr = sql.toString();
-                    LOGGER.info("更新的sql语句为: {}", sqlStr);
-                    return sqlStr;
-                }
-            } else {
-                throw new IllegalArgumentException("model 无效");
-            }
-        }
+        /* ***************************************************** select ******************************************************/
 
         public String selectByCondition(Map<String, Object> para) {
-            JSONObject condition = (JSONObject) para.get("condition");
             JSONObject packCondition = (JSONObject) para.get("packCondition");
             String tableName = (String) para.get("tableName");
             String orderBy = (String) para.get("orderBy");
@@ -619,7 +393,6 @@ public interface StandardlyMapper {
         }
 
         public String getByMap(Map<String, Object> para) {
-            JSONObject condition = (JSONObject) para.get("condition");
             JSONObject packCondition = (JSONObject) para.get("packCondition");
             String tableName = (String) para.get("tableName");
             boolean limitOne = (boolean) para.get("limitOne");
@@ -627,7 +400,7 @@ public interface StandardlyMapper {
             String result;
             StringBuilder wholeSql = new StringBuilder();
             wholeSql.append("select * from ").append(tableName);
-            if (isEmpty(condition)) {
+            if (isEmpty(packCondition)) {
                 result = wholeSql.toString();
             } else {
                 // 条件
@@ -636,7 +409,7 @@ public interface StandardlyMapper {
             }
 
             result = limitOne ? result + " limit 1" : result;
-            LOGGER.info("查询拼出的sql语句为: {} \r\n getByMap 查询条件: {}", result, condition);
+            LOGGER.info("查询拼出的sql语句为: {} \r\n getByMap 查询条件: {}", result, packCondition);
             return result;
         }
 
@@ -673,7 +446,6 @@ public interface StandardlyMapper {
         }
 
         public String countByCondition(Map<String, Object> para) {
-            JSONObject condition = (JSONObject) para.get("condition");
             JSONObject packCondition = (JSONObject) para.get("packCondition");
             String tableName = (String) para.get("tableName");
 
@@ -692,22 +464,24 @@ public interface StandardlyMapper {
             String tableName = (String) params.get("tableName");
             String pkName = (String) params.get("pkName");
             Long id = (Long) params.get("id");
-            String other = (String)params.get("other");
+            String other = (String) params.get("other");
             StringBuilder sqlBuilder = new StringBuilder();
-            if(StringUtils.isEmpty(other)) {
+            if (StringUtils.isEmpty(other)) {
                 sqlBuilder.append("select * from ")
                         .append(tableName).append(" where ")
-                        .append(pkName).append(" = ")
-                        .append(""+ id +"").append(" limit 1");
-            }else if(other.equals("leave")) {
+                        .append(pkName).append(" = ").append(id).append(" limit 1");
+            } else if ("leave".equals(other)) {
                 sqlBuilder.append("select t.*,u.nick_name  from ")
                         .append(tableName).append(" t ").append(" JOIN sys_user u ON u.user_name = t.leavefrom_user_name ")
                         .append(" where ")
-                        .append("t.").append(pkName).append(" = ").append(""+ id +"").append(" limit 1");
+                        .append("t.").append(pkName).append(" = ").append(id).append(" limit 1");
             }
             return sqlBuilder.toString();
         }
 
+
+        /* ***************************************************** utils ******************************************************/
+
         /**
          * 功能描述: 判断传过来的值是否需要转义
          *
@@ -746,7 +520,7 @@ public interface StandardlyMapper {
          */
         private String covert(String queryType, String columnType, String key, Object valueObj) {
             // false 不需要转义
-            boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)|| columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
+            boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR) || columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
             Object value;
             switch (queryType) {
                 case EQ:
@@ -772,7 +546,46 @@ public interface StandardlyMapper {
                 default:
                     // in
                     List<Object> list = valueObj instanceof List ? ((List<Object>) valueObj) : Lists.newArrayList(valueObj);
-                    return  " in (" + ColumnUtils.joinList(list) + ")";
+                    return " in (" + ColumnUtils.joinList(list) + ")";
+            }
+        }
+
+        static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
+
+        public SqlProvider() {
+        }
+
+        private static boolean isReadOnly(String column) {
+            String[] var1 = READONLY_COLUMNS;
+            int var2 = var1.length;
+
+            for (String readonlyColumn : var1) {
+                if (readonlyColumn.equals(column)) {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        private static boolean isNullOrEmpty(String str) {
+            return str == null || str.length() == 0 || str.trim().length() == 0;
+        }
+
+        private static boolean isNullOrEmpty(JSONObject json) {
+            return json == null || json.isEmpty();
+        }
+
+        private static void keyToUpper(JSONObject json) {
+            String[] keys = new String[json.size()];
+            json.keySet().toArray(keys);
+            int var3 = keys.length;
+
+            for (String key : keys) {
+                if (!key.equals(key.toUpperCase())) {
+                    json.put(key.toUpperCase(), json.get(key));
+                    json.remove(key);
+                }
             }
         }
     }

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

@@ -292,7 +292,7 @@ public class TableServiceCmdService {
         IdUtils.putIfNotContains(showData, IdUtils.getPkName(columns));
 
         JSONObject rows = new JSONObject();
-        int total = selectService.countByCondition(genTable.getTableName(), condition, packCondition);
+        int total = selectService.countByCondition(genTable.getTableName(), packCondition);
         rows.put(FormDataConstant.PAGE_TOTAL, total);
         rows.put(TABLE_HEAD_LIST, getTableHeadList(genTable));
         if (total <= 0) {

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

@@ -139,7 +139,7 @@ public class AttendanceServiceImpl implements AttendanceService {
         GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
         List<GenTableColumn> columns = genTable.getColumns();
         JSONObject packCondition = ifNullSetEmpty(selectService.packColCondition(columns, condition));
-        int total = selectService.countByCondition(tableName, condition, packCondition);
+        int total = selectService.countByCondition(tableName, packCondition);
         JSONObject result = new JSONObject();
         result.put(FormDataConstant.PAGE_TOTAL, total);
         if (total <= 0) {

+ 38 - 1
boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java

@@ -4,11 +4,15 @@ import com.alibaba.fastjson.JSONObject;
 import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
 import com.boman.domain.GenTable;
+import com.boman.domain.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.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.IdUtils;
 import org.springframework.stereotype.Service;
 
@@ -33,6 +37,10 @@ public class CommonServiceImpl implements ICommonService {
     private TableServiceCmdService cmdService;
     @Resource
     private IBaseSaveService saveService;
+    @Resource
+    private IBaseDeleteService deleteService;
+    @Resource
+    private IBaseUpdateService updateService;
 
     /**
      * 功能描述: 根据表名和id查找
@@ -95,7 +103,7 @@ public class CommonServiceImpl implements ICommonService {
         requireNonNull(tableName, "tableName is empty");
         GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
         JSONObject packCondition = selectService.packColCondition(genTable.getColumns(), condition);
-        return selectService.countByCondition(tableName, condition, packCondition);
+        return selectService.countByCondition(tableName, packCondition);
     }
 
     /**
@@ -123,4 +131,33 @@ public class CommonServiceImpl implements ICommonService {
 
         return saveService.insertList(tableName, dataList);
     }
+
+    /**
+     * 功能描述: 通用删除数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @Override
+    public int delete(DeleteDto dto) {
+        String tableName = requireNonNull(dto.getTableName(), "tableName is empty");
+        JSONObject condition = requireNonNull(dto.getCondition(), "condition is empty");
+
+        return deleteService.delete(tableName, condition);
+    }
+
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    @Override
+    public int update(UpdateDto dto) {
+        String tableName = requireNonNull(dto.getTableName(), "tableName is empty");
+        JSONObject condition = requireNonNull(dto.getCondition(), "condition is empty, 条件为空不允许调用修改接口,防止误操作");
+        JSONObject commitData = requireNonNull(dto.getCommitData(), "commitData is empty");
+
+        return updateService.update(tableName, commitData, condition);
+    }
 }

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

@@ -1,8 +1,10 @@
 package com.boman.web.core.service.common;
 
 import com.alibaba.fastjson.JSONObject;
+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 java.util.List;
 
@@ -65,4 +67,20 @@ public interface ICommonService {
      * @return int
      */
     int insertList(InsertListDto dto);
+
+    /**
+     * 功能描述: 通用删除数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    int delete(DeleteDto dto);
+
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param dto dto
+     * @return int
+     */
+    int update(UpdateDto dto);
 }

+ 37 - 6
boman-web-core/src/main/java/com/boman/web/core/service/delete/BaseDeleteServiceImpl.java

@@ -1,14 +1,25 @@
 package com.boman.web.core.service.delete;
 
 import com.alibaba.fastjson.JSONObject;
-import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.common.redis.RedisKey;
+import com.boman.common.redis.service.RedisService;
+import com.boman.domain.GenTable;
+import com.boman.domain.GenTableColumn;
 import com.boman.web.core.domain.RowResult;
-import com.boman.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.mapper.StandardMapper;
+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.Arrays;
+import java.util.List;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
+import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+
 /**
  * @author shiqian
  * @date 2021年03月26日 11:16
@@ -19,7 +30,9 @@ public class BaseDeleteServiceImpl implements IBaseDeleteService {
     private static final Logger LOGGER = LoggerFactory.getLogger(BaseDeleteServiceImpl.class);
 
     @Autowired
-    private StandardlyMapper mapper;
+    private StandardMapper mapper;
+    @Autowired
+    private RedisService redisService;
 
     /**
      * 功能描述: 在此不对入参进行校验,所以在调用此方法之前一定要对参数进行校验,以免报错
@@ -31,7 +44,7 @@ public class BaseDeleteServiceImpl implements IBaseDeleteService {
      */
     @Override
     public RowResult objectDelete(Long[] idArr, String tableName, String pkName) {
-        int delete = mapper.deleteByIds(tableName, idArr, pkName);
+        int delete = mapper.deleteByIdList(tableName, Arrays.asList(idArr), pkName);
         return RowResult.ok("共删除了 " + delete + " 条记录");
     }
 
@@ -45,7 +58,7 @@ public class BaseDeleteServiceImpl implements IBaseDeleteService {
      */
     @Override
     public RowResult deleteById(String tableName, String pkName, Long id) {
-        int delete = mapper.deleteById(tableName, pkName, id);
+        int delete = mapper.deleteByIdList(tableName, Lists.newArrayList(id), pkName);
         return delete > 0 ? RowResult.ok() : RowResult.fail();
     }
 
@@ -60,9 +73,27 @@ public class BaseDeleteServiceImpl implements IBaseDeleteService {
      */
     @Override
     public RowResult objectLogicDelete(Long[] idArr, String tableName, String pkName, JSONObject model) {
-        int delete = mapper.updateById(tableName, model, pkName, idArr);
+        int delete = mapper.updateByIdList(tableName, pkName, Arrays.asList(idArr), model);
         return delete > 0 ? RowResult.ok() : RowResult.fail();
     }
 
+    /**
+     * 功能描述: 通用删除数据
+     *
+     * @param tableName tableName
+     * @param condition condition
+     * @return int
+     */
+    @Override
+    public int delete(String tableName, JSONObject condition) {
+        requireNonNull(tableName, "tableName is empty");
+        requireNonNull(condition, "condition is empty");
 
+        GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
+        List<GenTableColumn> columns = genTable.getColumns();
+        ColumnUtils.checkColumn(condition, columns);
+        JSONObject packColCondition = ColumnUtils.packColCondition(columns, condition);
+        Integer delete = mapper.delete(tableName, condition, packColCondition);
+        return isEmpty(delete) ? 0 : delete;
+    }
 }

+ 8 - 1
boman-web-core/src/main/java/com/boman/web/core/service/delete/IBaseDeleteService.java

@@ -42,5 +42,12 @@ public interface IBaseDeleteService {
      */
     RowResult objectLogicDelete(Long[] idArr, String tableName, String pkName, JSONObject model);
 
-
+    /**
+     * 功能描述: 通用删除数据
+     *
+     * @param tableName tableName
+     * @param condition condition
+     * @return int
+     */
+    int delete(String tableName, JSONObject condition);
 }

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

@@ -1,14 +1,11 @@
 package com.boman.web.core.service.save;
 
 import com.alibaba.fastjson.JSONObject;
-import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
-import com.boman.domain.GenTable;
-import com.boman.domain.GenTableColumn;
 import com.boman.domain.constant.FormDataConstant;
 import com.boman.domain.constant.TableNameConst;
 import com.boman.web.core.domain.RowResult;
-import com.boman.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.mapper.StandardMapper;
 import com.boman.web.core.utils.IdUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,7 +28,7 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
     private static final Logger LOGGER = LoggerFactory.getLogger(BaseSaveServiceImpl.class);
 
     @Autowired
-    private StandardlyMapper mapper;
+    private StandardMapper mapper;
     @Resource
     private RedisService redisService;
     /**

+ 7 - 10
boman-web-core/src/main/java/com/boman/web/core/service/select/BaseSelectServiceImpl.java

@@ -1,16 +1,14 @@
 package com.boman.web.core.service.select;
 
-import com.alibaba.fastjson.JSONArray;
 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.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.mapper.StandardMapper;
 import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.utils.ColumnUtils;
-import com.boman.web.core.utils.HandlerFormDataUtils;
 import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,7 +32,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
     private static final Logger LOGGER = LoggerFactory.getLogger(BaseSelectServiceImpl.class);
 
     @Autowired
-    private StandardlyMapper mapper;
+    private StandardMapper mapper;
     @Autowired
     private TableServiceCmdService cmdService;
 
@@ -54,7 +52,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
         requireNonNull(tableName, "表名为空");
         requireNonNull(showData, "表: [" + tableName + "] , 过滤了可展示字段,一个展示字段都没有,还查个鬼啊");
         String orderBy = requireNonNull(dto.getOrderBy(), "order by is empty");
-        return mapper.selectByCondition(tableName, condition, packCondition, showData, orderBy, dto.getLimit(), dto.getOffset());
+        return mapper.selectByCondition(tableName, packCondition, showData, orderBy, dto.getLimit(), dto.getOffset());
     }
 
     /**
@@ -72,7 +70,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
         GenTable gent = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
         ColumnUtils.checkColumn(param, gent.getColumns());
         JSONObject packColCondition = ColumnUtils.packColCondition(gent.getColumns(), param);
-        List<JSONObject> result = mapper.getByMap(tableName, param, packColCondition, false);
+        List<JSONObject> result = mapper.getByMap(tableName, packColCondition, false);
 
         handleBlob(result, gent.getIsContainsBlob());
         handleDateTimeForQueryList(result, gent.getColumns());
@@ -98,7 +96,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
         GenTable gent = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
         ColumnUtils.checkColumn(param, gent.getColumns());
         JSONObject packColCondition = ColumnUtils.packColCondition(gent.getColumns(), param);
-        List<JSONObject> result = mapper.getByMap(tableName, param, packColCondition, true);
+        List<JSONObject> result = mapper.getByMap(tableName, packColCondition, true);
 
         handleBlob(result, gent.getIsContainsBlob());
         handleDateTimeForQueryList(result, gent.getColumns());
@@ -112,15 +110,14 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
      * 功能描述: 根据条件查询
      *
      * @param tableName     tableName
-     * @param condition     原始查询条件
      * @param packCondition 封装的查询条件
      * @return int
      */
     @Override
-    public int countByCondition(String tableName, JSONObject condition, JSONObject packCondition) {
+    public int countByCondition(String tableName, JSONObject packCondition) {
         requireNonNull(tableName, "表名为空");
 
-        return mapper.countByCondition(tableName, condition, packCondition);
+        return mapper.countByCondition(tableName, packCondition);
     }
 
     /**

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

@@ -51,7 +51,7 @@ public interface IBaseSelectService {
      * @param packCondition 封装的查询条件
      * @return int
      */
-    int countByCondition(String tableName, JSONObject condition, JSONObject packCondition);
+    int countByCondition(String tableName, JSONObject packCondition);
 
     /**
      * 功能描述: 根据id查所有,不支持自定义查询列

+ 2 - 5
boman-web-core/src/main/java/com/boman/web/core/service/submit/BaseSubmitServiceImpl.java

@@ -1,14 +1,11 @@
 package com.boman.web.core.service.submit;
 
 import com.alibaba.fastjson.JSONObject;
-import com.boman.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.mapper.StandardMapper;
 import com.google.common.collect.Lists;
-import org.apache.commons.lang3.ArrayUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-
 import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
 
 
@@ -21,7 +18,7 @@ public class BaseSubmitServiceImpl implements IBaseSubmitService {
 
 
     @Autowired
-    private StandardlyMapper mapper;
+    private StandardMapper mapper;
 
     /**
      * 功能描述: 处理提交流程

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

@@ -2,21 +2,25 @@ package com.boman.web.core.service.update;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.common.redis.RedisKey;
+import com.boman.common.redis.service.RedisService;
+import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
 import com.boman.web.core.domain.TableContext;
-import com.boman.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.mapper.StandardMapper;
+import com.boman.web.core.service.select.IBaseSelectService;
 import com.boman.web.core.utils.ColumnUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.sql.Timestamp;
 import java.util.List;
 import java.util.Map;
 
-import static com.boman.common.core.utils.obj.ObjectUtils.escapeStr;
-import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
 import static com.boman.domain.constant.FormDataConstant.*;
 
 /**
@@ -29,7 +33,11 @@ public class BaseUpdateServiceImpl implements IBaseUpdateService {
     private static final Logger LOGGER = LoggerFactory.getLogger(BaseUpdateServiceImpl.class);
 
     @Autowired
-    private StandardlyMapper mapper;
+    private StandardMapper mapper;
+    @Resource
+    private RedisService redisService;
+    @Resource
+    private IBaseSelectService selectService;
 
     /**
      * 功能描述: 批量修改, 默认需要更改的model,更改的字段类型和字段值都是一致的
@@ -48,11 +56,39 @@ public class BaseUpdateServiceImpl implements IBaseUpdateService {
         Timestamp currentTime = new Timestamp(System.currentTimeMillis());
 
         ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime, false);
-        commitData = ObjectUtils.ifNullSetEmpty(escapeByQueryType(columns, commitData));
+        commitData = ifNullSetEmpty(escapeByQueryType(columns, commitData));
 
         return mapper.updateByIdList(tableName, pkName, idList, commitData);
     }
 
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param tableName  tableName
+     * @param commitData commitData
+     * @param condition  condition
+     * @return int
+     */
+    @Override
+    public int update(String tableName, JSONObject commitData, JSONObject condition) {
+        requireNonNull(tableName, "tableName is empty");
+        requireNonNull(condition, "condition is empty, 条件为空不允许调用修改接口,防止误操作");
+        requireNonNull(commitData, "commitData is empty");
+
+        GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
+        List<GenTableColumn> columns = genTable.getColumns();
+        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
+
+        ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime, false);
+        commitData = ifNullSetEmpty(escapeByQueryType(columns, commitData));
+
+        JSONObject packColCondition = selectService.packColCondition(columns, condition);
+        JSONObject packCommitData = selectService.packColCondition(columns, commitData);
+
+        return mapper.update(tableName, packCommitData, packColCondition);
+
+    }
+
     private JSONObject escapeByQueryType(List<GenTableColumn> columns, JSONObject commitData) {
         requireNonNull(columns, "columns is empty");
         JSONObject result = new JSONObject(columns.size());

+ 11 - 0
boman-web-core/src/main/java/com/boman/web/core/service/update/IBaseUpdateService.java

@@ -1,5 +1,6 @@
 package com.boman.web.core.service.update;
 
+import com.alibaba.fastjson.JSONObject;
 import com.boman.web.core.domain.TableContext;
 
 import java.util.List;
@@ -18,4 +19,14 @@ public interface IBaseUpdateService {
      * @return int
      */
     int updateByIdList(TableContext context, List<Long> idList);
+
+    /**
+     * 功能描述: 通用修改数据
+     *
+     * @param tableName  tableName
+     * @param commitData commitData
+     * @param condition  condition
+     * @return int
+     */
+    int update(String tableName, JSONObject commitData, JSONObject condition);
 }

+ 2 - 4
boman-web-core/src/main/java/com/boman/web/core/utils/IdUtils.java

@@ -1,12 +1,10 @@
 package com.boman.web.core.utils;
 
-import com.alibaba.fastjson.JSONArray;
 import com.boman.common.core.utils.SpringUtils;
 import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
-import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
-import com.boman.web.core.mapper.StandardlyMapper;
+import com.boman.web.core.mapper.StandardMapper;
 import org.apache.commons.collections.CollectionUtils;
 
 import java.util.ArrayList;
@@ -33,7 +31,7 @@ public class IdUtils {
         }
 
         // 查数据库
-        StandardlyMapper mapper = SpringUtils.getBean(StandardlyMapper.class);
+        StandardMapper mapper = SpringUtils.getBean(StandardMapper.class);
         int maxId = mapper.selectMaxId(tableName, pkName);
         if (maxId <= 0) {
             maxId = 1;