Explorar el Código

Merge remote-tracking branch 'origin/master'

Administrator hace 4 años
padre
commit
ec3f81999e
Se han modificado 18 ficheros con 446 adiciones y 131 borrados
  1. 22 0
      boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/JSONArrayUtils.java
  2. 17 0
      boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/collection/CollectionUtils.java
  3. 75 0
      boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/obj/ObjectUtils.java
  4. 14 0
      boman-common/boman-common-redis/src/main/java/com/boman/common/redis/RedisKey.java
  5. 0 1
      boman-modules/boman-gen/pom.xml
  6. 1 1
      boman-modules/boman-system/pom.xml
  7. 24 36
      boman-modules/boman-system/src/main/java/com/boman/system/common/BaseTableSaveDTO.java
  8. 6 24
      boman-modules/boman-system/src/main/java/com/boman/system/common/BusinessResult.java
  9. 13 0
      boman-modules/boman-system/src/main/java/com/boman/system/common/FormDataConstant.java
  10. 2 2
      boman-modules/boman-system/src/main/java/com/boman/system/common/RowRecord.java
  11. 8 0
      boman-modules/boman-system/src/main/java/com/boman/system/common/RowResult.java
  12. 73 13
      boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceCmdService.java
  13. 7 6
      boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceContext.java
  14. 36 1
      boman-modules/boman-system/src/main/java/com/boman/system/common/ValueHolder.java
  15. 65 0
      boman-modules/boman-system/src/main/java/com/boman/system/controller/ObjController.java
  16. 0 32
      boman-modules/boman-system/src/main/java/com/boman/system/controller/ObjSaveController.java
  17. 32 15
      boman-modules/boman-system/src/main/java/com/boman/system/mapper/StandardlyMapper.java
  18. 51 0
      boman-modules/boman-system/src/main/java/com/boman/system/service/impl/BaseDeleteService.java

+ 22 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/JSONArrayUtils.java

@@ -0,0 +1,22 @@
+package com.boman.common.core.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.boman.common.core.utils.obj.ObjectUtils;
+
+/**
+ * @author shiqian
+ * @date 2021年03月26日 11:07
+ **/
+public class JSONArrayUtils {
+    
+    public static long[] jsonArrayToLongArray(JSONArray jsonArray){
+        ObjectUtils.requireNonNull(jsonArray);
+        long[] result = new long[jsonArray.size()];
+        for (int i = 0; i < jsonArray.size(); i++) {
+            result[i] = jsonArray.getLong(i);
+        }
+
+        return result;
+    }
+
+}

+ 17 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/collection/CollectionUtils.java

@@ -0,0 +1,17 @@
+package com.boman.common.core.utils.collection;
+
+import com.boman.common.core.utils.obj.ObjectUtils;
+
+import java.util.List;
+
+/**
+ * @author shiqian
+ * @date 2021年03月26日 14:16
+ **/
+public class CollectionUtils {
+
+    public static Long[] listToArray(List<Long> longList){
+        ObjectUtils.requireNonNull(longList);
+        return longList.toArray(new Long[0]);
+    }
+}

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

@@ -0,0 +1,75 @@
+package com.boman.common.core.utils.obj;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.lang3.ArrayUtils;
+
+import java.util.Collection;
+
+/**
+ * @author shiqian
+ * @date 2021年03月26日 10:39
+ **/
+public class ObjectUtils {
+
+    private static final String NULL = "null";
+    private static final String UNDEFINED = "undefined";
+
+    public static  <T> Collection<T> requiredNonNull(Collection<T> input){
+        if (null == input || input.size() == 0) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+        return input;
+    }
+
+    public static long[] requiredNonNull(long[] input){
+        if (ArrayUtils.isEmpty(input)) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+
+        return input;
+    }
+
+
+    public static Long[] requiredNonNull(Long[] input){
+        if (ArrayUtils.isEmpty(input)) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+
+        return input;
+    }
+
+    public static <T> T requireNonNull(T input) {
+        if (input == null) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+        return input;
+    }
+
+
+    public static String requireNonNull(String input) {
+        if (input == null || input.isEmpty() || NULL.equalsIgnoreCase(input) || UNDEFINED.equalsIgnoreCase(input)) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+        return input;
+    }
+
+
+    public static JSONObject requireNonNull(JSONObject input) {
+        if (input == null || input.isEmpty()) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+        return input;
+    }
+
+
+    public static JSONArray requireNonNull(JSONArray input) {
+        if (input == null || input.isEmpty()) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+        return input;
+    }
+
+
+
+}

+ 14 - 0
boman-common/boman-common-redis/src/main/java/com/boman/common/redis/RedisKey.java

@@ -0,0 +1,14 @@
+package com.boman.common.redis;
+
+/**
+ * @author shiqian
+ * @date 2021年03月26日 13:25
+ **/
+public class RedisKey {
+
+    /**
+     * 建表的信息存在redis中的key
+     * eg: table:tableName
+     */
+    public static final String TABLE_INFO = "table:";
+}

+ 0 - 1
boman-modules/boman-gen/pom.xml

@@ -85,5 +85,4 @@
             </plugin>
         </plugins>
     </build>
-   
 </project>

+ 1 - 1
boman-modules/boman-system/pom.xml

@@ -114,5 +114,5 @@
             </plugin>
         </plugins>
     </build>
-   
+
 </project>

+ 24 - 36
boman-modules/boman-system/src/main/java/com/boman/system/common/BaseTableSaveDTO.java

@@ -2,14 +2,21 @@ package com.boman.system.common;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * @author:zc
  * @since:2018/12/27
  * @createat:2018/12/274:41 PM
  */
+@Data
+@ToString
+@EqualsAndHashCode
 public class BaseTableSaveDTO implements Serializable {
 
     private static final long serialVersionUID = -8653990707913725671L;
@@ -22,40 +29,21 @@ public class BaseTableSaveDTO implements Serializable {
     @JSONField(name = "table")
     private String table;
 
-    public static long getSerialVersionUID() {
-        return serialVersionUID;
-    }
-
-    public Long getObjId() {
-        return objId;
-    }
-
-    public void setObjId(Long objId) {
-        this.objId = objId;
-    }
-
-    public JSONObject getFixedData() {
-        return fixedData;
-    }
-
-    public void setFixedData(JSONObject fixedData) {
-        this.fixedData = fixedData;
-    }
-
-    public String getTable() {
-        return table;
-    }
-
-    public void setTable(String table) {
-        this.table = table;
-    }
-
-    @Override
-    public String toString() {
-        return "BaseTableSaveDTO{" +
-                "objId=" + objId +
-                ", fixedData=" + fixedData +
-                ", table='" + table + '\'' +
-                '}';
-    }
+    /**
+     * 逻辑删除,数据库对应的属性名称
+     */
+    @JSONField(name = "logicDelName")
+    private String logicDelName;
+
+    /**
+     * 逻辑删除,数据库对应的属性值
+     */
+    @JSONField(name = "logicDelValue")
+    private String logicDelValue;
+
+    /**
+     * 删除时,前台传过来需要删除的idList
+     */
+    @JSONField(name = "idList")
+    private List<Long> idList;
 }

+ 6 - 24
boman-modules/boman-system/src/main/java/com/boman/system/common/BusinessResult.java

@@ -116,14 +116,8 @@ public class BusinessResult implements Serializable {
                 Object this$notice = this.getNotice();
                 Object other$notice = other.getNotice();
                 if (this$notice == null) {
-                    if (other$notice != null) {
-                        return false;
-                    }
-                } else if (!this$notice.equals(other$notice)) {
-                    return false;
-                }
-
-                return true;
+                    return other$notice == null;
+                } else return this$notice.equals(other$notice);
             }
         }
     }
@@ -227,14 +221,8 @@ public class BusinessResult implements Serializable {
                     Object this$message = this.getMessage();
                     Object other$message = other.getMessage();
                     if (this$message == null) {
-                        if (other$message != null) {
-                            return false;
-                        }
-                    } else if (!this$message.equals(other$message)) {
-                        return false;
-                    }
-
-                    return true;
+                        return other$message == null;
+                    } else return this$message.equals(other$message);
                 }
             }
         }
@@ -292,14 +280,8 @@ public class BusinessResult implements Serializable {
                     Object this$msgType = this.getMsgType();
                     Object other$msgType = other.getMsgType();
                     if (this$msgType == null) {
-                        if (other$msgType != null) {
-                            return false;
-                        }
-                    } else if (!this$msgType.equals(other$msgType)) {
-                        return false;
-                    }
-
-                    return true;
+                        return other$msgType == null;
+                    } else return this$msgType.equals(other$msgType);
                 }
             }
         }

+ 13 - 0
boman-modules/boman-system/src/main/java/com/boman/system/common/FormDataConstant.java

@@ -0,0 +1,13 @@
+package com.boman.system.common;
+
+/**
+ * @author shiqian
+ * @date 2021年03月26日 09:47
+ **/
+public class FormDataConstant {
+
+    /**
+     * 删除数据时,需要删除的业务表的主键
+     */
+    public static final String ID_LIST = "idList";
+}

+ 2 - 2
boman-modules/boman-system/src/main/java/com/boman/system/common/RowRecord.java

@@ -3,6 +3,7 @@ package com.boman.system.common;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.gen.domain.GenTable;
 import com.boman.system.mapper.StandardlyMapper;
+import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
@@ -11,7 +12,7 @@ import lombok.extern.slf4j.Slf4j;
  * @author zc
  * @date 2019/02/19
  */
-@Getter
+@Data
 @Slf4j
 public class RowRecord {
 
@@ -19,7 +20,6 @@ public class RowRecord {
 
     private Table table;
 
-    @Setter
     private Long id;
     private DbRowAction action;
 

+ 8 - 0
boman-modules/boman-system/src/main/java/com/boman/system/common/RowResult.java

@@ -78,4 +78,12 @@ public class RowResult {
     public void setData(final Object data) {
         this.data = data;
     }
+
+    public static boolean checkSuccess(RowResult rowResult){
+        return null != rowResult && ValueHolder.OK == rowResult.getCode();
+    }
+
+    public static boolean checkFail(RowResult rowResult){
+        return !checkSuccess(rowResult);
+    }
 }

+ 73 - 13
boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceCmdService.java

@@ -1,9 +1,15 @@
 package com.boman.system.common;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.boman.common.core.utils.SpringUtils;
 import com.boman.common.core.utils.StringUtils;
+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.gen.domain.GenTable;
 import com.boman.gen.domain.GenTableColumn;
+import com.boman.system.service.impl.BaseDeleteService;
 import com.boman.system.service.impl.BaseSaveService;
 import com.boman.system.utils.IdUtils;
 import org.slf4j.Logger;
@@ -11,8 +17,11 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.Arrays;
 import java.util.List;
 
+import static  com.boman.common.core.utils.obj.ObjectUtils.*;
+
 /**
  * @author shiqian
  * @description
@@ -22,33 +31,84 @@ import java.util.List;
 public class TableServiceCmdService {
 
     @Autowired
-    private TableServiceContext tableServiceContext;
+    private BaseDeleteService deleteService;
+    @Autowired
+    private BaseSaveService saveService;
+    @Autowired
+    private RedisService redisService;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
 
-    public final ValueHolder execute(BaseTableSaveDTO baseTableSaveDTO, String actionName) throws Exception {
+    private BaseTableDTO packTableDTO(BaseTableSaveDTO baseTableSaveDTO) {
         BaseTableDTO baseTableDTO = new BaseTableDTO();
         baseTableDTO.setFixedData(baseTableSaveDTO.getFixedData());
         baseTableDTO.setObjId(baseTableSaveDTO.getObjId());
         baseTableDTO.setTable(baseTableSaveDTO.getTable());
-        return execute(baseTableDTO, actionName);
+        return baseTableDTO;
     }
 
-    public final ValueHolder execute(BaseTableDTO baseTableDTO, String actionName) {
-        TableServiceContext context = TableServiceContext.createFrom(baseTableDTO, actionName);
-        BaseSaveService baseSaveService = SpringUtils.getBean(BaseSaveService.class);
+    public final ValueHolder<RowResult> objectSave(BaseTableSaveDTO baseTableSaveDTO) {
+        BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
+        TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
+//        BaseSaveService baseSaveService = SpringUtils.getBean(BaseSaveService.class);
         // 拿到pkName和maxId
         List<GenTableColumn> columns = context.getTable().getColumns();
         String pkName = IdUtils.getPkName(columns);
         StringUtils.requireNonNull(pkName);
         Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
-        RowResult rowResult = baseSaveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0));
+        RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0));
+        if (RowResult.checkSuccess(rowResult)) {
+            LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
+        } else {
+            LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(baseTableSaveDTO));
+        }
+
+        return ValueHolder.ok(rowResult);
+    }
+
+    /**
+     * 功能描述: 通用删除接口 (真的删除)
+     *
+     * @param dto 前台传过来的dto
+     * @return com.boman.system.common.ValueHolder
+     */
+    public ValueHolder<RowResult> objectDelete(BaseTableSaveDTO dto) {
+        requireNonNull(dto.getTable());
+        Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
+        requiredNonNull(idArr);
+        // 拿到pkName
+        GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + requireNonNull(dto.getTable()));
+        requireNonNull(genTable);
+        String pkName = IdUtils.getPkName(genTable.getColumns());
+
+        RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName));
+        LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
+        return ValueHolder.ok(rowResult);
+    }
+
+
+    /**
+     * 功能描述: 通用删除接口 (真的删除)
+     *
+     * @param dto 前台传过来的dto
+     * @return com.boman.system.common.ValueHolder
+     */
+    public ValueHolder<RowResult> objectLogicDelete(BaseTableSaveDTO dto) {
+        requireNonNull(dto.getTable());
+        Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
+        requiredNonNull(idArr);
+
+        // 拿到pkName
+        GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + requireNonNull(dto.getTable()));
+        requireNonNull(genTable);
+        String pkName = IdUtils.getPkName(genTable.getColumns());
+
+        JSONObject jsonObject= new JSONObject();
+        jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
 
-        ValueHolder valueHolder = new ValueHolder();
-        valueHolder.setCode(ResultCode.SUCCESS);
-        valueHolder.setMessage("操作成功" + ((JSONObject) rowResult.getData()).getInteger("successCnt") + "条!");
-        valueHolder.setData(rowResult);
-        return valueHolder;
+        RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName), jsonObject);
+        LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
+        return ValueHolder.ok(rowResult);
     }
 
 }

+ 7 - 6
boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceContext.java

@@ -2,6 +2,7 @@ package com.boman.system.common;
 
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.SpringUtils;
+import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
 import com.boman.gen.domain.GenTable;
 import com.google.common.base.Strings;
@@ -91,13 +92,13 @@ public class TableServiceContext {
     @Resource
     private RedisService redisService;
 
-    public static TableServiceContext createFrom(BaseTableDTO baseTableDTO, String actionName) {
+    public static TableServiceContext createFrom(BaseTableDTO baseTableDTO) {
         TableServiceContext result = new TableServiceContext();
         result.user = RequestUtil.getUser();
-        result.actionName = actionName.replace(PREFIX, "").toUpperCase();
-        if (StringUtils.isEmpty(result.actionName)) {
-            throw new IllegalArgumentException("actionName不能为空");
-        }
+//        result.actionName = actionName.replace(PREFIX, "").toUpperCase();
+//        if (StringUtils.isEmpty(result.actionName)) {
+//            throw new IllegalArgumentException("actionName不能为空");
+//        }
 
         String tableName = baseTableDTO.getTable();
         if (StringUtils.isEmpty(tableName)) {
@@ -106,7 +107,7 @@ public class TableServiceContext {
 
         //从redis中获取表信息
         RedisService redisService = SpringUtils.getBean(RedisService.class);
-        result.table = redisService.getCacheObject("table:" + tableName);
+        result.table = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
 
         if (result.table == null) {
             throw new IllegalArgumentException(tableName + "表信息不存在");

+ 36 - 1
boman-modules/boman-system/src/main/java/com/boman/system/common/ValueHolder.java

@@ -1,6 +1,8 @@
 package com.boman.system.common;
 
 import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+
 import java.io.Serializable;
 
 /**
@@ -8,8 +10,12 @@ import java.io.Serializable;
  * @description
  * @date 2021年03月22日 09:26
  **/
+@Data
 public class ValueHolder<T> implements Serializable {
 
+    public static final int OK = 0;
+    public static final int FAIL = -1;
+
     private T data;
     private int code;
     private String message;
@@ -17,7 +23,7 @@ public class ValueHolder<T> implements Serializable {
     public ValueHolder() {
     }
 
-    public ValueHolder(T data, int code, String message) {
+    public ValueHolder(int code, String message, T data) {
         this.data = data;
         this.code = code;
         this.message = message;
@@ -36,6 +42,35 @@ public class ValueHolder<T> implements Serializable {
         return obj;
     }
 
+    public static <T> ValueHolder<T> ok(String message){
+        return new ValueHolder<>(OK, message);
+    }
+
+    public static <T> ValueHolder<T> ok(String message, T data){
+        return new ValueHolder<>(OK, message, data);
+    }
+
+
+    public static <T> ValueHolder<T> ok(T data){
+        return new ValueHolder<>(OK, "成功", data);
+    }
+
+
+    public static <T> ValueHolder<T> fail(String message, T data){
+        return new ValueHolder<>(FAIL, message, data);
+    }
+
+    public static <T> ValueHolder<T> fail(String message){
+        return new ValueHolder<>(FAIL, message);
+    }
+
+
+
+
+
+
+
+
     public boolean isOK() {
         return this.code == 0;
     }

+ 65 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/ObjController.java

@@ -0,0 +1,65 @@
+package com.boman.system.controller;
+
+import com.boman.system.common.BaseTableSaveDTO;
+import com.boman.system.common.RowResult;
+import com.boman.system.common.TableServiceCmdService;
+import com.boman.system.common.ValueHolder;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * @author shiqian
+ * @description
+ * @date 2021年03月22日 09:19
+ **/
+@RestController
+@RequestMapping("/p/cs")
+public class ObjController {
+
+    @Autowired
+    private TableServiceCmdService tableServiceCmdService;
+
+    /**
+     * 功能描述: 通用保存接口
+     *
+     * @param baseTableSaveDTO 前台传过来的dto
+     * @return com.boman.system.common.ValueHolder
+     */
+    @ApiOperation(value = "单对象保存")
+    @PostMapping("/objectSave")
+    public ValueHolder<RowResult> objectSave(@RequestBody BaseTableSaveDTO baseTableSaveDTO) {
+        return tableServiceCmdService.objectSave(baseTableSaveDTO);
+    }
+
+    /**
+     * 功能描述: 通用删除接口 (真的删除)
+     *
+     * @param baseTableSaveDTO 前台传过来的dto
+     * @return com.boman.system.common.ValueHolder
+     */
+    @ApiOperation(value = "单对象删除")
+    @PostMapping("/objectDelete")
+    public ValueHolder<RowResult> objectDelete(@RequestBody BaseTableSaveDTO baseTableSaveDTO) {
+        return tableServiceCmdService.objectDelete(baseTableSaveDTO);
+    }
+
+    /**
+     * 功能描述: 通用删除接口 (逻辑删除)
+     *
+     * @param baseTableSaveDTO 前台传过来的dto
+     * @return com.boman.system.common.ValueHolder
+     */
+    @ApiOperation(value = "单对象逻辑删除")
+    @PostMapping("/objectLogicDelete")
+    public ValueHolder<RowResult> objectLogicDelete(@RequestBody BaseTableSaveDTO baseTableSaveDTO) {
+        return tableServiceCmdService.objectLogicDelete(baseTableSaveDTO);
+    }
+
+
+
+}

+ 0 - 32
boman-modules/boman-system/src/main/java/com/boman/system/controller/ObjSaveController.java

@@ -1,32 +0,0 @@
-package com.boman.system.controller;
-
-import com.boman.system.common.BaseTableSaveDTO;
-import com.boman.system.common.TableServiceCmdService;
-import com.boman.system.common.ValueHolder;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-
-/**
- * @author shiqian
- * @description
- * @date 2021年03月22日 09:19
- **/
-@RestController
-@RequestMapping("/obj")
-public class ObjSaveController {
-
-    @Autowired
-    private TableServiceCmdService tableServiceCmdService;
-
-    @ApiOperation(value = "单对象保存")
-    @PostMapping("/objectSave")
-    public ValueHolder doSave(@RequestBody BaseTableSaveDTO baseTableSaveDTO) throws Exception {
-        return tableServiceCmdService.execute(baseTableSaveDTO, "SAVE");
-    }
-
-}

+ 32 - 15
boman-modules/boman-system/src/main/java/com/boman/system/mapper/StandardlyMapper.java

@@ -3,6 +3,7 @@ package com.boman.system.mapper;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.*;
+import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.jdbc.SQL;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,7 +27,8 @@ public interface StandardlyMapper {
             type = StandardlyMapper.SqlProvider.class,
             method = "update"
     )
-    int updateById(@Param("tableName") String var1, @Param("model") JSONObject var2);
+    int updateById(@Param("tableName") String var1, @Param("model") JSONObject var2
+            , @Param("pkName") String pkName, @Param("ids") Long[] ids);
 
     @UpdateProvider(
             type = StandardlyMapper.SqlProvider.class,
@@ -39,7 +41,7 @@ public interface StandardlyMapper {
             type = StandardlyMapper.SqlProvider.class,
             method = "delete"
     )
-    int deleteByIds(@Param("tableName") String var1, @Param("ids") long[] var2);
+    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 var1, @Param("id") long var2);
@@ -130,24 +132,34 @@ public interface StandardlyMapper {
         public String update(Map<String, Object> para) {
             String tableName = (String) para.get("tableName");
             JSONObject model = (JSONObject) para.get("model");
-            //if (isNullOrEmpty(tableName)) {
+            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);
-                Iterator var5 = model.keySet().iterator();
 
-                while (var5.hasNext()) {
-                    String key = (String) var5.next();
+                // 拼装set
+                model.forEach((key, value)->{
                     if (!isReadOnly(key)) {
-                        sql.SET(key + "= #{model." + 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("ID = #{model.ID}");
-                return sql.toString();
+                sql.WHERE(pkName + " in (" + inSql.toString());
+                String wholeSql = StringUtils.substringBeforeLast(sql.toString(), ",") + "))";
+                LOGGER.info("更改的sql语句为: {}", wholeSql);
+                return wholeSql;
             } else {
                 throw new IllegalArgumentException("model 无效");
             }
@@ -224,14 +236,15 @@ public interface StandardlyMapper {
                 }
 
                 String sqlStr = sql.toString();
-                LOGGER.info("新增拼接的sql语句为: {}", sqlStr);
+                LOGGER.info("新增的sql语句为: {}", sqlStr);
                 return sqlStr;
             }
         }
 
         public String delete(Map<String, Object> para) {
-            long[] ids = (long[]) ((long[]) para.get("ids"));
+            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) {
@@ -239,13 +252,13 @@ public interface StandardlyMapper {
             } else if (ids.length == 0) {
                 return "";
             } else if (ids.length == 1) {
-                return "DELETE FROM " + tableName + " where ID = #{ids[0]}";
+                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("ID in (");
+                sql.append(pkName + " in (");
 
                 for (int i = 0; i < ids.length; ++i) {
                     sql.append(String.format("#{ids[%d]}", i));
@@ -253,7 +266,9 @@ public interface StandardlyMapper {
                 }
 
                 sql.setCharAt(sql.length() - 1, ')');
-                return sql.toString();
+                String sqlStr = sql.toString();
+                LOGGER.info("删除的sql语句为: {}", sqlStr);
+                return sqlStr;
             }
         }
 
@@ -360,7 +375,9 @@ public interface StandardlyMapper {
                     }
 
                     sql.deleteCharAt(sql.length() - 1);
-                    return sql.toString();
+                    String sqlStr = sql.toString();
+                    LOGGER.info("更新的sql语句为: {}", sqlStr);
+                    return sqlStr;
                 }
             } else {
                 throw new IllegalArgumentException("model 无效");

+ 51 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/BaseDeleteService.java

@@ -0,0 +1,51 @@
+package com.boman.system.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.system.common.RowResult;
+import com.boman.system.mapper.StandardlyMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author shiqian
+ * @date 2021年03月26日 11:16
+ **/
+@Service
+public class BaseDeleteService {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(BaseDeleteService.class);
+
+    @Autowired
+    private StandardlyMapper mapper;
+
+    /**
+     * 功能描述: 在此不对入参进行校验,所以在调用此方法之前一定要对参数进行校验,以免报错
+     *
+     * @param idArr     需要删除的iD
+     * @param tableName 业务主表
+     * @param pkName    业务表的主键名
+     * @return com.boman.system.common.RowResult
+     */
+    public RowResult objectDelete(Long[] idArr, String tableName, String pkName) {
+        int delete = mapper.deleteByIds(tableName, idArr, pkName);
+        return RowResult.ok("共删除了 " + delete + " 条记录");
+    }
+
+    /**
+     * 功能描述: 在此不对入参进行校验,所以在调用此方法之前一定要对参数进行校验,以免报错
+     *
+     * @param idArr     需要删除的iD
+     * @param tableName 业务主表
+     * @param pkName    业务表的主键名
+     * @param model     逻辑删除的字段和值
+     * @return com.boman.system.common.RowResult
+     */
+    public RowResult objectLogicDelete(Long[] idArr, String tableName, String pkName, JSONObject model) {
+        int delete = mapper.updateById(tableName, model, pkName, idArr);
+        return RowResult.ok("共删除了 " + delete + " 条记录");
+    }
+
+
+}