From 2d338a0e7480330ecb78e6d5471c2f47867b0a80 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期四, 05 九月 2024 17:13:04 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java | 184 +++++++++++++++++++++++++++++++-------------- 1 files changed, 125 insertions(+), 59 deletions(-) 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 d41c20d..21ce3ea 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 @@ -4,7 +4,6 @@ import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.account.api.feignClient.*; import com.ruoyi.account.api.model.*; @@ -16,11 +15,9 @@ import com.ruoyi.common.core.dto.ChargingOrderGroup; import com.ruoyi.common.core.dto.ChargingPercentProvinceDto; import com.ruoyi.common.core.web.domain.AjaxResult; -import com.ruoyi.common.core.web.page.BasePage; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.service.TokenService; -import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.integration.api.feignClient.ChargingHandshakeClient; import com.ruoyi.integration.api.feignClient.PlatformStartChargingReplyClient; import com.ruoyi.integration.api.feignClient.SendMessageClient; @@ -43,6 +40,10 @@ import com.ruoyi.order.api.vo.TCharingOrderVO; import com.ruoyi.order.dto.*; import com.ruoyi.order.mapper.TChargingOrderMapper; +import com.ruoyi.order.service.TChargingOrderAccountingStrategyService; +import com.ruoyi.order.service.TChargingOrderRefundService; +import com.ruoyi.order.service.TChargingOrderService; +import com.ruoyi.order.service.TOrderEvaluateService; import com.ruoyi.order.service.*; import com.ruoyi.other.api.domain.TCoupon; import com.ruoyi.other.api.domain.TGoods; @@ -57,7 +58,6 @@ import com.ruoyi.payment.api.model.RefundResp; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.api.vo.*; -import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.feignClient.SysUserClient; import io.seata.spring.annotation.GlobalTransactional; import io.swagger.annotations.ApiModelProperty; @@ -77,7 +77,6 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.*; import java.util.concurrent.*; import java.util.stream.Collectors; @@ -94,7 +93,7 @@ public class TChargingOrderServiceImpl extends ServiceImpl<TChargingOrderMapper, TChargingOrder> implements TChargingOrderService { private Logger log = LoggerFactory.getLogger(TChargingOrderServiceImpl.class); - + @Resource private ChargingGunClient chargingGunClient; @@ -144,45 +143,45 @@ @Resource private TOrderEvaluateService orderEvaluateService; - + @Resource private AccountingStrategyDetailClient accountingStrategyDetailClient; - + @Resource private AccountingStrategyDetailOrderClient accountingStrategyDetailOrderClient; - + @Resource private AccountingStrategyClient accountingStrategyClient; - + @Resource private PlatformStartChargingReplyClient platformStartChargingReplyClient; - + @Resource private TChargingOrderRefundService chargingOrderRefundService; - + @Resource private PlatformStopChargingReplyClient platformStopChargingReplyClient; - + @Resource private AccountingStrategyOrderService accountingStrategyOrderService; - + @Resource private AccountingStrategyDetailOrderService accountingStrategyDetailOrderService; - + @Resource private InviteUserClient inviteUserClient; - + @Resource private AppUserIntegralChangeClient appUserIntegralChangeClient; - + @Resource private IntegralRuleClient integralRuleClient; - + //计数器 private Map<String, Integer> counter_map = new HashMap<>(); - - - + + + /** * 获取小程序充电记录列表数据 @@ -441,9 +440,10 @@ chargingOrder.setVipDiscountAmount(discountAmount); } } + } this.save(chargingOrder); - + //添加订单的计费策略 TAccountingStrategy accountingStrategy = accountingStrategyClient.getAccountingStrategyById(tChargingGun.getAccountingStrategyId()).getData(); List<TAccountingStrategyDetail> strategyDetailList = accountingStrategyDetailClient.getListByAccountingStrategyId(tChargingGun.getAccountingStrategyId()).getData(); @@ -459,7 +459,7 @@ list1.add(accountingStrategyDetailOrder); } accountingStrategyDetailOrderService.saveBatch(list1); - + //会员优惠折扣将其计入增加充电时长(增加总充电金额) //如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额) if(1 == addChargingOrder.getPaymentType()){ @@ -507,7 +507,7 @@ chargingOrder.setRechargePaymentStatus(2); chargingOrder.setRechargeSerialNumber(transaction_id); chargingOrder.setStatus(2); - + //添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据 PreChargeCheck preChargeCheck = new PreChargeCheck(); preChargeCheck.setElectronicLockLock(false); @@ -529,7 +529,7 @@ //计算电费金额和服务费 BigDecimal serviceCharge = strategyDetail.getServiceCharge().multiply(degrees); BigDecimal electrovalence = strategyDetail.getElectrovalence().multiply(degrees); - + //再处理会员折扣 BigDecimal discount = BigDecimal.ZERO; TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); @@ -547,8 +547,8 @@ electrovalence = electrovalence.add(discount); chargingOrder.setChargeAmount(electrovalence); this.updateById(chargingOrder); - - + + TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingGun.getChargingPileId()).getData(); //调用远程启动充电消息 PlatformStartCharging platformStartCharging = new PlatformStartCharging(); @@ -665,11 +665,11 @@ } } } - + } } - - + + /** * 启动失败后微信退款的回调处理 * @param out_refund_no @@ -688,10 +688,10 @@ } return AjaxResult.success(); } - - - - + + + + /** * 获取充电中的详情 * @param id @@ -754,7 +754,7 @@ chargingOrder.setStatus(4); chargingOrder.setEndMode(1); this.updateById(chargingOrder); - + //异步线程处理停机 ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1); cachedThreadPool.execute(()->{ @@ -779,7 +779,7 @@ } continue; } - + if(0 == reply.getStop_result()){ String failure_cause = ""; switch (reply.getFailure_cause()){ @@ -799,14 +799,14 @@ log.error("停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause); throw new RuntimeException(failure_cause); } - + //计算费用,处理退款 endCharge(chargingOrder); break; } }); - - + + //处理推荐奖励(被推荐首单奖励) TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); long count = this.count(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, chargingOrder.getAppUserId()) @@ -841,15 +841,15 @@ appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1); appUserIntegralChange.setCreateTime(LocalDateTime.now()); appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); - + appUser1.setPoints(appUser1.getPoints() + num1); appUserClient.updateAppUser(appUser1); } - + return AjaxResult.success(); } - - + + /** * 手动结束后的费用计算和退款逻辑 */ @@ -876,14 +876,14 @@ orderAmount = orderAmount.divide(chargingOrder.getVipDiscount().divide(new BigDecimal(10))); chargingOrder.setOrderAmount(total); } - + if(chargingOrder.getEndMode() == 2){ chargingOrder.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3); } chargingOrder.setStatus(5); chargingOrder.setPaymentAmount(payAmount); this.updateById(chargingOrder); - + //计算优惠券 if(null != chargingOrder.getAppCouponId()){ //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。 @@ -919,7 +919,7 @@ } } } - + if(null != chargingOrder.getVipDiscount()){ BigDecimal subtract = orderAmount.subtract(total); chargingOrder.setVipDiscountAmount(subtract); @@ -975,9 +975,9 @@ } } } - + } - + } @@ -1326,10 +1326,10 @@ return chargingOrderTimeVO; } - @Override - public R payRefund(PayOrderRefundDto payOrderQueryDto) { - return null; - } +// @Override +// public R payRefund(PayOrderRefundDto payOrderQueryDto) { +// return null; +// } @Override public ChargingOrderListInfoVO chargingInfo(String uid) { @@ -1381,6 +1381,7 @@ chargingOrderListInfoVO.setList1(list); return chargingOrderListInfoVO; } + /** * 处理充电订单实时监控数据相关的业务逻辑 @@ -1466,7 +1467,7 @@ chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy1); } } - + List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>() .eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId())); BigDecimal t = BigDecimal.ZERO; @@ -1480,8 +1481,8 @@ this.updateById(chargingOrder); } } - - + + /** * 自动结束充电后的处理逻辑 * @param orderCode @@ -1497,10 +1498,10 @@ chargingOrder.setStatus(5); chargingOrder.setEndMode(endMode); this.updateById(chargingOrder); - + //计算费用,处理退款 endCharge(chargingOrder); - + //处理推荐奖励(被推荐首单奖励) TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); long count = this.count(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, chargingOrder.getAppUserId()) @@ -1535,12 +1536,12 @@ appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1); appUserIntegralChange.setCreateTime(LocalDateTime.now()); appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); - + appUser1.setPoints(appUser1.getPoints() + num1); appUserClient.updateAppUser(appUser1); } } - + /** * 异常结束充电处理逻辑 * @param orderCode @@ -1549,4 +1550,69 @@ public void excelEndCharge(String orderCode) { endCharge(orderCode, 0); } + + + + @Override + public R payRefund(PayOrderRefundDto payOrderQueryDto) { + if (payOrderQueryDto.getType()==1){ + TChargingOrder tChargingOrder = this.baseMapper.selectById(payOrderQueryDto.getOrderId()); + TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund(); + chargingOrderRefund.setChargingOrderId(tChargingOrder.getId()); + chargingOrderRefund.setRefundAmount(payOrderQueryDto.getRefundAmount()); + chargingOrderRefund.setRefundStatus(1); + chargingOrderRefund.setPayType(tChargingOrder.getRechargePaymentType()); + chargingOrderRefund.setRefundTime(LocalDateTime.now()); + chargingOrderRefund.setCode(tChargingOrder.getCode()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + chargingOrderRefund.setRefundCode("GDF" + sdf.format(new Date()) + (Math.random() * 1000)); + chargingOrderRefund.setRefundTitle("后台退款"); + chargingOrderRefund.setRefundContent("后台退款"); + chargingOrderRefund.setRefundReason("后台退款"); + chargingOrderRefund.setRefundRemark("后台退款"); + chargingOrderRefund.setRefundTotalAmount(tChargingOrder.getRefundAmount().add(payOrderQueryDto.getRefundAmount())); + chargingOrderRefund.setPayAmount(tChargingOrder.getPaymentAmount()); + + if(1 == tChargingOrder.getRechargePaymentType()){ + WxPaymentRefundModel model = new WxPaymentRefundModel(); + model.setOut_trade_no(tChargingOrder.getCode()); + model.setOut_refund_no(chargingOrderRefund.getRefundCode()); + model.setTransaction_id(tChargingOrder.getRechargeSerialNumber()); + model.setReason("取消订单"); + model.setNotify_url("http://127.0.0.1:9000/order/t-shopping-order/cancelShoppingOrderWxRefund"); + WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); + amount.setRefund(payOrderQueryDto.getRefundAmount().multiply(new BigDecimal(100)).intValue()); + amount.setTotal(tChargingOrder.getPaymentAmount().multiply(new BigDecimal(100)).intValue()); + amount.setCurrency("CNY"); + model.setAmount(amount); + R<String> orderR = wxPaymentClient.refundOrderR(model); + if(200 == orderR.getCode()){ + chargingOrderRefundService.save(chargingOrderRefund); + } + } + + if(2 == tChargingOrder.getRechargePaymentType()){ + RefundReq dto = new RefundReq(); + dto.setOutTradeNo(tChargingOrder.getCode()); + dto.setOutRequestNo(tChargingOrder.getCode()); + dto.setRefundAmount(payOrderQueryDto.getRefundAmount().toString()); + dto.setRefundReason("取消订单"); + RefundResp resp = aliPaymentClient.refund(dto).getData(); + if(null != resp){ + SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); + chargingOrderRefundService.save(chargingOrderRefund); + + } + } + + + + + + } + + + + return null; + } } -- Gitblit v1.7.1