From 31def6fdf20349936c5aabea5d2512cadb95d9b7 Mon Sep 17 00:00:00 2001 From: liuzhaotian Date: Tue, 28 May 2024 14:31:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8E=92=E5=8D=95=E6=8E=A5=E5=8F=A3=20-=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=92=E5=8D=95=E5=88=86=E9=A1=B5bug?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/mysql/planitem/PlanItemMapper.java | 3 + .../optimizeplan/OptimizePlanServiceImpl.java | 35 +++++++--- .../service/plan/PlanServiceImpl.java | 67 +++++++++++++------ .../mapper/planitem/PlanItemMapper.xml | 39 +++++++++++ .../resources/mapper/plate/PlateMapper.xml | 5 +- 5 files changed, 117 insertions(+), 32 deletions(-) create mode 100644 cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/planitem/PlanItemMapper.xml diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/planitem/PlanItemMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/planitem/PlanItemMapper.java index 9c4f9e629..3f756527d 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/planitem/PlanItemMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/planitem/PlanItemMapper.java @@ -5,8 +5,10 @@ import java.util.*; import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX; import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; +import com.cf.imes.module.executor.controller.admin.plan.vo.PlateInfoVO; import com.cf.imes.module.executor.dal.dataobject.planitem.PlanItemDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 生产单开料排单明细 Mapper @@ -17,4 +19,5 @@ import org.apache.ibatis.annotations.Mapper; public interface PlanItemMapper extends BaseMapperX { + List selectGoodsList(@Param("planIds") List planIds); } \ No newline at end of file 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 e3bbca85b..13b2c6042 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,23 +1,20 @@ package com.cf.imes.module.executor.service.optimizeplan; +import cn.hutool.Hutool; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.FieldValue; -import co.elastic.clients.elasticsearch._types.query_dsl.Query; -import co.elastic.clients.elasticsearch._types.query_dsl.TermQuery; -import co.elastic.clients.elasticsearch._types.query_dsl.TermsQuery; -import co.elastic.clients.elasticsearch.core.SearchRequest; -import co.elastic.clients.elasticsearch.core.SearchResponse; +import co.elastic.clients.elasticsearch.core.*; import co.elastic.clients.elasticsearch.core.search.Hit; import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.util.json.JsonUtils; -import com.cf.imes.framework.es.core.dal.ESDocument; +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.LambdaQueryWrapperX; import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX; -import com.cf.imes.framework.organ.core.db.OrganBaseDO; import com.cf.imes.module.executor.controller.admin.plan.bo.OrderSource; import com.cf.imes.module.executor.controller.admin.plan.dto.Material; import com.cf.imes.module.executor.controller.admin.plan.vo.*; @@ -44,14 +41,23 @@ import com.cf.imes.module.infra.api.file.FileApi; import com.cf.imes.module.infra.api.file.dto.FileCreateReqDTO; import com.cf.imes.module.system.api.dataSource.DataSourceApi; import com.cf.imes.module.system.api.machine.MachineApi; -import com.github.yulichang.interfaces.MPJBaseJoin; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.handler.codec.http2.DefaultHttp2Headers; +import io.netty.handler.codec.http2.DefaultHttp2HeadersDecoder; +import io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder; +import io.netty.handler.codec.http2.Http2Headers; +import io.swagger.v3.core.util.Json; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; @@ -61,6 +67,9 @@ import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.e import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_NOT_EXISTS; import static com.cf.imes.module.executor.enums.ErrorCodeConstants.PLAN_NOT_EXISTS; +import io.netty.handler.codec.http2.Http2HeadersEncoder; +import io.netty.handler.codec.http2.Http2HeadersDecoder; + /** * @author there */ @@ -312,8 +321,9 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { PlanDO planDO = planMapper.selectByOrderId(orderId); List plateDOS = plateMapper.selectPlateDetialList(orderId); + int size = plateDOS.size(); - List orderModelDOS = buildRespByOrderId(orderId, ORDER_PLATE_MODEL); + List orderModelDOS = buildRespByOrderId(orderId, ORDER_PLATE_MODEL,size); orderSource.setOptimizePlateDetialRespVO(optimizePlateDetialRespVO); orderSource.setPlan(planDO); @@ -348,8 +358,9 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { List goodsDOS = goodsMapper.selectList(new LambdaQueryWrapperX().in(GoodsDO::getOrderId, orderIds)); List plateDOS = plateMapper.selectPlateDetialListByIds(orderIds); + int size = plateDOS.size(); - List orderModelDOS = buildRespByOrderIds(orderIds, ORDER_PLATE_MODEL); + List orderModelDOS = buildRespByOrderIds(orderIds, ORDER_PLATE_MODEL,size); return OrderSource.builder() .optimizePlateDetialRespVO(optimizePlateDetialRespVOS) .orderList(orderDOS) @@ -364,6 +375,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { List fieldValues = orderIds.stream().map(FieldValue::of).toList(); SearchRequest.Builder builder = new SearchRequest.Builder(); builder.index(index); + builder.size(size); builder.query(q -> q.terms(b -> b.field("orderId").terms(e->e.value(fieldValues)))); try { SearchResponse search = elasticsearchClient.search(builder.build(), OrderModelDO.class); @@ -378,9 +390,10 @@ public class OptimizePlanServiceImpl implements OptimizePlanService { } } - private List buildRespByOrderId(Long orderId, String index) { + private List buildRespByOrderId(Long orderId, String index,int size) { SearchRequest.Builder builder = new SearchRequest.Builder(); builder.index(index); + builder.size(size); builder.query(q -> q.term(b -> b.field("orderId").value(orderId))); try { SearchResponse search = elasticsearchClient.search(builder.build(), OrderModelDO.class); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java index 542f386d9..d22a6b1d3 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java @@ -91,12 +91,15 @@ public class PlanServiceImpl implements PlanService { @Override @Transactional(rollbackFor = Exception.class) public Long createPlan(PlanSaveReqVO createReqVO) { + List itemList = createReqVO.getItemList(); // 插入 long sort = System.currentTimeMillis(); PlanDO plan = BeanUtils.toBean(createReqVO, PlanDO.class); plan.setIsPay(Boolean.FALSE); plan.setSort(sort); plan.setPlanNo(identifierGenerator.nextId(null).toString()); + String orderNos = itemList.stream().map(i -> i.getOrderId()).collect(Collectors.toList()).toString(); + plan.setOrderNos(orderNos); planMapper.insert(plan); Long planId = plan.getId(); /* List orderIds = createReqVO.getOrderIds(); @@ -111,12 +114,13 @@ public class PlanServiceImpl implements PlanService { planOrderMapper.insertBatch(planOrderDOS); }*/ //List plateIds = createReqVO.getPlateIds(); - List itemList = createReqVO.getItemList(); - Set plateIds = plateMapper.selectBatchOrderIdsAndGoodsIds(itemList); - if (CollectionUtil.isNotEmpty(plateIds)) { + + Set itemIds = plateMapper.selectBatchOrderIdsAndGoodsIds(itemList); + + if (CollectionUtil.isNotEmpty(itemIds)) { ArrayList planItemDOS = new ArrayList<>(); - for (Long plateId : plateIds) { + for (Long plateId : itemIds) { planItemDOS.add(PlanItemDO.builder() .planId(planId) .itemId(plateId) @@ -227,29 +231,54 @@ public class PlanServiceImpl implements PlanService { } Set macheineIds = planDOPageResult.getList().stream().map(PlanDO::getMachineId).collect(Collectors.toSet()); List machines = machineApi.list(macheineIds).getCheckedData(); - Set ids = planDOPageResult.getList().stream().map(PlanDO::getId).collect(Collectors.toSet()); - List goodsDOS = goodsMapper.selectList(new LambdaQueryWrapperX().in(GoodsDO::getOrderId, ids)); - List plateDOS = plateMapper.selectList(new LambdaQueryWrapperX().in(PlateDO::getGoodsId, goodsDOS.stream().map(GoodsDO::getGoodsId).collect(Collectors.toSet()))); + + + + List planIds = planDOPageResult.getList().stream().map(PlanDO::getId).collect(Collectors.toList()); +// // 根据排单ID查询排单明细表对应的明细ID +// List itemDOS = planItemMapper.selectList(new LambdaQueryWrapperX().in(PlanItemDO::getPlanId, ids)); +// +// List goodsDOS = goodsMapper.selectList(new LambdaQueryWrapperX().in(GoodsDO::getOrderId, ids)); +// +// List longs = goodsDOS.stream().map(GoodsDO::getGoodsId).collect(Collectors.toList()); +// +// +// List plateDOS = plateMapper.selectList(new LambdaQueryWrapperX().in(PlateDO::getGoodsId,longs )); + + List plateInfoVOS = planItemMapper.selectGoodsList(planIds); + + PageResult planRespVOPageResult = BeanUtils.toBean(planDOPageResult, PlanRespVO.class); + +// planRespVOPageResult.getList().forEach(e -> { +// e.setMachineName(machines.stream() +// .filter(f -> Objects.equals(f.getId(), e.getMachineId())) +// .map(CuttingRespDTO::getName) +// .findAny() +// .orElse(null)); +// e.setPlateInfoList(goodsDOS.stream() +// .filter(f -> Objects.equals(f.getOrderId(), e.getId())) +// .map(p -> PlateInfoVO.builder() +// .material(p.getMaterial()) +// .width(p.getWidth()) +// .height(p.getHeight()) +// .thickness(p.getThickness()) +// .color(p.getColor()) +// .area(p.getHeight().multiply(p.getWidth()).setScale(2, RoundingMode.HALF_UP)) +// .count(plateDOS.stream().filter(f -> Objects.equals(f.getGoodsId(), p.getGoodsId())).collect(Collectors.toSet()).size()) +// .build()) +// .collect(Collectors.toList())); +// }); + planRespVOPageResult.getList().forEach(e -> { e.setMachineName(machines.stream() .filter(f -> Objects.equals(f.getId(), e.getMachineId())) .map(CuttingRespDTO::getName) .findAny() .orElse(null)); - e.setPlateInfoList(goodsDOS.stream() - .filter(f -> Objects.equals(f.getOrderId(), e.getId())) - .map(p -> PlateInfoVO.builder() - .material(p.getMaterial()) - .width(p.getWidth()) - .height(p.getHeight()) - .thickness(p.getThickness()) - .color(p.getColor()) - .area(p.getHeight().multiply(p.getWidth()).setScale(2, RoundingMode.HALF_UP)) - .count(plateDOS.stream().filter(f -> Objects.equals(f.getGoodsId(), p.getGoodsId())).collect(Collectors.toSet()).size()) - .build()) - .collect(Collectors.toList())); + e.setPlateInfoList(plateInfoVOS); }); + return planRespVOPageResult; } 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 new file mode 100644 index 000000000..8ba41281b --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/planitem/PlanItemMapper.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file 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 863d8240d..65e6f2e70 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 @@ -78,8 +78,9 @@