This commit is contained in:
YAS\29473
2025-09-27 13:46:26 +08:00
parent 79e057703f
commit 79bd34d9f6
5 changed files with 102 additions and 42 deletions

View File

@@ -3,15 +3,21 @@ package com.jsowell.api.thirdparty;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.dto.thirdparty.JCTCommonParamsDTO;
import com.jsowell.common.dto.thirdparty.JCTPushRealTimeInfoDTO;
import com.jsowell.common.dto.thirdparty.JCTQueryStationInfoDTO;
import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.service.ThirdPartyService;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.platform.dto.RetryOrderDTO;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
@@ -35,6 +41,10 @@ public class ChangZhouController extends ThirdPartyBaseController {
@Qualifier("changZhouPlatformServiceImpl")
private ThirdPartyPlatformService platformLogic;
@DubboReference(group = "third", version = "1.0.0", timeout = 10000)
private ThirdPartyService thirdPartyService;
/**
* getToken
@@ -43,8 +53,15 @@ public class ChangZhouController extends ThirdPartyBaseController {
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("{}-请求令牌 params:{}" , platformName , JSON.toJSONString(dto));
try {
// Map<String, String> map = zdlService.generateToken(dto);
Map<String, String> map = platformLogic.queryToken(dto);
// Map<String, String> map = platformLogic.queryToken(dto);
// 新方法
JCTCommonParamsDTO jctCommonParamsDTO = new JCTCommonParamsDTO();
BeanUtils.copyProperties(dto, jctCommonParamsDTO);
jctCommonParamsDTO.setPlatformType(platformType);
logger.info("请求参数转换后:{}" , JSON.toJSONString(jctCommonParamsDTO));
Map<String, String> map = thirdPartyService.queryToken(jctCommonParamsDTO);
logger.info("{}-请求令牌 result:{}" , platformName , map);
return CommonResult.success(0 , "请求令牌成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
@@ -78,8 +95,15 @@ public class ChangZhouController extends ThirdPartyBaseController {
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class);
JCTQueryStationInfoDTO jctQueryStationInfoDTO = new JCTQueryStationInfoDTO();
BeanUtils.copyProperties(queryStationInfoDTO, jctQueryStationInfoDTO);
jctQueryStationInfoDTO.setPlatformType(platformType);
logger.info("请求参数转换后:{}" , JSON.toJSONString(jctQueryStationInfoDTO));
// 执行逻辑
Map<String, String> map = platformLogic.queryStationsInfo(queryStationInfoDTO);
Map<String, String> map = thirdPartyService.queryStationsInfo(jctQueryStationInfoDTO);
// 执行逻辑
// Map<String, String> map = platformLogic.queryStationsInfo(queryStationInfoDTO);
logger.info("{}-查询充电站信息 result:{}" , platformName , JSON.toJSONString(map));
return CommonResult.success(0 , "查询充电站信息成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
@@ -100,7 +124,14 @@ public class ChangZhouController extends ThirdPartyBaseController {
public RestApiResponse<?> notification_stationStatus(@RequestBody PushRealTimeInfoDTO pushRealTimeInfoDTO , HttpServletRequest request) {
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationStationStatus(pushRealTimeInfoDTO);
// String result = platformLogic.notificationStationStatus(pushRealTimeInfoDTO);
JCTPushRealTimeInfoDTO jctPushRealTimeInfoDTO = new JCTPushRealTimeInfoDTO();
BeanUtils.copyProperties(pushRealTimeInfoDTO, jctPushRealTimeInfoDTO);
jctPushRealTimeInfoDTO.setPlatformType(platformType);
logger.info("请求参数转换后:{}" , JSON.toJSONString(jctPushRealTimeInfoDTO));
Map<String, String> result = thirdPartyService.notificationStationStatus(jctPushRealTimeInfoDTO);
logger.info("【{}】推送设备状态 result:{}" , this.getClass().getSimpleName() , result);
response = new RestApiResponse<>(result);
} catch (BusinessException e) {

View File

@@ -1281,82 +1281,98 @@ public class TempService {
* @return
*/
public OrderCountByTimeVO queryOrderCountByTime(QueryOrderDTO dto) {
// 处理时间默认值
if (dto == null) {
dto = new QueryOrderDTO();
}
// 如果开始时间为空,则默认为当天开始时间
if (dto.getStartTime() == null || dto.getStartTime().isEmpty()) {
LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
dto.setStartTime(todayStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}
// 如果结束时间为空,则默认为当前时间
if (dto.getEndTime() == null || dto.getEndTime().isEmpty()) {
dto.setEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}
//条件查询订单
List<OrderListVO> orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
//统计订单
List<OrderCountByTimeVO.OrderCountByTimeListVO> result = new ArrayList<>();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS);
try {
// 将开始时间和结束时间转换为LocalDateTime类型
LocalDateTime queryStartTime = LocalDateTime.parse(dto.getStartTime(), dateTimeFormatter);
LocalDateTime queryEndTime = LocalDateTime.parse(dto.getEndTime(), dateTimeFormatter);
// 开始时间默认:当天零点
if (StringUtils.isEmpty(dto.getStartTime())) {
LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
dto.setStartTime(todayStart.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; // 总保险金额
try {
// 转换查询时间
LocalDateTime queryStart = LocalDateTime.parse(dto.getStartTime(), dateTimeFormatter);
LocalDateTime queryEnd = LocalDateTime.parse(dto.getEndTime(), dateTimeFormatter);
// 按小时分组订单
Map<LocalDateTime, List<OrderListVO>> ordersByHour = orderListVOS.stream()
Map<LocalDateTime, List<OrderListVO>> ordersByHour = orderList.stream()
.collect(Collectors.groupingBy(order -> {
LocalDateTime createTime;
// 如果订单创建时间为空,则默认为当前时间
if (order.getCreateTime() != null) {
createTime = LocalDateTime.parse((String) order.getCreateTime(), dateTimeFormatter);
return LocalDateTime.parse(order.getCreateTime() , dateTimeFormatter)
.withMinute(0).withSecond(0).withNano(0);
} else {
logger.warn("订单创建时间为空,订单号:{}", order.getOrderCode());
return LocalDateTime.now();
return LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
}
// 将订单创建时间按小时分组
return createTime.withMinute(0).withSecond(0).withNano(0);
}));
// 从开始时间开始,按小时统计订单数量
LocalDateTime currentHour = queryStartTime.withMinute(0).withSecond(0).withNano(0);
while (currentHour.isBefore(queryEndTime)) {
// 查询当前小时订单数量
// 从开始时间到结束时间,逐小时统计
LocalDateTime currentHour = queryStart.withMinute(0).withSecond(0).withNano(0);
while (currentHour.isBefore(queryEnd)) {
LocalDateTime nextHour = currentHour.plusHours(1);
int count = ordersByHour.getOrDefault(currentHour, Collections.emptyList()).size();
// 当前小时的订单集合
List<OrderListVO> ordersInHour = ordersByHour.getOrDefault(currentHour, Collections.emptyList());
int count = ordersInHour.size();
// 统计该小时保险金额
BigDecimal hourInsuranceAmount = ordersInHour.stream()
.map(OrderListVO::getInsuranceAmount) // 假设 VO 里有该字段
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 封装结果
OrderCountByTimeVO.OrderCountByTimeListVO vo = new OrderCountByTimeVO.OrderCountByTimeListVO();
vo.setStartTime(currentHour.format(dateTimeFormatter));
vo.setEndTime(nextHour.format(dateTimeFormatter));
vo.setCount(count);
vo.setOrderCount(count);
vo.setInsuranceAmount(hourInsuranceAmount);
result.add(vo);
// 累加总保险金额
totalInsuranceAmount = totalInsuranceAmount.add(hourInsuranceAmount);
currentHour = nextHour;
}
// 按开始时间排序
// 排序(确保结果有序)
result.sort(Comparator.comparing(OrderCountByTimeVO.OrderCountByTimeListVO::getStartTime));
} catch (Exception e) {
logger.error("统计订单数量失败", e);
}
logger.info("查询订单数量结果:{}", JSONObject.toJSONString(result));
// ====== 封装返回结果 ======
OrderCountByTimeVO orderCountByTimeVO = new OrderCountByTimeVO();
orderCountByTimeVO.setOrderCountByTimeList(result);
//订单
Integer totalCount = 0;
// 计算总订单数
int totalCount = 0;
for (OrderCountByTimeVO.OrderCountByTimeListVO vo : result) {
totalCount += vo.getCount();
}
orderCountByTimeVO.setTotalCount(totalCount);
orderCountByTimeVO.setTotalInsuranceAmount(totalInsuranceAmount);
logger.info("查询订单数量结果:{}", JSONObject.toJSONString(orderCountByTimeVO));
return orderCountByTimeVO;
}