Ver Fonte

fix:修复批量删除接口单条数据删除逻辑问题

韩帛霖 há 1 ano atrás
pai
commit
c15aee0e5d

+ 12 - 2
zkqy-process-execution/src/main/java/com/zkqy/execution/produce/dispersed/service/impl/CommonServiceImpl.java

@@ -1,6 +1,8 @@
 package com.zkqy.execution.produce.dispersed.service.impl;
 
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONException;
 import com.alibaba.fastjson2.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
@@ -101,7 +103,15 @@ public class CommonServiceImpl implements ICommonService {
         Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getConditionMap()));
         Map<String, Object> endConditions = new HashMap<>();
         conditions.keySet().forEach(item -> {
-            endConditions.put(toUnderScoreCase(item), conditions.get(item));
+            Object value = conditions.get(item);
+            // 判断value是否为String类型且非JSON数组格式
+            if (((String) value).startsWith("[")) {
+                // 将单个值转换成JSON数组
+                JSONArray jsonArray = new JSONArray(Arrays.asList((String) value));
+                endConditions.put(toUnderScoreCase(item), jsonArray.toJSONString());
+            } else {
+                endConditions.put(toUnderScoreCase(item), value);
+            }
         });
         return commonMapper.batchDelete(tableName, endConditions);
     }
@@ -231,7 +241,7 @@ public class CommonServiceImpl implements ICommonService {
     }
 
     @Override
-    public CommonEntity  getInfoById(CommonEntity commonEntity) {
+    public CommonEntity getInfoById(CommonEntity commonEntity) {
         String tableName = (String) commonEntity.getBasicMap().get("tableName");
         Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getConditionMap()));
         CommonEntity common = new CommonEntity();