From 4428dbedc3237b2145e557afb41fc8e581b6525c Mon Sep 17 00:00:00 2001 From: gaoqr <13665037151@163.com> Date: Thu, 15 Aug 2024 18:26:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=9E=90=E9=A1=B5=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=EF=BC=9A1=E3=80=81=E5=B0=8F=E6=9D=BF=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90name=E5=AE=8C=E5=96=84=EF=BC=8C=E5=AE=BD=E9=AB=98?= =?UTF-8?q?=E5=8E=9A=E5=B0=8F=E6=95=B0=E7=82=B90=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E7=94=A8x=E8=BF=9E=E6=8E=A5=EF=BC=9B2=E3=80=81x?= =?UTF-8?q?=E8=BD=B4=E6=97=A5=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9=EF=BC=9B?= =?UTF-8?q?3=E3=80=81=E5=B0=8F=E6=9D=BF=E6=8E=92=E5=90=8D=E5=89=8D10?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/OrderStatisticsController.java | 7 ++ .../order/vo/order/OrderGoodsPlateRespVO.java | 50 ++++---- .../goods/OptimizeBoardModelDO.java | 3 + .../plate/OrderPlateStatisticsMapper.java | 26 +++- .../order/OrderStatisticsServiceImpl.java | 114 +++++++++++++----- .../plate/OrderPlateStatisticsMapper.xml | 64 +++++++--- 6 files changed, 178 insertions(+), 86 deletions(-) diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java index 2ba56866e..22d0f16c4 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java @@ -86,4 +86,11 @@ public class OrderStatisticsController { public CommonResult> getPlateArea(@Valid OrderStatisticsReqVO reqVO) { return success(orderStatisticsService.getOrderPlateAreaGroup(reqVO)); } + + @GetMapping("/bigPlateCount/group") + @Operation(summary = "大板数量分组统计") + public CommonResult> getBigPlateCount(@Valid OrderStatisticsReqVO reqVO) { + return success(null); + } + } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderGoodsPlateRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderGoodsPlateRespVO.java index c700b6a32..5396f1470 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderGoodsPlateRespVO.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderGoodsPlateRespVO.java @@ -61,40 +61,32 @@ public class OrderGoodsPlateRespVO implements Comparable @Override public int compareTo(@NotNull OrderGoodsPlateRespVO other) { - // 解析 date 字符串为年、月、周 - String[] partsThis = orderDate.split("-"); - String[] partsOther = other.orderDate.split("-"); + if (orderDate != null && other.orderDate != null) { + // 解析 date 字符串为年、月、周 + String[] partsThis = orderDate.split("-"); + String[] partsOther = other.orderDate.split("-"); - // 比较年份 - int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); - if (yearComparison != 0) { - return yearComparison; - } - - // 比较月份 - if (partsThis.length > 1 && partsOther.length > 1) { - int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); - if (monthComparison != 0) { - return monthComparison; + // 比较年份 + int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); + if (yearComparison != 0) { + return yearComparison; } - } - // 比较周/日 - if (partsThis.length > 2 && partsOther.length > 2) { - int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); - if (weekComparison != 0) { - return weekComparison; + // 比较月份 + if (partsThis.length + partsOther.length > 2) { + int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); + if (monthComparison != 0) { + return monthComparison; + } } - } - // 比较数量 - if (orderCount != null && other.orderCount != null) { - return orderCount.compareTo(other.orderCount); - } - - // 比较面积 - if (orderArea != null && other.orderArea != null) { - return orderArea.compareTo(other.orderArea); + // 比较周/日 + if (partsThis.length + partsOther.length > 4) { + int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); + if (weekComparison != 0) { + return weekComparison; + } + } } return 0; } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/goods/OptimizeBoardModelDO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/goods/OptimizeBoardModelDO.java index 8b98331c1..d3fa767f8 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/goods/OptimizeBoardModelDO.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/goods/OptimizeBoardModelDO.java @@ -21,6 +21,9 @@ public class OptimizeBoardModelDO extends ESDocument { @Schema(description = "排单ID") private Long planId; + @Schema(description ="排单优化的大板数里") + private Long placeBoardNumber; + @Schema(description = "生产单id") private Long orderId; diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/OrderPlateStatisticsMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/OrderPlateStatisticsMapper.java index 1eedfe6a5..78e34ff98 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/OrderPlateStatisticsMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/OrderPlateStatisticsMapper.java @@ -18,19 +18,37 @@ import java.util.List; @Mapper public interface OrderPlateStatisticsMapper extends BaseMapperX { /** - * 基于生产单时间分组统计小板数量 + * 基于商品id分组的小板数量列表 * * @param reqVO * @return */ - List selectPlateAnalysisListByCount(@Param("req") OrderStatisticsReqVO reqVO); + List selectPlateCountList(@Param("req") OrderStatisticsReqVO reqVO); + /** - * 基于生产单时间分组统计小板面积 + * 基于订单日期分组的前10小板数量分组 + * @param goodsIdList + * @param reqVO + * @return + */ + List selectTopTenPlateCountListGroupByOrderDate(@Param("goodsIds") List goodsIdList, @Param("req") OrderStatisticsReqVO reqVO); + + + /** + * 基于商品id分组的小板面积列表 + * @param reqVO + * @return + */ + List selectPlateAreaList(@Param("req") OrderStatisticsReqVO reqVO); + + + /** + * 基于订单日期分组的前10小板面积分组 * * @param reqVO * @return */ - List selectPlateAnalysisListByArea(@Param("req") OrderStatisticsReqVO reqVO); + List selectTopTenPlateAreaListGroupByOrderDate(@Param("goodsIds") List goodsIdList, @Param("req") OrderStatisticsReqVO reqVO); } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java index a1151d625..f98679ff6 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java @@ -12,6 +12,9 @@ import com.cf.imes.module.executor.dal.mysql.order.OrderStatisticsMapper; import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper; import com.cf.imes.module.executor.dal.mysql.plate.OrderPlateStatisticsMapper; import com.cf.imes.module.executor.enums.OrderStatisticsUnit; +import com.cf.imes.module.system.api.dict.DictDataApi; +import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO; +import com.cf.imes.module.system.enums.DictTypeConstants; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -47,6 +50,9 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { @Resource private OrderPlateStatisticsMapper orderPlateStatisticsMapper; + @Resource + private DictDataApi dictDataApi; + // 常用的字段key private static final String DATELIST_FIELD_NAME = "dateList"; private static final String SERIES_FIELD_NAME = "series"; @@ -200,22 +206,33 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { // 所有的日期集合 List dateList = getDateList(reqVO); - List orderGoodsPlateRespVOList = orderPlateStatisticsMapper.selectPlateAnalysisListByCount(reqVO); - // 基于相同的orderDate分组 - Map> orderGoodsPlateRespMap = orderGoodsPlateRespVOList.stream() + // 查询时间段内数量最多的小板,排序列出数量前10的goods_id + List topTenCountGoodsId = orderPlateStatisticsMapper.selectPlateCountList(reqVO).stream() + .sorted(Comparator.comparingLong(OrderGoodsPlateRespVO::getOrderCount).reversed()) + .map(OrderGoodsPlateRespVO::getGoodsId) + .limit(10) + .collect(Collectors.toList()); + + + // 前十goods_id基于时间分组 + Map> orderGoodsPlateRespMap = orderPlateStatisticsMapper.selectTopTenPlateCountListGroupByOrderDate(topTenCountGoodsId, reqVO).stream() .sorted(Comparator.naturalOrder()) .collect(Collectors.groupingBy(OrderGoodsPlateRespVO::getOrderDate, LinkedHashMap::new, Collectors.toList())); - // 获取所有商品map - Map goodsMap = orderGoodsPlateRespMap.values().stream() - .flatMap(List::stream) - .collect(Collectors.toMap( - OrderGoodsPlateRespVO::getGoodsId, - vo -> vo, - (oldValue, newValue) -> oldValue - )); + // 获取所有商品{goodsId:respvo},根据top10排序 + Map goodsMap = new LinkedHashMap<>(); + for (Long id : topTenCountGoodsId) { + List list = orderGoodsPlateRespMap.values().stream() + .flatMap(List::stream) + .filter(vo -> vo.getGoodsId().equals(id)) + .collect(Collectors.toList()); + if (!list.isEmpty()) { + // goodsId相同,其他属性任取 + goodsMap.put(id, list.get(0)); + } + } - // 遍历订单状态所有枚举值 + // 遍历所有goods_id List> series = new ArrayList<>(); for (Map.Entry entry : goodsMap.entrySet()) { Map seriesItem = new HashMap<>(); @@ -228,10 +245,10 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { List orderGoodsPlateRespVOS = orderGoodsPlateRespMap.get(dateStr); int count = 0; if (orderGoodsPlateRespVOS != null) { - count = orderGoodsPlateRespVOS.stream() + Optional matchingRespVO = orderGoodsPlateRespVOS.stream() .filter(respVO -> Objects.equals(entry.getKey(), respVO.getGoodsId())) - .map(OrderGoodsPlateRespVO::getOrderCount) - .findFirst().orElse(0); + .findFirst(); + count = matchingRespVO.map(OrderGoodsPlateRespVO::getOrderCount).orElse(0); } sumArr[index++] = count; } @@ -240,9 +257,12 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { seriesItem.put("id", entry.getKey()); // 材质-商品名称-颜色-纹理-宽-高-厚-品牌 OrderGoodsPlateRespVO orderGoodsPlateRespVO = entry.getValue(); + // 获取纹路描述 + DictDataRespDTO grainDTO = dictDataApi.getDictData(DictTypeConstants.GRAIN_TYPE, String.valueOf(orderGoodsPlateRespVO.getTexture())).getData(); + String texture = ObjectUtil.isNotNull(grainDTO) ? grainDTO.getLabel() : ""; seriesItem.put("name", orderGoodsPlateRespVO.getMaterial() + "-" + orderGoodsPlateRespVO.getGoodsName() + - "-" + orderGoodsPlateRespVO.getColor() + "-" + orderGoodsPlateRespVO.getTexture() + "-" + orderGoodsPlateRespVO.getWidth() + - "-" + orderGoodsPlateRespVO.getHeight() + "-" + orderGoodsPlateRespVO.getThickness() + "-" + orderGoodsPlateRespVO.getBrand()); + "-" + orderGoodsPlateRespVO.getColor() + "-" + texture + "-" + stripTrailingZeros(orderGoodsPlateRespVO.getWidth()) + + "×" + stripTrailingZeros(orderGoodsPlateRespVO.getHeight()) + "×" + stripTrailingZeros(orderGoodsPlateRespVO.getThickness()) + "-" + orderGoodsPlateRespVO.getBrand()); series.add(seriesItem); } resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList()); @@ -257,22 +277,33 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { // 所有的日期集合 List dateList = getDateList(reqVO); - List orderGoodsPlateRespVOList = orderPlateStatisticsMapper.selectPlateAnalysisListByArea(reqVO); - // 基于相同的orderDate分组 - Map> orderGoodsPlateRespMap = orderGoodsPlateRespVOList.stream() + // 查询时间段内面积最多的小板,排序列出前10面积的goods_id + List topTenCountGoodsId = orderPlateStatisticsMapper.selectPlateAreaList(reqVO).stream() + .sorted(Comparator.comparing(OrderGoodsPlateRespVO::getOrderArea).reversed()) + .map(OrderGoodsPlateRespVO::getGoodsId) + .limit(10) + .collect(Collectors.toList()); + + + // 前十goods_id基于时间分组 + Map> orderGoodsPlateRespMap = orderPlateStatisticsMapper.selectTopTenPlateAreaListGroupByOrderDate(topTenCountGoodsId, reqVO).stream() .sorted(Comparator.naturalOrder()) .collect(Collectors.groupingBy(OrderGoodsPlateRespVO::getOrderDate, LinkedHashMap::new, Collectors.toList())); - // 获取所有商品map - Map goodsMap = orderGoodsPlateRespMap.values().stream() - .flatMap(List::stream) - .collect(Collectors.toMap( - OrderGoodsPlateRespVO::getGoodsId, - vo -> vo, - (oldValue, newValue) -> newValue - )); + // 获取所有商品{goodsId:respvo},根据top10排序 + Map goodsMap = new LinkedHashMap<>(); + for (Long id : topTenCountGoodsId) { + List list = orderGoodsPlateRespMap.values().stream() + .flatMap(List::stream) + .filter(vo -> vo.getGoodsId().equals(id)) + .collect(Collectors.toList()); + if (!list.isEmpty()) { + // goodsId相同,其他属性任取 + goodsMap.put(id, list.get(0)); + } + } - // 遍历订单状态所有枚举值 + // 遍历所有goods_id List> series = new ArrayList<>(); for (Map.Entry entry : goodsMap.entrySet()) { Map seriesItem = new HashMap<>(); @@ -287,7 +318,7 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { if (orderGoodsPlateRespVOS != null) { area = orderGoodsPlateRespVOS.stream() .filter(respVO -> Objects.equals(entry.getKey(), respVO.getGoodsId())) - .map(OrderGoodsPlateRespVO::getOrderArea) + .map(vo -> vo.getOrderArea().stripTrailingZeros()) .findFirst().orElse(new BigDecimal(0)); } areaArr[index++] = area; @@ -297,9 +328,12 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { seriesItem.put("id", entry.getKey()); // 材质-商品名称-颜色-纹理-宽-高-厚-品牌 OrderGoodsPlateRespVO orderGoodsPlateRespVO = entry.getValue(); + // 获取纹路描述 + DictDataRespDTO grainDTO = dictDataApi.getDictData(DictTypeConstants.GRAIN_TYPE, String.valueOf(orderGoodsPlateRespVO.getTexture())).getData(); + String texture = ObjectUtil.isNotNull(grainDTO) ? grainDTO.getLabel() : ""; seriesItem.put("name", orderGoodsPlateRespVO.getMaterial() + "-" + orderGoodsPlateRespVO.getGoodsName() + - "-" + orderGoodsPlateRespVO.getColor() + "-" + orderGoodsPlateRespVO.getTexture() + "-" + orderGoodsPlateRespVO.getWidth() + - "-" + orderGoodsPlateRespVO.getHeight() + "-" + orderGoodsPlateRespVO.getThickness() + "-" + orderGoodsPlateRespVO.getBrand()); + "-" + orderGoodsPlateRespVO.getColor() + "-" + texture + "-" + stripTrailingZeros(orderGoodsPlateRespVO.getWidth()) + + "×" + stripTrailingZeros(orderGoodsPlateRespVO.getHeight()) + "×" + stripTrailingZeros(orderGoodsPlateRespVO.getThickness()) + "-" + orderGoodsPlateRespVO.getBrand()); series.add(seriesItem); } resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList()); @@ -435,11 +469,25 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { newDateStrBuffer.append("第").append(dateSplit[2]).append("周"); break; case DAY: - newDateStrBuffer.append(dateSplit[2]).append("日"); + newDateStrBuffer.append(dateSplit[2]); break; default: } return newDateStrBuffer.toString(); } + /** + * 移除尾数的0,600.000 -> 600 + * + * @param data + * @return + */ + private String stripTrailingZeros(BigDecimal data) { + if (ObjectUtil.isNotNull(data)) { + return data.stripTrailingZeros().toPlainString(); + } else { + return ""; + } + } + } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/OrderPlateStatisticsMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/OrderPlateStatisticsMapper.xml index 3da18362c..30c9e277b 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/OrderPlateStatisticsMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/OrderPlateStatisticsMapper.xml @@ -1,7 +1,20 @@ - + select g.goods_id, + count(a.id) as orderCount + from order_goods g + left join order_plate a ON g.id = a.goods_id and a.deleted = 0 + left join orders o ON o.id = a.order_id and o.deleted = 0 + where g.deleted = 0 + and o.order_date between #{req.createTime[0]} and #{req.createTime[1]} + group by g.goods_id + having orderCount > 0 + order by null; + + + - + + \ No newline at end of file