mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 12:05:05 +08:00
Merge branch 'dev' of https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web into dev
This commit is contained in:
@@ -631,4 +631,6 @@ public interface OrderBasicInfoService{
|
||||
* @return
|
||||
*/
|
||||
List<BusinessOrderDetailInfoVO> getOrderDetailByStationIdsForMonth(List<String> stationIds , String startTime , String endTime);
|
||||
|
||||
OrderCountByTimeVO queryOrderInsuranceAmountByTime(QueryOrderDTO dto);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,11 @@ import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.ParseException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -618,7 +622,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
|
||||
// 结算时间设置为当前时间
|
||||
orderInfo.setSettlementTime(new Date());
|
||||
|
||||
|
||||
// 启动失败原因
|
||||
orderInfo.setReason(failedReasonMsg);
|
||||
// 订单退款(结算订单)
|
||||
@@ -5958,5 +5962,77 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
public List<BusinessOrderDetailInfoVO> getOrderDetailByStationIdsForMonth(List<String> stationIds , String startTime , String endTime) {
|
||||
return orderBasicInfoMapper.getOrderDetailByStationIdsForMonth(stationIds, startTime, endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单数量与保险金额时间区统计
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OrderCountByTimeVO queryOrderInsuranceAmountByTime(QueryOrderDTO dto) {
|
||||
if (dto == null) {
|
||||
dto = new QueryOrderDTO();
|
||||
}
|
||||
|
||||
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
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(dateTimeFormatter));
|
||||
}
|
||||
// 处理 endTime,取下个月月初,保证 < endTime 不丢数据
|
||||
if (StringUtils.isNotEmpty(dto.getEndTime())) {
|
||||
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");
|
||||
}
|
||||
|
||||
// 默认本月
|
||||
if (StringUtils.isEmpty(dto.getStartTime()) || StringUtils.isEmpty(dto.getEndTime())) {
|
||||
YearMonth currentMonth = YearMonth.now();
|
||||
dto.setStartTime(currentMonth.atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||
dto.setEndTime(currentMonth.plusMonths(1).atDay(1).atStartOfDay().format(dateTimeFormatter));
|
||||
}
|
||||
|
||||
// 查询数据库聚合结果
|
||||
List<OrderMonthStatVO> stats = orderBasicInfoMapper.selectOrderCountAndInsuranceByMonth(dto);
|
||||
|
||||
// 封装返回结果
|
||||
BigDecimal totalInsuranceAmount = BigDecimal.ZERO;
|
||||
int totalCount = 0;
|
||||
List<OrderCountByTimeVO.OrderCountByTimeListVO> result = new ArrayList<>();
|
||||
|
||||
for (OrderMonthStatVO stat : stats) {
|
||||
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());
|
||||
BigDecimal insuranceAmount = stat.getInsuranceAmount() == null ? BigDecimal.ZERO : stat.getInsuranceAmount();
|
||||
vo.setInsuranceAmount(totalInsuranceAmount);
|
||||
|
||||
result.add(vo);
|
||||
|
||||
totalCount += stat.getOrderCount();
|
||||
totalInsuranceAmount = totalInsuranceAmount.add(insuranceAmount);
|
||||
}
|
||||
|
||||
OrderCountByTimeVO vo = new OrderCountByTimeVO();
|
||||
vo.setOrderCountByTimeList(result);
|
||||
vo.setTotalCount(totalCount);
|
||||
vo.setTotalInsuranceAmount(totalInsuranceAmount);
|
||||
|
||||
|
||||
logger.info("按月统计结果: {}", JSONObject.toJSONString(vo));
|
||||
return vo;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user