From 4c77ac6367145e4740141e872e1cda1c16efa9b1 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期一, 09 六月 2025 15:17:16 +0800
Subject: [PATCH] 优化功能及重复退款问题
---
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java | 671 ++++++++++++++++++++++----------------------
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/util/TaskUtil.java | 24 +
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/util/TaskUtil.java | 20 +
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java | 10
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/MsgUtil.java | 1
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java | 6
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java | 120 ++++---
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/util/TaskUtil.java | 15
8 files changed, 456 insertions(+), 411 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/MsgUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/MsgUtil.java
index b616ffc..34be928 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/MsgUtil.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/MsgUtil.java
@@ -187,7 +187,6 @@
String reqText = JSON.toJSONString(submitReq);
//加密
String encode = Base64.encodeBase64String(reqText.getBytes());
- System.err.println(encode);
return encode;
}
/**
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
index 754743b..e5db1a4 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
@@ -1442,15 +1442,7 @@
}
}
-
- public static void main(String[] args) {
-// String reqStr1 = MsgUtil.codeMsg("19983174515", "123456");
-// String result1 = HttpUtils.post(MsgConstants.SEND_URL, reqStr1);
-
- String reqStr3 = MsgUtil.faultMsg("18398968484", "长河服务区充电站(遂", "123");
- String result3 = HttpUtils.post(MsgConstants.SEND_URL, reqStr3);
- System.err.println(result3);
- }
+
@Log(title = "【我的】退出登录", businessType = BusinessType.STOP,operatorType = OperatorType.MOBILE)
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
index 2216d2a..99f11b7 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
@@ -234,7 +234,11 @@
TChargingGun chargingGun = chargingGunService.getById(gunId);
TAccountingStrategy accountingStrategy = accountingStrategyMapper.selectById(chargingGun.getAccountingStrategyId());
if(Objects.isNull(accountingStrategy)){
- throw new ServiceException("未查询到计费策略");
+ Site site = siteService.getById(chargingGun.getSiteId());
+ accountingStrategy = accountingStrategyMapper.selectById(site.getAccountingStrategyId());
+ if(Objects.isNull(accountingStrategy)){
+ throw new ServiceException("未查询到计费策略");
+ }
}
List<TAccountingStrategyDetailVO> list = this.queryAccountingStrategyDetailByStrategyId(accountingStrategy.getId());
list.stream().filter(item -> "00:00".equals(item.getEndTime())).forEach(item -> item.setEndTime("23:59:59"));
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
index 2bfa42a..954b3ca 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -43,6 +43,7 @@
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.feignClient.SysUserRoleClient;
import com.ruoyi.system.api.model.SysUserRoleVo;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@@ -63,6 +64,7 @@
* @author xiaochen
* @since 2024-08-06
*/
+@Slf4j
@Service
public class TChargingPileServiceImpl extends ServiceImpl<TChargingPileMapper, TChargingPile> implements TChargingPileService {
@@ -703,63 +705,75 @@
*/
@Override
public void updateStatus() {
- List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getDelFlag, 0));
+ //查询出redis集合汇总符合条件的数据
+ Set keys = redisTemplate.opsForHash().keys("charging_gun_online");
+ List<String> fullNumbers = new ArrayList<>();
+ keys.forEach(key -> {
+ Long time = (Long) redisTemplate.opsForHash().get("charging_gun_online", key);
+ if(null != time && System.currentTimeMillis() - time > 300000){
+ log.info("设备编号:{}已离线", key);
+ log.info("间隔时间", System.currentTimeMillis() - time);
+ fullNumbers.add(key.toString());
+ }
+ });
+ if(fullNumbers.size() == 0){
+ return;
+ }
+
+ //处理符合条件的数据,修改设备状态
+ List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getFullNumber, fullNumbers).eq(TChargingGun::getDelFlag, 0));
for (TChargingGun chargingGun : list) {
- Long time = (Long) redisTemplate.opsForHash().get("charging_gun_online", chargingGun.getFullNumber());
- //判断设备是否真的离线5分钟
- if(null != time && System.currentTimeMillis() - time > 300000){
- TChargingGun chargingGun1 = new TChargingGun();
- chargingGun1.setId(chargingGun.getId());
- chargingGun1.setStatus(1);
- chargingGunService.updateById(chargingGun1);
- new Thread(new Runnable() {
- @Override
- public void run() {
- //推送状态给三方平台
- tcecClient.pushChargingGunStatus(chargingGun1.getFullNumber(), chargingGun1.getStatus());
- }
- }).start();
-
- //桩处于正常,桩所属的枪都处于非正常,修改桩状态为异常
- TChargingPile chargingPile = this.getById(chargingGun.getChargingPileId());
- List<TChargingGun> list1 = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, chargingPile.getId()).eq(TChargingGun::getDelFlag, 0));
- int size = list1.stream().filter(s -> s.getStatus() == 1 || s.getStatus() == 7).collect(Collectors.toList()).size();
- if(chargingPile.getStatus() == 1 && list1.size() == size){
- TChargingPile chargingPile1 = new TChargingPile();
- chargingPile1.setId(chargingGun.getChargingPileId());
- chargingPile1.setStatus(2);
- this.updateById(chargingPile1);
+ TChargingGun chargingGun1 = new TChargingGun();
+ chargingGun1.setId(chargingGun.getId());
+ chargingGun1.setStatus(1);
+ chargingGunService.updateById(chargingGun1);
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ //推送状态给三方平台
+ tcecClient.pushChargingGunStatus(chargingGun1.getFullNumber(), chargingGun1.getStatus());
}
+ }).start();
+
+ //桩处于正常,桩所属的枪都处于非正常,修改桩状态为异常
+ TChargingPile chargingPile = this.getById(chargingGun.getChargingPileId());
+ List<TChargingGun> list1 = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, chargingPile.getId()).eq(TChargingGun::getDelFlag, 0));
+ int size = list1.stream().filter(s -> s.getStatus() == 1 || s.getStatus() == 7).collect(Collectors.toList()).size();
+ if(chargingPile.getStatus() == 1 && list1.size() == size){
+ TChargingPile chargingPile1 = new TChargingPile();
+ chargingPile1.setId(chargingGun.getChargingPileId());
+ chargingPile1.setStatus(2);
+ this.updateById(chargingPile1);
+ }
+
+ //添加记录
+ TFaultMessage faultMessage = faultMessageService.getOne(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingPileId, chargingGun.getChargingPileId())
+ .eq(TFaultMessage::getChargingGunId, chargingGun.getId()).eq(TFaultMessage::getStatus, 1).eq(TFaultMessage::getDelFlag, 0).isNull(TFaultMessage::getEndTime));
+ if(null == faultMessage){
+ faultMessage = new TFaultMessage();
+ faultMessage.setSiteId(chargingGun.getSiteId());
+ faultMessage.setChargingPileId(chargingGun.getChargingPileId());
+ faultMessage.setChargingGunId(chargingGun.getId());
+ faultMessage.setStatus(1);
+ faultMessage.setDownTime(LocalDateTime.now());
+ faultMessage.setCreateTime(LocalDateTime.now());
+ faultMessage.setDelFlag(false);
+ faultMessage.setContent("设备离线");
+ faultMessageService.save(faultMessage);
- //添加记录
- TFaultMessage faultMessage = faultMessageService.getOne(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingPileId, chargingGun.getChargingPileId())
- .eq(TFaultMessage::getChargingGunId, chargingGun.getId()).eq(TFaultMessage::getStatus, 1).eq(TFaultMessage::getDelFlag, 0).isNull(TFaultMessage::getEndTime));
- if(null == faultMessage){
- faultMessage = new TFaultMessage();
- faultMessage.setSiteId(chargingGun.getSiteId());
- faultMessage.setChargingPileId(chargingGun.getChargingPileId());
- faultMessage.setChargingGunId(chargingGun.getId());
- faultMessage.setStatus(1);
- faultMessage.setDownTime(LocalDateTime.now());
- faultMessage.setCreateTime(LocalDateTime.now());
- faultMessage.setDelFlag(false);
- faultMessage.setContent("设备离线");
- faultMessageService.save(faultMessage);
-
- // 发送故障短信
- Site site = siteService.getById(faultMessage.getSiteId());
- String siteName = site.getName();
- SendMessageDTO sendMessageDTO = new SendMessageDTO();
- sendMessageDTO.setPhone(site.getPhone());
- sendMessageDTO.setSite(site.getName());
- sendMessageDTO.setChargeGun(chargingPile.getNumber() + "");
- sendMessageDTO.setType(3);
- String result = appUserClient.sendMessage(sendMessageDTO).getData();
- if(siteName.length()>10){
- siteName = siteName.substring(0,10);
- }
- chargingPileNotificationService.saveData(4,faultMessage.getSiteId(),faultMessage.getChargingPileId(),site.getPhone(),"检测到"+siteName+"..."+chargingPile.getNumber()+"号桩设备离线,请及时查看处理!");
+ // 发送故障短信
+ Site site = siteService.getById(faultMessage.getSiteId());
+ String siteName = site.getName();
+ SendMessageDTO sendMessageDTO = new SendMessageDTO();
+ sendMessageDTO.setPhone(site.getPhone());
+ sendMessageDTO.setSite(site.getName());
+ sendMessageDTO.setChargeGun(chargingPile.getNumber() + "");
+ sendMessageDTO.setType(3);
+ String result = appUserClient.sendMessage(sendMessageDTO).getData();
+ if(siteName.length()>10){
+ siteName = siteName.substring(0,10);
}
+ chargingPileNotificationService.saveData(4,faultMessage.getSiteId(),faultMessage.getChargingPileId(),site.getPhone(),"检测到"+siteName+"..."+chargingPile.getNumber()+"号桩设备离线,请及时查看处理!");
}
}
}
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/util/TaskUtil.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/util/TaskUtil.java
index 15d3d74..a463b33 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/util/TaskUtil.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/util/TaskUtil.java
@@ -2,6 +2,8 @@
import com.ruoyi.chargingPile.service.TChargingPileService;
+import org.springframework.boot.web.context.WebServerInitializedEvent;
+import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -12,19 +14,29 @@
* 定时任务工具类
*/
@Component
-public class TaskUtil {
+public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
@Resource
- private TChargingPileService chargingPileService;;
+ private TChargingPileService chargingPileService;
+
+ private Integer port = null;
-
+ @Override
+ public void onApplicationEvent(WebServerInitializedEvent event) {
+ port = event.getWebServer().getPort();
+ System.out.println("端口号:" + port);
+ }
/**
- * 每隔2分钟去处理的定时任务
+ * 每隔1分钟去处理的定时任务
*/
- @Scheduled(fixedRate = 120000)
+ @Scheduled(fixedRate = 60000)
public void taskMinute(){
- chargingPileService.updateStatus();
+ if(null != port && port == 5300){
+ chargingPileService.updateStatus();
+ }
}
+
+
}
diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/util/TaskUtil.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/util/TaskUtil.java
index f324ead..258b1f5 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/util/TaskUtil.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/util/TaskUtil.java
@@ -18,6 +18,8 @@
import com.ruoyi.order.api.model.TChargingBill;
import com.ruoyi.order.api.model.TChargingOrder;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.web.context.WebServerInitializedEvent;
+import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -36,7 +38,7 @@
* @date 2023/7/11 8:39
*/
@Component
-public class TaskUtil {
+public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
@Resource
@@ -52,12 +54,21 @@
@Resource
private ChargingPileClient chargingPileClient;
+
+ private Integer port = null;
+
+
+ @Override
+ public void onApplicationEvent(WebServerInitializedEvent event) {
+ port = event.getWebServer().getPort();
+ System.out.println("端口号:" + port);
+ }
+
// 每天凌晨12点30执行 推送充电用能统计
@Scheduled(cron = "0 30 0 * * ?")
public void superviseNotificationOperationStatsInfo() {
- String port = System.getProperty("server.port");
- if("5701".equals(port)){
+ if(null != port && port == 5701){
StationStatsInfoResult res = new StationStatsInfoResult();
int dayOfMonth1 = LocalDateTime.now().getYear();
int dayOfMonth2 = LocalDateTime.now().getMonthValue();
@@ -142,8 +153,7 @@
// 每15分钟执行一次的定时任务
@Scheduled(cron = "0 0/15 * * * ?")
public void supervise_notification_realtime_power_info() {
- String port = System.getProperty("server.port");
- if("5701".equals(port)){
+ if(null != port && port == 5701){
List<Site> data = siteClient.getSiteAll().getData();
List<Integer> siteIds = data.stream().filter(s->s.getStatus() == 1).map(Site::getId).collect(Collectors.toList());
List<TChargingPile> tChargingPiles = chargingPileClient.getChargingPileBySiteIds(siteIds).getData();
diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/util/TaskUtil.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/util/TaskUtil.java
index 236ff04..9ed48f0 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/util/TaskUtil.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/util/TaskUtil.java
@@ -1,6 +1,8 @@
//package com.ruoyi.integration.util;
//
//import com.ruoyi.integration.mongodb.service.*;
+//import org.springframework.boot.web.context.WebServerInitializedEvent;
+//import org.springframework.context.ApplicationListener;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
@@ -12,7 +14,7 @@
// * @Date 2025/5/21 11:43
// */
//@Component
-//public class TaskUtil {
+//public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
//
// @Resource
// private AcquisitionBillingModeReplyService acquisitionBillingModeReplyService;
@@ -38,15 +40,20 @@
// @Resource
// private ChargingHandshakeService chargingHandshakeService;
//
+// private Integer port = null;
+//
+// @Override
+// public void onApplicationEvent(WebServerInitializedEvent event) {
+// port = event.getWebServer().getPort();
+// }
+//
//
// /**
// * 定时任务
// */
// @Scheduled(cron = "0 0 9 * * ?")
// public void run(){
-// //获取当前运行的端口号
-// String port = System.getProperty("server.port");
-// if("5701".equals(port)){
+// if(null != port && port == 5701){
// acquisitionBillingModeReplyService.taskDelete();
// acquisitionBillingModeService.taskDelete();
// billingModeVerifyReplyService.taskDelete();
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
index 46af198..654db7e 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -2179,31 +2179,37 @@
*/
@Override
public R endChargeBillingCharge(TransactionRecordMessageVO vo) {
- TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
- if(null == chargingOrder){
+ Boolean hasKey = redisService.hasKey("endOrder:" + vo.getTransaction_serial_number());
+ if(hasKey){
return R.ok();
}
- Integer status = chargingOrder.getStatus();
- if(status == 5){
- return R.ok();
- }
-
- //如果使用优惠券需要判断优惠券是否满足使用条件
- //退款金额=优惠券金额+剩余充电金额
- BigDecimal periodElectricPrice_total = BigDecimal.ZERO;
- BigDecimal periodServicePrice_total = BigDecimal.ZERO;
- BigDecimal vipDiscountAmount_total = BigDecimal.ZERO;
- BigDecimal serviceCharge_total = BigDecimal.ZERO;
- BigDecimal total = BigDecimal.ZERO;
-
- //获取订单的计费策略
- List<AccountingStrategyDetailOrder> accountingStrategyDetailOrderList = accountingStrategyDetailOrderClient.getAllAccountingStrategyDetailOrder(chargingOrder.getId()).getData();
- accountingStrategyDetailOrderList.get(accountingStrategyDetailOrderList.size() - 1).setEndTime("23:59");
- //开始处理计费明细数据和优惠数据
- chargingOrderAccountingStrategyService.remove(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
- SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- List<AccountingStrategyDetailOrderVo> lists = new ArrayList<>();
+ //添加1分钟的缓存
+ redisService.setCacheObject("endOrder:" + vo.getTransaction_serial_number(), vo.getTransaction_serial_number(), 1L, TimeUnit.MINUTES);
try {
+ TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
+ if(null == chargingOrder){
+ return R.ok();
+ }
+ Integer status = chargingOrder.getStatus();
+ if(status == 5){
+ return R.ok();
+ }
+
+ //如果使用优惠券需要判断优惠券是否满足使用条件
+ //退款金额=优惠券金额+剩余充电金额
+ BigDecimal periodElectricPrice_total = BigDecimal.ZERO;
+ BigDecimal periodServicePrice_total = BigDecimal.ZERO;
+ BigDecimal vipDiscountAmount_total = BigDecimal.ZERO;
+ BigDecimal serviceCharge_total = BigDecimal.ZERO;
+ BigDecimal total = BigDecimal.ZERO;
+
+ //获取订单的计费策略
+ List<AccountingStrategyDetailOrder> accountingStrategyDetailOrderList = accountingStrategyDetailOrderClient.getAllAccountingStrategyDetailOrder(chargingOrder.getId()).getData();
+ accountingStrategyDetailOrderList.get(accountingStrategyDetailOrderList.size() - 1).setEndTime("23:59");
+ //开始处理计费明细数据和优惠数据
+ chargingOrderAccountingStrategyService.remove(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
+ SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ List<AccountingStrategyDetailOrderVo> lists = new ArrayList<>();
//跨天
if(!vo.getStart_time().split(" ")[0].equals(vo.getEnd_time().split(" ")[0])){
//当天的
@@ -2324,330 +2330,331 @@
lists.add(vo1);
}
}
- }catch (Exception e){
- e.printStackTrace();
- R.fail("处理失败");
- }
-
- //开始处理明细
- for (int i = 0; i < lists.size(); i++) {
- AccountingStrategyDetailOrderVo strategyDetail = lists.get(i);
- BigDecimal sharp_peak_charge = strategyDetail.getChargingCapacity();
- TChargingOrderAccountingStrategy chargingOrderAccountingStrategy = new TChargingOrderAccountingStrategy();
- chargingOrderAccountingStrategy.setChargingOrderId(chargingOrder.getId());
- chargingOrderAccountingStrategy.setAccountingStrategyDetailId(strategyDetail.getId());
- chargingOrderAccountingStrategy.setType(strategyDetail.getType());
- chargingOrderAccountingStrategy.setElectrovalence(strategyDetail.getElectrovalence());
- chargingOrderAccountingStrategy.setServiceCharge(strategyDetail.getServiceCharge());
- chargingOrderAccountingStrategy.setCostServiceCharge(strategyDetail.getCostServiceCharge());
- if(i == 0){
- String time = vo.getStart_time().split(" ")[1];
- chargingOrderAccountingStrategy.setStartTime(time.substring(0, time.lastIndexOf(":")));
- }else{
- chargingOrderAccountingStrategy.setStartTime(strategyDetail.getStartTime());
- }
- if(i == lists.size() - 1){
- String time = vo.getEnd_time().split(" ")[1];
- chargingOrderAccountingStrategy.setEndTime(time.substring(0, time.lastIndexOf(":")));
- }else{
- chargingOrderAccountingStrategy.setEndTime(strategyDetail.getEndTime());
+
+ //开始处理明细
+ for (int i = 0; i < lists.size(); i++) {
+ AccountingStrategyDetailOrderVo strategyDetail = lists.get(i);
+ BigDecimal sharp_peak_charge = strategyDetail.getChargingCapacity();
+ TChargingOrderAccountingStrategy chargingOrderAccountingStrategy = new TChargingOrderAccountingStrategy();
+ chargingOrderAccountingStrategy.setChargingOrderId(chargingOrder.getId());
+ chargingOrderAccountingStrategy.setAccountingStrategyDetailId(strategyDetail.getId());
+ chargingOrderAccountingStrategy.setType(strategyDetail.getType());
+ chargingOrderAccountingStrategy.setElectrovalence(strategyDetail.getElectrovalence());
+ chargingOrderAccountingStrategy.setServiceCharge(strategyDetail.getServiceCharge());
+ chargingOrderAccountingStrategy.setCostServiceCharge(strategyDetail.getCostServiceCharge());
+ if(i == 0){
+ String time = vo.getStart_time().split(" ")[1];
+ chargingOrderAccountingStrategy.setStartTime(time.substring(0, time.lastIndexOf(":")));
+ }else{
+ chargingOrderAccountingStrategy.setStartTime(strategyDetail.getStartTime());
+ }
+ if(i == lists.size() - 1){
+ String time = vo.getEnd_time().split(" ")[1];
+ chargingOrderAccountingStrategy.setEndTime(time.substring(0, time.lastIndexOf(":")));
+ }else{
+ chargingOrderAccountingStrategy.setEndTime(strategyDetail.getEndTime());
+ }
+
+ //已充电总度数
+ BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge);
+ BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge);
+ BigDecimal serviceCharge = originalServicePrice;
+ BigDecimal vipDiscountAmount = BigDecimal.ZERO;
+ //计算优惠金额
+ if(null != chargingOrder.getVipDiscount()){
+ //0.58折
+ vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount()));
+ serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount());
+ }
+ chargingOrderAccountingStrategy.setChargingCapacity(sharp_peak_charge);
+ chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc.setScale(4, RoundingMode.HALF_EVEN));
+ chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge.setScale(4, RoundingMode.HALF_EVEN));
+ chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice.setScale(4, RoundingMode.HALF_EVEN));
+ chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount.setScale(4, RoundingMode.HALF_EVEN));
+ chargingOrderAccountingStrategy.setCreateTime(LocalDateTime.now());
+ chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy);
+ //电费
+ periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc);
+ //服务费(含折扣)
+ serviceCharge_total = serviceCharge_total.add(serviceCharge);
+ //服务费(不含折扣)
+ periodServicePrice_total = periodServicePrice_total.add(originalServicePrice);
+ //会员折扣优惠金额
+ vipDiscountAmount_total = vipDiscountAmount_total.add(vipDiscountAmount);
+ //原始总金额(不含折扣)
+ total = total.add(electrovalenc.add(originalServicePrice));
}
- //已充电总度数
- BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge);
- BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge);
- BigDecimal serviceCharge = originalServicePrice;
- BigDecimal vipDiscountAmount = BigDecimal.ZERO;
- //计算优惠金额
- if(null != chargingOrder.getVipDiscount()){
- //0.58折
- vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount()));
- serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount());
- }
- chargingOrderAccountingStrategy.setChargingCapacity(sharp_peak_charge);
- chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc.setScale(4, RoundingMode.HALF_EVEN));
- chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge.setScale(4, RoundingMode.HALF_EVEN));
- chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice.setScale(4, RoundingMode.HALF_EVEN));
- chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount.setScale(4, RoundingMode.HALF_EVEN));
- chargingOrderAccountingStrategy.setCreateTime(LocalDateTime.now());
- chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy);
- //电费
- periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc);
- //服务费(含折扣)
- serviceCharge_total = serviceCharge_total.add(serviceCharge);
- //服务费(不含折扣)
- periodServicePrice_total = periodServicePrice_total.add(originalServicePrice);
- //会员折扣优惠金额
- vipDiscountAmount_total = vipDiscountAmount_total.add(vipDiscountAmount);
- //原始总金额(不含折扣)
- total = total.add(electrovalenc.add(originalServicePrice));
- }
-
- BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue());
- //原金额
- BigDecimal rechargeAmount = chargingOrder.getRechargeAmount();
- //支付金额
- BigDecimal payAmount = periodElectricPrice_total.add(serviceCharge_total);
- //退款金额=充值金额-实际支付金额
- BigDecimal refundAmount = rechargeAmount.subtract(payAmount);
-
- TChargingOrder order = new TChargingOrder();
- order.setId(chargingOrder.getId());
- order.setAppUserId(chargingOrder.getAppUserId());
- UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataService.getLastDataById(chargingOrder.getCode());
- if(null != uploadRealTimeMonitoringData && null == chargingOrder.getEndMode()){
- Integer soc = uploadRealTimeMonitoringData.getSoc();
- if(soc >= 98){
- order.setEndMode(2);
- }else if(chargingOrder.getResidualAmount().compareTo(new BigDecimal(1)) <= 0){
- order.setEndMode(3);
- }else{
- order.setEndMode(0);
- }
- }
- order.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.HALF_EVEN));
- order.setStartTime(LocalDateTime.parse(vo.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
- order.setEndTime(LocalDateTime.parse(vo.getEnd_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
- order.setStatus(5);
- order.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN));
- order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN));
- order.setChargingCapacity(vo.getTotal_electricity());
- order.setElectricity(vo.getTotal_electricity());
- order.setVipDiscountAmount(vipDiscountAmount_total);
- if(vipDiscountAmount_total.compareTo(BigDecimal.ZERO) == 0){
- order.setVipDiscount(BigDecimal.valueOf(1));
- }
-
- //计算优惠券
- BigDecimal couponDiscount = BigDecimal.ZERO;
- if(null != chargingOrder.getAppCouponId()){
- //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。
- TAppCoupon appCoupon = appCouponClient.getAppCouponById(chargingOrder.getAppCouponId()).getData();
- String couponJson = appCoupon.getCouponJson();
- TCoupon tCoupon = JSON.parseObject(couponJson, TCoupon.class);
- Integer preferentialMode = tCoupon.getPreferentialMode();
- if(1 == preferentialMode){
- //满减
- if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
- BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount();
- //如果优惠金额大于服务费金额,以服务费作为最大限制
- if(serviceCharge_total.compareTo(couponDiscountAmount) < 0){
- couponDiscount = serviceCharge_total;
- serviceCharge_total = BigDecimal.ZERO;
- }else{
- couponDiscount = couponDiscountAmount;
- }
- appCoupon.setStatus(2);
- appCouponClient.updateAppCoupon(appCoupon);
+ BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue());
+ //原金额
+ BigDecimal rechargeAmount = chargingOrder.getRechargeAmount();
+ //支付金额
+ BigDecimal payAmount = periodElectricPrice_total.add(serviceCharge_total);
+ //退款金额=充值金额-实际支付金额
+ BigDecimal refundAmount = rechargeAmount.subtract(payAmount);
+
+ TChargingOrder order = new TChargingOrder();
+ order.setId(chargingOrder.getId());
+ order.setAppUserId(chargingOrder.getAppUserId());
+ UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataService.getLastDataById(chargingOrder.getCode());
+ if(null != uploadRealTimeMonitoringData && null == chargingOrder.getEndMode()){
+ Integer soc = uploadRealTimeMonitoringData.getSoc();
+ if(soc >= 98){
+ order.setEndMode(2);
+ }else if(chargingOrder.getResidualAmount().compareTo(new BigDecimal(1)) <= 0){
+ order.setEndMode(3);
}else{
- order.setAppCouponId(null);
- order.setCouponDiscountAmount(BigDecimal.ZERO);
- appCouponClient.refund(chargingOrder.getAppCouponId().toString());
+ order.setEndMode(0);
}
}
- if(2 == preferentialMode){
- //抵扣
- if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
- //折扣金额
- BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10));
- divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
- //如果优惠金额大于服务费金额,以服务费作为最大限制
- if(serviceCharge_total.compareTo(divide) < 0){
- couponDiscount = serviceCharge_total;
- serviceCharge_total = BigDecimal.ZERO;
+ order.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.HALF_EVEN));
+ order.setStartTime(LocalDateTime.parse(vo.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
+ order.setEndTime(LocalDateTime.parse(vo.getEnd_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
+ order.setStatus(5);
+ order.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN));
+ order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN));
+ order.setChargingCapacity(vo.getTotal_electricity());
+ order.setElectricity(vo.getTotal_electricity());
+ order.setVipDiscountAmount(vipDiscountAmount_total);
+ if(vipDiscountAmount_total.compareTo(BigDecimal.ZERO) == 0){
+ order.setVipDiscount(BigDecimal.valueOf(1));
+ }
+
+ //计算优惠券
+ BigDecimal couponDiscount = BigDecimal.ZERO;
+ if(null != chargingOrder.getAppCouponId()){
+ //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。
+ TAppCoupon appCoupon = appCouponClient.getAppCouponById(chargingOrder.getAppCouponId()).getData();
+ String couponJson = appCoupon.getCouponJson();
+ TCoupon tCoupon = JSON.parseObject(couponJson, TCoupon.class);
+ Integer preferentialMode = tCoupon.getPreferentialMode();
+ if(1 == preferentialMode){
+ //满减
+ if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
+ BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount();
+ //如果优惠金额大于服务费金额,以服务费作为最大限制
+ if(serviceCharge_total.compareTo(couponDiscountAmount) < 0){
+ couponDiscount = serviceCharge_total;
+ serviceCharge_total = BigDecimal.ZERO;
+ }else{
+ couponDiscount = couponDiscountAmount;
+ }
+ appCoupon.setStatus(2);
+ appCouponClient.updateAppCoupon(appCoupon);
}else{
- couponDiscount = divide;
+ order.setAppCouponId(null);
+ order.setCouponDiscountAmount(BigDecimal.ZERO);
+ appCouponClient.refund(chargingOrder.getAppCouponId().toString());
+ }
+ }
+ if(2 == preferentialMode){
+ //抵扣
+ if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
+ //折扣金额
+ BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10));
+ divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
+ //如果优惠金额大于服务费金额,以服务费作为最大限制
+ if(serviceCharge_total.compareTo(divide) < 0){
+ couponDiscount = serviceCharge_total;
+ serviceCharge_total = BigDecimal.ZERO;
+ }else{
+ couponDiscount = divide;
+ }
+
+ appCoupon.setStatus(2);
+ appCouponClient.updateAppCoupon(appCoupon);
+ }else{
+ order.setAppCouponId(null);
+ order.setCouponDiscountAmount(BigDecimal.ZERO);
+ appCouponClient.refund(chargingOrder.getAppCouponId().toString());
+ }
+ }
+ }
+ //优惠券优惠金额
+ couponDiscount = couponDiscount.setScale(4, RoundingMode.HALF_EVEN);
+ //退款金额+优惠券
+ refundAmount = refundAmount.add(couponDiscount);
+ //实际支付金额-优惠券
+ payAmount = payAmount.subtract(couponDiscount);
+ if(serviceCharge_total.compareTo(BigDecimal.ZERO) > 0){
+ serviceCharge_total = serviceCharge_total.subtract(couponDiscount);
+ }
+ order.setCouponDiscountAmount(couponDiscount.setScale(2, RoundingMode.HALF_EVEN));
+ order.setServiceCharge(serviceCharge_total.setScale(2, RoundingMode.HALF_EVEN));
+ order.setPaymentAmount(payAmount.setScale(2, RoundingMode.HALF_EVEN));
+ order.setRefundAmount(refundAmount.setScale(2, RoundingMode.HALF_EVEN));
+ order.setRefundStatus(1);
+ this.updateById(order);
+ chargingOrder = this.getById(order.getId());
+
+ //推送三方平台
+ if(2 == chargingOrder.getOrderSource()){
+ TChargingOrder finalChargingOrder = chargingOrder;
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ tcecClient.notificationEquipChargeStatus(finalChargingOrder.getStartChargeSeq(), finalChargingOrder.getOperatorId());
+ tcecClient.notificationStopChargeResult(finalChargingOrder.getStartChargeSeq(), finalChargingOrder.getChargingGunId().toString(),
+ finalChargingOrder.getOperatorId());
+ tcecClient.notificationChargeOrderInfo(finalChargingOrder.getStartChargeSeq(), finalChargingOrder.getOperatorId());
+ }
+ }).start();
+ }
+
+ //开始将优惠券优惠的金额添加到明细中
+ BigDecimal couponDiscountAmount = order.getCouponDiscountAmount();
+ if(null != couponDiscountAmount && couponDiscountAmount.compareTo(BigDecimal.ZERO) > 0){
+ List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, order.getId()));
+ BigDecimal reduce = list.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+ for (TChargingOrderAccountingStrategy chargingOrderAccountingStrategy : list) {
+ BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodServicePrice();
+ BigDecimal multiply = couponDiscountAmount.multiply(periodServicePrice.divide(reduce, new MathContext(4, RoundingMode.HALF_EVEN)));
+ periodServicePrice = periodServicePrice.subtract(multiply);
+ chargingOrderAccountingStrategy.setPeriodServicePrice(periodServicePrice.setScale(2, RoundingMode.HALF_EVEN));
+ chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.HALF_EVEN));
+ }
+ chargingOrderAccountingStrategyService.updateBatchById(list);
+ }
+
+ // 将枪状态重置为空闲
+ TChargingGun chargingGun = new TChargingGun();
+ chargingGun.setId(chargingOrder.getChargingGunId());
+ chargingGun.setStatus(2);
+ chargingGun.setChargingPower(BigDecimal.ZERO);
+ chargingGunClient.updateChargingGunById(chargingGun);
+ //推送状态给三方平台
+ if(2 == chargingOrder.getOrderSource()){
+ tcecClient.pushChargingGunStatus(chargingGun.getFullNumber(), chargingGun.getStatus());
+ }
+
+ //添加积分
+ if(1 == chargingOrder.getOrderSource()){
+ TIntegralRule integralRule = integralRuleClient.getSet().getData();
+ if(null != integralRule){
+ TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
+ Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1");
+ Integer integral = chargingOrder.getServiceCharge().intValue() * num1;
+ if(null != appUser.getVipId()){
+ TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
+ Integer doubleIntegration = vip.getDoubleIntegration();
+ //双倍积分
+ if(1 == doubleIntegration){
+ integral *= 2;
+ }
}
- appCoupon.setStatus(2);
- appCouponClient.updateAppCoupon(appCoupon);
- }else{
- order.setAppCouponId(null);
- order.setCouponDiscountAmount(BigDecimal.ZERO);
- appCouponClient.refund(chargingOrder.getAppCouponId().toString());
- }
- }
- }
- //优惠券优惠金额
- couponDiscount = couponDiscount.setScale(4, RoundingMode.HALF_EVEN);
- //退款金额+优惠券
- refundAmount = refundAmount.add(couponDiscount);
- //实际支付金额-优惠券
- payAmount = payAmount.subtract(couponDiscount);
- if(serviceCharge_total.compareTo(BigDecimal.ZERO) > 0){
- serviceCharge_total = serviceCharge_total.subtract(couponDiscount);
- }
- order.setCouponDiscountAmount(couponDiscount.setScale(2, RoundingMode.HALF_EVEN));
- order.setServiceCharge(serviceCharge_total.setScale(2, RoundingMode.HALF_EVEN));
- order.setPaymentAmount(payAmount.setScale(2, RoundingMode.HALF_EVEN));
- order.setRefundAmount(refundAmount.setScale(2, RoundingMode.HALF_EVEN));
- order.setRefundStatus(1);
- this.updateById(order);
- chargingOrder = this.getById(order.getId());
-
- //推送三方平台
- if(2 == chargingOrder.getOrderSource()){
- TChargingOrder finalChargingOrder = chargingOrder;
- new Thread(new Runnable() {
- @Override
- public void run() {
- tcecClient.notificationEquipChargeStatus(finalChargingOrder.getStartChargeSeq(), finalChargingOrder.getOperatorId());
- tcecClient.notificationStopChargeResult(finalChargingOrder.getStartChargeSeq(), finalChargingOrder.getChargingGunId().toString(),
- finalChargingOrder.getOperatorId());
- tcecClient.notificationChargeOrderInfo(finalChargingOrder.getStartChargeSeq(), finalChargingOrder.getOperatorId());
- }
- }).start();
- }
-
- //开始将优惠券优惠的金额添加到明细中
- BigDecimal couponDiscountAmount = order.getCouponDiscountAmount();
- if(null != couponDiscountAmount && couponDiscountAmount.compareTo(BigDecimal.ZERO) > 0){
- List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, order.getId()));
- BigDecimal reduce = list.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
- for (TChargingOrderAccountingStrategy chargingOrderAccountingStrategy : list) {
- BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodServicePrice();
- BigDecimal multiply = couponDiscountAmount.multiply(periodServicePrice.divide(reduce, new MathContext(4, RoundingMode.HALF_EVEN)));
- periodServicePrice = periodServicePrice.subtract(multiply);
- chargingOrderAccountingStrategy.setPeriodServicePrice(periodServicePrice.setScale(2, RoundingMode.HALF_EVEN));
- chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.HALF_EVEN));
- }
- chargingOrderAccountingStrategyService.updateBatchById(list);
- }
-
- // 将枪状态重置为空闲
- TChargingGun chargingGun = new TChargingGun();
- chargingGun.setId(chargingOrder.getChargingGunId());
- chargingGun.setStatus(2);
- chargingGun.setChargingPower(BigDecimal.ZERO);
- chargingGunClient.updateChargingGunById(chargingGun);
- //推送状态给三方平台
- if(2 == chargingOrder.getOrderSource()){
- tcecClient.pushChargingGunStatus(chargingGun.getFullNumber(), chargingGun.getStatus());
- }
-
- //添加积分
- if(1 == chargingOrder.getOrderSource()){
- TIntegralRule integralRule = integralRuleClient.getSet().getData();
- if(null != integralRule){
- TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
- Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1");
- Integer integral = chargingOrder.getServiceCharge().intValue() * num1;
- if(null != appUser.getVipId()){
- TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
- Integer doubleIntegration = vip.getDoubleIntegration();
- //双倍积分
- if(1 == doubleIntegration){
- integral *= 2;
+ if(integral > 0){
+ TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange();
+ appUserIntegralChange.setAppUserId(appUser.getId());
+ appUserIntegralChange.setChangeType(2);
+ appUserIntegralChange.setHistoricalIntegral(appUser.getPoints());
+ appUser.setPoints(appUser.getPoints() + integral);
+ appUserIntegralChange.setCurrentIntegral(appUser.getPoints());
+ appUserIntegralChange.setCreateTime(LocalDateTime.now());
+ appUserIntegralChange.setOrderCode(chargingOrder.getCode());
+ appUserIntegralChange.setExtension(chargingOrder.getId().toString());
+ appUserClient.updateAppUser(appUser);
+ appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
}
}
- if(integral > 0){
- TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange();
- appUserIntegralChange.setAppUserId(appUser.getId());
- appUserIntegralChange.setChangeType(2);
- appUserIntegralChange.setHistoricalIntegral(appUser.getPoints());
- appUser.setPoints(appUser.getPoints() + integral);
- appUserIntegralChange.setCurrentIntegral(appUser.getPoints());
- appUserIntegralChange.setCreateTime(LocalDateTime.now());
- appUserIntegralChange.setOrderCode(chargingOrder.getCode());
- appUserIntegralChange.setExtension(chargingOrder.getId().toString());
- appUserClient.updateAppUser(appUser);
- appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
- }
- }
-
- //计算用户标签
- editUserTag(chargingOrder);
- //用户推荐奖励
- referralReward(chargingOrder);
-
- //开始构建退款费用
- refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN);
- if(refundAmount.compareTo(BigDecimal.ZERO) > 0){
- Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
- //构建退款明细
- TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund();
- chargingOrderRefund.setChargingOrderId(chargingOrder.getId());
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
- chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue()));
- chargingOrderRefund.setRefundAmount(refundAmount);
- chargingOrderRefund.setRefundStatus(1);
- chargingOrderRefund.setPayType(rechargePaymentType);
- chargingOrderRefund.setRefundStatus(1);
- chargingOrderRefund.setCode(chargingOrder.getCode());
- chargingOrderRefund.setRefundTitle("充电完成退款");
- chargingOrderRefund.setRefundContent("充电完成退款");
- chargingOrderRefund.setRefundReason("充电完成退款");
- chargingOrderRefund.setRefundRemark("实际充电消费金额:" + chargingOrder.getPaymentAmount());
- chargingOrderRefund.setRefundTotalAmount(refundAmount);
- chargingOrderRefund.setPayAmount(rechargeAmount);
- if(1 == rechargePaymentType){
- WxPaymentRefundModel model = new WxPaymentRefundModel();
- model.setOut_trade_no(chargingOrder.getCode());
- model.setOut_refund_no(chargingOrderRefund.getRefundCode());
- model.setReason("充电完成退款");
- model.setNotify_url("/payment/wx/refund/notify");
- WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount();
- amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue());
- amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
- amount.setCurrency("CNY");
- model.setAmount(amount);
- R<Map<String, Object>> result = wxPaymentClient.refundOrderR(model);
- if(200 == result.getCode()){
- chargingOrderRefundService.save(chargingOrderRefund);
- //手续费
- Map<String, Object> amount1 = (Map<String, Object>) result.getData().get("amount");
- Object refund_fee1 = amount1.get("refund_fee");
- BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
- chargingOrderRefund.setRefundFee(refund_fee);
- chargingOrderRefundService.updateById(chargingOrderRefund);
- }
- }
- if(2 == rechargePaymentType){
- RefundReq dto = new RefundReq();
- dto.setOutTradeNo(chargingOrder.getCode());
- dto.setOutRequestNo(chargingOrderRefund.getRefundCode());
- dto.setRefundAmount(refundAmount.toString());
- dto.setRefundReason("充电完成退款");
- RefundResp resp = aliPaymentClient.refund(dto).getData();
- if(null != resp){
- chargingOrderRefundService.save(chargingOrderRefund);
- this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
- }
- }
+ //计算用户标签
+ editUserTag(chargingOrder);
+ //用户推荐奖励
+ referralReward(chargingOrder);
+ //开始构建退款费用
+ refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN);
+ if(refundAmount.compareTo(BigDecimal.ZERO) > 0){
+ Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
+ //构建退款明细
+ TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund();
+ chargingOrderRefund.setChargingOrderId(chargingOrder.getId());
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+ chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue()));
+ chargingOrderRefund.setRefundAmount(refundAmount);
+ chargingOrderRefund.setRefundStatus(1);
+ chargingOrderRefund.setPayType(rechargePaymentType);
+ chargingOrderRefund.setRefundStatus(1);
+ chargingOrderRefund.setCode(chargingOrder.getCode());
+ chargingOrderRefund.setRefundTitle("充电完成退款");
+ chargingOrderRefund.setRefundContent("充电完成退款");
+ chargingOrderRefund.setRefundReason("充电完成退款");
+ chargingOrderRefund.setRefundRemark("实际充电消费金额:" + chargingOrder.getPaymentAmount());
+ chargingOrderRefund.setRefundTotalAmount(refundAmount);
+ chargingOrderRefund.setPayAmount(rechargeAmount);
+ if(1 == rechargePaymentType){
+ WxPaymentRefundModel model = new WxPaymentRefundModel();
+ model.setOut_trade_no(chargingOrder.getCode());
+ model.setOut_refund_no(chargingOrderRefund.getRefundCode());
+ model.setReason("充电完成退款");
+ model.setNotify_url("/payment/wx/refund/notify");
+ WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount();
+ amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue());
+ amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
+ amount.setCurrency("CNY");
+ model.setAmount(amount);
+ R<Map<String, Object>> result = wxPaymentClient.refundOrderR(model);
+ if(200 == result.getCode()){
+ chargingOrderRefundService.save(chargingOrderRefund);
+ //手续费
+ Map<String, Object> amount1 = (Map<String, Object>) result.getData().get("amount");
+ Object refund_fee1 = amount1.get("refund_fee");
+ BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
+ chargingOrderRefund.setRefundFee(refund_fee);
+ chargingOrderRefundService.updateById(chargingOrderRefund);
+ }
+ }
+ if(2 == rechargePaymentType){
+ RefundReq dto = new RefundReq();
+ dto.setOutTradeNo(chargingOrder.getCode());
+ dto.setOutRequestNo(chargingOrderRefund.getRefundCode());
+ dto.setRefundAmount(refundAmount.toString());
+ dto.setRefundReason("充电完成退款");
+ RefundResp resp = aliPaymentClient.refund(dto).getData();
+ if(null != resp){
+ chargingOrderRefundService.save(chargingOrderRefund);
+ this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
+ }
+ }
+
+ }
}
+
+ //添加汇总统计数据
+ List<TChargingOrderAccountingStrategy> list4 = chargingOrderAccountingStrategyService.list(new QueryWrapper<TChargingOrderAccountingStrategy>().eq("charging_order_id", chargingOrder.getId()));
+ BigDecimal electronic_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodElectricPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+ BigDecimal service_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+ BigDecimal chargingCapacity = list4.stream().map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add);
+ BigDecimal serviceMoney = BigDecimal.ZERO;
+ BigDecimal paymentMoney = BigDecimal.ZERO;
+ long time = 0;
+ if (!chargingOrder.getOrderSource().equals(2)) {
+ serviceMoney = serviceMoney.add(service_reduce);
+ paymentMoney = paymentMoney.add(electronic_reduce).add(service_reduce);
+ }else{
+ serviceMoney = serviceMoney.add(service_reduce.multiply(new BigDecimal("0.8")));
+ paymentMoney = paymentMoney.add(electronic_reduce).add(service_reduce.multiply(new BigDecimal("0.8")));
+ }
+ if (chargingOrder.getStartTime()!=null && chargingOrder.getEndTime()!=null){
+ LocalDateTime startTime = chargingOrder.getStartTime();
+ LocalDateTime endTime = chargingOrder.getEndTime();
+ // 计算时间差 单位秒
+ time = ChronoUnit.SECONDS.between(startTime, endTime);
+ }
+ TChargingOrderSummaryData summaryData = new TChargingOrderSummaryData();
+ summaryData.setChargingOrderId(chargingOrder.getId());
+ summaryData.setChargingCapacity(chargingCapacity);
+ summaryData.setChargingDuration(time);
+ summaryData.setIncome(paymentMoney.setScale(2, BigDecimal.ROUND_HALF_EVEN));
+ summaryData.setElectricPrice(electronic_reduce.setScale(2, BigDecimal.ROUND_HALF_EVEN));
+ summaryData.setServicePrice(serviceMoney.setScale(2, BigDecimal.ROUND_HALF_EVEN));
+ chargingOrderSummaryDataService.save(summaryData);
+ }catch (Exception e) {
+ e.printStackTrace();
+ }finally {
+ redisService.deleteObject("endOrder:" + vo.getTransaction_serial_number());
}
-
- //添加汇总统计数据
- List<TChargingOrderAccountingStrategy> list4 = chargingOrderAccountingStrategyService.list(new QueryWrapper<TChargingOrderAccountingStrategy>().eq("charging_order_id", chargingOrder.getId()));
- BigDecimal electronic_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodElectricPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
- BigDecimal service_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
- BigDecimal chargingCapacity = list4.stream().map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add);
- BigDecimal serviceMoney = BigDecimal.ZERO;
- BigDecimal paymentMoney = BigDecimal.ZERO;
- long time = 0;
- if (!chargingOrder.getOrderSource().equals(2)) {
- serviceMoney = serviceMoney.add(service_reduce);
- paymentMoney = paymentMoney.add(electronic_reduce).add(service_reduce);
- }else{
- serviceMoney = serviceMoney.add(service_reduce.multiply(new BigDecimal("0.8")));
- paymentMoney = paymentMoney.add(electronic_reduce).add(service_reduce.multiply(new BigDecimal("0.8")));
- }
- if (chargingOrder.getStartTime()!=null && chargingOrder.getEndTime()!=null){
- LocalDateTime startTime = chargingOrder.getStartTime();
- LocalDateTime endTime = chargingOrder.getEndTime();
- // 计算时间差 单位秒
- time = ChronoUnit.SECONDS.between(startTime, endTime);
- }
- TChargingOrderSummaryData summaryData = new TChargingOrderSummaryData();
- summaryData.setChargingOrderId(chargingOrder.getId());
- summaryData.setChargingCapacity(chargingCapacity);
- summaryData.setChargingDuration(time);
- summaryData.setIncome(paymentMoney.setScale(2, BigDecimal.ROUND_HALF_EVEN));
- summaryData.setElectricPrice(electronic_reduce.setScale(2, BigDecimal.ROUND_HALF_EVEN));
- summaryData.setServicePrice(serviceMoney.setScale(2, BigDecimal.ROUND_HALF_EVEN));
- chargingOrderSummaryDataService.save(summaryData);
return R.ok();
}
--
Gitblit v1.7.1