| | |
| | | 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.*; |
| | |
| | | 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; |
| | |
| | | import com.ruoyi.order.api.vo.*; |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | public class TChargingOrderServiceImpl extends ServiceImpl<TChargingOrderMapper, TChargingOrder> implements TChargingOrderService { |
| | | |
| | | private Logger log = LoggerFactory.getLogger(TChargingOrderServiceImpl.class); |
| | | |
| | | |
| | | @Resource |
| | | private ChargingGunClient chargingGunClient; |
| | | |
| | |
| | | @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<>(); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取小程序充电记录列表数据 |
| | |
| | | chargingOrder.setVipDiscountAmount(discountAmount); |
| | | } |
| | | } |
| | | |
| | | } |
| | | this.save(chargingOrder); |
| | | |
| | | |
| | | //添加订单的计费策略 |
| | | TAccountingStrategy accountingStrategy = accountingStrategyClient.getAccountingStrategyById(tChargingGun.getAccountingStrategyId()).getData(); |
| | | List<TAccountingStrategyDetail> strategyDetailList = accountingStrategyDetailClient.getListByAccountingStrategyId(tChargingGun.getAccountingStrategyId()).getData(); |
| | |
| | | list1.add(accountingStrategyDetailOrder); |
| | | } |
| | | accountingStrategyDetailOrderService.saveBatch(list1); |
| | | |
| | | |
| | | //会员优惠折扣将其计入增加充电时长(增加总充电金额) |
| | | //如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额) |
| | | if(1 == addChargingOrder.getPaymentType()){ |
| | |
| | | chargingOrder.setRechargePaymentStatus(2); |
| | | chargingOrder.setRechargeSerialNumber(transaction_id); |
| | | chargingOrder.setStatus(2); |
| | | |
| | | |
| | | //添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据 |
| | | PreChargeCheck preChargeCheck = new PreChargeCheck(); |
| | | preChargeCheck.setElectronicLockLock(false); |
| | |
| | | //计算电费金额和服务费 |
| | | BigDecimal serviceCharge = strategyDetail.getServiceCharge().multiply(degrees); |
| | | BigDecimal electrovalence = strategyDetail.getElectrovalence().multiply(degrees); |
| | | |
| | | |
| | | //再处理会员折扣 |
| | | BigDecimal discount = BigDecimal.ZERO; |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | |
| | | electrovalence = electrovalence.add(discount); |
| | | chargingOrder.setChargeAmount(electrovalence); |
| | | this.updateById(chargingOrder); |
| | | |
| | | |
| | | |
| | | |
| | | TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingGun.getChargingPileId()).getData(); |
| | | //调用远程启动充电消息 |
| | | PlatformStartCharging platformStartCharging = new PlatformStartCharging(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 启动失败后微信退款的回调处理 |
| | | * @param out_refund_no |
| | |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取充电中的详情 |
| | | * @param id |
| | |
| | | chargingOrder.setStatus(4); |
| | | chargingOrder.setEndMode(1); |
| | | this.updateById(chargingOrder); |
| | | |
| | | |
| | | //异步线程处理停机 |
| | | ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1); |
| | | cachedThreadPool.execute(()->{ |
| | |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | |
| | | if(0 == reply.getStop_result()){ |
| | | String failure_cause = ""; |
| | | switch (reply.getFailure_cause()){ |
| | |
| | | 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()) |
| | |
| | | appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1); |
| | | appUserIntegralChange.setCreateTime(LocalDateTime.now()); |
| | | appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); |
| | | |
| | | |
| | | appUser1.setPoints(appUser1.getPoints() + num1); |
| | | appUserClient.updateAppUser(appUser1); |
| | | } |
| | | |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 手动结束后的费用计算和退款逻辑 |
| | | */ |
| | |
| | | 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()){ |
| | | //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | if(null != chargingOrder.getVipDiscount()){ |
| | | BigDecimal subtract = orderAmount.subtract(total); |
| | | chargingOrder.setVipDiscountAmount(subtract); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | return chargingOrderTimeVO; |
| | | } |
| | | |
| | | @Override |
| | | public R payRefund(PayOrderRefundDto payOrderQueryDto) { |
| | | return null; |
| | | } |
| | | // @Override |
| | | // public R payRefund(PayOrderRefundDto payOrderQueryDto) { |
| | | // return null; |
| | | // } |
| | | |
| | | @Override |
| | | public ChargingOrderListInfoVO chargingInfo(String uid) { |
| | |
| | | chargingOrderListInfoVO.setList1(list); |
| | | return chargingOrderListInfoVO; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 处理充电订单实时监控数据相关的业务逻辑 |
| | |
| | | chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy1); |
| | | } |
| | | } |
| | | |
| | | |
| | | List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>() |
| | | .eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId())); |
| | | BigDecimal t = BigDecimal.ZERO; |
| | |
| | | this.updateById(chargingOrder); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 自动结束充电后的处理逻辑 |
| | | * @param orderCode |
| | |
| | | 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()) |
| | |
| | | appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1); |
| | | appUserIntegralChange.setCreateTime(LocalDateTime.now()); |
| | | appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); |
| | | |
| | | |
| | | appUser1.setPoints(appUser1.getPoints() + num1); |
| | | appUserClient.updateAppUser(appUser1); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 异常结束充电处理逻辑 |
| | | * @param orderCode |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /** |