mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-08 20:10:16 +08:00
计算站点订单日报
This commit is contained in:
@@ -218,6 +218,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
|
||||
/**
|
||||
* 计算相差天数 (会显示负值)
|
||||
*
|
||||
* @param endDate
|
||||
* @param nowDate
|
||||
* @return
|
||||
@@ -574,6 +575,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
return simpleDateFormat.format(date);
|
||||
}
|
||||
|
||||
public static String formatDateTime(LocalDateTime localDateTime) {
|
||||
if (localDateTime == null) {
|
||||
return "";
|
||||
}
|
||||
Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
||||
return formatDateTime(date);
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -788,11 +797,12 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
|
||||
/**
|
||||
* 秒 转 天时分秒
|
||||
* 时分秒HoursMinutesSeconds
|
||||
*
|
||||
* @param mss 秒数
|
||||
* @return xx天xx小时xx分钟xx秒
|
||||
*/
|
||||
public static String formatDateTime(long mss) {
|
||||
public static String formatHoursMinutesSeconds(long mss) {
|
||||
String DateTimes = null;
|
||||
long days = mss / (60 * 60 * 24);
|
||||
long hours = (mss % (60 * 60 * 24)) / (60 * 60);
|
||||
@@ -828,7 +838,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
if (time.compareTo(beginTime) == 0 || time.compareTo(endTime) == 0) {
|
||||
return true;
|
||||
}
|
||||
if (beginTime.isBefore(time) && endTime.isAfter(time)){
|
||||
if (beginTime.isBefore(time) && endTime.isAfter(time)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -56,7 +56,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -137,6 +139,9 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
@Autowired
|
||||
private IMemberTransactionRecordService memberTransactionRecordService;
|
||||
|
||||
@Autowired
|
||||
private ISettleOrderReportService settleOrderReportService;
|
||||
|
||||
/**
|
||||
* 条件查询订单基本信息
|
||||
*
|
||||
@@ -1841,12 +1846,62 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
// 查询站点前一天完成的订单
|
||||
QueryOrderDTO dto = new QueryOrderDTO();
|
||||
dto.setStationId(stationId);
|
||||
LocalDate yesterday = LocalDate.now().plusDays(-1);
|
||||
dto.setStartTime(DateUtils.formatDateTime(LocalDateTime.of(yesterday, LocalTime.MIN)));
|
||||
dto.setEndTime(DateUtils.formatDateTime(LocalDateTime.of(yesterday, LocalTime.MAX)));
|
||||
List<OrderListVO> orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
|
||||
if (CollectionUtils.isEmpty(orderListVOS)) {
|
||||
return;
|
||||
}
|
||||
// 统计出日报信息
|
||||
|
||||
BigDecimal useElectricity = BigDecimal.ZERO;
|
||||
int chargeNum = 0;
|
||||
long chargeTime = 0L;
|
||||
BigDecimal totalElectricityAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalServiceAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalOrderAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalVirtualAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalSettleAmount = BigDecimal.ZERO;
|
||||
for (OrderListVO vo : orderListVOS) {
|
||||
BigDecimal chargingDegree = new BigDecimal(vo.getChargingDegree());
|
||||
if (chargingDegree.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
// 只统计用电量大于0的
|
||||
continue;
|
||||
}
|
||||
// 充电度数
|
||||
useElectricity = useElectricity.add(chargingDegree);
|
||||
// 充电次数
|
||||
chargeNum += chargeNum;
|
||||
// 充电时间
|
||||
long l = DateUtils.intervalTime(vo.getChargeStartTime(), vo.getChargeEndTime());
|
||||
chargeTime += l;
|
||||
// 电费金额
|
||||
totalElectricityAmount = totalElectricityAmount.add(vo.getTotalElectricityAmount());
|
||||
// 服务费金额
|
||||
totalServiceAmount = totalServiceAmount.add(vo.getTotalServiceAmount());
|
||||
// 订单金额
|
||||
totalOrderAmount = totalOrderAmount.add(new BigDecimal(vo.getOrderAmount()));
|
||||
// 虚拟金额
|
||||
totalVirtualAmount = totalVirtualAmount.add(new BigDecimal(vo.getVirtualAmount()));
|
||||
// 结算金额
|
||||
totalSettleAmount = totalSettleAmount.add(new BigDecimal(vo.getSettleAmount()));
|
||||
}
|
||||
// 保存到数据库
|
||||
SettleOrderReport settleOrderReport = new SettleOrderReport();
|
||||
settleOrderReport.setMerchantId("");
|
||||
settleOrderReport.setStationId(stationId);
|
||||
settleOrderReport.setUseElectricity(useElectricity);
|
||||
settleOrderReport.setChargeNum(chargeNum + "");
|
||||
settleOrderReport.setChargeTime(chargeTime + "");
|
||||
settleOrderReport.setElectricityAmount(totalElectricityAmount);
|
||||
settleOrderReport.setServiceAmount(totalServiceAmount);
|
||||
settleOrderReport.setTotalAmount(totalOrderAmount);
|
||||
settleOrderReport.setVirtualAmount(totalVirtualAmount);
|
||||
settleOrderReport.setTradeDate(yesterday.toString());
|
||||
// 计算手续费 = 结算金额 * 0.55%
|
||||
BigDecimal tradeFee = totalSettleAmount.multiply(new BigDecimal("0.0055"));
|
||||
settleOrderReport.setTradeFee(tradeFee);
|
||||
settleOrderReport.setTradeAmount(totalSettleAmount.subtract(tradeFee));
|
||||
settleOrderReportService.insertSettleOrderReport(settleOrderReport);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,32 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
return amLong.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "{\n" +
|
||||
" \"mchid\": \"1632405339\",\n" +
|
||||
" \"appid\": \"wxbb3e0d474569481d\",\n" +
|
||||
" \"out_trade_no\": \"823422832569454592\",\n" +
|
||||
" \"transaction_id\": \"4200001841202305301676160680\",\n" +
|
||||
" \"trade_type\": \"JSAPI\",\n" +
|
||||
" \"trade_state\": \"SUCCESS\",\n" +
|
||||
" \"trade_state_desc\": \"支付成功\",\n" +
|
||||
" \"bank_type\": \"OTHERS\",\n" +
|
||||
" \"attach\": \"{\\\"memberId\\\":\\\"82507801\\\",\\\"orderCode\\\":\\\"C27473779928\\\",\\\"type\\\":\\\"order\\\"}\",\n" +
|
||||
" \"success_time\": \"2023-05-30T15:15:20+08:00\",\n" +
|
||||
" \"payer\": {\n" +
|
||||
" \"openid\": \"o4REX5FPLsLOxM2x9ig2MHuuHPqU\"\n" +
|
||||
" },\n" +
|
||||
" \"amount\": {\n" +
|
||||
" \"total\": 5000,\n" +
|
||||
" \"payer_total\": 5000,\n" +
|
||||
" \"currency\": \"CNY\",\n" +
|
||||
" \"payer_currency\": \"CNY\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
WechatPayNotifyResource wechatPayNotifyResource = JSON.parseObject(s, WechatPayNotifyResource.class);
|
||||
System.out.println(wechatPayNotifyResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付回调
|
||||
* @param request
|
||||
|
||||
@@ -6,6 +6,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 后管订单列表页面
|
||||
*
|
||||
@@ -184,4 +186,14 @@ public class OrderListVO {
|
||||
* 支付机构
|
||||
*/
|
||||
private String paymentInstitutions;
|
||||
|
||||
/**
|
||||
* 电费金额
|
||||
*/
|
||||
private BigDecimal totalElectricityAmount;
|
||||
|
||||
/**
|
||||
* 服务费金额
|
||||
*/
|
||||
private BigDecimal totalServiceAmount;
|
||||
}
|
||||
|
||||
@@ -181,6 +181,8 @@
|
||||
t1.virtual_amount as virtualAmount,
|
||||
t1.settle_amount as settleAmount,
|
||||
t4.total_used_electricity as chargingDegree,
|
||||
t4.total_electricity_amount as totalElectricityAmount,
|
||||
t4.total_service_amount as totalServiceAmount,
|
||||
t5.payment_institutions as paymentInstitutions
|
||||
from order_basic_info t1
|
||||
left join member_basic_info t2 on t1.member_id = t2.member_id
|
||||
|
||||
Reference in New Issue
Block a user