|
@@ -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;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|