From d672eff8c8474b76017f0c5f798a264026682403 Mon Sep 17 00:00:00 2001 From: "YAS\\29473" <2947326429@qq.com> Date: Thu, 13 Nov 2025 15:07:55 +0800 Subject: [PATCH] update --- .../impl/OrderBasicInfoServiceImpl.java | 30 +++++++++---------- .../jsowell/pile/vo/web/OrderMonthStatVO.java | 4 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 9351a8f0e..c62a59489 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -5955,18 +5955,19 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService { dto = new QueryOrderDTO(); } - // 只允许 yyyy-MM 格式 DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); - DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); try { + // 处理 startTime if (StringUtils.isNotEmpty(dto.getStartTime())) { YearMonth startMonth = YearMonth.parse(dto.getStartTime(), monthFormatter); - dto.setStartTime(startMonth.atDay(1).atStartOfDay().format(fullFormatter)); + dto.setStartTime(startMonth.atDay(1).atStartOfDay().format(dateTimeFormatter)); } + // 处理 endTime,取下个月月初,保证 < endTime 不丢数据 if (StringUtils.isNotEmpty(dto.getEndTime())) { - YearMonth endMonth = YearMonth.parse(dto.getEndTime(), monthFormatter).plusMonths(1); - dto.setEndTime(endMonth.atDay(1).atStartOfDay().format(fullFormatter)); + YearMonth endMonth = YearMonth.parse(dto.getEndTime(), monthFormatter); + dto.setEndTime(endMonth.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter)); } } catch (Exception e) { throw new IllegalArgumentException("时间格式错误,应为 yyyy-MM"); @@ -5975,42 +5976,41 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService { // 默认本月 if (StringUtils.isEmpty(dto.getStartTime()) || StringUtils.isEmpty(dto.getEndTime())) { YearMonth currentMonth = YearMonth.now(); - dto.setStartTime(currentMonth.atDay(1).atStartOfDay().format(fullFormatter)); - dto.setEndTime(currentMonth.plusMonths(1).atDay(1).atStartOfDay().format(fullFormatter)); + dto.setStartTime(currentMonth.atDay(1).atStartOfDay().format(dateTimeFormatter)); + dto.setEndTime(currentMonth.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter)); } - // 查询数据库聚合结果(仅一次) + // 查询数据库聚合结果 List stats = orderBasicInfoMapper.selectOrderCountAndInsuranceByMonth(dto); - // 封装结果 + // 封装返回结果 BigDecimal totalInsuranceAmount = BigDecimal.ZERO; int totalCount = 0; List result = new ArrayList<>(); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - for (OrderMonthStatVO stat : stats) { - YearMonth ym = YearMonth.parse(stat.getMonth(), DateTimeFormatter.ofPattern("yyyy-MM")); + YearMonth ym = YearMonth.parse(stat.getMonth(), monthFormatter); OrderCountByTimeVO.OrderCountByTimeListVO vo = new OrderCountByTimeVO.OrderCountByTimeListVO(); vo.setStartTime(ym.atDay(1).atStartOfDay().format(dateTimeFormatter)); vo.setEndTime(ym.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter)); vo.setCount(stat.getOrderCount()); vo.setOrderCount(stat.getOrderCount()); - vo.setInsuranceAmount(stat.getTotalInsuranceAmount()); + BigDecimal insuranceAmount = stat.getInsuranceAmount() == null ? BigDecimal.ZERO : stat.getInsuranceAmount(); + vo.setInsuranceAmount(totalInsuranceAmount); result.add(vo); totalCount += stat.getOrderCount(); - totalInsuranceAmount = totalInsuranceAmount.add(stat.getTotalInsuranceAmount()); + totalInsuranceAmount = totalInsuranceAmount.add(insuranceAmount); } - // 汇总 OrderCountByTimeVO vo = new OrderCountByTimeVO(); vo.setOrderCountByTimeList(result); vo.setTotalCount(totalCount); vo.setTotalInsuranceAmount(totalInsuranceAmount); + logger.info("按月统计结果: {}", JSONObject.toJSONString(vo)); return vo; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderMonthStatVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderMonthStatVO.java index 53e7d172f..fc96649a1 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderMonthStatVO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderMonthStatVO.java @@ -5,7 +5,7 @@ import java.math.BigDecimal; @Data public class OrderMonthStatVO { - private String month; // 2025-10 + private String month; private Integer orderCount; - private BigDecimal totalInsuranceAmount; + private BigDecimal insuranceAmount; }