mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update临时接口条件统计订单数量
This commit is contained in:
@@ -22,6 +22,7 @@ import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.service.programlogic.AbstractProgramLogic;
|
||||
import com.jsowell.pile.service.programlogic.ProgramLogicFactory;
|
||||
import com.jsowell.pile.vo.uniapp.customer.MemberBalanceVO;
|
||||
import com.jsowell.pile.vo.web.OrderCountByTimeVO;
|
||||
import com.jsowell.pile.vo.web.PileStationVO;
|
||||
import com.jsowell.service.OrderService;
|
||||
import com.jsowell.service.TempService;
|
||||
@@ -909,4 +910,22 @@ public class TempController extends BaseController {
|
||||
logger.info("青海平台推送订单信息 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 时间区间查询订单统计
|
||||
*/
|
||||
@PostMapping("/queryOrderCountByTime")
|
||||
public RestApiResponse<?> queryOrderCountByTime(@RequestBody QueryOrderDTO dto) {
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
//stationId ,merchantIdList,stationIdList,merchantId,startTime,endTime
|
||||
List<OrderCountByTimeVO> result = tempService.queryOrderCountByTime(dto);
|
||||
response = new RestApiResponse<>(result);
|
||||
} catch (Exception e) {
|
||||
logger.error("时间区间查询订单统计 error", e);
|
||||
}
|
||||
logger.info("时间区间查询订单统计 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
|
||||
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.ykc.*;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
@@ -35,11 +34,8 @@ import com.jsowell.pile.service.programlogic.AbstractProgramLogic;
|
||||
import com.jsowell.pile.service.programlogic.ProgramLogicFactory;
|
||||
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
|
||||
import com.jsowell.pile.transaction.service.TransactionService;
|
||||
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
|
||||
import com.jsowell.pile.vo.base.StationInfoVO;
|
||||
import com.jsowell.pile.vo.uniapp.business.BusinessOrderDetailInfoVO;
|
||||
import com.jsowell.pile.vo.web.*;
|
||||
import com.jsowell.thirdparty.common.CommonService;
|
||||
import com.jsowell.thirdparty.common.NotificationDTO;
|
||||
import com.jsowell.thirdparty.common.NotificationService;
|
||||
import com.jsowell.thirdparty.platform.dto.PushOrderDTO;
|
||||
@@ -55,11 +51,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -1260,5 +1256,80 @@ public class TempService {
|
||||
notificationService.notificationChargeOrderInfoHistory(notificationDTO);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间区间批量查询订单数量
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
public List<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> 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);
|
||||
|
||||
|
||||
// 按小时分组订单
|
||||
Map<LocalDateTime, List<OrderListVO>> ordersByHour = orderListVOS.stream()
|
||||
.collect(Collectors.groupingBy(order -> {
|
||||
LocalDateTime createTime;
|
||||
// 如果订单创建时间为空,则默认为当前时间
|
||||
if (order.getCreateTime() != null) {
|
||||
createTime = LocalDateTime.parse((String) order.getCreateTime(), dateTimeFormatter);
|
||||
} else {
|
||||
logger.warn("订单创建时间为空,订单号:{}", order.getOrderCode());
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
// 将订单创建时间按小时分组
|
||||
return createTime.withMinute(0).withSecond(0).withNano(0);
|
||||
}));
|
||||
|
||||
|
||||
// 从开始时间开始,按小时统计订单数量
|
||||
LocalDateTime currentHour = queryStartTime.withMinute(0).withSecond(0).withNano(0);
|
||||
while (currentHour.isBefore(queryEndTime)) {
|
||||
// 查询当前小时订单数量
|
||||
LocalDateTime nextHour = currentHour.plusHours(1);
|
||||
int count = ordersByHour.getOrDefault(currentHour, Collections.emptyList()).size();
|
||||
|
||||
OrderCountByTimeVO vo = new OrderCountByTimeVO();
|
||||
vo.setStartTime(currentHour.format(dateTimeFormatter));
|
||||
vo.setEndTime(nextHour.format(dateTimeFormatter));
|
||||
vo.setCount(count);
|
||||
result.add(vo);
|
||||
|
||||
currentHour = nextHour;
|
||||
}
|
||||
|
||||
// 按开始时间排序
|
||||
result.sort(Comparator.comparing(OrderCountByTimeVO::getStartTime));
|
||||
} catch (Exception e) {
|
||||
logger.error("统计订单数量失败", e);
|
||||
}
|
||||
logger.info("查询订单数量结果:{}", JSONObject.toJSONString(result));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.jsowell.pile.vo.web;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderCountByTimeVO {
|
||||
/**
|
||||
* 时间段
|
||||
*/
|
||||
private String timeSlot;
|
||||
|
||||
/**
|
||||
* 订单数量
|
||||
*/
|
||||
private Integer orderCount;
|
||||
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private Integer count ;
|
||||
}
|
||||
@@ -602,8 +602,17 @@ public class ChangZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
|
||||
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
|
||||
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
|
||||
// 通过订单号查询实时数据
|
||||
|
||||
|
||||
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
|
||||
RealTimeMonitorData data = realTimeData.get(0);
|
||||
if (CollectionUtils.isEmpty(realTimeData)) {
|
||||
throw new BusinessException(ReturnCodeEnum.valueOf("没有实时记录"));
|
||||
}
|
||||
String chargingAmount = data.getChargingAmount() == null ? Constants.ZERO : data.getChargingAmount();
|
||||
String chargingDegree = data.getChargingDegree() == null ? Constants.ZERO : data.getChargingDegree();
|
||||
|
||||
Integer orderStatus = OrderStatusEnum.convertToNewStatus(orderInfo.getOrderStatus());
|
||||
Integer connectorStatus = info.getStatus();
|
||||
if(connectorStatus == Integer.parseInt(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())){
|
||||
@@ -619,10 +628,10 @@ public class ChangZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
.soc(new BigDecimal(soc))
|
||||
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间
|
||||
.endTime(DateUtils.getDateTime()) // 本次采样时间
|
||||
.totalPower(info.getChargingDegree()) // 累计充电量
|
||||
.totalPower(new BigDecimal(chargingDegree).setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计充电量
|
||||
.elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费
|
||||
.seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费
|
||||
.totalMoney(info.getChargingAmount()) // 已充金额
|
||||
.totalMoney(new BigDecimal(chargingAmount).setScale(2, BigDecimal.ROUND_HALF_UP)) // 已充金额
|
||||
|
||||
.build();
|
||||
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue();
|
||||
|
||||
@@ -826,6 +826,35 @@ public class WeiWangKuaiDianPlatformServiceImpl implements ThirdPartyPlatformSer
|
||||
|
||||
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
|
||||
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
|
||||
// 通过订单号查询实时数据
|
||||
String orderStatus = orderInfo.getOrderStatus();
|
||||
int connectorStatus = 0;
|
||||
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
|
||||
RealTimeMonitorData data = realTimeData.get(0);
|
||||
if (CollectionUtils.isEmpty(realTimeData)) {
|
||||
throw new BusinessException(ReturnCodeEnum.valueOf("没有实时记录"));
|
||||
} else {
|
||||
if (StringUtils.equals(orderStatus , OrderStatusEnum.IN_THE_CHARGING.getValue())) {
|
||||
// 充电中
|
||||
orderStatus = "2";
|
||||
} else if (StringUtils.equals(orderStatus , OrderStatusEnum.ORDER_COMPLETE.getValue())) {
|
||||
// 充电完成
|
||||
orderStatus = "4";
|
||||
} else {
|
||||
// 直接给 5-未知
|
||||
orderStatus = "5";
|
||||
}
|
||||
String status = data.getConnectorStatus();
|
||||
if (StringUtils.isBlank(status)) {
|
||||
// 查询当前枪口状态
|
||||
PileConnectorInfoVO connectorInfoVO = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode());
|
||||
connectorStatus = connectorInfoVO.getStatus();
|
||||
} else {
|
||||
connectorStatus = Integer.parseInt(status);
|
||||
}
|
||||
}
|
||||
String chargingAmount = data.getChargingAmount() == null ? Constants.ZERO : data.getChargingAmount();
|
||||
String chargingDegree = data.getChargingDegree() == null ? Constants.ZERO : data.getChargingDegree();
|
||||
|
||||
QueryChargingStatusVO vo = QueryChargingStatusVO.builder()
|
||||
.startChargeSeq(orderInfo.getOrderCode()) // 订单号
|
||||
@@ -837,10 +866,10 @@ public class WeiWangKuaiDianPlatformServiceImpl implements ThirdPartyPlatformSer
|
||||
.soc(new BigDecimal(soc))
|
||||
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间
|
||||
.endTime(DateUtils.getDateTime()) // 本次采样时间
|
||||
.totalPower(info.getChargingDegree()) // 累计充电量
|
||||
.totalPower(new BigDecimal(chargingDegree).setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计充电量
|
||||
.elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费
|
||||
.seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费
|
||||
.totalMoney(info.getChargingAmount()) // 已充金额
|
||||
.totalMoney(new BigDecimal(chargingAmount).setScale(2, BigDecimal.ROUND_HALF_UP)) // 已充金额
|
||||
|
||||
.build();
|
||||
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue();
|
||||
|
||||
Reference in New Issue
Block a user