diff --git a/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/util/json/JsonUtils.java b/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/util/json/JsonUtils.java index 436a6de90..81aaf6348 100644 --- a/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/util/json/JsonUtils.java +++ b/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/util/json/JsonUtils.java @@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.List; @@ -75,7 +76,7 @@ public class JsonUtils { try { return objectMapper.readValue(text, clazz); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -89,7 +90,7 @@ public class JsonUtils { JsonNode pathNode = treeNode.path(path); return objectMapper.readValue(pathNode.toString(), clazz); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -101,7 +102,7 @@ public class JsonUtils { try { return objectMapper.readValue(text, objectMapper.getTypeFactory().constructType(type)); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -129,7 +130,7 @@ public class JsonUtils { try { return objectMapper.readValue(bytes, clazz); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, bytes, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, bytes, e); throw new RuntimeException(e); } } @@ -138,7 +139,7 @@ public class JsonUtils { try { return objectMapper.readValue(text, typeReference); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -150,7 +151,7 @@ public class JsonUtils { try { return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -164,7 +165,7 @@ public class JsonUtils { JsonNode pathNode = treeNode.path(path); return objectMapper.readValue(pathNode.toString(), objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -173,7 +174,7 @@ public class JsonUtils { try { return objectMapper.readTree(text); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -182,7 +183,7 @@ public class JsonUtils { try { return objectMapper.readTree(text); } catch (IOException e) { - log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); +// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e); throw new RuntimeException(e); } } @@ -269,5 +270,80 @@ public class JsonUtils { } } + /** + * 压缩 + * + * @param str + * @return + */ + public static byte[] zip(String str) { + + Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION); + + deflater.setInput(str.getBytes(StandardCharsets.UTF_8)); + + deflater.finish(); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + byte[] buffer = new byte[1024]; + + while (!deflater.finished()) { + int len = deflater.deflate(buffer); + outputStream.write(buffer, 0, len); + } + + deflater.end(); + + return outputStream.toByteArray(); + } + + /** + * 解压缩 + * + * @param data + * @return + */ + public static String unzip(byte[] data) { + + Inflater inflater = new Inflater(); + + inflater.setInput(data); + + byte[] buffer = new byte[1024]; + + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + + while (!inflater.finished()) { + + int len = inflater.inflate(buffer); + + // 防止异常数据导致死循环 + if (len == 0) { + + if (inflater.needsInput()) { + break; + } + + if (inflater.needsDictionary()) { + throw new RuntimeException("Inflater needs dictionary"); + } + } + + outputStream.write(buffer, 0, len); + } + + return outputStream.toString(StandardCharsets.UTF_8); + + } catch (DataFormatException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + inflater.end(); + } + } } diff --git a/cf-framework/cf-spring-boot-starter-mybatis/src/main/java/com/cf/imes/framework/mybatis/core/type/CompressByteTypeHandler.java b/cf-framework/cf-spring-boot-starter-mybatis/src/main/java/com/cf/imes/framework/mybatis/core/type/CompressByteTypeHandler.java new file mode 100644 index 000000000..b00439cff --- /dev/null +++ b/cf-framework/cf-spring-boot-starter-mybatis/src/main/java/com/cf/imes/framework/mybatis/core/type/CompressByteTypeHandler.java @@ -0,0 +1,74 @@ +package com.cf.imes.framework.mybatis.core.type; + +import com.cf.imes.framework.common.util.json.JsonUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * mb自定义压缩字符串到byte[]类型转换器 + * + * @author Gqr + * @since 2026/5/11 14:22 + */ +public class CompressByteTypeHandler extends BaseTypeHandler { + + @Override + public void setNonNullParameter( + PreparedStatement ps, + int i, + String parameter, + JdbcType jdbcType + ) throws SQLException { + + if (StringUtils.isBlank(parameter)) { + ps.setBytes(i, null); + return; + } + + byte[] compressed = JsonUtils.zip(parameter); + + ps.setBytes(i, compressed); + } + + @Override + public String getNullableResult(ResultSet rs, String columnName) + throws SQLException { + + byte[] bytes = rs.getBytes(columnName); + + return unzip(bytes); + } + + @Override + public String getNullableResult(ResultSet rs, int columnIndex) + throws SQLException { + + byte[] bytes = rs.getBytes(columnIndex); + + return unzip(bytes); + } + + @Override + public String getNullableResult(CallableStatement cs, int columnIndex) + throws SQLException { + + byte[] bytes = cs.getBytes(columnIndex); + + return unzip(bytes); + } + + private String unzip(byte[] bytes) { + + if (bytes == null || bytes.length == 0) { + return null; + } + + return JsonUtils.unzip(bytes); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateDetailRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateDetailRespVO.java index 186ccb637..5d018b7ad 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateDetailRespVO.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateDetailRespVO.java @@ -220,5 +220,6 @@ public class PlateDetailRespVO { @Schema(description = "加工组名称", requiredMode = Schema.RequiredMode.REQUIRED) private List processGroupLists; - + @Schema(description = "造型数据") + private String modelData; } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java index 8cf419c79..3001f4cd1 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java @@ -1,7 +1,6 @@ package com.cf.imes.module.executor.service.optimizeplan; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.PageUtil; @@ -20,6 +19,7 @@ import co.elastic.clients.elasticsearch.sql.TranslateRequest; import co.elastic.clients.elasticsearch.sql.TranslateResponse; import co.elastic.clients.json.JsonData; import co.elastic.clients.json.JsonpMappingException; +import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -32,6 +32,7 @@ import com.cf.imes.framework.common.enums.PlanTypeEnum; import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.common.util.Assert.AssertUtils; +import com.cf.imes.framework.common.util.json.JsonUtils; import com.cf.imes.framework.common.util.object.BeanUtils; import com.cf.imes.framework.es.core.service.ESDocumentService; import com.cf.imes.framework.mybatis.core.query.QueryWrapperX; @@ -308,10 +309,14 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { AssertUtils.notEmpty(plateDOS, ORDER_PLATE_EMPTY); - List orderModelDOS = getOrderModels(ListUtil.of(orderId), goodsDOS.stream().map(GoodsReqVO::getId).collect(Collectors.toList())); - - AssertUtils.notEmpty(orderModelDOS,ORDER_PLATE_MODEL_DATE_ERROR); + List models = + plateDOS.stream() + .map(PlateDetailRespVO::getModelData) + .filter(StringUtils::isNotBlank) + .map(json -> JsonUtils.parseObject(json, OrderModelDO.class)) + .toList(); + AssertUtils.notEmpty(models, ORDER_PLATE_MODEL_DATE_ERROR); // 查询订单对应的配件信息 List printOrderPartsRespVOS = orderPartsMapper.selectPartList(Collections.singletonList(orderId), getUserOrganId()); @@ -338,7 +343,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { .orderList(Collections.singletonList(orderDO)) .goodsList(goodsDOS) .plateList(plateDOS) - .plateModels(orderModelDOS) + .plateModels(models) .orderPartsRespVOS(printOrderPartsRespVOS) .orderPartsRemarks(orderPartsRemarks) .orderPackReqVOS(printOrderPackReqVOS) @@ -389,18 +394,14 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { AssertUtils.notEmpty(orderDOS, ORDER_PLAN_ORDERS_EMPTY); - // 需要查询小板造型信息的板材ID - List plateIds = plateDetailRespVOS.stream().map(PlateDetailRespVO::getPlateId).toList(); + List models = + plateDetailRespVOS.stream() + .map(PlateDetailRespVO::getModelData) + .filter(StringUtils::isNotBlank) + .map(json -> JsonUtils.parseObject(json, OrderModelDO.class)) + .toList(); - // 每一千块查询一次es - List> batchPlateIdsList = batchProcess(plateIds); - - List orderModelDOS = new ArrayList<>(); - for (List plateIdsList : batchPlateIdsList) { - orderModelDOS.addAll(esUtils.getEsDocument(FIELD_PLATE_ID, plateIdsList, plateIdsList.size(), ORDER_PLATE_MODEL.getIndex(), OrderModelDO.class)); - } - - AssertUtils.notEmpty(orderModelDOS, ORDER_PLAN_PLATE_MODEL_DATE_ERROR); + AssertUtils.notEmpty(models, ORDER_PLAN_PLATE_MODEL_DATE_ERROR); List remainPlateDOS = remainPlateMapper.selectByPlanId(planId,getUserOrganId()); @@ -446,7 +447,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { .plan(planDO) .goodsList(goodsDOS) .plateList(plateDetailRespVOS) - .plateModels(orderModelDOS) + .plateModels(models) .planActualGoodsModelDO(planActualGoodsModelDO) .optimizeRemainPlates(optimizeRemainPlates) .orderPartsRespVOS(printOrderPartsRespVOS) @@ -791,8 +792,12 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { AssertUtils.notEmpty(plateDetailRespVOS, ORDER_PLATE_EMPTY); - // todo 数据结构改后,可以增加排单ID作为筛选,只查为 0 的 -// List orderModelDOS = getOrderModels(orderIds, orderGoodsIds); + List models = + plateDetailRespVOS.stream() + .map(PlateDetailRespVO::getModelData) + .filter(StringUtils::isNotBlank) + .map(json -> JsonUtils.parseObject(json, OrderModelDO.class)) + .toList(); AssertUtils.notEmpty(plateDetailRespVOS,ORDER_PLATE_MODEL_DATE_ERROR); @@ -800,7 +805,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { .orderList(buildTree(orderDOS)) .goodsList(goodsReqVOS) .plateList(plateDetailRespVOS) - .plateModels(Collections.emptyList()) + .plateModels(models) .build(); } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/planitem/PlanItemMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/planitem/PlanItemMapper.xml index 46732418b..5b48d2402 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/planitem/PlanItemMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/planitem/PlanItemMapper.xml @@ -405,6 +405,7 @@ + @@ -453,7 +454,8 @@ op.open_door_type as openDoorType, op.is_special_shaped as isSpecialShaped, op.is_sculpt as isSculpt, - op.remark as remark + op.remark as remark, + op.model_data as modelData from order_plate op left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml index c8185f3bf..e6cea56ac 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml @@ -76,6 +76,7 @@ + @@ -379,6 +380,7 @@ +