mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
add新增订单数量与保险金额时间区统计
This commit is contained in:
@@ -22,10 +22,7 @@ import com.jsowell.pile.service.OrderSplitRecordService;
|
||||
import com.jsowell.pile.service.PileMerchantInfoService;
|
||||
import com.jsowell.pile.service.PileStationInfoService;
|
||||
import com.jsowell.pile.util.UserUtils;
|
||||
import com.jsowell.pile.vo.web.OrderListVO;
|
||||
import com.jsowell.pile.vo.web.SplitAggregateDataVO;
|
||||
import com.jsowell.pile.vo.web.SplitConfigOrderVO;
|
||||
import com.jsowell.pile.vo.web.SplitRecordInfoVO;
|
||||
import com.jsowell.pile.vo.web.*;
|
||||
import com.jsowell.service.OrderService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -364,4 +361,24 @@ public class OrderBasicInfoController extends BaseController {
|
||||
logger.info("订单保险金额退款 params:{}, result:{}", JSON.toJSONString(orderBasicInfo), response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单数量与保险金额时间区统计
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/queryOrderInsuranceAmountByTime")
|
||||
public RestApiResponse<?> queryOrderInsuranceAmountByTime(@RequestBody QueryOrderDTO dto) {
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
//stationId ,merchantIdList,stationIdList,merchantId,startTime,endTime
|
||||
OrderCountByTimeVO result = orderBasicInfoService.queryOrderInsuranceAmountByTime(dto);
|
||||
response = new RestApiResponse<>(result);
|
||||
} catch (Exception e) {
|
||||
logger.error("时间区间查询订单统计 error", e);
|
||||
}
|
||||
logger.info("时间区间查询订单统计 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -599,7 +603,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
|
||||
// 结算时间设置为当前时间
|
||||
orderInfo.setSettlementTime(new Date());
|
||||
|
||||
|
||||
// 启动失败原因
|
||||
orderInfo.setReason(failedReasonMsg);
|
||||
// 订单退款(结算订单)
|
||||
@@ -5939,5 +5943,101 @@ 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 dateTimeFormatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS);
|
||||
|
||||
// 开始时间默认:本月第一天
|
||||
if (StringUtils.isEmpty(dto.getStartTime())) {
|
||||
LocalDate firstDayOfMonth = LocalDate.now().withDayOfMonth(1);
|
||||
LocalDateTime monthStart = LocalDateTime.of(firstDayOfMonth, LocalTime.MIN);
|
||||
dto.setStartTime(monthStart.format(dateTimeFormatter));
|
||||
}
|
||||
|
||||
// 结束时间默认:当前时间
|
||||
if (StringUtils.isEmpty(dto.getEndTime())) {
|
||||
dto.setEndTime(LocalDateTime.now().format(dateTimeFormatter));
|
||||
}
|
||||
|
||||
// 查询订单数据
|
||||
List<OrderListVO> orderList = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
|
||||
|
||||
List<OrderCountByTimeVO.OrderCountByTimeListVO> result = new ArrayList<>();
|
||||
BigDecimal totalInsuranceAmount = BigDecimal.ZERO;
|
||||
int totalCount = 0;
|
||||
|
||||
try {
|
||||
LocalDateTime queryStart = LocalDateTime.parse(dto.getStartTime(), dateTimeFormatter);
|
||||
LocalDateTime queryEnd = LocalDateTime.parse(dto.getEndTime(), dateTimeFormatter);
|
||||
|
||||
// 按月分组订单
|
||||
Map<YearMonth, List<OrderListVO>> ordersByMonth = orderList.stream()
|
||||
.collect(Collectors.groupingBy(order -> {
|
||||
if (order.getCreateTime() != null) {
|
||||
LocalDateTime createTime = LocalDateTime.parse(order.getCreateTime(), dateTimeFormatter);
|
||||
return YearMonth.from(createTime);
|
||||
} else {
|
||||
logger.warn("订单创建时间为空,订单号:{}", order.getOrderCode());
|
||||
return YearMonth.from(LocalDateTime.now());
|
||||
}
|
||||
}));
|
||||
|
||||
// 循环每个月
|
||||
YearMonth currentMonth = YearMonth.from(queryStart);
|
||||
YearMonth endMonth = YearMonth.from(queryEnd);
|
||||
|
||||
while (!currentMonth.isAfter(endMonth)) {
|
||||
LocalDateTime monthStartTime = currentMonth.atDay(1).atStartOfDay();
|
||||
LocalDateTime monthEndTime = currentMonth.plusMonths(1).atDay(1).atStartOfDay();
|
||||
|
||||
List<OrderListVO> ordersInMonth = ordersByMonth.getOrDefault(currentMonth, Collections.emptyList());
|
||||
int monthCount = ordersInMonth.size();
|
||||
|
||||
BigDecimal monthInsuranceAmount = ordersInMonth.stream()
|
||||
.map(OrderListVO::getInsuranceAmount)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
OrderCountByTimeVO.OrderCountByTimeListVO vo = new OrderCountByTimeVO.OrderCountByTimeListVO();
|
||||
vo.setStartTime(monthStartTime.format(dateTimeFormatter));
|
||||
vo.setEndTime(monthEndTime.format(dateTimeFormatter));
|
||||
vo.setCount(monthCount);
|
||||
vo.setOrderCount(monthCount);
|
||||
vo.setInsuranceAmount(monthInsuranceAmount);
|
||||
|
||||
result.add(vo);
|
||||
|
||||
totalCount += monthCount;
|
||||
totalInsuranceAmount = totalInsuranceAmount.add(monthInsuranceAmount);
|
||||
|
||||
currentMonth = currentMonth.plusMonths(1);
|
||||
}
|
||||
|
||||
// 排序
|
||||
result.sort(Comparator.comparing(OrderCountByTimeVO.OrderCountByTimeListVO::getStartTime));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("统计订单数量失败", e);
|
||||
}
|
||||
|
||||
// 封装返回
|
||||
OrderCountByTimeVO orderCountByTimeVO = new OrderCountByTimeVO();
|
||||
orderCountByTimeVO.setOrderCountByTimeList(result);
|
||||
orderCountByTimeVO.setTotalCount(totalCount);
|
||||
orderCountByTimeVO.setTotalInsuranceAmount(totalInsuranceAmount);
|
||||
|
||||
logger.info("按月查询订单数量结果:{}", JSONObject.toJSONString(orderCountByTimeVO));
|
||||
return orderCountByTimeVO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user