api接口数据获取提示修改

This commit is contained in:
lym
2025-01-14 16:08:37 +08:00
parent c23b8aa49b
commit 290b713206
5 changed files with 75 additions and 71 deletions
@@ -50,8 +50,8 @@ public class ErrorCodeConstants {
public static final ErrorCode RAW_GOODS_NOT_EXISTS = new ErrorCode(1_002_029_005, "生产单中未用到此板材");
public static final ErrorCode APP_TOKEN_ERROR = new ErrorCode(1_002_029_007, "token获取失败");
public static final ErrorCode ORDER_NOT_FOUND = new ErrorCode(1_002_029_006, "生产单不存在");
public static final ErrorCode PLATE_PLAN_DATA_ERROR = new ErrorCode(1_002_029_008, "板材生产数据获取错误或此单不存在");
public static final ErrorCode PLATE_PLAN_DATA_NULL = new ErrorCode(1_002_029_008, "板材生产源数据为空");
public static final ErrorCode PLATE_PLAN_DATA_ERROR = new ErrorCode(1_002_029_008, "接口数据获取,板件明细源数据缺少,请确定接口数据正确");
public static final ErrorCode PLATE_GOOD_DATA_NULL = new ErrorCode(1_002_029_13, "接口数据获取,板材源数据缺少,请确定接口数据正确");
public static final ErrorCode PARTS_DATA_ERROR = new ErrorCode(1_002_029_009, "配件数据获取错误");
public static final ErrorCode BODY_DATA_ERROR = new ErrorCode(1_002_029_010, "柜体数据获取错误");
public static final ErrorCode GOODS_DATA_ERROR = new ErrorCode(1_002_029_011, "商品信息获取错误");
@@ -66,6 +66,7 @@ public class ErrorCodeConstants {
public static final ErrorCode ORDER_RESTORE_ERR = new ErrorCode(1_002_029_006, "生产单还原失败");
public static final ErrorCode DATA_ERR = new ErrorCode(1_002_030_000, "当前正在导入,请稍后");
public static final ErrorCode LOCK_ERR = new ErrorCode(1_002_030_001, "当前存在导入情况,请稍后");
public static final ErrorCode API_MES_ERR = new ErrorCode(1_002_031_001, "MES接口数据出错:{}");
// ========== 自定义板编号生成 ==========
public static final ErrorCode CUSTOM_PLATENO_GENERATE_ORDERNO_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_001, "自定义版编号生产单序号规则中存在不支持的复位类型:{}");
@@ -47,8 +47,8 @@ import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.File;
import java.util.*;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.pojo.CommonResult.error;
@@ -225,7 +225,7 @@ public class OrderController {
Long id = orderService.importApiData(apiTypeRealize.apiDataChange(orderNo, orderId, organId));
return success(String.valueOf(id));
} catch (Exception e) {
} catch (CompletionException | ExecutionException | InterruptedException e) {
// 进行判断,为空,写入时出现了错误,数据库数据回滚,此时删除 ES 里的数据
OrderDO orderDO = orderMapper.selectById(orderId);
if (orderDO == null) {
@@ -234,10 +234,8 @@ public class OrderController {
}
log.error(errKey, e);
assert e instanceof ServiceException;
ServiceException cause = (ServiceException) e;
return error(cause.getCode(),cause.getMessage());
Throwable cause = e.getCause();
return error((ServiceException) cause);
} finally {
redisLockUtil.unlock(lockKey);
@@ -305,10 +303,11 @@ public class OrderController {
// list 校验
ExcelCheckVO excelCheckVO = excelCheckListUtil.checkExcelLargeFile(listBoth[1]);
list = excelCheckVO.getList();
flag = excelCheckVO.getFlag() & flag;
if (excelCheckVO.getFlag() && excelCheckVO.getList().size() == 0) {
flag = excelCheckVO.getFlag();
if (flag && list.isEmpty()) {
orderDO.setStatus(OrderStatusEnum.EMPTY.getStatus());
} else if (excelCheckVO.getFlag()){
} else if (flag){
orderDO.setStatus(OrderStatusEnum.NEW_ORDER.getStatus());
listMap = excelTypeRealize.changeDate(list, orderDO.getId());
}
@@ -28,7 +28,7 @@ import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.*;
import com.cf.imes.module.executor.controller.admin.remainplate.vo.*;
import com.cf.imes.module.executor.service.remainplate.RemainPlateService;
@Tag(name = "管理后台 - 生产单余料板表 order_remain_plate_{N}")
@Tag(name = "管理后台 - 生产单余料板表")
@RestController
@RequestMapping("/executor/remain-plate")
@Validated
@@ -12,12 +12,7 @@ import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.function.BiFunction;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*;
@@ -44,6 +39,7 @@ public class ApiDataAchieve {
private static final String CURR_PAGE_KEY = "curr_page";
private static final String PAGE_COUNT_KEY = "page_count"; //请求
private static final String ERR_CODE_KEY = "err_code";
private static final String ERR_MSG_KEY = "err_msg";
private static final String ALL_PAGE_COUNT_KEY = "PageCount"; // 页数
private static final String VALUE_KEY = "value";
private static final String GOODS_ID = "goods_id";
@@ -56,8 +52,10 @@ public class ApiDataAchieve {
String appSecret = app.getString("appSecret");
JSONObject json = apiDataProduction.getApiTokenMessage(appId, appSecret);
if (!json.getString("err_msg").equals("success")) {
throw exception(APP_TOKEN_ERROR);
if (!json.getString(ERR_MSG_KEY).equals("success")) {
log.error(APP_TOKEN_ERROR.getMsg());
throw exception(API_MES_ERR, "身份认证-" + json.getString(ERR_MSG_KEY));
// throw exception(APP_TOKEN_ERROR);
}
return new AsyncResult<>(json);
}
@@ -77,8 +75,9 @@ public class ApiDataAchieve {
JSONObject parts = apiDataProduction.getApiOrderPartsMessage(token, jsonParts);
if (!parts.getString(ERR_CODE_KEY).equals("0")) {
log.error("配件数据获取错误" + "N" + orderNo);
throw exception(PARTS_DATA_ERROR);
log.error("N" + orderNo + "配件数据获取错误:" + parts.getString(ERR_MSG_KEY));
throw exception(API_MES_ERR, "配件信息获取-" + parts.getString(ERR_MSG_KEY));
// throw exception(PARTS_DATA_ERROR);
}
if (parts.getJSONObject(VALUE_KEY).getJSONArray("List") == null || parts.getJSONObject(VALUE_KEY).getJSONArray("List").isEmpty()) {
return null;
@@ -94,8 +93,9 @@ public class ApiDataAchieve {
jsonBody.put(ORDER_NO_KEY, "N" + orderNo);
JSONObject body = apiDataProduction.getApiOrderBodyMessage(token, jsonBody);
if (!body.getString(ERR_CODE_KEY).equals("0")) {
log.error("柜体数据获取错误" + "N" + orderNo);
throw exception(BODY_DATA_ERROR);
log.error("N" + orderNo + "柜体数据获取错误:" + body.getString(ERR_MSG_KEY));
throw exception(API_MES_ERR, "柜体信息获取-" + body.getString(ERR_MSG_KEY));
// throw exception(BODY_DATA_ERROR);
}
JSONObject dataBody = new JSONObject();
for (int i = 1; i <= body.getJSONObject(VALUE_KEY).getInteger(ALL_PAGE_COUNT_KEY); i++) {
@@ -115,8 +115,9 @@ public class ApiDataAchieve {
jsonGoods.put(ORDER_NO_KEY, "N" + orderNo);
JSONObject goods = apiDataProduction.getApiOrderGoodsMessage(token, jsonGoods);
if (!goods.getString(ERR_CODE_KEY).equals("0")) {
log.error("商品信息转换失败" + "N" + orderNo);
throw exception(GOODS_DATA_ERROR);
log.error("N" + orderNo + "商品信息转换失败:" + goods.getString(ERR_MSG_KEY));
throw exception(API_MES_ERR, "商品信息获取-" + goods.getString(ERR_MSG_KEY));
// throw exception(GOODS_DATA_ERROR);
}
JSONObject dataGoods = new JSONObject();
for (int i = 1; i <= goods.getJSONObject(VALUE_KEY).getInteger(ALL_PAGE_COUNT_KEY); i++) {
@@ -132,8 +133,9 @@ public class ApiDataAchieve {
public JSONObject getApiPlateDetailMessage(String token, String orderNo, JSONObject jsonPlates) {
JSONObject plates = apiDataProduction.getApiBlocksDataMessage(token, jsonPlates);
if (!plates.getString(ERR_CODE_KEY).equals("0")) {
log.error("板材明细获取错误" + "N" + orderNo);
throw exception(PLATE_DATA_ERROR);
log.error("N" + orderNo + "板材明细信息获取错误" + plates.getString(ERR_MSG_KEY));
throw exception(API_MES_ERR, "板材明细信息获取-" + plates.getString(ERR_MSG_KEY));
// throw exception(PLATE_DATA_ERROR);
}
if (plates.getJSONObject(VALUE_KEY).getJSONArray("List") == null || plates.getJSONObject(VALUE_KEY).getJSONArray("List").isEmpty()) {
return null;
@@ -145,8 +147,7 @@ public class ApiDataAchieve {
public JSONObject getApiGroupMessage(String token, String orderNo) {
JSONObject jsonModule = new JSONObject();
jsonModule.put(ORDER_NO_KEY, "N" + orderNo);
JSONObject dataModule = apiDataProduction.getApiModuleTypeDataMessage(token, jsonModule);
return dataModule;
return apiDataProduction.getApiModuleTypeDataMessage(token, jsonModule);
}
// 板材数据信息转换
@@ -157,7 +158,8 @@ public class ApiDataAchieve {
jsonBlocks.put(ORDER_NO_KEY, "N" + orderNo);
JSONObject blocks = apiDataProduction.getApiBlocksMessage(token, jsonBlocks);
if (!blocks.getString(ERR_CODE_KEY).equals("0")) {
log.error("板材数据获取错误" + "N" + orderNo);
log.error("N" + orderNo + "板材数据获取错误" + blocks.getString(ERR_MSG_KEY));
throw exception(API_MES_ERR, "板材数据信息获取-" + blocks.getString(ERR_MSG_KEY));
}
JSONObject block = new JSONObject();
for (int i = 1; i <= blocks.getJSONObject(VALUE_KEY).getInteger(ALL_PAGE_COUNT_KEY); i++) {
@@ -175,7 +177,9 @@ public class ApiDataAchieve {
jsonGoods.put(GOODS_ID, id);
JSONObject good = apiDataProduction.getApiGoods(token, jsonGoods);
if (!good.getString(ERR_CODE_KEY).equals("0")) {
log.error("配件数据获取错误" + id);
log.error(id + "配件数据获取错误" + good.getString(ERR_MSG_KEY));
throw exception(API_MES_ERR, "配件数据信息获取-" + good.getString(ERR_MSG_KEY));
}
return new AsyncResult<>(good);
}
@@ -85,7 +85,7 @@ public class ApiTypeRealize {
JSONObject oauth = apiDataAchieve.getApiToken(organId).get();
String token = oauth.getJSONObject("info").getString("access_token");
// 将orderInfoChange(),goodsInfoChange(),groupInfoChange(),bodyInfoChange(),partsInfoChange(), platesDetailChange()方法使用线程,同时运行,并对每个方法返回的数据进行标识
ConcurrentHashMap<String, CompletableFuture<ApiDataTypeVo>> results = new ConcurrentHashMap<>();
// 添加各个API调用到映射中,并指定结果字段名
@@ -112,6 +112,7 @@ public class ApiTypeRealize {
// 判断生产数据是否可以为空
if (!platesData.getMapPlatesInfos().isEmpty() && plateDetailData.getMapPlateDetails().isEmpty() ) {
throw exception(ORDER_DETAIL_DATE_ERR);
// throw exception(API_MES_ERR, "生产数据信息获取-小板缺少生产数据,导致无法正常导单");
}
// 小板数据补充,order_goods_id添加造型相关数据判断获取,以及配件中添加goods_id
@@ -266,7 +267,6 @@ public class ApiTypeRealize {
Long orderId,
String orderNo,
Long organId){
// System.out.println("开始: " + System.currentTimeMillis());
// 订单获取
JSONObject order = apiDataAchieve.getApiOrder(token, orderNo)
.getJSONArray(ProduceApiConstants.DATA).getJSONObject(INDEX);
@@ -323,7 +323,6 @@ public class ApiTypeRealize {
String orderNo,
Long organId){
// System.out.println("开始2 " + System.currentTimeMillis());
JSONObject goodsMessage = apiDataAchieve.getApiGoodsMessage(token, orderNo); // 全部信息
Map<String, RawGoodsDO> rawGoodsDOS = new HashMap<>();
@@ -334,7 +333,6 @@ public class ApiTypeRealize {
return new ApiDataTypeVo().setMapRawGoodsDO(rawGoodsDOS).setMapGoodsDO(goodsDOS);
}
// Map<String, Object> map = new HashMap<>();
@@ -402,13 +400,15 @@ public class ApiTypeRealize {
String orderNo,
Long organId){
// System.out.println("开始3 " + System.currentTimeMillis());
JSONObject bodyMessage = apiDataAchieve.getApiBodyMessage(token, orderNo);
JSONArray bodyLists = bodyMessage.getJSONArray(ProduceApiConstants.LIST);
if (bodyLists == null || bodyLists.isEmpty()) {
return new ApiDataTypeVo();
log.error("{}房间柜体信息获取失败",orderNo);
throw exception(ORDER_BODY_NOT_EXISTS);
}
Map<String, OrderBodyDO> bodyInfos = new HashMap<>();
@@ -444,10 +444,8 @@ public class ApiTypeRealize {
String orderNo,
Long organId) {
// System.out.println("开始4 " + System.currentTimeMillis());
JSONObject groupMessage = apiDataAchieve.getApiGroupMessage(token, orderNo);
// Map<String, Object> map = new HashMap<>();
Map<String, OrderGroupDO> orderGroupDOs = new HashMap<>();// 加工组id 和 加工组信息
Map<String, List<String>> groupLists = new HashMap<>();// 加工组id 和 详细信息
@@ -481,8 +479,6 @@ public class ApiTypeRealize {
}
// map.put(GROUP_LINK_PLATE, groupLists);
// map.put(FieldConstants.GROUP, orderGroupDOs);
return new ApiDataTypeVo().setMapOrderGroupDO(orderGroupDOs).setMapGroupLists(groupLists);
}
@@ -493,7 +489,6 @@ public class ApiTypeRealize {
String orderNo,
Long organId) {
// System.out.println("开始5 " + System.currentTimeMillis());
// 配件api调用参数生成
JSONObject jsonParts = new JSONObject();
jsonParts.put(ProduceApiConstants.CURR_PAGE_KEY, 1);
@@ -575,14 +570,20 @@ public class ApiTypeRealize {
Long organId,
String token) {
if (partJSONObject == null || partJSONObject.isEmpty() || partJSONObject.getJSONObject(ProduceApiConstants.VALUE).getJSONArray(ProduceApiConstants.LIST).isEmpty()) {
return Collections.emptyMap();
}
Map<String, Object> map = new HashMap<>();
Map<String, OrderPartsDO> partsInfos = new HashMap<>();
Map<String, List<OrderItemDO>> partsItem = new HashMap<>();
Map<String, OrderPartsRemark> remarks = new HashMap<>();
map.put(FieldConstants.PARTS, partsInfos);
map.put(FieldConstants.ITEM, partsItem);
map.put(FieldConstants.PARTS_REMARK, remarks);
if (partJSONObject == null || partJSONObject.isEmpty() || partJSONObject.getJSONObject(ProduceApiConstants.VALUE).getJSONArray(ProduceApiConstants.LIST).isEmpty()) {
return map;
}
JSONArray partsLists = partJSONObject.getJSONObject(ProduceApiConstants.VALUE).getJSONArray(ProduceApiConstants.LIST);
for (int i = 0; i < partsLists.size(); i++) {
JSONObject part = partsLists.getJSONObject(i);
@@ -668,9 +669,7 @@ public class ApiTypeRealize {
partsInfos.put(key, partsInfo);
}
map.put(FieldConstants.PARTS, partsInfos);
map.put(FieldConstants.ITEM, partsItem);
map.put(FieldConstants.PARTS_REMARK, remarks);
return map;
}
@@ -679,15 +678,15 @@ public class ApiTypeRealize {
Long orderId,
String orderNo,
Long organId) {
// System.out.println("开始6 " + System.currentTimeMillis());
Map<String, PlateDetail> plateDetails = new HashMap<>();
JSONObject jsonPlatesDetail = apiDataAchieve.getApiPlateProData(token, orderNo);
ApiDataTypeVo map = new ApiDataTypeVo().setMapPlateDetails(plateDetails);
// 获取板件详情数据
if (jsonPlatesDetail.getJSONObject(ProduceApiConstants.VALUE) == null) {
return new ApiDataTypeVo().setMapPlateDetails(plateDetails);
return map;
}
@@ -695,7 +694,7 @@ public class ApiTypeRealize {
// 获取 Orders 字段对应的数组
JSONArray ordersArray = jsonPlatesDetail.getJSONObject(ProduceApiConstants.VALUE).getJSONArray(ProduceApiConstants.OPD_ORDER);
if (ordersArray == null || ordersArray.isEmpty()) {
return new ApiDataTypeVo().setMapPlateDetails(plateDetails);
return map;
}
for (int i = 0; i < ordersArray.size(); i++) {
@@ -704,7 +703,7 @@ public class ApiTypeRealize {
// 获取材料信息
JSONArray materialJson = order.getJSONArray(ProduceApiConstants.BPD_MATERIALS);
if (materialJson == null || materialJson.isEmpty()) {
return new ApiDataTypeVo().setMapPlateDetails(plateDetails);
return map;
}
for (int j = 0; j < materialJson.size(); j++) {
JSONObject material = materialJson.getJSONObject(j);
@@ -712,7 +711,7 @@ public class ApiTypeRealize {
// 板件信息
JSONArray blocks = material.getJSONArray(ProduceApiConstants.BPD_BLOCKS);
if (blocks == null || blocks.isEmpty()) {
return new ApiDataTypeVo().setMapPlateDetails(plateDetails);
return map;
}
for (int k = 0; k < blocks.size(); k++) {
JSONObject block = blocks.getJSONObject(k);// 每块板
@@ -773,7 +772,7 @@ public class ApiTypeRealize {
}
return new ApiDataTypeVo().setMapPlateDetails(plateDetails);
return map;
}
// 小板,大板,造型,item信息获取
public ApiDataTypeVo platesInfoChange(String token,
@@ -800,13 +799,15 @@ public class ApiTypeRealize {
Map<String, Integer> totalPlateCountMapToGroup = new HashMap<>();
Map<String, Integer> irregularPlateCountMapToGroup = new HashMap<>();
ApiDataTypeVo apiDataTypeVo = new ApiDataTypeVo().setMapPlatesInfos(plateInfos).setMapItemByGroup(plateItem)
.setTotalPlateCountMapToBody(totalPlateCountMapToBody)
.setIrregularPlateCountMapToBody(irregularPlateCountMapToBody)
.setTotalPlateCountMapToGroup(totalPlateCountMapToGroup)
.setIrregularPlateCountMapToGroup(irregularPlateCountMapToGroup)
.setMapPlateDetails(plateDetailMap);
if (apiDataAchieve.getApiPlateDetailMessage(token, orderNo, jsonPlates) == null) {
return new ApiDataTypeVo().setMapPlatesInfos(plateInfos).setMapItemByGroup(plateItem)
.setTotalPlateCountMapToBody(totalPlateCountMapToBody)
.setIrregularPlateCountMapToBody(irregularPlateCountMapToBody)
.setTotalPlateCountMapToGroup(totalPlateCountMapToGroup)
.setIrregularPlateCountMapToGroup(irregularPlateCountMapToGroup)
.setMapPlateDetails(plateDetailMap);
return apiDataTypeVo;
}
Integer pageCount = apiDataAchieve.getApiPlateDetailMessage(token, orderNo, jsonPlates).getJSONObject(ProduceApiConstants.VALUE).getInteger(ProduceApiConstants.PAGE_COUNT); // 获取页码总数
@@ -866,12 +867,7 @@ public class ApiTypeRealize {
}
}
return new ApiDataTypeVo().setMapPlatesInfos(plateInfos).setMapItemByGroup(plateItem)
.setTotalPlateCountMapToBody(totalPlateCountMapToBody)
.setIrregularPlateCountMapToBody(irregularPlateCountMapToBody)
.setTotalPlateCountMapToGroup(totalPlateCountMapToGroup)
.setIrregularPlateCountMapToGroup(irregularPlateCountMapToGroup)
.setMapPlateDetails(plateDetailMap);
return apiDataTypeVo;
}
@@ -880,7 +876,6 @@ public class ApiTypeRealize {
JSONObject blocksJSONObject,
Long orderId,
Long organId) {
// System.out.println("开始时间 " + System.currentTimeMillis());
Map<String, Object> map = new HashMap<>();
Map<String, PlateDO> partsInfos = new HashMap<>();
@@ -906,10 +901,14 @@ public class ApiTypeRealize {
map.put(PLATE_DETAILS_REMARKS, plateDetailMap);
if (platesJSONObject == null || platesJSONObject.isEmpty()) {
return map;
log.error("获取板件明细数据失败");
throw exception(PLATE_PLAN_DATA_ERROR);
}
if (blocksJSONObject == null || blocksJSONObject.isEmpty()) {
return map;
log.error("获取板材数据失败");
throw exception(PLATE_GOOD_DATA_NULL);
}
// 板材数据
Map<String, JSONObject> blocksMap = getBlocksData(blocksJSONObject);
@@ -1149,7 +1148,7 @@ public class ApiTypeRealize {
.depth(Double.valueOf(hole.getString(ProduceApiConstants.BPD_HOLE_DEPTH)))
.build());
} catch (Exception e) {
// System.out.println("HoleDetail " + hole);
log.error("解析孔数据异常", e);
}
}
@@ -1172,6 +1171,7 @@ public class ApiTypeRealize {
} catch (Exception e) {
// 处理异常,例如记录日志或抛出自定义异常
log.error("解析造型数据异常", e);
}
return modelDetails;
@@ -1459,7 +1459,7 @@ public class ApiTypeRealize {
map.put(blockNo, block);
}
}
// System.out.println("map 板材 " + map);
return map;
}