mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-13 11:49:49 +08:00
update
This commit is contained in:
@@ -5955,18 +5955,19 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
|||||||
dto = new QueryOrderDTO();
|
dto = new QueryOrderDTO();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只允许 yyyy-MM 格式
|
|
||||||
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("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 {
|
try {
|
||||||
|
// 处理 startTime
|
||||||
if (StringUtils.isNotEmpty(dto.getStartTime())) {
|
if (StringUtils.isNotEmpty(dto.getStartTime())) {
|
||||||
YearMonth startMonth = YearMonth.parse(dto.getStartTime(), monthFormatter);
|
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())) {
|
if (StringUtils.isNotEmpty(dto.getEndTime())) {
|
||||||
YearMonth endMonth = YearMonth.parse(dto.getEndTime(), monthFormatter).plusMonths(1);
|
YearMonth endMonth = YearMonth.parse(dto.getEndTime(), monthFormatter);
|
||||||
dto.setEndTime(endMonth.atDay(1).atStartOfDay().format(fullFormatter));
|
dto.setEndTime(endMonth.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("时间格式错误,应为 yyyy-MM");
|
throw new IllegalArgumentException("时间格式错误,应为 yyyy-MM");
|
||||||
@@ -5975,42 +5976,41 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
|||||||
// 默认本月
|
// 默认本月
|
||||||
if (StringUtils.isEmpty(dto.getStartTime()) || StringUtils.isEmpty(dto.getEndTime())) {
|
if (StringUtils.isEmpty(dto.getStartTime()) || StringUtils.isEmpty(dto.getEndTime())) {
|
||||||
YearMonth currentMonth = YearMonth.now();
|
YearMonth currentMonth = YearMonth.now();
|
||||||
dto.setStartTime(currentMonth.atDay(1).atStartOfDay().format(fullFormatter));
|
dto.setStartTime(currentMonth.atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||||
dto.setEndTime(currentMonth.plusMonths(1).atDay(1).atStartOfDay().format(fullFormatter));
|
dto.setEndTime(currentMonth.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询数据库聚合结果(仅一次)
|
// 查询数据库聚合结果
|
||||||
List<OrderMonthStatVO> stats = orderBasicInfoMapper.selectOrderCountAndInsuranceByMonth(dto);
|
List<OrderMonthStatVO> stats = orderBasicInfoMapper.selectOrderCountAndInsuranceByMonth(dto);
|
||||||
|
|
||||||
// 封装结果
|
// 封装返回结果
|
||||||
BigDecimal totalInsuranceAmount = BigDecimal.ZERO;
|
BigDecimal totalInsuranceAmount = BigDecimal.ZERO;
|
||||||
int totalCount = 0;
|
int totalCount = 0;
|
||||||
List<OrderCountByTimeVO.OrderCountByTimeListVO> result = new ArrayList<>();
|
List<OrderCountByTimeVO.OrderCountByTimeListVO> result = new ArrayList<>();
|
||||||
|
|
||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
for (OrderMonthStatVO stat : stats) {
|
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();
|
OrderCountByTimeVO.OrderCountByTimeListVO vo = new OrderCountByTimeVO.OrderCountByTimeListVO();
|
||||||
vo.setStartTime(ym.atDay(1).atStartOfDay().format(dateTimeFormatter));
|
vo.setStartTime(ym.atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||||
vo.setEndTime(ym.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter));
|
vo.setEndTime(ym.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||||
vo.setCount(stat.getOrderCount());
|
vo.setCount(stat.getOrderCount());
|
||||||
vo.setOrderCount(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);
|
result.add(vo);
|
||||||
|
|
||||||
totalCount += stat.getOrderCount();
|
totalCount += stat.getOrderCount();
|
||||||
totalInsuranceAmount = totalInsuranceAmount.add(stat.getTotalInsuranceAmount());
|
totalInsuranceAmount = totalInsuranceAmount.add(insuranceAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 汇总
|
|
||||||
OrderCountByTimeVO vo = new OrderCountByTimeVO();
|
OrderCountByTimeVO vo = new OrderCountByTimeVO();
|
||||||
vo.setOrderCountByTimeList(result);
|
vo.setOrderCountByTimeList(result);
|
||||||
vo.setTotalCount(totalCount);
|
vo.setTotalCount(totalCount);
|
||||||
vo.setTotalInsuranceAmount(totalInsuranceAmount);
|
vo.setTotalInsuranceAmount(totalInsuranceAmount);
|
||||||
|
|
||||||
|
|
||||||
logger.info("按月统计结果: {}", JSONObject.toJSONString(vo));
|
logger.info("按月统计结果: {}", JSONObject.toJSONString(vo));
|
||||||
return vo;
|
return vo;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.math.BigDecimal;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class OrderMonthStatVO {
|
public class OrderMonthStatVO {
|
||||||
private String month; // 2025-10
|
private String month;
|
||||||
private Integer orderCount;
|
private Integer orderCount;
|
||||||
private BigDecimal totalInsuranceAmount;
|
private BigDecimal insuranceAmount;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user