瀏覽代碼

Merge remote-tracking branch 'origin/matser' into matser

wy 5 月之前
父節點
當前提交
22b0382940

+ 9 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/impl/AuditServiceImpl.java

@@ -16,6 +16,7 @@ import com.lc.ibps.common.system.persistence.entity.NewsPo;
 import com.lc.ibps.untils.JsonUtil;
 import com.lc.ibps.untils.JsonUtil;
 import com.lc.ibps.untils.SqlUtil;
 import com.lc.ibps.untils.SqlUtil;
 import lombok.extern.log4j.Log4j2;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -433,6 +434,14 @@ public class AuditServiceImpl implements AuditService {
             StringBuilder sqlBuilder = new StringBuilder();
             StringBuilder sqlBuilder = new StringBuilder();
             for (int i = 0; i < jsonArray.size(); i++) {
             for (int i = 0; i < jsonArray.size(); i++) {
                 JSONObject jsonObject = jsonArray.getJSONObject(i);
                 JSONObject jsonObject = jsonArray.getJSONObject(i);
+
+                //bpm数据的特殊处理,要把 SUBJECT_ 字段里的单引号恢复成双引号(之前因为要做json转换避免报错,把双引号转为了单引号,所以要再转回来)
+                String subject = jsonObject.getStr("SUBJECT_");
+                if(StringUtils.isNotEmpty(subject)){
+                    subject = subject.replace("'", "\"");
+                    jsonObject.set("SUBJECT_",subject);
+                }
+
                 String tableName = jsonObject.getStr("table_name");
                 String tableName = jsonObject.getStr("table_name");
                 String id = jsonObject.getStr("id_");
                 String id = jsonObject.getStr("id_");
                 String sql2 = "select id_ from "+tableName+" where id_ ='"+id+"'";
                 String sql2 = "select id_ from "+tableName+" where id_ ='"+id+"'";

+ 42 - 7
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/untils/JsonUtil.java

@@ -3,6 +3,7 @@ package com.lc.ibps.untils;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.json.JSONUtil;
+import org.apache.commons.lang3.StringUtils;
 
 
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Date;
@@ -14,6 +15,7 @@ public class JsonUtil {
             Pattern.compile("\"(\\w+)\":\"(\\{.*?\\})\"");
             Pattern.compile("\"(\\w+)\":\"(\\{.*?\\})\"");
 
 
     public static String fixNestedJson(String jsonStr) {
     public static String fixNestedJson(String jsonStr) {
+        jsonStr = converForBpmData(jsonStr);
         jsonStr = convertTimestamp(jsonStr);
         jsonStr = convertTimestamp(jsonStr);
         // 处理嵌套JSON结构
         // 处理嵌套JSON结构
         Matcher matcher = NESTED_JSON_PATTERN.matcher(jsonStr);
         Matcher matcher = NESTED_JSON_PATTERN.matcher(jsonStr);
@@ -43,23 +45,37 @@ public class JsonUtil {
     /**
     /**
      * [bug-4718] 冰箱温湿度记录、室内温湿度记录 删除sql解析失败,列表上没有显示请求操作时间
      * [bug-4718] 冰箱温湿度记录、室内温湿度记录 删除sql解析失败,列表上没有显示请求操作时间
      * 前端传入时间戳格式时间导致报错
      * 前端传入时间戳格式时间导致报错
-     * 如果shi_ji_shi_jian_为时间戳格式转换成时间格式
+     * 有需要把时间戳转换为时间日期格式(mysql的datetime类型),把对应字段加在这个数组中
+     * 目前对shi_ji_shi_jian_、CREATE_TIME_、UPDATE_TIME_ 做了处理
      * */
      * */
     public static String convertTimestamp(String jsonStr) {
     public static String convertTimestamp(String jsonStr) {
+        try {
+            //有需要把时间戳转换为时间日期格式(mysql的datetime类型),把对应字段加在这个数组中
+            String[] timeFields = {"shi_ji_shi_jian_", "CREATE_TIME_", "UPDATE_TIME_"};
+            for (String field : timeFields) {
+                jsonStr = convertTimestampField(jsonStr, field);
+            }
+            return jsonStr;
+        } catch (Exception e) {
+            return jsonStr;
+        }
+    }
+
+    private static String convertTimestampField(String jsonStr, String fieldName) {
         try {
         try {
             JSONObject jsonObj = new JSONObject(jsonStr.substring(1, jsonStr.length()-1));
             JSONObject jsonObj = new JSONObject(jsonStr.substring(1, jsonStr.length()-1));
-            if(jsonObj.isNull("shi_ji_shi_jian_") == false) {
-                Object timeValue = jsonObj.get("shi_ji_shi_jian_");
-                if(timeValue instanceof Number) {
+            if (!jsonObj.isNull(fieldName)) {
+                Object timeValue = jsonObj.get(fieldName);
+                if (timeValue instanceof Number) {
                     long timestamp = ((Number)timeValue).longValue();
                     long timestamp = ((Number)timeValue).longValue();
                     String timestampStr = String.valueOf(timestamp);
                     String timestampStr = String.valueOf(timestamp);
-                    if(timestampStr.length() == 10 || timestampStr.length() == 13) {
-                        if(timestampStr.length() == 10) {
+                    if (timestampStr.length() == 10 || timestampStr.length() == 13) {
+                        if (timestampStr.length() == 10) {
                             timestamp *= 1000;
                             timestamp *= 1000;
                         }
                         }
                         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                         String mysqlTime = sdf.format(new Date(timestamp));
                         String mysqlTime = sdf.format(new Date(timestamp));
-                        jsonObj.put("shi_ji_shi_jian_", mysqlTime);
+                        jsonObj.put(fieldName, mysqlTime);
                         return "[" + jsonObj.toString() + "]";
                         return "[" + jsonObj.toString() + "]";
                     }
                     }
                 }
                 }
@@ -70,4 +86,23 @@ public class JsonUtil {
         }
         }
     }
     }
 
 
+    /**
+     * 解析bpm数据的时候(ibps_bpm_tasks表或者ibps_bpm_inst表),由于 SUBJECT_ 字段带有双引号,导致两层双引号报错,json转换报错。
+     * 解决方法:把SUBJECT_ 字段 里面的数据双引号转换成单引号
+     *
+     */
+    public static String converForBpmData(String jsonStr){
+        try {
+            if (jsonStr.contains("SUBJECT_") && jsonStr.contains("timeLimit") && jsonStr.contains("dept")){
+                jsonStr = jsonStr
+                        .replace("\"timeLimit\":", "'timeLimit':")
+                        .replace(",\"dept\":\"", ",'dept':'")
+                        .replace("\"\",", "'\","); // 将 dept value 后的双引号+双引号 替换为 单引号+双引号
+            }
+            return jsonStr;
+        }catch (Exception e){
+            return jsonStr;
+        }
+    }
+
 }
 }