diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java index 43ee1793..46038d44 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java @@ -49,4 +49,9 @@ public class ServiceNameConstants { */ public static final String XHPC_USER = "xhpc-user"; + /** + * 付款服务 + */ + public static final String XHPC_PAYMENT = "xhpc-payment"; + } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/RefundOrderService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/RefundOrderService.java new file mode 100644 index 00000000..a76a911b --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/RefundOrderService.java @@ -0,0 +1,21 @@ +package com.xhpc.common.api; + +import com.xhpc.common.api.factory.RefundOrderFallbackFactory; +import com.xhpc.common.core.constant.ServiceNameConstants; +import com.xhpc.common.core.domain.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Map; + +/** + * @author yuyang + * @date 2021/12/28 15:32 + */ +@FeignClient(contextId = "refundOrderService",value = ServiceNameConstants.XHPC_PAYMENT,fallbackFactory = RefundOrderFallbackFactory.class) +public interface RefundOrderService { + + @PostMapping("/refund/order/checkOut") + R sendNotice(@RequestBody Map map); +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/RefundOrderFallbackFactory.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/RefundOrderFallbackFactory.java new file mode 100644 index 00000000..2d491a01 --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/RefundOrderFallbackFactory.java @@ -0,0 +1,30 @@ +package com.xhpc.common.api.factory; + +import com.xhpc.common.api.RefundOrderService; +import com.xhpc.common.core.domain.R; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @author yuyang + * @date 2021/12/28 15:34 + */ +@Component +public class RefundOrderFallbackFactory implements FallbackFactory { + private static final Logger logger = LoggerFactory.getLogger(RefundOrderFallbackFactory.class); + + @Override + public RefundOrderService create(Throwable cause) { + logger.error("申请退款服务调用失败:{} //fallback", cause.getMessage()); + return new RefundOrderService() { + @Override + public R sendNotice(Map map) { + return R.fail("自动申请退款失败:" + cause.getMessage()); + } + }; + } +} 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 74209510..b679c100 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 @@ -94,21 +94,20 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { if (userMessage == null || userMessage.get("balance") == null || a.compareTo(new BigDecimal(userMessage.get("balance").toString())) == 1) { return AjaxResult.error(1100, "金额小于5元,不能充电,请充值后再进行充电"); } + //充电用户是否存在异常的订单 + int j = xhpcChargeOrderMapper.countXhpcChargeOrder(userId); + if (j > 0) { + return AjaxResult.error(1103, "你有异常订单未解决,请拨打客服电话进行解决"); + } //查看充电用户是否有申请退款的订单,还未处理 if (Integer.parseInt(userMessage.get("isRefundApplication").toString()) != 0) { return AjaxResult.error(1101, "你有申请退款订单在审核中,需要充电请取消申请退款"); } //充电用户是否在充电中 String i = xhpcChargeOrderMapper.countXhpcRealTimeOrder(userId); - if (!"".equals(i) && i!=null) { return AjaxResult.error(1102, "车辆正在充电,请查询车辆充电信息"); } - //充电用户是否存在异常的订单 - int j = xhpcChargeOrderMapper.countXhpcChargeOrder(userId); - if (j > 0) { - return AjaxResult.error(1103, "你有异常订单未解决,请拨打客服电话进行解决"); - } //终端状态是否空闲 //是否插枪 Map cacheMap = REDIS.getCacheMap("gun:" + terminalSerialNumber); @@ -147,10 +146,8 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { //余额 String balance = new BigDecimal(userMessage.get("balance").toString()).multiply(new BigDecimal(100)).toString(); - //获取桩信息 - Map xhpcChargingPileById = - xhpcChargeOrderMapper.getXhpcChargingPileById(xhpcTerminal.getChargingPileId()); + Map xhpcChargingPileById =xhpcChargeOrderMapper.getXhpcChargingPileById(xhpcTerminal.getChargingPileId()); //启动充电 StartChargingData startChargingData = new StartChargingData(); 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 16f32bfe..b0f62396 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 @@ -6,15 +6,18 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; +import com.xhpc.common.api.RefundOrderService; import com.xhpc.common.api.SmsService; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.common.redis.service.RedisService; +import com.xhpc.common.util.EvcsUtil; import com.xhpc.order.domain.XhpcChargeOrder; import com.xhpc.order.domain.XhpcHistoryOrder; import com.xhpc.order.dto.XhpcChargeHistoryOrder; import com.xhpc.order.mapper.XhpcHistoryOrderMapper; +import com.xhpc.order.mapper.XhpcRealTimeOrderMapper; import com.xhpc.order.service.IXhpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; import com.xhpc.order.service.IXhpcRealTimeOrderService; @@ -45,6 +48,8 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { @Autowired private IXhpcChargeOrderService xhpcChargeOrderService; + @Autowired + private XhpcRealTimeOrderMapper xhpcRealTimeOrderMapper; @Autowired private SmsService smsService; @@ -58,7 +63,8 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { @Autowired private IXhpcRealTimeOrderService xhpcRealTimeOrderService; - + @Autowired + private RefundOrderService refundOrderService; @Override public List> list(Long userId) { @@ -326,6 +332,8 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { BigDecimal internetCommission = new BigDecimal(0); //流量方服务费抽成 BigDecimal internetSvcCommission = new BigDecimal(0); + //流量方电量抽成 + BigDecimal internetDegreeCommission =new BigDecimal(0); //平台总金额抽成 BigDecimal platformCommission = new BigDecimal(0); //平台服务费抽成 @@ -334,99 +342,146 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { BigDecimal operationCommission = new BigDecimal(0); //运维服务费抽成 BigDecimal operationSvcCommission = new BigDecimal(0); + //判断是C端用户还是流量端用户 - if (xhpcChargeOrder.getSource() == 0) { - String state = ""; - BigDecimal discount = new BigDecimal(0); + //先计算第三方优惠力度 + 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 ( source== 0) { //用户第几次充电 - int count = xhpcChargeOrderService.getCount(userId, xhpcChargeOrder.getChargeOrderId()); + int count = xhpcChargeOrderService.getCount(userId,xhpcChargeOrder.getChargeOrderId()); if (count == 0) { //活动折扣 Map promotion = xhpcChargeOrderService.getPromotion(); if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) { //state 1.总金额 2.电费 3.服务费 discount 折扣率 - state = promotion.get("state").toString(); - discount = new BigDecimal(promotion.get("discount").toString()); - } - } - if (!"".equals(state)) { + String state = promotion.get("state").toString(); + BigDecimal discount =new BigDecimal(promotion.get("discount").toString()).divide(new BigDecimal(100)); - //查看是否优惠为0 - boolean fan = discount.compareTo(new BigDecimal(0)) != 0; - if ("1".equals(state)) { - //总金额 - if (fan) { - promotionDiscount = money.multiply(discount); - actPrice = money.subtract(promotionDiscount); - surplusPowerPrice = surplusPowerPrice.subtract(promotionDiscount.divide(new BigDecimal(2))); - surplusServicePrice = surplusServicePrice.subtract(promotionDiscount.divide(new BigDecimal(2))); - } - } else if ("2".equals(state)) { - if (fan) { - //电费 - promotionDiscount = powerPrice.multiply(balance); - actPrice = money.subtract(promotionDiscount); - surplusPowerPrice = surplusPowerPrice.subtract(promotionDiscount); - } - } else if ("3".equals(state)) { - if (fan) { - //服务费 - promotionDiscount = servicePrice.multiply(balance); - actPrice = money.subtract(promotionDiscount); - surplusServicePrice = surplusServicePrice.subtract(promotionDiscount); + 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)); + //折扣的钱 + 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); + } + } } } } - xhpcHistoryOrder.setInternetCommission(internetCommission); - xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission); - } else { - //流量方,未实现,新增接口 } //获取运营商 Map operatorMessage = xhpcChargeOrderService.getOperatorMessage(xhpcChargeOrder.getChargingStationId()); - if (operatorMessage != null) { - if (operatorMessage.get("operatorIdEvcs") != null) { + if(operatorMessage !=null){ + if(operatorMessage.get("operatorIdEvcs")!=null){ - if (operatorMessage.get("operatorIdEvcs") != null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())) { + if(operatorMessage.get("operatorIdEvcs") !=null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())){ String stw = operatorMessage.get("operatorIdEvcs").toString(); - if (stw.length() > 9) { + 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) { + 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)); + 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)); + 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); - BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); + 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); - BigDecimal multiply3 = surplusPowerPrice.multiply(maintenanceCommissionRate); - BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate); - operationCommission = multiply1.add(multiply2); - //剩下的钱 + + //运维总金额抽成 + operationCommission = multiply3.add(multiply4); + //剩下的钱电费和服务 surplusPowerPrice = surplusPowerPrice.subtract(multiply3); surplusServicePrice = surplusServicePrice.subtract(multiply4); - } else if (commissionType == 1) { - BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); - platformSvcCommission = multiply2; + }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); - - BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate); - operationCommission = multiply4; - //剩下的钱 - surplusServicePrice = surplusServicePrice.subtract(multiply4); } - } else { + if("微信".equals(xhpcChargeOrder.getChargingMode())){ + xhpcHistoryOrder.setChargingMode("微信"); + } + if("支付宝".equals(xhpcChargeOrder.getChargingMode())){ + xhpcHistoryOrder.setChargingMode("支付宝"); + } + }else{ //订单异常 xhpcChargeOrder.setStatus(2); //异常原因 @@ -456,6 +511,7 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { 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)); @@ -467,36 +523,56 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { xhpcHistoryOrder.setChargeModelEvcs(3); xhpcHistoryOrder.setUserNameEvcs(userMessage.get("phone").toString()); xhpcHistoryOrder.setPhone(userMessage.get("phone").toString()); - xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); + if(xhpcChargeOrder.getPower()!=null){ + xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); + } + Map map =new HashMap<>(); + if(source==0){ + 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); + } - - //扣除用户实际消费金额,添加消费记录 - Map user = xhpcChargeOrderService.getUserMessage(userId); - //剩余的钱 - BigDecimal balance1 = (BigDecimal) user.get("balance"); - BigDecimal subtract = balance1.subtract(actPrice); - int i = xhpcChargeOrderService.updateUserBalance(userId, subtract); - if (i == 0) { - //扣钱失败 - xhpcChargeOrder.setStatus(2); - xhpcChargeOrder.setErroRemark("扣钱失败"); - } else { - insert(xhpcHistoryOrder); - //添加流水 - xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); - try { + //扣除用户实际消费金额,添加消费记录 + Map user = xhpcChargeOrderService.getUserMessage(userId); + //剩余的钱 + BigDecimal balance1 =(BigDecimal) user.get("balance"); + BigDecimal subtract = balance1.subtract(actPrice); + int i = xhpcChargeOrderService.updateUserBalance(userId, subtract); + 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(xhpcChargingPile !=null){ //发送短信 - if (user.get("phone") != null) { - if ("1".equals(xhpcChargingPile.get("type").toString())) { + if(user.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", user.get("phone").toString()); paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); smsService.sendNotice(paramMap); - } else { + }else { HashMap paramMap = new HashMap<>(); paramMap.put("sumMoney", actPrice.toString()); paramMap.put("phone", user.get("phone").toString()); @@ -505,18 +581,22 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { } } } - } catch (Exception e) { + }catch (Exception e){ logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>"); } - // 另起线程处理业务上传redis数据 - executorService.execute(new Runnable() { - @Override - public void run() { - - xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(), 1); - } - }); } + insert(xhpcHistoryOrder); + // 另起线程处理业务上传redis数据 + executorService.execute(new Runnable() { + @Override + public void run() { + //充电结算后自动申请退款 + if(userMessage !=null && "1".equals(userMessage.get("isRefund").toString()) && map !=null){ + refundOrderService.sendNotice(map); + } + xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(), 1); + } + }); } xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); } catch (Exception e) { 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 0cdd3444..bc31dfa8 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 @@ -3,6 +3,7 @@ package com.xhpc.order.service.impl; import cn.hutool.core.date.DateTime; 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.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; @@ -48,6 +49,9 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { @Autowired private SmsService smsService; + @Autowired + private RefundOrderService refundOrderService; + private final ExecutorService executorService = Executors.newFixedThreadPool(20); @@ -361,7 +365,6 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { 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(); @@ -534,16 +537,13 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { if(xhpcChargeOrder.getPower()!=null){ xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); } + Map map =new HashMap<>(); if(source==0){ - 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()); - logger.info("》》》》evcs》》》:"+evcs); - logger.info("》》》》evcs》》》:"+evcs); - logger.info("》》》》evcs》》》:"+evcs); xhpcHistoryOrder.setEvcsOrderNo(evcs); } @@ -557,9 +557,20 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { //扣钱失败 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","充电结算自动申请退款"); } - //添加流水 - xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); try{ Map xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId()); if(xhpcChargingPile !=null){ @@ -594,10 +605,17 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { executorService.execute(new Runnable() { @Override public void run() { + //充电结算后自动申请退款 + if(userMessage !=null && "1".equals(userMessage.get("isRefund").toString()) && map !=null){ + refundOrderService.sendNotice(map); + } addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1); } }); // redisService.deleteObject("pushOrder:"+xhpcChargeOrder.getSerialNumber()); + + + } @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 8624b51a..1599aa46 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -109,6 +109,9 @@ balance as balance, phone as phone, soc as soc, + is_refund as isRefund, + weixin_open_id as weixinOpenId, + alipay_open_id as alipayOpenId, is_refund_application as isRefundApplication from xhpc_app_user where del_flag=0 and app_user_id=#{userId} diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundAuditController.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundAuditController.java index 79197f65..7133c268 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundAuditController.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundAuditController.java @@ -616,13 +616,13 @@ public class XhpcRefundAuditController extends BaseController { } /** - * 定时任务,每5分钟,扫描一次,退款订单金额小于100,自动审核通过 + * 定时任务,每1分钟,扫描一次,退款订单金额小于100,自动审核通过 * */ - @Scheduled(cron = "0 */5 * * * ?") + @Scheduled(cron = "0 */1 * * * ?") @GetMapping("/moneyPage") public void moneyPage(){ - logger.info("++++++++++++每5分钟,扫描一次,退款订单金额小于100,自动审核通过++++++++++++++++"); + logger.info("++++++++++++每1分钟,扫描一次,退款订单金额小于100,自动审核通过++++++++++++++++"); try { List list = iXhpcRefundOrderService.moneyPage(); if(list !=null && list.size()>0){ diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/domain/XhpcAppUser.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/domain/XhpcAppUser.java index 79f9835b..e4555dc7 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/domain/XhpcAppUser.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/domain/XhpcAppUser.java @@ -82,6 +82,11 @@ public class XhpcAppUser extends BaseEntity { */ private Integer soc; + /** + * 是否退款 0 不退款 1 退款 + */ + private Integer isRefund; + public Long getAppUserId() { return appUserId; @@ -189,4 +194,11 @@ public class XhpcAppUser extends BaseEntity { this.soc = soc; } + public Integer getIsRefund() { + return isRefund; + } + + public void setIsRefund(Integer isRefund) { + this.isRefund = isRefund; + } }