shiqian 3 лет назад
Родитель
Сommit
15f28ccfc2

+ 48 - 1
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardMapper.java

@@ -71,7 +71,7 @@ public interface StandardMapper {
             , @Param("foreignKeyList") List<Long> foreignKeyList, @Param("model") JSONObject models);
 
     /**
-     * 功能描述: 通用修改  {@link SqlProvider#update(java.util.Map)}
+     * 功能描述: 通用修改
      *
      * @param tableName      tableName
      * @param packCommitData packCommitData
@@ -82,6 +82,19 @@ public interface StandardMapper {
     int update(@Param("tableName") String tableName, @Param("packCommitData") JSONObject packCommitData
             , @Param("packColCondition") JSONObject packColCondition, @Param("condition") JSONObject condition);
 
+    /**
+     * 功能描述: 逻辑删除 {@link SqlProvider#objectLogicDelete(java.util.Map)}
+     *
+     * @param tableName tableName
+     * @param pkName    pkName
+     * @param idList    idList
+     * @param model     model
+     * @return int
+     */
+    @UpdateProvider(type = SqlProvider.class, method = "objectLogicDelete")
+    int objectLogicDelete(@Param("tableName") String tableName, @Param("pkName") String pkName
+            , @Param("idList") List<Long> idList, @Param("model") JSONObject model);
+
 
     /* ***************************************************** select ******************************************************/
     @Select("select max(${pkName}) from ${tableName}")
@@ -312,6 +325,7 @@ public interface StandardMapper {
             String pkName = (String) para.get("pkName");
             List<Long> idList = (List<Long>) para.get("idList");
             JSONObject models = (JSONObject) para.get("model");
+            JSONObject packCommitData = (JSONObject) para.get("packCommitData");
 
             StringBuilder wholeSql = new StringBuilder();
             wholeSql.append("update ").append(tableName).append(" set ");
@@ -321,6 +335,17 @@ public interface StandardMapper {
                 wholeSql.append(key).append(" = ").append(value).append(" , ");
             }
 
+            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 = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), ","));
             wholeSql.append(" where ").append(pkName).append(" in ( ");
 
@@ -362,6 +387,28 @@ public interface StandardMapper {
             return sqlStr;
         }
 
+        public String objectLogicDelete(Map<String, Object> para) {
+            String tableName = (String) para.get("tableName");
+            String pkName = (String) para.get("pkName");
+            List<String> idList = (List<String>) para.get("idList");
+            JSONObject model = (JSONObject) para.get("model");
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("update ").append(tableName).append(" set ");
+
+            for (Map.Entry<String, Object> entry : model.entrySet()) {
+                Object valueObj = entry.getValue();
+                wholeSql.append(entry.getKey()).append(" = ").append("'").append(valueObj.toString()).append("'").append(" , ");
+            }
+
+            wholeSql = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), " , "));
+            wholeSql.append(" where ").append(pkName).append(" in ( ").append(ColumnUtils.joinList1(idList)).append(" ) ");
+
+            String sqlStr = wholeSql.toString();
+            LOGGER.info("逻辑删除sql语句为: {} \r\n 提交的数据为: {} \r\n idList: {}", sqlStr, model, idList);
+            return sqlStr;
+        }
+
         public String updateByForeignKey(Map<String, Object> para) {
             String tableName = (String) para.get("tableName");
             String foreignKeyName = (String) para.get("foreignKeyName");

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

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
 import com.aliyuncs.exceptions.ClientException;
+import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.SecurityUtils;
 import com.boman.common.core.utils.StringUtils;
 import com.boman.common.core.utils.collection.CollectionUtils;
@@ -291,17 +292,19 @@ public class TableServiceCmdService {
      * @return com.boman.domain.dto.AjaxResult
      */
     public AjaxResult objectLogicDelete(FormDataDto dto) {
-        requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
+        String tableName = requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
         Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
         requireNonNull(idArr, "objectLogicDelete idArr is empty");
 
         // 拿到pkName
-        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
+        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
         String pkName = IdUtils.getPkName(genTable.getColumns());
 
         List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
+        JSONObject model = new JSONObject();
+        model.put(dto.getLogicDelName(), dto.getLogicDelValue());
+        model.put(UPDATE_TIME, DateUtils.getTime());
+        model.put(UPDATE_BY, SecurityUtils.getUsername());
 
         RowResult rowResult;
         for (Long id : idArr) {
@@ -312,14 +315,14 @@ public class TableServiceCmdService {
                 continue;
             }
 
-            rowResult = deleteService.objectLogicDelete(new Long[]{id}, dto.getTable(), pkName, jsonObject);
+            rowResult = deleteService.objectLogicDelete(new Long[]{id}, tableName, pkName, model);
             if (!rowResult.isOk()) {
-                LOGGER.info("逻辑删除失败, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getCurrentUsername());
+                LOGGER.info("逻辑删除失败, tableName: {}, id: {}, 操作人: {}", tableName, id, getCurrentUsername());
                 result.add(rowResult);
                 continue;
             }
 
-            LOGGER.info("逻辑删除成功, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getCurrentUsername());
+            LOGGER.info("逻辑删除成功, tableName: {}, id: {}, 操作人: {}", tableName, id, getCurrentUsername());
             Boolean stopProcess = dto.getStopProcess();
             if (BooleanUtils.isTrue(stopProcess)) {
                 ProcessDto processDto = new ProcessDto();

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

@@ -73,7 +73,7 @@ public class BaseDeleteServiceImpl implements IBaseDeleteService {
      */
     @Override
     public RowResult objectLogicDelete(Long[] idArr, String tableName, String pkName, JSONObject model) {
-        int delete = mapper.updateByIdList(tableName, pkName, Arrays.asList(idArr), model);
+        int delete = mapper.objectLogicDelete(tableName, pkName, Arrays.asList(idArr), model);
         return delete > 0 ? RowResult.ok() : RowResult.fail();
     }