# Conflicts:
#	jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java
#	jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java
#	jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java
#	jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml
This commit is contained in:
Lemon
2025-11-14 14:01:56 +08:00
12 changed files with 233 additions and 51 deletions

View File

@@ -107,4 +107,9 @@ public class QueryOrderDTO extends BaseEntity {
* 车牌号
*/
private String plateNumber;
/**
* 排除的站点Id列表
*/
private List<Integer> excludeStationIdList;
}

View File

@@ -1,10 +1,7 @@
package com.jsowell.pile.mapper;
import com.alipay.api.domain.ChargeOrderInfo;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.OrderDetail;
import com.jsowell.pile.domain.OrderSplitRecord;
import com.jsowell.pile.domain.UserFrequentedStationInfo;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
@@ -437,4 +434,10 @@ public interface OrderBasicInfoMapper {
* @return
*/
List<IndexPlatformProfitVO> getPlatformProfit(IndexQueryDTO dto);
/*
* @param dto 查询条件startTime/endTime 必须是 yyyy-MM 拼装后的时间段
* @return List<OrderMonthStatVO>
*/
List<OrderMonthStatVO> selectOrderCountAndInsuranceByMonth(@Param("dto") QueryOrderDTO dto);
}

View File

@@ -638,4 +638,7 @@ public interface OrderBasicInfoService{
* @return
*/
List<IndexPlatformProfitVO> getPlatformProfit(IndexQueryDTO dto);
OrderCountByTimeVO queryOrderInsuranceAmountByTime(QueryOrderDTO dto);
}

View File

@@ -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;
@@ -291,6 +295,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
*/
@Override
public List<OrderListVO> selectOrderBasicInfoList(QueryOrderDTO dto) {
excludePersonalPileStation(dto); // 筛选个人桩站点
List<OrderListVO> orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
if (CollectionUtils.isEmpty(orderListVOS)) {
return orderListVOS;
@@ -339,6 +344,24 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
return orderListVOS;
}
/**
* 如果查询订单状态只有异常的情况下,排除个人桩的异常订单
*/
private void excludePersonalPileStation(QueryOrderDTO dto) {
// 如果orderStatus不等于异常直接返回
if (!OrderStatusEnum.ABNORMAL.getValue().equals(dto.getOrderStatus())) {
return;
}
// 如果dto中除了订单状态还有其他查询条件则返回
if (dto.getMerchantId() != null || dto.getStationId() != null || dto.getOrderCode() != null
|| dto.getMobileNumber() != null || dto.getTransactionCode() != null || dto.getPileSn() != null
|| dto.getPlateNumber() != null) {
return;
}
// 设置个人桩站id, 148-个人桩站点; 684-7KW小直流个人桩站点
dto.setExcludeStationIdList(Lists.newArrayList(148, 684));
}
private void batchQueryFeeAmt(List<OrderListVO> orderListVOS) {
// 批量查手续费
List<String> orderCodeList = orderListVOS.stream().map(OrderListVO::getOrderCode).collect(Collectors.toList());
@@ -599,7 +622,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
// 结算时间设置为当前时间
orderInfo.setSettlementTime(new Date());
// 启动失败原因
orderInfo.setReason(failedReasonMsg);
// 订单退款(结算订单)
@@ -5942,6 +5965,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
/**
* 查询平台抽成金额
* 订单数量与保险金额时间区统计
* @param dto
* @return
*/
@@ -5949,5 +5973,71 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
public List<IndexPlatformProfitVO> getPlatformProfit(IndexQueryDTO dto) {
return orderBasicInfoMapper.getPlatformProfit(dto);
}
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;
}
}

View File

@@ -609,32 +609,43 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
// 查询订单信息
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderBasicInfo.getOrderCode());
// 订单消费金额, 除了充满自停是需要计算实际消费, 其他金额都是按次收费
BigDecimal orderAmount;
BigDecimal orderAmount = BigDecimal.ZERO;
// 耗电量
BigDecimal consumedEnergy = message.getConsumedEnergy();
if (fullOfSelfStopping.compareTo(orderBasicInfo.getPayAmount()) == 0) {
// 计费模板, 只取平时段的价格
BigDecimal flatElectricityPrice = orderDetail.getFlatElectricityPrice() != null ? orderDetail.getFlatElectricityPrice() : BigDecimal.ZERO; // x元/每度
// BigDecimal flatServicePrice = orderDetail.getFlatServicePrice() != null ? orderDetail.getFlatServicePrice() : BigDecimal.ZERO; // x元/每度
BigDecimal flatServicePrice = BigDecimal.ZERO; // x元/每度 服务费默认0
// 单价 = 电费单价 + 服务费单价
BigDecimal price = flatElectricityPrice.add(flatServicePrice);
// 如果耗电量或单价为空或者为0则订单消费为0
// if (consumedEnergy == null || consumedEnergy.compareTo(BigDecimal.ZERO) == 0 || price.compareTo(BigDecimal.ZERO) == 0) {
// logger.info("计算电单车退款逻辑,耗电量或计费模板为空,不执行退款逻辑, orderCode:{}, 耗电量:{}, 每度电费:{}", orderBasicInfo.getOrderCode(), consumedEnergy, price);
// return;
// }
// 计算实际消费, 保留两位小数
orderAmount = consumedEnergy.multiply(price).setScale(2, RoundingMode.UP);
} else {
// 2025.07.28如果耗电量为 0也进行退款
if (consumedEnergy.compareTo(BigDecimal.ZERO) == 0) {
orderAmount = BigDecimal.ZERO;
}else {
// 其他金额、并且耗电量不为 0 ,都是按次收费, 不退款
orderAmount = orderBasicInfo.getPayAmount();
}
}
// 计算实际消费金额
// 计费模板, 只取平时段的价格
BigDecimal flatElectricityPrice = orderDetail.getFlatElectricityPrice() != null ? orderDetail.getFlatElectricityPrice() : BigDecimal.ZERO; // x元/每度
// BigDecimal flatServicePrice = orderDetail.getFlatServicePrice() != null ? orderDetail.getFlatServicePrice() : BigDecimal.ZERO; // x元/每度
BigDecimal flatServicePrice = BigDecimal.ZERO; // x元/每度 服务费默认0
// 单价 = 电费单价 + 服务费单价
BigDecimal price = flatElectricityPrice.add(flatServicePrice);
// 计算实际消费, 保留两位小数
orderAmount = consumedEnergy.multiply(price).setScale(2, RoundingMode.UP);
// if (fullOfSelfStopping.compareTo(orderBasicInfo.getPayAmount()) == 0) {
// // 计费模板, 只取平时段的价格
// BigDecimal flatElectricityPrice = orderDetail.getFlatElectricityPrice() != null ? orderDetail.getFlatElectricityPrice() : BigDecimal.ZERO; // x元/每度
// // BigDecimal flatServicePrice = orderDetail.getFlatServicePrice() != null ? orderDetail.getFlatServicePrice() : BigDecimal.ZERO; // x元/每度
// BigDecimal flatServicePrice = BigDecimal.ZERO; // x元/每度 服务费默认0
// // 单价 = 电费单价 + 服务费单价
// BigDecimal price = flatElectricityPrice.add(flatServicePrice);
// // 如果耗电量或单价为空或者为0则订单消费为0
// // if (consumedEnergy == null || consumedEnergy.compareTo(BigDecimal.ZERO) == 0 || price.compareTo(BigDecimal.ZERO) == 0) {
// // logger.info("计算电单车退款逻辑,耗电量或计费模板为空,不执行退款逻辑, orderCode:{}, 耗电量:{}, 每度电费:{}", orderBasicInfo.getOrderCode(), consumedEnergy, price);
// // return;
// // }
// // 计算实际消费, 保留两位小数
// orderAmount = consumedEnergy.multiply(price).setScale(2, RoundingMode.UP);
// } else {
// // 2025.07.28如果耗电量为 0也进行退款
// if (consumedEnergy.compareTo(BigDecimal.ZERO) == 0) {
// orderAmount = BigDecimal.ZERO;
// }else {
// // 其他金额、并且耗电量不为 0 ,都是按次收费, 不退款
// orderAmount = orderBasicInfo.getPayAmount();
// }
// }
// 退款金额 = 支付金额 - 优惠后总消费金额
BigDecimal refundAmount = orderBasicInfo.getPayAmount().subtract(orderAmount);

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.vo.web;
import com.jsowell.common.annotation.Excel;
import lombok.Data;
import java.math.BigDecimal;
@@ -13,16 +14,36 @@ import java.math.BigDecimal;
@Data
public class OccupyOrderVO {
private String id;
@Excel(name = "占桩订单号")
private String occupyCode;
private String status;
@Excel(name = "会员ID")
private String memberId;
private String stationId;
private String plateNumber;
@Excel(name = "站点名称")
private String stationName;
@Excel(name = "占桩开始时间")
private String startTime;
@Excel(name = "占桩结束时间")
private String endTime;
@Excel(name = "支付状态")
private String payStatus;
@Excel(name = "订单金额")
private BigDecimal orderAmount;
@Excel(name = "充电桩编号")
private String pileSn;
@Excel(name = "充电桩枪口号")
private String connectorCode;
}

View File

@@ -0,0 +1,11 @@
package com.jsowell.pile.vo.web;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class OrderMonthStatVO {
private String month;
private Integer orderCount;
private BigDecimal insuranceAmount;
}