fastjson升级到fastjson2

This commit is contained in:
gaoqr
2026-07-29 11:31:46 +08:00
parent 10170d2ea2
commit a31286c1cd
74 changed files with 210 additions and 193 deletions
@@ -1,7 +1,7 @@
package com.cf.imes.module.plan.controller.admin.orderimport.webcad.vo;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -1,6 +1,6 @@
package com.cf.imes.module.plan.dal.dataobject.ordermodel;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONObject;
import com.cf.imes.module.plan.dal.elasticsearch.BasePosition;
import com.cf.imes.module.plan.dal.elasticsearch.HoleDetail;
import com.cf.imes.module.plan.dal.elasticsearch.ModelDetail;
@@ -1,6 +1,6 @@
package com.cf.imes.module.plan.dal.dataobject.ordermodel;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONObject;
import com.cf.imes.module.plan.dal.elasticsearch.BasePosition;
import com.cf.imes.module.plan.dal.elasticsearch.HoleDetail;
import com.cf.imes.module.plan.dal.elasticsearch.ModelDetail;
@@ -1,6 +1,6 @@
package com.cf.imes.module.plan.dal.elasticsearch;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -2,7 +2,7 @@ package com.cf.imes.module.plan.service.customplateno;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.exception.ServiceException;
@@ -2,7 +2,7 @@ package com.cf.imes.module.plan.service.customplatenorule;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.exception.ServiceException;
@@ -1,7 +1,7 @@
package com.cf.imes.module.plan.service.customplatenorule;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.exception.ServiceException;
@@ -2,7 +2,7 @@ package com.cf.imes.module.plan.service.customplatenorule;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.exception.ServiceException;
@@ -2,7 +2,7 @@ package com.cf.imes.module.plan.service.customplatenorule;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.util.json.JsonUtils;
@@ -1,7 +1,7 @@
package com.cf.imes.module.plan.service.orderImport.consumer;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -1,7 +1,7 @@
package com.cf.imes.module.plan.service.orderImport.consumer;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -6,7 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.PageUtil;
import cn.hutool.json.JSONObject;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -5,8 +5,8 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -8,9 +8,9 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -8,10 +8,11 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONReader;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -243,13 +244,14 @@ public class WebCadOrderImportAsyncFactory {
public void analyzeTempData(Long taskId, String webcadJsonCachePath) throws FileNotFoundException {
tempFilePath = webcadJsonCachePath + File.separator + taskId + ".json";
try (JSONReader reader = new JSONReader(new FileReader(tempFilePath))) {
reader.startObject();
while (reader.hasNext()) {
String fieldName = reader.readString();
try (JSONReader reader = JSONReader.of(new FileReader(tempFilePath))) {
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
while (!reader.nextIfObjectEnd()) {
String fieldName = reader.readFieldName();
processFieldData(fieldName, reader);
}
reader.endObject();
performPostProcessing(taskId);
} catch (Exception e) {
@@ -292,7 +294,7 @@ public class WebCadOrderImportAsyncFactory {
processParts(reader);
break;
case "CadViewFileId":
cadViewFileId = reader.readLong();
cadViewFileId = reader.readInt64();
AssertUtils.notEmpty(cadViewFileId, ErrorCodeConstants.WEBCAD_ORDER_IMPORT_CAD_VIEW_FILE_ID_EMPTY_ERROR);
break;
case "ComponentGroupTree":
@@ -300,7 +302,7 @@ public class WebCadOrderImportAsyncFactory {
break;
default:
// 跳过未知字段
reader.readObject();
reader.skipValue();
break;
}
}
@@ -446,10 +448,12 @@ public class WebCadOrderImportAsyncFactory {
* @param reader
*/
private void analyzeMaterials(JSONReader reader) {
reader.startArray();
while (reader.hasNext()) {
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
// 读取json内容序列化
WebCadDataMaterialReqVO materialReqVO = reader.readObject(WebCadDataMaterialReqVO.class);
WebCadDataMaterialReqVO materialReqVO = reader.read(WebCadDataMaterialReqVO.class);
String plateGoodsGoodsId = materialReqVO.getGoodsId();
@@ -512,9 +516,7 @@ public class WebCadOrderImportAsyncFactory {
// 缓存goodCode和orderGoodsId的对应关系
materialMap.put(plateGoodsGoodsId, goodsDO);
}
}
reader.endArray();
}
/**
@@ -523,9 +525,11 @@ public class WebCadOrderImportAsyncFactory {
* @param reader
*/
private void analyzeGroups(JSONReader reader) {
reader.startArray();
while (reader.hasNext()) {
WebCadDataProcessGroupReqVO processGroup = reader.readObject(WebCadDataProcessGroupReqVO.class);
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
WebCadDataProcessGroupReqVO processGroup = reader.read(WebCadDataProcessGroupReqVO.class);
String groupTypeName = processGroup.getType();
Long groupTypeId = (Long) snowFlakeGenerator.nextId(null);
List<WebCadDataProcessGroupReqVO.ProjectsDTO> projects = processGroup.getProjects();
@@ -543,7 +547,6 @@ public class WebCadOrderImportAsyncFactory {
}
}
}
reader.endArray();
}
/**
@@ -552,31 +555,34 @@ public class WebCadOrderImportAsyncFactory {
* @param reader
*/
private void analyzeRoomBody(JSONReader reader) {
reader.startArray();
while (reader.hasNext()) {
reader.startObject();
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
String roomName = null;
while (reader.hasNext()) {
String key = reader.readString();
while (!reader.nextIfObjectEnd()) {
String key = reader.readFieldName();
if ("name".equals(key)) {
roomName = reader.readString();
} else if ("count".equals(key)) {
// 无用count
reader.readObject();
reader.skipValue();
} else if (CHILDREN_FIELD.equals(key)) {
reader.startArray();
while (reader.hasNext()) {
WebCadDataDoubleRoomTreeReqVO.ChildrenDTO childrenDTO = reader.readObject(WebCadDataDoubleRoomTreeReqVO.ChildrenDTO.class);
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
WebCadDataDoubleRoomTreeReqVO.ChildrenDTO childrenDTO = reader.read(WebCadDataDoubleRoomTreeReqVO.ChildrenDTO.class);
// 缓存柜体成倍信息
roomBodyMap.put(roomName + childrenDTO.getName(), childrenDTO.getCount());
}
reader.endArray();
}
}
reader.endObject();
}
reader.endArray();
}
/**
@@ -585,11 +591,12 @@ public class WebCadOrderImportAsyncFactory {
* @param reader
*/
private void analyzeBlockRoomList(JSONReader reader) {
reader.startArray();
while (reader.hasNext()) {
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
processBlockRoom(reader);
}
reader.endArray();
orderPlateBatchInsertWithinThreshold(plateDOS, true);
}
@@ -597,22 +604,23 @@ public class WebCadOrderImportAsyncFactory {
* 处理单个房间的板件数据
*/
private void processBlockRoom(JSONReader reader) {
reader.startObject();
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
String roomName = null;
Long roomId = null;
while (reader.hasNext()) {
String key = reader.readString();
while (!reader.nextIfObjectEnd()) {
String key = reader.readFieldName();
if ("name".equals(key)) {
roomName = reader.readString();
roomId = getOrCreateRoomId(roomName);
} else if (CHILDREN_FIELD.equals(key)) {
processBlockChildren(reader, roomName, roomId);
} else {
reader.readObject();
reader.skipValue();
}
}
reader.endObject();
}
/**
@@ -653,11 +661,12 @@ public class WebCadOrderImportAsyncFactory {
* 处理房间下的柜体列表
*/
private void processBlockChildren(JSONReader reader, String roomName, Long roomId) {
reader.startArray();
while (reader.hasNext()) {
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
analyzeBlockBodyList(reader, roomName, roomId);
}
reader.endArray();
}
/**
@@ -668,12 +677,14 @@ public class WebCadOrderImportAsyncFactory {
* @param roomId
*/
private void analyzeBlockBodyList(JSONReader reader, String roomName, Long roomId) {
reader.startObject();
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
String boxName = null;
Integer count = 1;
while (reader.hasNext()) {
String key = reader.readString();
while (!reader.nextIfObjectEnd()) {
String key = reader.readFieldName();
if ("name".equals(key)) {
boxName = reader.readString();
@@ -682,16 +693,16 @@ public class WebCadOrderImportAsyncFactory {
} else if ("blockList".equals(key)) {
// Blocks.children.blockList开始
reader.startArray();
while (reader.hasNext()) {
WebCadDataBlockReqVO block = reader.readObject(WebCadDataBlockReqVO.class);
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
WebCadDataBlockReqVO block = reader.read(WebCadDataBlockReqVO.class);
// 成倍创建
multiCreateBodyPlate(count, roomId, roomName, boxName, block);
}
reader.endArray();
}
}
reader.endObject();
}
/**
@@ -1415,11 +1426,12 @@ public class WebCadOrderImportAsyncFactory {
* @param reader
*/
private void analyzePartsRoomList(JSONReader reader) {
reader.startArray();
while (reader.hasNext()) {
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
processPartsRoom(reader);
}
reader.endArray();
orderPartBatchInsertWithinThreshold(orderPartsDOS, true);
}
@@ -1427,44 +1439,48 @@ public class WebCadOrderImportAsyncFactory {
* 处理单个房间的配件数据
*/
private void processPartsRoom(JSONReader reader) {
reader.startObject();
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
String roomName = null;
Long roomId = null;
while (reader.hasNext()) {
String key = reader.readString();
while (!reader.nextIfObjectEnd()) {
String key = reader.readFieldName();
if ("name".equals(key)) {
roomName = reader.readString();
roomId = getOrCreateRoomId(roomName);
} else if (CHILDREN_FIELD.equals(key)) {
processPartsChildren(reader, roomName, roomId);
} else {
reader.readObject();
reader.skipValue();
}
}
reader.endObject();
}
/**
* 处理房间下的配件列表
*/
private void processPartsChildren(JSONReader reader, String roomName, Long roomId) {
reader.startArray();
while (reader.hasNext()) {
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
analyzePartsBodyList(reader, roomName, roomId);
}
reader.endArray();
}
private void analyzePartsBodyList(JSONReader reader, String roomName, Long roomId) {
reader.startObject();
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
String boxName = null;
String roomBoxKey = null;
Integer count = 1;
while (reader.hasNext()) {
String key = reader.readString();
while (!reader.nextIfObjectEnd()) {
String key = reader.readFieldName();
if ("name".equals(key)) {
boxName = reader.readString();
@@ -1474,9 +1490,11 @@ public class WebCadOrderImportAsyncFactory {
} else if ("objList".equals(key)) {
// Blocks.children.objList开始
reader.startArray();
while (reader.hasNext()) {
WebCadDataPartsReqVO.BlockObjectListDTO part = reader.readObject(WebCadDataPartsReqVO.BlockObjectListDTO.class);
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
while (!reader.nextIfArrayEnd()) {
WebCadDataPartsReqVO.BlockObjectListDTO part = reader.read(WebCadDataPartsReqVO.BlockObjectListDTO.class);
// 成倍创建
if (ObjectUtil.isNull(count)) {
// 房间+柜体不在成倍缓存中, 再检查bodyMap, 再没有创建房间,缓存房间到bodyMap
@@ -1485,10 +1503,8 @@ public class WebCadOrderImportAsyncFactory {
multipleCreateProcessGroup(count, roomBoxKey, part);
}
}
reader.endArray();
}
}
reader.endObject();
}
/**
@@ -1890,13 +1906,13 @@ public class WebCadOrderImportAsyncFactory {
List<OrderComponentTreeCompareVO> roots = new ArrayList<>();
reader.startArray();
while (reader.hasNext()) {
roots.add(readNode(reader));
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
reader.endArray();
while (!reader.nextIfArrayEnd()) {
roots.add(readNode(reader));
}
return roots;
}
@@ -1915,16 +1931,18 @@ public class WebCadOrderImportAsyncFactory {
List<OrderComponentTreeCompareVO> children = new ArrayList<>();
reader.startObject();
if (!reader.nextIfObjectStart()) {
throw new JSONException("期望 JSON 对象");
}
while (reader.hasNext()) {
while (!reader.nextIfObjectEnd()) {
String key = reader.readString();
String key = reader.readFieldName();
switch (key) {
case "groupID":
groupId = reader.readInteger();
groupId = reader.readInt32();
break;
case "name":
@@ -1932,27 +1950,25 @@ public class WebCadOrderImportAsyncFactory {
break;
case "boxSize":
boxSize = reader.readObject(WebCadDataComponentGroupReqVO.BoxSizeDTO.class);
boxSize = reader.read(WebCadDataComponentGroupReqVO.BoxSizeDTO.class);
break;
case "children":
reader.startArray();
while (reader.hasNext()) {
children.add(readNode(reader));
if (!reader.nextIfArrayStart()) {
throw new JSONException("期望 JSON 数组");
}
reader.endArray();
while (!reader.nextIfArrayEnd()) {
children.add(readNode(reader));
}
break;
default:
reader.readObject();
reader.skipValue();
}
}
reader.endObject();
OrderComponentTreeCompareVO node = new OrderComponentTreeCompareVO();
node.setId(groupId == null ? null : groupId);
node.setName(name);
@@ -8,9 +8,9 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -1,7 +1,7 @@
package com.cf.imes.module.plan.service.orderImport.producing.dto;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;