From 5e4c675bb466226fec57cc6c3d56837e71fd99f2 Mon Sep 17 00:00:00 2001 From: yuyang Date: Thu, 27 Jan 2022 17:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A4=BE=E5=8C=BA=E3=80=81B?= =?UTF-8?q?=E7=AB=AF=E7=94=A8=E6=88=B7=E5=85=85=E7=94=B5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xhpc/common/core/constant/Constants.java | 5 + .../service/impl/XhpcInvoiceServiceImpl.java | 2 +- .../order/api/XhpcPileOrderController.java | 32 +- .../order/mapper/XhpcChargeOrderMapper.java | 20 +- .../service/IXhpcChargeOrderService.java | 2 +- .../service/IXhpcRealTimeOrderService.java | 7 +- .../impl/XhpcChargeOrderServiceImpl.java | 242 ++++---- .../impl/XhpcHistoryOrderServiceImpl.java | 8 +- .../impl/XhpcRealTimeOrderServiceImpl.java | 529 +++++++++--------- .../mapper/XhpcChargeOrderMapper.xml | 10 +- 10 files changed, 470 insertions(+), 387 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java index 9f36a59f..656eb56d 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java @@ -197,4 +197,9 @@ public class Constants * 模板id为null */ public static final String LNVALID_RATE_MODE = "lnvalid rateModelId"; + + /** + * 数据问题(报错) + */ + public static final String DATA_EXCEPTION = "data exception"; } diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java index bbe93280..244cc220 100644 --- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java @@ -326,7 +326,7 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService { OrderDatasDTO orderDatasDTO = new OrderDatasDTO(); orderDatasDTO.setOrderId((Long) data.get("historyOrderId")); orderDatasDTO.setOrderNumber((String) data.get("serialNumber")); - orderDatasDTO.setOrderMoney((BigDecimal) data.get("actPrice")); + orderDatasDTO.setOrderMoney(new BigDecimal(data.get("actPrice").toString())); //因为数据库中存储的时间类型为datetime,所以Mybatis会将其转换为LocalDateTime类型对象,我们不能直接得到Date,所以我们需要对其进行转换。 LocalDateTime createTime = (LocalDateTime) data.get("createTime"); ZoneId zoneId = ZoneId.systemDefault(); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java index e02ceed1..a26f13e2 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java @@ -396,22 +396,26 @@ public class XhpcPileOrderController extends BaseController { } xhpcHistoryOrder.setType(1); //结算 - xhpcRealTimeOrderService.addSettlement(powerPrice,servicePrice,money,surplusPowerPrice,surplusServicePrice,xhpcChargeOrder,userId,userMessage,1,cacheOrderData.getVinNormal(),xhpcHistoryOrder); - Map map = new HashMap<>(); - map.put("code", 500); - map.put("userId", userId); - JSONObject json = new JSONObject(map); + R r = xhpcRealTimeOrderService.addSettlement(powerPrice,servicePrice,money,surplusPowerPrice,surplusServicePrice,xhpcChargeOrder,userId,userMessage,1,cacheOrderData.getVinNormal(),xhpcHistoryOrder); + if(r.getCode()==200){ + Map map = new HashMap<>(); + map.put("code", 500); + map.put("userId", userId); + JSONObject json = new JSONObject(map); - if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ - String message =""; - if(UserTypeUtil.USER_TYPE.equals(source)){ - message=tenantId+UserTypeUtil.USER+userId; - }else if(UserTypeUtil.COMMUNIT_TYPE.equals(source)){ - message=tenantId+UserTypeUtil.COMMUNIT+userId; - }else{ - message=tenantId+UserTypeUtil.CUSTOMERS+userId; + if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ + String message =""; + if(UserTypeUtil.USER_TYPE.equals(source)){ + message=tenantId+UserTypeUtil.USER+userId; + }else if(UserTypeUtil.COMMUNIT_TYPE.equals(source)){ + message=tenantId+UserTypeUtil.COMMUNIT+userId; + }else{ + message=tenantId+UserTypeUtil.CUSTOMERS+userId; + } + webSocketService.getMessage(message,json.toString()); } - webSocketService.getMessage(message,json.toString()); + }else{ + return R.fail(); } }catch (Exception e){ e.printStackTrace(); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java index f682d2e6..c79fbff3 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java @@ -44,13 +44,29 @@ public interface XhpcChargeOrderMapper { Map getUserMessage(@Param("userId")Long userId); /** - * 修改余额 + * C端用户修改余额 * @param userId * @param balance * @return */ int updateUserBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance); + /** + * 社区用户修改余额 + * @param userId + * @param balance + * @return + */ + int updateCommunityBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance); + + + /** + * B端用户修改余额 + * @param userId + * @param balance + * @return + */ + int updateCustomersBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance); /** * 判断用户是否在充电中 */ @@ -137,7 +153,7 @@ public interface XhpcChargeOrderMapper { * @param date 时间 * @return */ - int insertUserAccountStatement(@Param("userId") Long userId,@Param("amount") BigDecimal amount,@Param("remainingSum") BigDecimal remainingSum,@Param("chargeOrderId") Long chargeOrderId,@Param("type") Integer type,@Param("date") Date date); + int insertUserAccountStatement(@Param("userId") Long userId,@Param("amount") BigDecimal amount,@Param("remainingSum") BigDecimal remainingSum,@Param("chargeOrderId") Long chargeOrderId,@Param("type") Integer type,@Param("date") Date date,@Param("source")Integer source); /** * 获取费率 diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java index 134f3527..6e656e04 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java @@ -129,7 +129,7 @@ public interface IXhpcChargeOrderService { * @return */ int addUserAccountStatement(Long userId, BigDecimal amount, BigDecimal remainingSum, Long chargeOrderId, Integer type, - Date date); + Date date,Integer source); XhpcChargeOrder getChargingOrderId(Long chargingOrderId); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java index 1bddceb4..5849f419 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java @@ -1,5 +1,6 @@ package com.xhpc.order.service; +import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.order.domain.*; @@ -115,9 +116,9 @@ public interface IXhpcRealTimeOrderService { * @param type 0 不发短信 1发短信 * @param vinNormal VUN 码 */ - void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, - BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, - Map userMessage, Integer type, String vinNormal, XhpcHistoryOrder xhpcHistoryOrder); + R addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, + BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, + Map userMessage, Integer type, String vinNormal, XhpcHistoryOrder xhpcHistoryOrder); /** * 添加redis到数据库 diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java index 0bcecfd1..c5949c45 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; @@ -230,8 +231,8 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar //用户、桩、平台(最小的) int number =0; - if(!"".equals(userMessage.get("soc")) && userMessage.get("soc") !=null && !"".equals(userMessage.get("soc"))){ - number =Integer.parseInt(userMessage.get("soc").toString()); + if(!"".equals(userMessage.get("socUser")) && userMessage.get("socUser") !=null && !"".equals(userMessage.get("socUser"))){ + number =Integer.parseInt(userMessage.get("socUser").toString()); } //平台 String soc = redisService.getCacheObject("global:SOC"); @@ -381,8 +382,15 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar @Override public int updateUserBalance(Long userId, BigDecimal balance,Integer source,String tenantId) { - - return xhpcChargeOrderMapper.updateUserBalance(userId, balance); + //修改用户余额 + if(UserTypeUtil.USER_TYPE.equals(source)){ + return xhpcChargeOrderMapper.updateUserBalance(userId, balance); + }else if (UserTypeUtil.COMMUNIT_TYPE.equals(source)){ + return xhpcChargeOrderMapper.updateCommunityBalance(userId, balance); + }else if(UserTypeUtil.CUSTOMERS_TYPE.equals(source)){ + return xhpcChargeOrderMapper.updateCustomersBalance(userId, balance); + } + return 0; } @Override @@ -399,9 +407,9 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar @Override public int addUserAccountStatement(Long userId, BigDecimal amount, BigDecimal remainingSum, Long chargeOrderId, - Integer type, Date date) { + Integer type, Date date,Integer source) { - return xhpcChargeOrderMapper.insertUserAccountStatement(userId, amount, remainingSum, chargeOrderId, type, date); + return xhpcChargeOrderMapper.insertUserAccountStatement(userId, amount, remainingSum, chargeOrderId, type, date,source); } @Override @@ -629,116 +637,148 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar @Override public R cardStartup(Long userId, String serialNumber, Integer userType,String tenantId, Integer type, String grantOperator,String rateModelId) { + try{ + R user = userTypeService.getUser(null, userId, userType, null,tenantId); + if(user ==null || user.getData() ==null){ + return R.fail(Constants.LNVALID_USER); + } - R user = userTypeService.getUser(null, userId, userType, null,tenantId); - if(user ==null || user.getData() ==null){ - return R.fail(Constants.LNVALID_USER); - } + Map userMessage = (Map)user.getData(); + //桩号是否有效 + String pattern = "^([0-9]{16})"; + Pattern compile = Pattern.compile(pattern); + Matcher m = compile.matcher(serialNumber); + if (serialNumber.length() != 16 || !m.matches()) { + return R.fail(Constants.LNVALID_TERMINAL); + } - Map userMessage = (Map)user.getData(); - //桩号是否有效 - String pattern = "^([0-9]{16})"; - Pattern compile = Pattern.compile(pattern); - Matcher m = compile.matcher(serialNumber); - if (serialNumber.length() != 16 || !m.matches()) { - return R.fail(Constants.LNVALID_TERMINAL); - } + //终端信息 + XhpcTerminal xhpcTerminal = xhpcChargeOrderMapper.getXhpcTerminalSerialNumber(serialNumber,tenantId); + if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) { + return R.fail(Constants.LNVALID_TERMINAL); + } - //终端信息 - XhpcTerminal xhpcTerminal = xhpcChargeOrderMapper.getXhpcTerminalSerialNumber(serialNumber,tenantId); - if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) { - return R.fail(Constants.LNVALID_TERMINAL); - } + if(type !=0){ + //获取桩信息 + Map xhpcChargingPileById =xhpcChargeOrderMapper.getXhpcChargingPileById(xhpcTerminal.getChargingPileId(),tenantId); + if(xhpcChargingPileById ==null || !xhpcChargingPileById.get("operatorId").toString().equals(grantOperator)){ + return R.fail(Constants.LNVALID_OPERATOR); + } + } - if(type !=0){ + + BigDecimal a = new BigDecimal(5); + if (userMessage == null || userMessage.get("balance") == null || a.compareTo(new BigDecimal(userMessage.get("balance").toString())) == 1) { + return R.fail(Constants.INSUFFICIENT_ACCOUNT); + } + + //充电用户是否存在异常的订单 + int j = xhpcChargeOrderMapper.countXhpcChargeOrder(userId,userType,tenantId); + if (j > 0) { + return R.fail(Constants.EXCEPTION_ORDER); + } + //查看充电用户是否有申请退款的订单,还未处理 + if (Integer.parseInt(userMessage.get("isRefundApplication").toString()) != 0) { + return R.fail(Constants.REFUND_ORDER); + } + //充电用户是否在充电中 + String i = xhpcChargeOrderMapper.countXhpcRealTimeOrder(userId,userType,tenantId); + if (!"".equals(i) && i!=null) { + return R.fail(Constants.CHARGE_ORDER); + } + Map cacheMap = REDIS.getCacheMap("gun:" + serialNumber); + if(cacheMap==null){ + return R.fail(Constants.UNREGISTERED_TERMINAL); + }else{ + if(cacheMap.get("status") ==null){ + return R.fail(Constants.UNKNOWN_TERMINAL); + }else{ + String status = cacheMap.get("status").toString(); + //不同的状态 + if("离线".equals(status)){ + return R.fail(Constants.OFFLINE_TERMINAL); + } + if("故障".equals(status)){ + return R.fail(Constants.FAULT_TERMINAL); + } + if("充电".equals(status)){ + return R.fail(Constants.CHARGE_TERMINAL); + } + } + if(cacheMap.get("vehicleGunStatus") ==null){ + return R.fail(Constants.UNKNOWN_GUN); + }else{ + String vehicleGunStatus = cacheMap.get("vehicleGunStatus").toString(); + if(!"是".equals(vehicleGunStatus)){ + return R.fail(Constants.INSERT_THE_GUN); + } + } + } + + //创建订单 + //订单流水号 终端号+年月日时分秒+自增4位 共32位 + String orderNo = genOrder(serialNumber); + XhpcChargeOrder xhpcChargeOrder = new XhpcChargeOrder(); + xhpcChargeOrder.setChargingStationId(xhpcTerminal.getChargingStationId()); + xhpcChargeOrder.setUserId(userId); + xhpcChargeOrder.setTerminalId(xhpcTerminal.getTerminalId()); + xhpcChargeOrder.setGunId(xhpcTerminal.getSerialNumber()); + xhpcChargeOrder.setSerialNumber(orderNo); + xhpcChargeOrder.setSource(userType); + xhpcChargeOrder.setStatus(-1); + xhpcChargeOrder.setTenantId(tenantId); //获取桩信息 Map xhpcChargingPileById =xhpcChargeOrderMapper.getXhpcChargingPileById(xhpcTerminal.getChargingPileId(),tenantId); - if(xhpcChargingPileById ==null || !xhpcChargingPileById.get("operatorId").toString().equals(grantOperator)){ - return R.fail(Constants.LNVALID_OPERATOR); + if (xhpcChargingPileById != null && xhpcChargingPileById.get("power") != null) { + xhpcChargeOrder.setPower(xhpcChargingPileById.get("power").toString()); } - } + xhpcChargeOrder.setRateModelId(Long.valueOf(rateModelId)); + xhpcChargeOrder.setChargingMode("刷卡"); + xhpcChargeOrder.setCreateTime(Calendar.getInstance().getTime()); + xhpcChargeOrder.setType(40); + xhpcChargeOrderMapper.addXhpcChargeOrder(xhpcChargeOrder); - BigDecimal a = new BigDecimal(5); - if (userMessage == null || userMessage.get("balance") == null || a.compareTo(new BigDecimal(userMessage.get("balance").toString())) == 1) { - return R.fail(Constants.INSUFFICIENT_ACCOUNT); - } + //插一帧实时数据 + extracted(xhpcChargeOrder); - //充电用户是否存在异常的订单 - int j = xhpcChargeOrderMapper.countXhpcChargeOrder(userId,userType,tenantId); - if (j > 0) { - return R.fail(Constants.EXCEPTION_ORDER); - } - //查看充电用户是否有申请退款的订单,还未处理 - if (Integer.parseInt(userMessage.get("isRefundApplication").toString()) != 0) { - return R.fail(Constants.REFUND_ORDER); - } - //充电用户是否在充电中 - String i = xhpcChargeOrderMapper.countXhpcRealTimeOrder(userId,userType,tenantId); - if (!"".equals(i) && i!=null) { - return R.fail(Constants.CHARGE_ORDER); - } - Map cacheMap = REDIS.getCacheMap("gun:" + serialNumber); - if(cacheMap==null){ - return R.fail(Constants.UNREGISTERED_TERMINAL); - }else{ - if(cacheMap.get("status") ==null){ - return R.fail(Constants.UNKNOWN_TERMINAL); - }else{ - String status = cacheMap.get("status").toString(); - //不同的状态 - if("离线".equals(status)){ - return R.fail(Constants.OFFLINE_TERMINAL); - } - if("故障".equals(status)){ - return R.fail(Constants.FAULT_TERMINAL); - } - if("充电".equals(status)){ - return R.fail(Constants.CHARGE_TERMINAL); + Map map =new HashMap<>(); + map.put("balance",userMessage.get("balance")); + map.put("serialNumber",orderNo); + //用户、桩、平台(最小的) + int number =0; + if(!"".equals(userMessage.get("socUser")) && userMessage.get("socUser") !=null && !"".equals(userMessage.get("socUser"))){ + number =Integer.parseInt(userMessage.get("socUser").toString()); + } + //平台 + String soc = redisService.getCacheObject("global:SOC"); + if(!"".equals(soc) && soc!=null){ + if(number!=0){ + if(Integer.parseInt(soc)-number<0){ + number=Integer.parseInt(soc); + } + }else{ + number=Integer.parseInt(soc); } } - if(cacheMap.get("vehicleGunStatus") ==null){ - return R.fail(Constants.UNKNOWN_GUN); - }else{ - String vehicleGunStatus = cacheMap.get("vehicleGunStatus").toString(); - if(!"是".equals(vehicleGunStatus)){ - return R.fail(Constants.INSERT_THE_GUN); + Map operatorMessage = xhpcChargeOrderMapper.getOperatorMessage(xhpcTerminal.getChargingStationId()); + if(operatorMessage !=null && operatorMessage.get("soc") !=null && !"".equals(operatorMessage.get("soc"))){ + if(number!=0){ + if(Integer.parseInt(operatorMessage.get("soc").toString())-number<0){ + number=Integer.parseInt(operatorMessage.get("soc").toString()); + } + }else{ + number=Integer.parseInt(operatorMessage.get("soc").toString()); } + } + map.put("soc",number); + return R.ok(map); + }catch (Exception e){ + //数据回滚 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } - - //创建订单 - //订单流水号 终端号+年月日时分秒+自增4位 共32位 - String orderNo = genOrder(serialNumber); - XhpcChargeOrder xhpcChargeOrder = new XhpcChargeOrder(); - xhpcChargeOrder.setChargingStationId(xhpcTerminal.getChargingStationId()); - xhpcChargeOrder.setUserId(userId); - xhpcChargeOrder.setTerminalId(xhpcTerminal.getTerminalId()); - xhpcChargeOrder.setGunId(xhpcTerminal.getSerialNumber()); - xhpcChargeOrder.setSerialNumber(orderNo); - xhpcChargeOrder.setSource(userType); - xhpcChargeOrder.setStatus(-1); - xhpcChargeOrder.setTenantId(tenantId); - //获取桩信息 - Map xhpcChargingPileById =xhpcChargeOrderMapper.getXhpcChargingPileById(xhpcTerminal.getChargingPileId(),tenantId); - if (xhpcChargingPileById != null && xhpcChargingPileById.get("power") != null) { - xhpcChargeOrder.setPower(xhpcChargingPileById.get("power").toString()); - } - xhpcChargeOrder.setRateModelId(Long.valueOf(rateModelId)); - xhpcChargeOrder.setChargingMode("刷卡"); - - xhpcChargeOrder.setCreateTime(Calendar.getInstance().getTime()); - xhpcChargeOrder.setType(40); - xhpcChargeOrderMapper.addXhpcChargeOrder(xhpcChargeOrder); - - //插一帧实时数据 - extracted(xhpcChargeOrder); - - Map map =new HashMap<>(); - map.put("balance",userMessage.get("balance")); - map.put("serialNumber",orderNo); - - return R.ok(map); + return R.fail(Constants.DATA_EXCEPTION); } public static boolean isValidDate(String str) { diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java index 84e52108..b002ef45 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java @@ -650,7 +650,7 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis } //扣除用户实际消费金额,添加消费记录-余的钱 - BigDecimal balance1 =(BigDecimal) userMessage.get("balance"); + BigDecimal balance1 =new BigDecimal(userMessage.get("balance").toString()); BigDecimal subtract = balance1.subtract(actPrice); int i = xhpcChargeOrderService.updateUserBalance(userId, subtract,source,xhpcChargeOrder.getTenantId()); if(i==0){ @@ -659,7 +659,7 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis xhpcChargeOrder.setErroRemark("扣钱失败"); }else{ //添加流水 - xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); + xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date,source); map.put("userId",userId); map.put("amount",subtract); if(userMessage.get("weixinOpenId") !=null && !"".equals(userMessage.get("weixinOpenId").toString())){ @@ -749,8 +749,8 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis Date updateTime = DateUtil.endOfDay(startTime2); Map map1 = getBigDecimal(actPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree, list); //获取 - BigDecimal powerPriceTotal1 = (BigDecimal) map1.get("powerPriceTotal"); - BigDecimal servicePriceTotal1 = (BigDecimal) map1.get("servicePriceTotal"); + BigDecimal powerPriceTotal1 = new BigDecimal(map1.get("powerPriceTotal").toString()); + BigDecimal servicePriceTotal1 = new BigDecimal(map1.get("servicePriceTotal").toString()); //明天 DateTime tomorrow = DateUtil.offsetDay(startTime2, 1); Date startTime3 = DateUtil.beginOfDay(tomorrow); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java index 73c0aa0a..82ae3f3b 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.xhpc.common.api.RefundOrderService; import com.xhpc.common.api.SmsService; +import com.xhpc.common.core.domain.R; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.service.BaseService; @@ -23,6 +24,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.math.BigDecimal; import java.util.*; @@ -355,287 +357,296 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe * @param type 0 不发短信 1发短信 */ @Override - public void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map userMessage,Integer type,String vinNormal,XhpcHistoryOrder xhpcHistoryOrder) { - xhpcHistoryOrder.setPowerPriceTotal(powerPrice); - xhpcHistoryOrder.setServicePriceTotal(servicePrice); - xhpcHistoryOrder.setVinNormal(vinNormal); + public R addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map userMessage, Integer type, String vinNormal, XhpcHistoryOrder xhpcHistoryOrder) { - //电站活动抵扣--抵扣的总金额 - BigDecimal promotionDiscount = new BigDecimal(0); - //实际价格-用户支付的钱 - BigDecimal actPrice =money; - //流量方总金额抽成 - BigDecimal internetCommission =new BigDecimal(0); - //流量方服务费抽成 - BigDecimal internetSvcCommission =new BigDecimal(0); - //流量方电量抽成 - BigDecimal internetDegreeCommission =new BigDecimal(0); - //平台总金额抽成 - BigDecimal platformCommission =new BigDecimal(0); - //平台服务费抽成 - BigDecimal platformSvcCommission =new BigDecimal(0); - //运维总抽成 - BigDecimal operationCommission =new BigDecimal(0); - //运维服务费抽成 - BigDecimal operationSvcCommission =new BigDecimal(0); - //判断是C端用户还是流量端用户 - //先计算第三方优惠力度 - Integer source = xhpcChargeOrder.getSource(); - String internetSerialNumber = xhpcChargeOrder.getInternetSerialNumber(); - if(source==1 && internetSerialNumber!=null){ - String substring = internetSerialNumber.substring(0, 9); - xhpcHistoryOrder.setInternetSerialNumber(xhpcChargeOrder.getInternetSerialNumber()); - Map operatorIdEvcs = xhpcRealTimeOrderMapper.getOperatorIdEvcs(substring); - if(operatorIdEvcs !=null){ - if(operatorIdEvcs.get("operatorIdEvcs")!=null && operatorIdEvcs.get("commissionType")!=null && operatorIdEvcs.get("commissionRate")!=null){ - BigDecimal commissionRate = new BigDecimal(operatorIdEvcs.get("commissionRate").toString()).divide(new BigDecimal(100)); - String commissionType = operatorIdEvcs.get("commissionType").toString(); - if(operatorIdEvcs.get("internetUserId") !=null){ - xhpcHistoryOrder.setChargingMode(operatorIdEvcs.get("internetUserId").toString()); - } - //0总金额提成 1服务费提成 - if(new BigDecimal(0).compareTo(commissionRate)==-1){ - if("0".equals(commissionType) || "1".equals(commissionType)|| "2".equals(commissionType)){ - //流量方的钱 - if("0".equals(commissionType)){ - BigDecimal decimal1 = surplusPowerPrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); - BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); - internetCommission = decimal1.add(decimal2); - surplusPowerPrice =surplusPowerPrice.subtract(decimal1); - surplusServicePrice =surplusServicePrice.subtract(decimal2); - }else if("1".equals(commissionType)){ - BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); - internetSvcCommission = decimal2; - surplusServicePrice = surplusServicePrice.subtract(decimal2); - }else{ - //电量抽成 - BigDecimal chargingDegree = xhpcChargeOrder.getChargingDegree(); - internetDegreeCommission = chargingDegree.multiply(new BigDecimal(operatorIdEvcs.get("commissionRate").toString())).setScale(2, BigDecimal.ROUND_DOWN); - //减服务费 - surplusServicePrice = surplusServicePrice.subtract(internetDegreeCommission); + try{ + xhpcHistoryOrder.setPowerPriceTotal(powerPrice); + xhpcHistoryOrder.setServicePriceTotal(servicePrice); + xhpcHistoryOrder.setVinNormal(vinNormal); + + //电站活动抵扣--抵扣的总金额 + BigDecimal promotionDiscount = new BigDecimal(0); + //实际价格-用户支付的钱 + BigDecimal actPrice =money; + //流量方总金额抽成 + BigDecimal internetCommission =new BigDecimal(0); + //流量方服务费抽成 + BigDecimal internetSvcCommission =new BigDecimal(0); + //流量方电量抽成 + BigDecimal internetDegreeCommission =new BigDecimal(0); + //平台总金额抽成 + BigDecimal platformCommission =new BigDecimal(0); + //平台服务费抽成 + BigDecimal platformSvcCommission =new BigDecimal(0); + //运维总抽成 + BigDecimal operationCommission =new BigDecimal(0); + //运维服务费抽成 + BigDecimal operationSvcCommission =new BigDecimal(0); + //判断是C端用户还是流量端用户 + //先计算第三方优惠力度 + Integer source = xhpcChargeOrder.getSource(); + String internetSerialNumber = xhpcChargeOrder.getInternetSerialNumber(); + if(source==1 && internetSerialNumber!=null){ + String substring = internetSerialNumber.substring(0, 9); + xhpcHistoryOrder.setInternetSerialNumber(xhpcChargeOrder.getInternetSerialNumber()); + Map operatorIdEvcs = xhpcRealTimeOrderMapper.getOperatorIdEvcs(substring); + if(operatorIdEvcs !=null){ + if(operatorIdEvcs.get("operatorIdEvcs")!=null && operatorIdEvcs.get("commissionType")!=null && operatorIdEvcs.get("commissionRate")!=null){ + BigDecimal commissionRate = new BigDecimal(operatorIdEvcs.get("commissionRate").toString()).divide(new BigDecimal(100)); + String commissionType = operatorIdEvcs.get("commissionType").toString(); + if(operatorIdEvcs.get("internetUserId") !=null){ + xhpcHistoryOrder.setChargingMode(operatorIdEvcs.get("internetUserId").toString()); + } + //0总金额提成 1服务费提成 + if(new BigDecimal(0).compareTo(commissionRate)==-1){ + if("0".equals(commissionType) || "1".equals(commissionType)|| "2".equals(commissionType)){ + //流量方的钱 + if("0".equals(commissionType)){ + BigDecimal decimal1 = surplusPowerPrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); + internetCommission = decimal1.add(decimal2); + surplusPowerPrice =surplusPowerPrice.subtract(decimal1); + surplusServicePrice =surplusServicePrice.subtract(decimal2); + }else if("1".equals(commissionType)){ + BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); + internetSvcCommission = decimal2; + surplusServicePrice = surplusServicePrice.subtract(decimal2); + }else{ + //电量抽成 + BigDecimal chargingDegree = xhpcChargeOrder.getChargingDegree(); + internetDegreeCommission = chargingDegree.multiply(new BigDecimal(operatorIdEvcs.get("commissionRate").toString())).setScale(2, BigDecimal.ROUND_DOWN); + //减服务费 + surplusServicePrice = surplusServicePrice.subtract(internetDegreeCommission); + } } } } } } - } - if ( !UserTypeUtil.INTERNET_TYPE.equals(source)) { - //用户第几次充电 - int count = xhpcChargeOrderService.getCount(userId,null,source,xhpcChargeOrder.getTenantId()); - if (count == 0) { - //活动折扣 - Map promotion = xhpcChargeOrderService.getPromotion(); - if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) { - //state 1.总金额 2.电费 3.服务费 discount 折扣率 - String state = promotion.get("state").toString(); - BigDecimal discount =new BigDecimal(promotion.get("discount").toString()).divide(new BigDecimal(100)); + if ( !UserTypeUtil.INTERNET_TYPE.equals(source)) { + //用户第几次充电 + int count = xhpcChargeOrderService.getCount(userId,null,source,xhpcChargeOrder.getTenantId()); + if (count == 0) { + //活动折扣 + Map promotion = xhpcChargeOrderService.getPromotion(); + if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) { + //state 1.总金额 2.电费 3.服务费 discount 折扣率 + String state = promotion.get("state").toString(); + BigDecimal discount =new BigDecimal(promotion.get("discount").toString()).divide(new BigDecimal(100)); - if(discount.compareTo(new BigDecimal(0))==1){ - if("1".equals(state) || "2".equals(state) || "3".equals(state)){ - //折扣的钱 - promotionDiscount=money.multiply(discount).setScale(2,BigDecimal.ROUND_DOWN); - //剩余的总金额 - actPrice = money.subtract(promotionDiscount); - - BigDecimal decimal1 = surplusPowerPrice.multiply(discount).setScale(2, BigDecimal.ROUND_DOWN); - BigDecimal decimal2 = surplusServicePrice.multiply(discount).setScale(2, BigDecimal.ROUND_DOWN); - if("1".equals(state)){ - //总金额 - actPrice =actPrice.subtract(decimal1.add(decimal2)); + if(discount.compareTo(new BigDecimal(0))==1){ + if("1".equals(state) || "2".equals(state) || "3".equals(state)){ //折扣的钱 - promotionDiscount = decimal1.add(decimal2); - surplusPowerPrice = surplusPowerPrice.subtract(decimal1); - surplusServicePrice= surplusServicePrice.subtract(decimal2); - }else if("2".equals(state)){ - //电费 - surplusPowerPrice=surplusPowerPrice.subtract(decimal1); - }else{ - //服务费 - surplusServicePrice =surplusServicePrice.subtract(decimal2); + promotionDiscount=money.multiply(discount).setScale(2,BigDecimal.ROUND_DOWN); + //剩余的总金额 + actPrice = money.subtract(promotionDiscount); + + BigDecimal decimal1 = surplusPowerPrice.multiply(discount).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal decimal2 = surplusServicePrice.multiply(discount).setScale(2, BigDecimal.ROUND_DOWN); + if("1".equals(state)){ + //总金额 + actPrice =actPrice.subtract(decimal1.add(decimal2)); + //折扣的钱 + promotionDiscount = decimal1.add(decimal2); + surplusPowerPrice = surplusPowerPrice.subtract(decimal1); + surplusServicePrice= surplusServicePrice.subtract(decimal2); + }else if("2".equals(state)){ + //电费 + surplusPowerPrice=surplusPowerPrice.subtract(decimal1); + }else{ + //服务费 + surplusServicePrice =surplusServicePrice.subtract(decimal2); + } } } } } } - } - //获取运营商 - Map operatorMessage = xhpcChargeOrderService.getOperatorMessage(xhpcChargeOrder.getChargingStationId()); - if(operatorMessage !=null){ - if(operatorMessage.get("operatorIdEvcs")!=null){ + //获取运营商 + Map operatorMessage = xhpcChargeOrderService.getOperatorMessage(xhpcChargeOrder.getChargingStationId()); + if(operatorMessage !=null){ + if(operatorMessage.get("operatorIdEvcs")!=null){ - if(operatorMessage.get("operatorIdEvcs") !=null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())){ - String stw = operatorMessage.get("operatorIdEvcs").toString(); - if(stw.length()>9){ - xhpcHistoryOrder.setOperatorIdEvcs(stw.substring(8, stw.length() - 1)); - } - } - } - if(operatorMessage.get("maintenanceCommissionRate") !=null && operatorMessage.get("commissionType") !=null && operatorMessage.get("platformCommissionRate") !=null){ - Integer commissionType = (Integer) operatorMessage.get("commissionType"); - //运维提成 - BigDecimal maintenanceCommissionRate = new BigDecimal(operatorMessage.get("maintenanceCommissionRate").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN); - //平台提成 - BigDecimal platformCommissionRate = new BigDecimal(operatorMessage.get("platformCommissionRate").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN); - //提成类型(0总金额提成 1服务费提成) - if(commissionType==0){ - //平台总抽成 - BigDecimal multiply1 = surplusPowerPrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - //运维总抽成 - BigDecimal multiply3 = surplusPowerPrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - - //平台总金额抽成 - platformCommission = multiply1.add(multiply2); - //剩下的钱电费和服务 - surplusPowerPrice = surplusPowerPrice.subtract(multiply1); - surplusServicePrice = surplusServicePrice.subtract(multiply2); - - //运维总金额抽成 - operationCommission = multiply3.add(multiply4); - //剩下的钱电费和服务 - surplusPowerPrice = surplusPowerPrice.subtract(multiply3); - surplusServicePrice = surplusServicePrice.subtract(multiply4); - - }else if(commissionType==1){ - BigDecimal multiply1 = surplusServicePrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - BigDecimal multiply2 = surplusServicePrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - //平台服务费抽成金额 - platformSvcCommission=multiply1; - //剩下的服务费钱 - surplusServicePrice = surplusServicePrice.subtract(multiply1); - - //运维服务费抽成金额 - operationCommission = multiply2; - //剩下的钱 - surplusServicePrice = surplusServicePrice.subtract(multiply2); - } - if("微信".equals(xhpcChargeOrder.getChargingMode())){ - xhpcHistoryOrder.setChargingMode("微信"); - } - if("支付宝".equals(xhpcChargeOrder.getChargingMode())){ - xhpcHistoryOrder.setChargingMode("支付宝"); - } - }else{ - //订单异常 - xhpcChargeOrder.setStatus(2); - //异常原因 - xhpcChargeOrder.setErroRemark("运营商数据为空"); - } - } - Long chargeOrderId = xhpcChargeOrder.getChargeOrderId(); - xhpcHistoryOrder.setChargeOrderId(chargeOrderId); - xhpcHistoryOrder.setChargingStationId(xhpcChargeOrder.getChargingStationId()); - xhpcHistoryOrder.setUserId(userId); - xhpcHistoryOrder.setTerminalId(xhpcChargeOrder.getTerminalId()); - xhpcHistoryOrder.setStartTime(xhpcChargeOrder.getStartTime()); - xhpcHistoryOrder.setStopReasonEvcs(xhpcChargeOrder.getStopReasonEvcs());//todo 从头开始设置所有evcs字段 - xhpcHistoryOrder.setChargeModelEvcs(xhpcChargeOrder.getChargeModelEvcs()); - xhpcHistoryOrder.setSerialNumber(xhpcChargeOrder.getSerialNumber()); - xhpcHistoryOrder.setRateModelId(xhpcChargeOrder.getRateModelId()); - xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); - xhpcHistoryOrder.setReconciliationStatus(0); - xhpcHistoryOrder.setSortingStatus(0); - //订单总价---运维服务费抽成 - xhpcHistoryOrder.setTotalPrice(money.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setPromotionDiscount(promotionDiscount.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setActPrice(actPrice.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setActServicePrice(surplusServicePrice.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setInternetCommission(internetCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setInternetDegreeCommission(internetDegreeCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setPlatformCommission(platformCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setOperationCommission(operationCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); - xhpcHistoryOrder.setEndSoc(xhpcChargeOrder.getEndSoc()); - xhpcHistoryOrder.setReconciliationStatus(0); - xhpcHistoryOrder.setSource(xhpcChargeOrder.getSource()); - Date date = new Date(); - xhpcHistoryOrder.setCreateTime(date); - xhpcHistoryOrder.setChargeModelEvcs(3); - if(xhpcChargeOrder.getPower()!=null){ - xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); - } - Map map =new HashMap<>(); - if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ - xhpcHistoryOrder.setUserNameEvcs(userMessage.get("phone").toString()); - xhpcHistoryOrder.setPhone(userMessage.get("phone").toString()); - //增加流水订单号 - if(operatorMessage!=null && operatorMessage.get("operatorId")!=null){ - String evcs = EvcsUtil.transferInternetOrderNo(xhpcChargeOrder.getSerialNumber(), operatorMessage.get("operatorId").toString()); - xhpcHistoryOrder.setEvcsOrderNo(evcs); - } - - //扣除用户实际消费金额,添加消费记录 剩余的钱 - BigDecimal balance1 =(BigDecimal) userMessage.get("balance"); - BigDecimal subtract = balance1.subtract(actPrice); - int i = xhpcChargeOrderService.updateUserBalance(userId, subtract,xhpcChargeOrder.getSource(),xhpcChargeOrder.getTenantId()); - if(i==0){ - //扣钱失败 - xhpcChargeOrder.setStatus(2); - xhpcChargeOrder.setErroRemark("扣钱失败"); - }else{ - //添加流水 - xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); - map.put("userId",userId); - map.put("amount",subtract); - if(userMessage.get("weixinOpenId") !=null && !"".equals(userMessage.get("weixinOpenId").toString())){ - map.put("openid",userMessage.get("weixinOpenId").toString()); - map.put("type",1); - }else{ - map.put("openid",userMessage.get("alipayOpenId").toString()); - map.put("type",2); - } - map.put("remark","充电结算自动申请退款"); - } - try{ - Map xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId()); - if(xhpcChargingPile !=null){ - //发送短信 - if(userMessage.get("phone") !=null){ - if("1".equals(xhpcChargingPile.get("type").toString())){ - HashMap paramMap = new HashMap<>(); - paramMap.put("elec", xhpcChargeOrder.getEndSoc()); - paramMap.put("sumMoney", actPrice.toString()); - paramMap.put("phone", userMessage.get("phone").toString()); - paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); - smsService.sendNotice(paramMap); - }else { - HashMap paramMap = new HashMap<>(); - paramMap.put("sumMoney", actPrice.toString()); - paramMap.put("phone", userMessage.get("phone").toString()); - paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); - smsService.sendNotice(paramMap); + if(operatorMessage.get("operatorIdEvcs") !=null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())){ + String stw = operatorMessage.get("operatorIdEvcs").toString(); + if(stw.length()>9){ + xhpcHistoryOrder.setOperatorIdEvcs(stw.substring(8, stw.length() - 1)); } } } - }catch (Exception e){ - logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>"); - } + if(operatorMessage.get("maintenanceCommissionRate") !=null && operatorMessage.get("commissionType") !=null && operatorMessage.get("platformCommissionRate") !=null){ + Integer commissionType = (Integer) operatorMessage.get("commissionType"); + //运维提成 + BigDecimal maintenanceCommissionRate = new BigDecimal(operatorMessage.get("maintenanceCommissionRate").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN); + //平台提成 + BigDecimal platformCommissionRate = new BigDecimal(operatorMessage.get("platformCommissionRate").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN); + //提成类型(0总金额提成 1服务费提成) + if(commissionType==0){ + //平台总抽成 + BigDecimal multiply1 = surplusPowerPrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); + //运维总抽成 + BigDecimal multiply3 = surplusPowerPrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); - } + //平台总金额抽成 + platformCommission = multiply1.add(multiply2); + //剩下的钱电费和服务 + surplusPowerPrice = surplusPowerPrice.subtract(multiply1); + surplusServicePrice = surplusServicePrice.subtract(multiply2); - xhpcHistoryOrderService.insert(xhpcHistoryOrder); + //运维总金额抽成 + operationCommission = multiply3.add(multiply4); + //剩下的钱电费和服务 + surplusPowerPrice = surplusPowerPrice.subtract(multiply3); + surplusServicePrice = surplusServicePrice.subtract(multiply4); - xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); - // 另起线程处理业务上传redis数据 - executorService.execute(new Runnable() { - @Override - public void run() { - //充电结算后自动申请退款 - if(userMessage !=null && "1".equals(userMessage.get("isRefund").toString()) && map !=null){ - refundOrderService.sendNotice(map); + }else if(commissionType==1){ + BigDecimal multiply1 = surplusServicePrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal multiply2 = surplusServicePrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_DOWN); + //平台服务费抽成金额 + platformSvcCommission=multiply1; + //剩下的服务费钱 + surplusServicePrice = surplusServicePrice.subtract(multiply1); + + //运维服务费抽成金额 + operationCommission = multiply2; + //剩下的钱 + surplusServicePrice = surplusServicePrice.subtract(multiply2); + } + if("微信".equals(xhpcChargeOrder.getChargingMode())){ + xhpcHistoryOrder.setChargingMode("微信"); + } + if("支付宝".equals(xhpcChargeOrder.getChargingMode())){ + xhpcHistoryOrder.setChargingMode("支付宝"); + } + }else{ + //订单异常 + xhpcChargeOrder.setStatus(2); + //异常原因 + xhpcChargeOrder.setErroRemark("运营商数据为空"); } - addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1); } - }); - // redisService.deleteObject("pushOrder:"+xhpcChargeOrder.getSerialNumber()); - - - + Long chargeOrderId = xhpcChargeOrder.getChargeOrderId(); + xhpcHistoryOrder.setChargeOrderId(chargeOrderId); + xhpcHistoryOrder.setChargingStationId(xhpcChargeOrder.getChargingStationId()); + xhpcHistoryOrder.setUserId(userId); + xhpcHistoryOrder.setTerminalId(xhpcChargeOrder.getTerminalId()); + xhpcHistoryOrder.setStartTime(xhpcChargeOrder.getStartTime()); + xhpcHistoryOrder.setStopReasonEvcs(xhpcChargeOrder.getStopReasonEvcs());//todo 从头开始设置所有evcs字段 + xhpcHistoryOrder.setChargeModelEvcs(xhpcChargeOrder.getChargeModelEvcs()); + xhpcHistoryOrder.setSerialNumber(xhpcChargeOrder.getSerialNumber()); + xhpcHistoryOrder.setRateModelId(xhpcChargeOrder.getRateModelId()); + xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); + xhpcHistoryOrder.setReconciliationStatus(0); + xhpcHistoryOrder.setSortingStatus(0); + //订单总价---运维服务费抽成 + xhpcHistoryOrder.setTotalPrice(money.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setPromotionDiscount(promotionDiscount.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setActPrice(actPrice.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setActServicePrice(surplusServicePrice.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setInternetCommission(internetCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setInternetDegreeCommission(internetDegreeCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setPlatformCommission(platformCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setOperationCommission(operationCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); + xhpcHistoryOrder.setEndSoc(xhpcChargeOrder.getEndSoc()); + xhpcHistoryOrder.setReconciliationStatus(0); + xhpcHistoryOrder.setSource(xhpcChargeOrder.getSource()); + Date date = new Date(); + xhpcHistoryOrder.setCreateTime(date); + xhpcHistoryOrder.setChargeModelEvcs(3); + if(xhpcChargeOrder.getPower()!=null){ + xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); + } + Map map =new HashMap<>(); + if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ + xhpcHistoryOrder.setUserNameEvcs(userMessage.get("phone").toString()); + xhpcHistoryOrder.setPhone(userMessage.get("phone").toString()); + //增加流水订单号 + if(operatorMessage!=null && operatorMessage.get("operatorId")!=null){ + String evcs = EvcsUtil.transferInternetOrderNo(xhpcChargeOrder.getSerialNumber(), operatorMessage.get("operatorId").toString()); + xhpcHistoryOrder.setEvcsOrderNo(evcs); + } + //扣除用户实际消费金额,添加消费记录 剩余的钱 + BigDecimal balance1 =new BigDecimal(userMessage.get("balance").toString()); + BigDecimal subtract = balance1.subtract(actPrice); + int i = xhpcChargeOrderService.updateUserBalance(userId, subtract,xhpcChargeOrder.getSource(),xhpcChargeOrder.getTenantId()); + if(i==0){ + //扣钱失败 + xhpcChargeOrder.setStatus(2); + xhpcChargeOrder.setErroRemark("扣钱失败"); + }else{ + //添加流水 + xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date,xhpcChargeOrder.getSource()); + map.put("userId",userId); + map.put("amount",subtract); + if(userMessage.get("weixinOpenId") !=null && !"".equals(userMessage.get("weixinOpenId").toString())){ + map.put("openid",userMessage.get("weixinOpenId").toString()); + map.put("type",1); + }else{ + map.put("openid",userMessage.get("alipayOpenId").toString()); + map.put("type",2); + } + map.put("remark","充电结算自动申请退款"); + } + } + xhpcHistoryOrderService.insert(xhpcHistoryOrder); + xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); + logger.info("<<<<<<<<<<<<<<<<订单结束异步之前>>>>>>>>>>>>>>>>>"+xhpcHistoryOrder.getSerialNumber()); + final BigDecimal balance = actPrice; + // 另起线程处理业务上传redis数据 + executorService.execute(new Runnable() { + @Override + public void run() { + try{ + Map xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId()); + //充电结算后自动申请退款 + if(userMessage !=null && "1".equals(userMessage.get("isRefund").toString()) && map !=null){ + logger.info("<<<<<<<<<<<<<<<<进入自动退款111>>>>>>>>>>>>>>>>>"); + if(UserTypeUtil.USER_TYPE.equals(source) || UserTypeUtil.COMMUNIT_TYPE.equals(source)){ + logger.info("<<<<<<<<<<<<<<<<进入自动退款222>>>>>>>>>>>>>>>>>"); + refundOrderService.sendNotice(map); + } + } + if(!UserTypeUtil.INSERT_BALANCE.equals(source)){ + Map userMassage = xhpcChargeOrderService.getUserMessage(userId); + if(xhpcChargingPile !=null){ + //发送短信 + if(userMassage !=null && userMassage.get("phone") !=null){ + if("1".equals(xhpcChargingPile.get("type").toString())){ + HashMap paramMap = new HashMap<>(); + paramMap.put("elec", xhpcChargeOrder.getEndSoc()); + paramMap.put("sumMoney", balance.toString()); + paramMap.put("phone", userMassage.get("phone").toString()); + paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + balance + "元,充电费用明细,请查询小华充电小程序,谢谢。"); + smsService.sendNotice(paramMap); + }else { + HashMap paramMap = new HashMap<>(); + paramMap.put("sumMoney", balance.toString()); + paramMap.put("phone", userMassage.get("phone").toString()); + paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + balance.toString() + "元,充电费用明细,请查询小华充电小程序,谢谢。"); + smsService.sendNotice(paramMap); + } + } + } + } + }catch (Exception e){ + logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>"); + } + addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1); + } + }); + }catch (Exception e){ + logger.info("<<<<<<<<<<<<<<<<运行异常,结算失败,数据回滚>>>>>>>>>>>>>>>>>"); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return R.fail(); + } + return R.ok(); } @Override diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml index b4daeefd..005fb0bb 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -127,6 +127,12 @@ update xhpc_app_user set balance=#{balance} where app_user_id=#{userId} + + update xhpc_community_personnel set surplus_money=#{balance} where community_personnel_id=#{userId} + + + update xhpc_customers_personnel set surplus_money=#{balance} where customers_personnel_id=#{userId} +