From 2a7f19d69f60933a6c9cc228d0ec85d2e9632d7a Mon Sep 17 00:00:00 2001 From: gaoqr <13665037151@163.com> Date: Wed, 7 Aug 2024 18:35:27 +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=9A=E5=B0=8F=E6=9D=BF=E6=95=B0=E9=87=8F=E3=80=81=E5=B0=8F?= =?UTF-8?q?=E6=9D=BF=E9=9D=A2=E7=A7=AF=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/order/OrderController.java | 34 ---- .../order/OrderStatisticsController.java | 12 ++ .../order/vo/order/OrderGoodsPlateRespVO.java | 46 ++++- .../plate/OrderPlateStatisticsMapper.java | 36 ++++ .../executor/dal/mysql/plate/PlateMapper.java | 10 -- .../executor/service/order/OrderService.java | 10 -- .../service/order/OrderServiceImpl.java | 32 ---- .../service/order/OrderStatisticsService.java | 18 +- .../order/OrderStatisticsServiceImpl.java | 159 +++++++++++++++--- .../plate/OrderPlateStatisticsMapper.xml | 80 +++++++++ .../resources/mapper/plate/PlateMapper.xml | 68 -------- 11 files changed, 326 insertions(+), 179 deletions(-) create mode 100644 cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/OrderPlateStatisticsMapper.java create mode 100644 cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/OrderPlateStatisticsMapper.xml diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java index 7fd8f4963..97a37c9a9 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java @@ -454,38 +454,4 @@ public class OrderController { public CommonResult>> getOrderOverdue() { return success(orderService.getOrderWarn()); } - - // 小板数量 <集合> - @GetMapping("/getPlateCount") - @Operation(summary = "小板数量") - @Parameters({ - @Parameter(name = "startTime", description = "开始时间", example = "2024-07-15"), - @Parameter(name = "endTime", description = "结束时间", example = "2024-07-16"), - @Parameter(name = "pageNo", description = "第几页", example = "1"), - @Parameter(name = "pageSize", description = "每页条数", example = "10") - }) - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult> getPlateCount(@RequestParam(value = "startTime") String startTime, - @RequestParam(value = "endTime") String endTime, - @RequestParam(value = "pageNo") Integer pageNo, - @RequestParam(value = "pageSize") Integer pageSize) { - return success(orderService.plateCount(startTime + " 00:00:00", endTime + " 23:59:59", pageNo, pageSize)); - } - - // 小板面积 <集合> - @GetMapping("/getPlateArea") - @Operation(summary = "小板面积") - @Parameters({ - @Parameter(name = "startTime", description = "开始时间", example = "2024-07-15"), - @Parameter(name = "endTime", description = "结束时间", example = "2024-07-16"), - @Parameter(name = "pageNo", description = "第几页", example = "1"), - @Parameter(name = "pageSize", description = "每页条数", example = "10") - }) - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult> getPlateArea(@RequestParam(value = "startTime") String startTime, - @RequestParam(value = "endTime") String endTime, - @RequestParam(value = "pageNo") Integer pageNo, - @RequestParam(value = "pageSize") Integer pageSize) { - return success(orderService.plateArea(startTime + " 00:00:00", endTime + " 23:59:59", pageNo, pageSize)); - } } \ 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/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 c8c09f68a..0981d4f2e 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 @@ -76,4 +76,16 @@ public class OrderStatisticsController { public CommonResult> getOrderAndPlanAreaGroup(@Valid OrderStatisticsReqVO reqVO) { return success(orderStatisticsService.getOrderAndPlanAreaSumGroup(reqVO)); } + + @GetMapping("/plateCount/group") + @Operation(summary = "小板数量分组统计") + public CommonResult> getPlateCount(@Valid OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.getOrderPlateCountGroup(reqVO)); + } + + @GetMapping("/plateArea/group") + @Operation(summary = "小板面积分组统计") + public CommonResult> getPlateArea(@Valid OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.getOrderPlateAreaGroup(reqVO)); + } } 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 173deff3a..c700b6a32 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 @@ -2,6 +2,7 @@ package com.cf.imes.module.executor.controller.admin.order.vo.order; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; +import org.jetbrains.annotations.NotNull; import java.math.BigDecimal; @@ -11,7 +12,7 @@ import java.math.BigDecimal; @AllArgsConstructor @NoArgsConstructor @ToString(callSuper = true) -public class OrderGoodsPlateRespVO { +public class OrderGoodsPlateRespVO implements Comparable { @Schema(description = "商品 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "243") private Long goodsId; @@ -54,4 +55,47 @@ public class OrderGoodsPlateRespVO { @Schema(description = "面积") private BigDecimal orderArea; + + @Schema(description = "生产单日期") + private String orderDate; + + @Override + public int compareTo(@NotNull OrderGoodsPlateRespVO other) { + // 解析 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; + } + } + + // 比较周/日 + 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 (orderCount != null && other.orderCount != null) { + return orderCount.compareTo(other.orderCount); + } + + // 比较面积 + if (orderArea != null && other.orderArea != null) { + return orderArea.compareTo(other.orderArea); + } + return 0; + } } 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 new file mode 100644 index 000000000..1eedfe6a5 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/OrderPlateStatisticsMapper.java @@ -0,0 +1,36 @@ +package com.cf.imes.module.executor.dal.mysql.plate; + +import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderGoodsPlateRespVO; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; +import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 生产单板件统计Mapper + * + * @author Gqr + * @since 2024/8/7 17:06 + */ +@Mapper +public interface OrderPlateStatisticsMapper extends BaseMapperX { + /** + * 基于生产单时间分组统计小板数量 + * + * @param reqVO + * @return + */ + List selectPlateAnalysisListByCount(@Param("req") OrderStatisticsReqVO reqVO); + + /** + * 基于生产单时间分组统计小板面积 + * + * @param reqVO + * @return + */ + List selectPlateAnalysisListByArea(@Param("req") OrderStatisticsReqVO reqVO); + +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java index 497ea1d6a..18ce24f2d 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java @@ -1,8 +1,6 @@ package com.cf.imes.module.executor.dal.mysql.plate; import java.math.BigDecimal; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.*; import com.baomidou.mybatisplus.core.conditions.Wrapper; @@ -12,7 +10,6 @@ import com.baomidou.mybatisplus.core.toolkit.Constants; 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.order.vo.order.OrderGoodsPlateRespVO; import com.cf.imes.module.executor.controller.admin.plan.bo.GoodsNum; import com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds; import com.cf.imes.module.executor.controller.admin.plan.vo.*; @@ -136,13 +133,6 @@ public interface PlateMapper extends BaseMapperX { List selectGoodsNum(@Param("orderIds") List orderIds,@Param("organId") Long organId); -// 小板数据分析 -// List selectPlateAnalysisListByCount(@Param("organId") Long organId, @Param("startTime") String startTime, @Param("endTime") String endTime); // 数量 - IPage selectPlateAnalysisListByCount(@Param("page") IPage page, @Param("organId") Long organId, @Param("startTime") String startTime, @Param("endTime") String endTime); // 数量 -// List selectPlateAnalysisListByArea(@Param("organId") Long organId, @Param("startTime") String startTime, @Param("endTime") String endTime); // 面积 - IPage selectPlateAnalysisListByArea(@Param("page") IPage page, @Param("organId") Long organId, @Param("startTime") String startTime, @Param("endTime") String endTime); // 面积 - - default List selectPlateNum(Long orderId, Long organId) { return selectList(new LambdaQueryWrapperX() .eq(PlateDO::getOrganId,organId) diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java index a71bfb299..fa0c936fd 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java @@ -178,14 +178,4 @@ public interface OrderService { * 生产单超期告警分析统计 */ Map> getOrderWarn(); - - /** - * 小板数量 - */ - PageResult plateCount(String startTime, String endTime, Integer pageNo, Integer pageSize); - - /** - * 小板面积 - */ - PageResult plateArea(String startTime, String endTime, Integer pageNo, Integer pageSize); } \ 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/order/OrderServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java index e56b0c7ac..36cc80d6d 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java @@ -294,38 +294,6 @@ public class OrderServiceImpl implements OrderService { return JsonUtils.zipString(orderBodyToString); } - @Override - public PageResult plateCount(String startTime, String endTime, Integer pageNo, Integer pageSize) { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - PageDTO page = new PageDTO<>(pageNo, pageSize); - IPage orderDetail; - if (loginUser.getIsSupAdmin()){ - orderDetail = plateMapper.selectPlateAnalysisListByCount(page,null, startTime, endTime); - }else { - orderDetail = plateMapper.selectPlateAnalysisListByCount(page,OrganContextHolder.getOrganId(), startTime, endTime); - } - PageResult pageResult = new PageResult(orderDetail.getRecords(), orderDetail.getTotal()); - return pageResult; - } - - @Override - public PageResult plateArea(String startTime, String endTime, Integer pageNo, Integer pageSize) { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - PageDTO page = new PageDTO<>(pageNo, pageSize); - IPage orderDetail; - if (loginUser.getIsSupAdmin()){ - orderDetail = plateMapper.selectPlateAnalysisListByArea(page,null, startTime, endTime); - }else { - orderDetail = plateMapper.selectPlateAnalysisListByArea(page,OrganContextHolder.getOrganId(), startTime, endTime); - } - PageResult pageResult = new PageResult(orderDetail.getRecords(), orderDetail.getTotal()); - return pageResult; - } - @Override public List getRoomAndBody(Long planId) { diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java index a125192da..f772699b4 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java @@ -50,10 +50,26 @@ public interface OrderStatisticsService { Map getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO); /** - * 生产单、排单平方数统计 + * 生产单、排单平方数分组统计 * * @param reqVO * @return */ Map getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO); + + /** + * 小板数量分组统计 + * + * @param reqVO + * @return + */ + Map getOrderPlateCountGroup(OrderStatisticsReqVO reqVO); + + /** + * 小板面积分组统计 + * + * @param reqVO + * @return + */ + Map getOrderPlateAreaGroup(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 235c6c028..1239cb63b 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 @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import com.cf.imes.framework.common.enums.OrderStatusEnum; import com.cf.imes.framework.organ.core.aop.OrganIgnore; import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderGoodsPlateRespVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO; @@ -11,6 +12,7 @@ import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsA import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsCountRespVO; 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 org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -44,6 +46,9 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { @Resource private PlanMapper planMapper; + @Resource + private OrderPlateStatisticsMapper orderPlateStatisticsMapper; + @Override @OrganIgnore public Integer orderCount(OrderStatisticsReqVO reqVO) { @@ -79,11 +84,9 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { public Map getOrderStatusCount(OrderStatisticsReqVO reqVO) { Map resultMap = new HashMap<>(); - // 获取机构id - reqVO.setOrganId(getOrganIdParam(reqVO)); - - // 计算时间跨度 - getTimeSpan(reqVO); + // 所有的日期集合 + List dateList = getDateList(reqVO); + resultMap.put("dateList", dateList); // 查询订单状态统计数据 List orderStatusRespVOS = orderStatisticsMapper.selectOrderStatusCountGroupBy(reqVO); @@ -93,10 +96,6 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { .sorted(Comparator.naturalOrder()) .collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList())); - // 所有的日期集合 - List dateList = generateDateRange(reqVO); - resultMap.put("dateList", dateList); - // 遍历订单状态所有枚举值 List> series = new ArrayList<>(); for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) { @@ -134,14 +133,8 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { public Map getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO) { Map resultMap = new LinkedHashMap<>(); - // 获取机构id - reqVO.setOrganId(getOrganIdParam(reqVO)); - - // 计算时间跨度 - getTimeSpan(reqVO); - // 所有的日期集合 - List dateList = generateDateRange(reqVO); + List dateList = getDateList(reqVO); Map> orderRespMap = orderStatisticsMapper.selectOrderCountGroupByOrderDate(reqVO).stream() .sorted(Comparator.naturalOrder()) @@ -179,14 +172,8 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { public Map getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO) { Map resultMap = new LinkedHashMap<>(); - // 获取机构id - reqVO.setOrganId(getOrganIdParam(reqVO)); - - // 计算时间跨度 - getTimeSpan(reqVO); - // 所有的日期集合 - List dateList = generateDateRange(reqVO); + List dateList = getDateList(reqVO); Map> orderRespMap = orderStatisticsMapper.selectOrderAreaGroupByOrderDate(reqVO).stream() .sorted(Comparator.naturalOrder()) @@ -213,6 +200,132 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { return resultMap; } + + @Override + public Map getOrderPlateCountGroup(OrderStatisticsReqVO reqVO) { + Map resultMap = new LinkedHashMap<>(); + + // 所有的日期集合 + List dateList = getDateList(reqVO); + resultMap.put("dateList", dateList); + + List orderGoodsPlateRespVOList = orderPlateStatisticsMapper.selectPlateAnalysisListByCount(reqVO); + // 基于相同的orderDate分组 + Map> orderGoodsPlateRespMap = orderGoodsPlateRespVOList.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, + OrderGoodsPlateRespVO::getMaterial, + (oldValue, newValue) -> newValue + )); + + // 遍历订单状态所有枚举值 + List> series = new ArrayList<>(); + for (Map.Entry entry : goodsMap.entrySet()) { + Map seriesItem = new HashMap<>(); + int[] sumArr = new int[dateList.size()]; + + // 遍历完整的日期范围 + int index = 0; + for (String dateStr : dateList) { + // 查找匹配的goodsId + List orderGoodsPlateRespVOS = orderGoodsPlateRespMap.get(dateStr); + int count = 0; + if (orderGoodsPlateRespVOS != null) { + count = orderGoodsPlateRespVOS.stream() + .filter(respVO -> Objects.equals(entry.getKey(), respVO.getGoodsId())) + .map(OrderGoodsPlateRespVO::getOrderCount) + .findFirst().orElse(0); + } + sumArr[index++] = count; + } + + seriesItem.put("data", sumArr); + seriesItem.put("id", entry.getKey()); + seriesItem.put("name", entry.getValue()); + series.add(seriesItem); + } + resultMap.put("series", series); + return resultMap; + } + + @Override + public Map getOrderPlateAreaGroup(OrderStatisticsReqVO reqVO) { + Map resultMap = new LinkedHashMap<>(); + + // 所有的日期集合 + List dateList = getDateList(reqVO); + resultMap.put("dateList", dateList); + + List orderGoodsPlateRespVOList = orderPlateStatisticsMapper.selectPlateAnalysisListByArea(reqVO); + // 基于相同的orderDate分组 + Map> orderGoodsPlateRespMap = orderGoodsPlateRespVOList.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, + OrderGoodsPlateRespVO::getMaterial, + (oldValue, newValue) -> newValue + )); + + // 遍历订单状态所有枚举值 + List> series = new ArrayList<>(); + for (Map.Entry entry : goodsMap.entrySet()) { + Map seriesItem = new HashMap<>(); + BigDecimal[] areaArr = new BigDecimal[dateList.size()]; + + // 遍历完整的日期范围 + int index = 0; + for (String dateStr : dateList) { + // 查找匹配的goodsId + List orderGoodsPlateRespVOS = orderGoodsPlateRespMap.get(dateStr); + BigDecimal area = new BigDecimal(0); + if (orderGoodsPlateRespVOS != null) { + area = orderGoodsPlateRespVOS.stream() + .filter(respVO -> Objects.equals(entry.getKey(), respVO.getGoodsId())) + .map(OrderGoodsPlateRespVO::getOrderArea) + .findFirst().orElse(new BigDecimal(0)); + } + areaArr[index++] = area; + } + + seriesItem.put("data", areaArr); + seriesItem.put("id", entry.getKey()); + seriesItem.put("name", entry.getValue()); + series.add(seriesItem); + } + resultMap.put("series", series); + return resultMap; + } + + /** + * 获取日期区间格式下的所有日期字符串 + * 1、reqVO设置机构id + * 2、计算时间跨度设置到reqVO + * 3、返回所有日期的集合 + * @param reqVO + * @return + */ + private List getDateList(OrderStatisticsReqVO reqVO) { + // 获取机构id + reqVO.setOrganId(getOrganIdParam(reqVO)); + + // 计算时间跨度 + getTimeSpan(reqVO); + + // 所有的日期集合 + return generateDateRange(reqVO); + } + /** * 获取统计的时间跨度 * 计算起止时间:前端不传入时间就根据维度单位从当前日期计算 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 new file mode 100644 index 000000000..f17aa9c58 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/OrderPlateStatisticsMapper.xml @@ -0,0 +1,80 @@ + + + + + + + \ 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 a3ff89e51..1196517e0 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 @@ -601,73 +601,5 @@ - - - - - \ No newline at end of file