Commit 15d6ca181ab2c303dddd85514370ad5d4ce9cb64
1 parent
f7cd8573
feat(wms):优化首页的代码实现
Showing
13 changed files
with
115 additions
and
183 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
| @@ -303,6 +303,17 @@ public class LocalDateTimeUtils { | @@ -303,6 +303,17 @@ public class LocalDateTimeUtils { | ||
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | /** | 305 | /** |
| 306 | + * 获取从开始日期起的日期列表 | ||
| 307 | + * | ||
| 308 | + * @param startDate 开始日期 | ||
| 309 | + * @param days 天数 | ||
| 310 | + * @return 日期列表,包含开始日期 | ||
| 311 | + */ | ||
| 312 | + public static List<LocalDate> getDateList(LocalDate startDate, int days) { | ||
| 313 | + return startDate.datesUntil(startDate.plusDays(days)).toList(); | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + /** | ||
| 306 | * 格式化时间范围 | 317 | * 格式化时间范围 |
| 307 | * | 318 | * |
| 308 | * @param startTime 开始时间 | 319 | * @param startTime 开始时间 |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/WmsHomeStatisticsController.java
| @@ -55,8 +55,10 @@ public class WmsHomeStatisticsController { | @@ -55,8 +55,10 @@ public class WmsHomeStatisticsController { | ||
| 55 | @Parameter(name = "warehouseId", description = "仓库编号", example = "1024") | 55 | @Parameter(name = "warehouseId", description = "仓库编号", example = "1024") |
| 56 | @PreAuthorize("@ss.hasPermission('wms:home:query')") | 56 | @PreAuthorize("@ss.hasPermission('wms:home:query')") |
| 57 | public CommonResult<WmsHomeInventorySummaryRespVO> getInventorySummary( | 57 | public CommonResult<WmsHomeInventorySummaryRespVO> getInventorySummary( |
| 58 | - @RequestParam(value = "warehouseId", required = false) Long warehouseId) { | ||
| 59 | - return success(homeStatisticsService.getInventorySummary(warehouseId)); | 58 | + @RequestParam(value = "warehouseId", required = false) Long warehouseId, |
| 59 | + @RequestParam(value = "goodsLimit", defaultValue = "5") @Min(1) @Max(20) Integer goodsLimit, | ||
| 60 | + @RequestParam(value = "warehouseLimit", defaultValue = "8") @Min(1) @Max(20) Integer warehouseLimit) { | ||
| 61 | + return success(homeStatisticsService.getInventorySummary(warehouseId, goodsLimit, warehouseLimit)); | ||
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | } | 64 | } |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/vo/WmsHomeInventoryItemRankRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.wms.controller.admin.home.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -import java.math.BigDecimal; | ||
| 7 | - | ||
| 8 | -@Schema(description = "管理后台 - WMS 首页商品库存排行 Response VO") | ||
| 9 | -@Data | ||
| 10 | -public class WmsHomeInventoryItemRankRespVO { | ||
| 11 | - | ||
| 12 | - // TODO @AI:改成 id、name 会不会更好? | ||
| 13 | - | ||
| 14 | - @Schema(description = "商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 15 | - private Long itemId; | ||
| 16 | - | ||
| 17 | - @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "A4 复印纸") | ||
| 18 | - private String itemName; | ||
| 19 | - | ||
| 20 | - @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 21 | - private BigDecimal quantity; | ||
| 22 | - | ||
| 23 | -} |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/vo/WmsHomeInventorySummaryRespVO.java
| @@ -10,15 +10,43 @@ import java.util.List; | @@ -10,15 +10,43 @@ import java.util.List; | ||
| 10 | @Data | 10 | @Data |
| 11 | public class WmsHomeInventorySummaryRespVO { | 11 | public class WmsHomeInventorySummaryRespVO { |
| 12 | 12 | ||
| 13 | - // TODO @AI:一次性的 VO ,要不合并到 WmsHomeInventorySummaryRespVO 里?一个叫 ItemRank,一个叫 WarehouseRank? | ||
| 14 | - | ||
| 15 | @Schema(description = "总库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000.00") | 13 | @Schema(description = "总库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000.00") |
| 16 | private BigDecimal totalQuantity; | 14 | private BigDecimal totalQuantity; |
| 17 | 15 | ||
| 18 | @Schema(description = "商品库存占比列表") | 16 | @Schema(description = "商品库存占比列表") |
| 19 | - private List<WmsHomeInventoryItemRankRespVO> goodsShareList; | 17 | + private List<ItemRank> goodsShareList; |
| 20 | 18 | ||
| 21 | @Schema(description = "仓库库存分布列表") | 19 | @Schema(description = "仓库库存分布列表") |
| 22 | - private List<WmsHomeInventoryWarehouseRankRespVO> warehouseDistributionList; | 20 | + private List<WarehouseRank> warehouseDistributionList; |
| 21 | + | ||
| 22 | + @Schema(description = "管理后台 - WMS 首页商品库存排行 Response VO") | ||
| 23 | + @Data | ||
| 24 | + public static class ItemRank { | ||
| 25 | + | ||
| 26 | + @Schema(description = "商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 27 | + private Long id; | ||
| 28 | + | ||
| 29 | + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "A4 复印纸") | ||
| 30 | + private String name; | ||
| 31 | + | ||
| 32 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 33 | + private BigDecimal quantity; | ||
| 34 | + | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Schema(description = "管理后台 - WMS 首页仓库库存排行 Response VO") | ||
| 38 | + @Data | ||
| 39 | + public static class WarehouseRank { | ||
| 40 | + | ||
| 41 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 42 | + private Long id; | ||
| 43 | + | ||
| 44 | + @Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海仓") | ||
| 45 | + private String name; | ||
| 46 | + | ||
| 47 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 48 | + private BigDecimal quantity; | ||
| 49 | + | ||
| 50 | + } | ||
| 23 | 51 | ||
| 24 | } | 52 | } |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/vo/WmsHomeInventoryWarehouseRankRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.wms.controller.admin.home.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -import java.math.BigDecimal; | ||
| 7 | - | ||
| 8 | -@Schema(description = "管理后台 - WMS 首页仓库库存排行 Response VO") | ||
| 9 | -@Data | ||
| 10 | -public class WmsHomeInventoryWarehouseRankRespVO { | ||
| 11 | - | ||
| 12 | - // TODO @AI:改成 id、name 会不会更好? | ||
| 13 | - | ||
| 14 | - @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 15 | - private Long warehouseId; | ||
| 16 | - | ||
| 17 | - @Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海仓") | ||
| 18 | - private String warehouseName; | ||
| 19 | - | ||
| 20 | - @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 21 | - private BigDecimal quantity; | ||
| 22 | - | ||
| 23 | -} |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/vo/WmsHomeOrderStatusRespVO.java
| 1 | package cn.iocoder.yudao.module.wms.controller.admin.home.vo; | 1 | package cn.iocoder.yudao.module.wms.controller.admin.home.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.AllArgsConstructor; | ||
| 5 | import lombok.Data; | 4 | import lombok.Data; |
| 6 | -import lombok.NoArgsConstructor; | ||
| 7 | 5 | ||
| 8 | @Schema(description = "管理后台 - WMS 首页单据状态统计 Response VO") | 6 | @Schema(description = "管理后台 - WMS 首页单据状态统计 Response VO") |
| 9 | @Data | 7 | @Data |
| 10 | -@NoArgsConstructor | ||
| 11 | -@AllArgsConstructor | ||
| 12 | public class WmsHomeOrderStatusRespVO { | 8 | public class WmsHomeOrderStatusRespVO { |
| 13 | 9 | ||
| 14 | @Schema(description = "状态值", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | 10 | @Schema(description = "状态值", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| 15 | private Integer status; | 11 | private Integer status; |
| 16 | 12 | ||
| 17 | - // TODO @AI:statusName 前端字段就翻译点? | ||
| 18 | - @Schema(description = "状态名", requiredMode = Schema.RequiredMode.REQUIRED, example = "草稿") | ||
| 19 | - private String statusName; | ||
| 20 | - | ||
| 21 | @Schema(description = "单据数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") | 13 | @Schema(description = "单据数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") |
| 22 | private Long count; | 14 | private Long count; |
| 23 | 15 |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/vo/WmsHomeOrderSummaryRespVO.java
| @@ -9,20 +9,13 @@ import java.util.List; | @@ -9,20 +9,13 @@ import java.util.List; | ||
| 9 | @Data | 9 | @Data |
| 10 | public class WmsHomeOrderSummaryRespVO { | 10 | public class WmsHomeOrderSummaryRespVO { |
| 11 | 11 | ||
| 12 | - // TODO @AI:orderType 缩写成 type? | ||
| 13 | - | ||
| 14 | @Schema(description = "单据类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 12 | @Schema(description = "单据类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 15 | - private Integer orderType; | ||
| 16 | - | ||
| 17 | - // TODO @AI:type 改成 dict tag 去翻译?或者字典工具类? | ||
| 18 | - @Schema(description = "单据类型名", requiredMode = Schema.RequiredMode.REQUIRED, example = "入库单") | ||
| 19 | - private String orderTypeName; | 13 | + private Integer type; |
| 20 | 14 | ||
| 21 | @Schema(description = "单据总数", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") | 15 | @Schema(description = "单据总数", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") |
| 22 | private Long total; | 16 | private Long total; |
| 23 | 17 | ||
| 24 | - // TODO @AI:statuses;状态分布; | ||
| 25 | @Schema(description = "状态分布") | 18 | @Schema(description = "状态分布") |
| 26 | - private List<WmsHomeOrderStatusRespVO> statusList; | 19 | + private List<WmsHomeOrderStatusRespVO> statuses; |
| 27 | 20 | ||
| 28 | } | 21 | } |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/home/vo/WmsHomeOrderTrendRespVO.java
| @@ -3,13 +3,14 @@ package cn.iocoder.yudao.module.wms.controller.admin.home.vo; | @@ -3,13 +3,14 @@ package cn.iocoder.yudao.module.wms.controller.admin.home.vo; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.Data; | 4 | import lombok.Data; |
| 5 | 5 | ||
| 6 | +import java.time.LocalDateTime; | ||
| 7 | + | ||
| 6 | @Schema(description = "管理后台 - WMS 首页单据趋势 Response VO") | 8 | @Schema(description = "管理后台 - WMS 首页单据趋势 Response VO") |
| 7 | @Data | 9 | @Data |
| 8 | public class WmsHomeOrderTrendRespVO { | 10 | public class WmsHomeOrderTrendRespVO { |
| 9 | 11 | ||
| 10 | - // TODO @AI:可以使用 localdatetime?前端按需翻译?无非是 time 是 00 00 00 这样。灵活性更大。 | ||
| 11 | - @Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2026-05-14") | ||
| 12 | - private String date; | 12 | + @Schema(description = "时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1778169600000") |
| 13 | + private LocalDateTime time; | ||
| 13 | 14 | ||
| 14 | @Schema(description = "入库单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") | 15 | @Schema(description = "入库单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") |
| 15 | private Long receiptCount; | 16 | private Long receiptCount; |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/dal/mysql/home/WmsHomeStatisticsMapper.java
| @@ -49,7 +49,7 @@ public interface WmsHomeStatisticsMapper { | @@ -49,7 +49,7 @@ public interface WmsHomeStatisticsMapper { | ||
| 49 | * | 49 | * |
| 50 | * @param warehouseId 仓库编号 | 50 | * @param warehouseId 仓库编号 |
| 51 | * @param limit 数量限制 | 51 | * @param limit 数量限制 |
| 52 | - * @return [{ "itemId": 1, "itemName": "A4 复印纸", "quantity": 100 }, ...] | 52 | + * @return [{ "id": 1, "name": "A4 复印纸", "quantity": 100 }, ...] |
| 53 | */ | 53 | */ |
| 54 | List<Map<String, Object>> selectInventoryItemRank(@Param("warehouseId") Long warehouseId, | 54 | List<Map<String, Object>> selectInventoryItemRank(@Param("warehouseId") Long warehouseId, |
| 55 | @Param("limit") Integer limit); | 55 | @Param("limit") Integer limit); |
| @@ -59,7 +59,7 @@ public interface WmsHomeStatisticsMapper { | @@ -59,7 +59,7 @@ public interface WmsHomeStatisticsMapper { | ||
| 59 | * | 59 | * |
| 60 | * @param warehouseId 仓库编号 | 60 | * @param warehouseId 仓库编号 |
| 61 | * @param limit 数量限制 | 61 | * @param limit 数量限制 |
| 62 | - * @return [{ "warehouseId": 1, "warehouseName": "上海仓", "quantity": 100 }, ...] | 62 | + * @return [{ "id": 1, "name": "上海仓", "quantity": 100 }, ...] |
| 63 | */ | 63 | */ |
| 64 | List<Map<String, Object>> selectInventoryWarehouseRank(@Param("warehouseId") Long warehouseId, | 64 | List<Map<String, Object>> selectInventoryWarehouseRank(@Param("warehouseId") Long warehouseId, |
| 65 | @Param("limit") Integer limit); | 65 | @Param("limit") Integer limit); |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/home/WmsHomeStatisticsService.java
| @@ -22,10 +22,10 @@ public interface WmsHomeStatisticsService { | @@ -22,10 +22,10 @@ public interface WmsHomeStatisticsService { | ||
| 22 | List<WmsHomeOrderSummaryRespVO> getOrderSummary(Long warehouseId); | 22 | List<WmsHomeOrderSummaryRespVO> getOrderSummary(Long warehouseId); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | - * 获得单据趋势 | 25 | + * 获得单据趋势,按日期统计入库、出库、移库、盘库单据数量。 |
| 26 | * | 26 | * |
| 27 | - * @param days 天数 | ||
| 28 | - * @param warehouseId 仓库编号 | 27 | + * @param days 最近天数,包含今天 |
| 28 | + * @param warehouseId 仓库编号,为空时统计全部仓库 | ||
| 29 | * @return 单据趋势 | 29 | * @return 单据趋势 |
| 30 | */ | 30 | */ |
| 31 | List<WmsHomeOrderTrendRespVO> getOrderTrend(Integer days, Long warehouseId); | 31 | List<WmsHomeOrderTrendRespVO> getOrderTrend(Integer days, Long warehouseId); |
| @@ -34,8 +34,10 @@ public interface WmsHomeStatisticsService { | @@ -34,8 +34,10 @@ public interface WmsHomeStatisticsService { | ||
| 34 | * 获得库存汇总统计 | 34 | * 获得库存汇总统计 |
| 35 | * | 35 | * |
| 36 | * @param warehouseId 仓库编号 | 36 | * @param warehouseId 仓库编号 |
| 37 | + * @param goodsLimit 商品排行数量 | ||
| 38 | + * @param warehouseLimit 仓库排行数量 | ||
| 37 | * @return 库存汇总统计 | 39 | * @return 库存汇总统计 |
| 38 | */ | 40 | */ |
| 39 | - WmsHomeInventorySummaryRespVO getInventorySummary(Long warehouseId); | 41 | + WmsHomeInventorySummaryRespVO getInventorySummary(Long warehouseId, Integer goodsLimit, Integer warehouseLimit); |
| 40 | 42 | ||
| 41 | } | 43 | } |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/home/WmsHomeStatisticsServiceImpl.java
| 1 | package cn.iocoder.yudao.module.wms.service.home; | 1 | package cn.iocoder.yudao.module.wms.service.home; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.date.DatePattern; | ||
| 4 | +import cn.hutool.core.map.MapUtil; | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 5 | import cn.hutool.core.util.ObjectUtil; |
| 4 | -import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeInventoryItemRankRespVO; | ||
| 5 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeInventorySummaryRespVO; | 6 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeInventorySummaryRespVO; |
| 6 | -import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeInventoryWarehouseRankRespVO; | ||
| 7 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeOrderStatusRespVO; | 7 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeOrderStatusRespVO; |
| 8 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeOrderSummaryRespVO; | 8 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeOrderSummaryRespVO; |
| 9 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeOrderTrendRespVO; | 9 | import cn.iocoder.yudao.module.wms.controller.admin.home.vo.WmsHomeOrderTrendRespVO; |
| @@ -16,14 +16,17 @@ import org.springframework.stereotype.Service; | @@ -16,14 +16,17 @@ import org.springframework.stereotype.Service; | ||
| 16 | import java.math.BigDecimal; | 16 | import java.math.BigDecimal; |
| 17 | import java.time.LocalDate; | 17 | import java.time.LocalDate; |
| 18 | import java.time.LocalDateTime; | 18 | import java.time.LocalDateTime; |
| 19 | -import java.time.format.DateTimeFormatter; | ||
| 20 | -import java.util.ArrayList; | ||
| 21 | import java.util.Collections; | 19 | import java.util.Collections; |
| 22 | import java.util.HashMap; | 20 | import java.util.HashMap; |
| 23 | import java.util.LinkedHashMap; | 21 | import java.util.LinkedHashMap; |
| 24 | import java.util.List; | 22 | import java.util.List; |
| 25 | import java.util.Map; | 23 | import java.util.Map; |
| 26 | 24 | ||
| 25 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 26 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | ||
| 27 | +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.getBigDecimal; | ||
| 28 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.getDateList; | ||
| 29 | + | ||
| 27 | /** | 30 | /** |
| 28 | * WMS 首页统计 Service 实现类 | 31 | * WMS 首页统计 Service 实现类 |
| 29 | * | 32 | * |
| @@ -32,137 +35,83 @@ import java.util.Map; | @@ -32,137 +35,83 @@ import java.util.Map; | ||
| 32 | @Service | 35 | @Service |
| 33 | public class WmsHomeStatisticsServiceImpl implements WmsHomeStatisticsService { | 36 | public class WmsHomeStatisticsServiceImpl implements WmsHomeStatisticsService { |
| 34 | 37 | ||
| 35 | - // TODO @AI:8、5、交给前端传递; | ||
| 36 | - private static final int GOODS_SHARE_LIMIT = 5; | ||
| 37 | - private static final int WAREHOUSE_DISTRIBUTION_LIMIT = 8; | ||
| 38 | - | ||
| 39 | @Resource | 38 | @Resource |
| 40 | private WmsHomeStatisticsMapper homeStatisticsMapper; | 39 | private WmsHomeStatisticsMapper homeStatisticsMapper; |
| 41 | 40 | ||
| 42 | @Override | 41 | @Override |
| 43 | public List<WmsHomeOrderSummaryRespVO> getOrderSummary(Long warehouseId) { | 42 | public List<WmsHomeOrderSummaryRespVO> getOrderSummary(Long warehouseId) { |
| 44 | List<Map<String, Object>> stats = homeStatisticsMapper.selectOrderCountGroupByTypeAndStatus(warehouseId); | 43 | List<Map<String, Object>> stats = homeStatisticsMapper.selectOrderCountGroupByTypeAndStatus(warehouseId); |
| 45 | - // TODO @AI:convertList 链式调用。 | ||
| 46 | - List<WmsHomeOrderSummaryRespVO> result = new ArrayList<>(); | ||
| 47 | - for (WmsOrderTypeEnum orderTypeEnum : WmsOrderTypeEnum.values()) { | ||
| 48 | - WmsHomeOrderSummaryRespVO vo = new WmsHomeOrderSummaryRespVO() | ||
| 49 | - .setOrderType(orderTypeEnum.getType()).setOrderTypeName(orderTypeEnum.getName()); | ||
| 50 | - // TODO @AI:collutils sum 是不是可以? | ||
| 51 | - long total = 0L; | ||
| 52 | - List<WmsHomeOrderStatusRespVO> statusList = new ArrayList<>(); | ||
| 53 | - for (WmsOrderStatusEnum statusEnum : WmsOrderStatusEnum.values()) { | ||
| 54 | - long count = getOrderCount(stats, orderTypeEnum.getType(), statusEnum.getStatus()); | ||
| 55 | - total += count; | ||
| 56 | - statusList.add(new WmsHomeOrderStatusRespVO(statusEnum.getStatus(), statusEnum.getName(), count)); | ||
| 57 | - } | ||
| 58 | - vo.setTotal(total).setStatusList(statusList); | ||
| 59 | - result.add(vo); | ||
| 60 | - } | ||
| 61 | - return result; | 44 | + return convertList(WmsOrderTypeEnum.values(), orderTypeEnum -> { |
| 45 | + List<WmsHomeOrderStatusRespVO> statuses = convertList(WmsOrderStatusEnum.values(), statusEnum -> | ||
| 46 | + new WmsHomeOrderStatusRespVO().setStatus(statusEnum.getStatus()) | ||
| 47 | + .setCount(getOrderCount(stats, orderTypeEnum.getType(), statusEnum.getStatus()))); | ||
| 48 | + Long total = getSumValue(statuses, WmsHomeOrderStatusRespVO::getCount, Long::sum, 0L); | ||
| 49 | + return new WmsHomeOrderSummaryRespVO().setType(orderTypeEnum.getType()).setTotal(total).setStatuses(statuses); | ||
| 50 | + }); | ||
| 62 | } | 51 | } |
| 63 | 52 | ||
| 64 | @Override | 53 | @Override |
| 65 | public List<WmsHomeOrderTrendRespVO> getOrderTrend(Integer days, Long warehouseId) { | 54 | public List<WmsHomeOrderTrendRespVO> getOrderTrend(Integer days, Long warehouseId) { |
| 66 | - // TODO @AI:同上? | 55 | + // 统计区间为 [今天 - days + 1, 明天),保证最近 days 天包含今天。 |
| 67 | LocalDate endDate = LocalDate.now().plusDays(1); | 56 | LocalDate endDate = LocalDate.now().plusDays(1); |
| 68 | LocalDate startDate = endDate.minusDays(days); | 57 | LocalDate startDate = endDate.minusDays(days); |
| 69 | LocalDateTime beginTime = startDate.atStartOfDay(); | 58 | LocalDateTime beginTime = startDate.atStartOfDay(); |
| 70 | LocalDateTime endTime = endDate.atStartOfDay(); | 59 | LocalDateTime endTime = endDate.atStartOfDay(); |
| 71 | - | 60 | + // 查询每天的单据数量 |
| 72 | List<Map<String, Object>> dbData = homeStatisticsMapper.selectDailyOrderTrend(beginTime, endTime, warehouseId); | 61 | List<Map<String, Object>> dbData = homeStatisticsMapper.selectDailyOrderTrend(beginTime, endTime, warehouseId); |
| 73 | Map<String, Map<Integer, Long>> dateMap = new LinkedHashMap<>(); | 62 | Map<String, Map<Integer, Long>> dateMap = new LinkedHashMap<>(); |
| 74 | for (Map<String, Object> row : dbData) { | 63 | for (Map<String, Object> row : dbData) { |
| 75 | - String date = (String) row.get("date"); | ||
| 76 | - Integer orderType = getInteger(row, "orderType"); | ||
| 77 | - Long count = getLong(row, "count"); | 64 | + String date = MapUtil.getStr(row, "date"); |
| 65 | + Integer orderType = MapUtil.getInt(row, "orderType"); | ||
| 66 | + Long count = MapUtil.getLong(row, "count", 0L); | ||
| 78 | dateMap.computeIfAbsent(date, key -> new HashMap<>()).put(orderType, count); | 67 | dateMap.computeIfAbsent(date, key -> new HashMap<>()).put(orderType, count); |
| 79 | } | 68 | } |
| 80 | - // TODO @AI:链式调用; | ||
| 81 | - DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
| 82 | - List<WmsHomeOrderTrendRespVO> result = new ArrayList<>(); | ||
| 83 | - for (LocalDate d = startDate; d.isBefore(endDate); d = d.plusDays(1)) { | ||
| 84 | - String dateStr = d.format(fmt); | 69 | + // 构造结果,保证每天都有数据 |
| 70 | + return convertList(getDateList(startDate, days), d -> { | ||
| 71 | + String dateStr = DatePattern.NORM_DATE_FORMATTER.format(d); | ||
| 85 | Map<Integer, Long> row = dateMap.getOrDefault(dateStr, Collections.emptyMap()); | 72 | Map<Integer, Long> row = dateMap.getOrDefault(dateStr, Collections.emptyMap()); |
| 86 | - WmsHomeOrderTrendRespVO vo = new WmsHomeOrderTrendRespVO(); | ||
| 87 | - vo.setDate(dateStr); | ||
| 88 | - vo.setReceiptCount(row.getOrDefault(WmsOrderTypeEnum.RECEIPT.getType(), 0L)); | ||
| 89 | - vo.setShipmentCount(row.getOrDefault(WmsOrderTypeEnum.SHIPMENT.getType(), 0L)); | ||
| 90 | - vo.setMovementCount(row.getOrDefault(WmsOrderTypeEnum.MOVEMENT.getType(), 0L)); | ||
| 91 | - vo.setCheckCount(row.getOrDefault(WmsOrderTypeEnum.CHECK.getType(), 0L)); | ||
| 92 | - result.add(vo); | ||
| 93 | - } | ||
| 94 | - return result; | 73 | + return new WmsHomeOrderTrendRespVO().setTime(d.atStartOfDay()) |
| 74 | + .setReceiptCount(row.getOrDefault(WmsOrderTypeEnum.RECEIPT.getType(), 0L)) | ||
| 75 | + .setShipmentCount(row.getOrDefault(WmsOrderTypeEnum.SHIPMENT.getType(), 0L)) | ||
| 76 | + .setMovementCount(row.getOrDefault(WmsOrderTypeEnum.MOVEMENT.getType(), 0L)) | ||
| 77 | + .setCheckCount(row.getOrDefault(WmsOrderTypeEnum.CHECK.getType(), 0L)); | ||
| 78 | + }); | ||
| 95 | } | 79 | } |
| 96 | 80 | ||
| 97 | @Override | 81 | @Override |
| 98 | - public WmsHomeInventorySummaryRespVO getInventorySummary(Long warehouseId) { | ||
| 99 | - // TODO @AI:要不都先查询;然后 set 设置值; | ||
| 100 | - return new WmsHomeInventorySummaryRespVO() | ||
| 101 | - .setTotalQuantity(getDecimal(homeStatisticsMapper.selectInventoryTotalQuantity(warehouseId))) | ||
| 102 | - .setGoodsShareList(buildInventoryItemRankList(homeStatisticsMapper.selectInventoryItemRank(warehouseId, GOODS_SHARE_LIMIT))) | ||
| 103 | - .setWarehouseDistributionList(buildInventoryWarehouseRankList(homeStatisticsMapper.selectInventoryWarehouseRank(warehouseId, WAREHOUSE_DISTRIBUTION_LIMIT))); | 82 | + public WmsHomeInventorySummaryRespVO getInventorySummary(Long warehouseId, Integer goodsLimit, Integer warehouseLimit) { |
| 83 | + BigDecimal totalQuantity = ObjectUtil.defaultIfNull(homeStatisticsMapper.selectInventoryTotalQuantity(warehouseId), BigDecimal.ZERO); | ||
| 84 | + List<Map<String, Object>> itemRows = homeStatisticsMapper.selectInventoryItemRank(warehouseId, goodsLimit); | ||
| 85 | + List<Map<String, Object>> warehouseRows = homeStatisticsMapper.selectInventoryWarehouseRank(warehouseId, warehouseLimit); | ||
| 86 | + return new WmsHomeInventorySummaryRespVO().setTotalQuantity(totalQuantity) | ||
| 87 | + .setGoodsShareList(buildInventoryItemRankList(itemRows)) | ||
| 88 | + .setWarehouseDistributionList(buildInventoryWarehouseRankList(warehouseRows)); | ||
| 104 | } | 89 | } |
| 105 | 90 | ||
| 106 | - // TODO @AI:这个 ===== 太短了,加长! | ||
| 107 | - // ========== 工具方法 ========== | 91 | + // ==================== 工具方法 ==================== |
| 108 | 92 | ||
| 109 | private long getOrderCount(List<Map<String, Object>> stats, Integer orderType, Integer status) { | 93 | private long getOrderCount(List<Map<String, Object>> stats, Integer orderType, Integer status) { |
| 110 | for (Map<String, Object> stat : stats) { | 94 | for (Map<String, Object> stat : stats) { |
| 111 | - if (ObjectUtil.equal(getInteger(stat, "orderType"), orderType) | ||
| 112 | - && ObjectUtil.equal(getInteger(stat, "status"), status)) { | ||
| 113 | - return getLong(stat, "count"); | 95 | + if (ObjectUtil.equal(MapUtil.getInt(stat, "orderType"), orderType) |
| 96 | + && ObjectUtil.equal(MapUtil.getInt(stat, "status"), status)) { | ||
| 97 | + return MapUtil.getLong(stat, "count", 0L); | ||
| 114 | } | 98 | } |
| 115 | } | 99 | } |
| 116 | return 0L; | 100 | return 0L; |
| 117 | } | 101 | } |
| 118 | 102 | ||
| 119 | - // TODO @AI:convertList;然后链式调用; | ||
| 120 | - private List<WmsHomeInventoryItemRankRespVO> buildInventoryItemRankList(List<Map<String, Object>> rows) { | ||
| 121 | - List<WmsHomeInventoryItemRankRespVO> result = new ArrayList<>(rows.size()); | ||
| 122 | - for (Map<String, Object> row : rows) { | ||
| 123 | - WmsHomeInventoryItemRankRespVO vo = new WmsHomeInventoryItemRankRespVO(); | ||
| 124 | - vo.setItemId(getLong(row, "itemId")); | ||
| 125 | - vo.setItemName((String) row.get("itemName")); | ||
| 126 | - vo.setQuantity(getDecimal(row.get("quantity"))); | ||
| 127 | - result.add(vo); | ||
| 128 | - } | ||
| 129 | - return result; | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - // TODO @AI:convertList;然后链式调用; | ||
| 133 | - private List<WmsHomeInventoryWarehouseRankRespVO> buildInventoryWarehouseRankList(List<Map<String, Object>> rows) { | ||
| 134 | - List<WmsHomeInventoryWarehouseRankRespVO> result = new ArrayList<>(rows.size()); | ||
| 135 | - for (Map<String, Object> row : rows) { | ||
| 136 | - WmsHomeInventoryWarehouseRankRespVO vo = new WmsHomeInventoryWarehouseRankRespVO(); | ||
| 137 | - vo.setWarehouseId(getLong(row, "warehouseId")); | ||
| 138 | - vo.setWarehouseName((String) row.get("warehouseName")); | ||
| 139 | - vo.setQuantity(getDecimal(row.get("quantity"))); | ||
| 140 | - result.add(vo); | ||
| 141 | - } | ||
| 142 | - return result; | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - // TODO @AI:maputil 直接使用 | ||
| 146 | - private Integer getInteger(Map<String, Object> map, String key) { | ||
| 147 | - Object value = map.get(key); | ||
| 148 | - return value == null ? null : ((Number) value).intValue(); | 103 | + private List<WmsHomeInventorySummaryRespVO.ItemRank> buildInventoryItemRankList(List<Map<String, Object>> rows) { |
| 104 | + return convertList(rows, row -> new WmsHomeInventorySummaryRespVO.ItemRank() | ||
| 105 | + .setId(ObjectUtil.defaultIfNull(MapUtil.getLong(row, "id"), MapUtil.getLong(row, "itemId"))) | ||
| 106 | + .setName(ObjectUtil.defaultIfNull(MapUtil.getStr(row, "name"), MapUtil.getStr(row, "itemName"))) | ||
| 107 | + .setQuantity(getBigDecimal(row, "quantity", BigDecimal.ZERO))); | ||
| 149 | } | 108 | } |
| 150 | 109 | ||
| 151 | - // TODO @AI:maputil 直接使用 | ||
| 152 | - private Long getLong(Map<String, Object> map, String key) { | ||
| 153 | - Object value = map.get(key); | ||
| 154 | - return value == null ? 0L : ((Number) value).longValue(); | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - // TODO @AI:maputil 直接使用 | ||
| 158 | - private BigDecimal getDecimal(Object value) { | ||
| 159 | - if (value == null) { | ||
| 160 | - return BigDecimal.ZERO; | ||
| 161 | - } | ||
| 162 | - if (value instanceof BigDecimal) { | ||
| 163 | - return (BigDecimal) value; | ||
| 164 | - } | ||
| 165 | - return new BigDecimal(value.toString()); | 110 | + private List<WmsHomeInventorySummaryRespVO.WarehouseRank> buildInventoryWarehouseRankList(List<Map<String, Object>> rows) { |
| 111 | + return convertList(rows, row -> new WmsHomeInventorySummaryRespVO.WarehouseRank() | ||
| 112 | + .setId(ObjectUtil.defaultIfNull(MapUtil.getLong(row, "id"), MapUtil.getLong(row, "warehouseId"))) | ||
| 113 | + .setName(ObjectUtil.defaultIfNull(MapUtil.getStr(row, "name"), MapUtil.getStr(row, "warehouseName"))) | ||
| 114 | + .setQuantity(getBigDecimal(row, "quantity", BigDecimal.ZERO))); | ||
| 166 | } | 115 | } |
| 167 | 116 | ||
| 168 | } | 117 | } |
yudao-module-wms/src/main/resources/mapper/home/WmsHomeStatisticsMapper.xml
| @@ -118,8 +118,8 @@ | @@ -118,8 +118,8 @@ | ||
| 118 | 118 | ||
| 119 | <!-- 按商品统计库存数量排行 --> | 119 | <!-- 按商品统计库存数量排行 --> |
| 120 | <select id="selectInventoryItemRank" resultType="java.util.Map"> | 120 | <select id="selectInventoryItemRank" resultType="java.util.Map"> |
| 121 | - SELECT item.id AS itemId, | ||
| 122 | - item.name AS itemName, | 121 | + SELECT item.id AS id, |
| 122 | + item.name AS name, | ||
| 123 | IFNULL(SUM(inventory.quantity), 0) AS quantity | 123 | IFNULL(SUM(inventory.quantity), 0) AS quantity |
| 124 | FROM wms_inventory inventory | 124 | FROM wms_inventory inventory |
| 125 | INNER JOIN wms_item_sku sku ON sku.id = inventory.sku_id AND sku.deleted = 0 | 125 | INNER JOIN wms_item_sku sku ON sku.id = inventory.sku_id AND sku.deleted = 0 |
| @@ -136,8 +136,8 @@ | @@ -136,8 +136,8 @@ | ||
| 136 | 136 | ||
| 137 | <!-- 按仓库统计库存数量排行 --> | 137 | <!-- 按仓库统计库存数量排行 --> |
| 138 | <select id="selectInventoryWarehouseRank" resultType="java.util.Map"> | 138 | <select id="selectInventoryWarehouseRank" resultType="java.util.Map"> |
| 139 | - SELECT warehouse.id AS warehouseId, | ||
| 140 | - warehouse.name AS warehouseName, | 139 | + SELECT warehouse.id AS id, |
| 140 | + warehouse.name AS name, | ||
| 141 | IFNULL(SUM(inventory.quantity), 0) AS quantity | 141 | IFNULL(SUM(inventory.quantity), 0) AS quantity |
| 142 | FROM wms_inventory inventory | 142 | FROM wms_inventory inventory |
| 143 | INNER JOIN wms_warehouse warehouse ON warehouse.id = inventory.warehouse_id AND warehouse.deleted = 0 | 143 | INNER JOIN wms_warehouse warehouse ON warehouse.id = inventory.warehouse_id AND warehouse.deleted = 0 |