From 0a22b587fc87dfe84228fc32ccdaa0b4e1cceacf Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Wed, 19 Jun 2024 19:31:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/app/AppVerifyController.java | 7 ++- .../common/core/domain/entity/SysDept.java | 12 +++++ .../web/service/SysLoginService.java | 1 + .../service/impl/AsDeviceServiceImpl.java | 32 ++++++----- .../service/impl/CallbackServiceImpl.java | 54 ++++++++++++------- .../service/impl/EtOrderServiceImpl.java | 8 ++- .../system/service/impl/WxPayService.java | 2 +- .../java/com/ruoyi/system/task/EtTask.java | 1 + .../resources/mapper/system/EtOrderMapper.xml | 39 +++++++++++++- .../resources/mapper/system/SysDeptMapper.xml | 5 +- 10 files changed, 121 insertions(+), 40 deletions(-) diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index 398e3c9..072132b 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -22,6 +22,7 @@ import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.response.FaultResponse; import com.ruoyi.system.domain.response.OrderResponse; import com.ruoyi.system.domain.vo.*; +import com.ruoyi.system.mapper.AsDeviceMapper; import com.ruoyi.system.service.*; import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import org.jetbrains.annotations.NotNull; @@ -29,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; @@ -74,6 +76,9 @@ public class AppVerifyController extends BaseController @Autowired private IEtOperatingAreaService etOperatingAreaService; + @Resource + private AsDeviceMapper asDeviceMapper; + /** * 故障上报 @@ -154,7 +159,7 @@ public class AppVerifyController extends BaseController return error("订单已结束,请重新扫码"); } } - AsDevice asDevice = asDeviceService.selectAsDeviceBySn(order.getSn()); + AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(order.getSn()); EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(asDevice.getAreaId()); //实名判断 if(area.getAuthentication().equals(ServiceConstants.IS_AUTHENTICATION_YES) && !asUserService.checkIsAuthentication(order.getUserId())){ diff --git a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java index 7da58aa..260b31f 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java +++ b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java @@ -1,5 +1,6 @@ package com.ruoyi.common.core.domain.entity; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import javax.validation.constraints.Email; @@ -75,6 +76,9 @@ public class SysDept extends BaseEntity /** 小程序名称 */ private String appName; + /** 余额 */ + private BigDecimal balance; + /** appSecret */ private String appSecret; @@ -96,6 +100,14 @@ public class SysDept extends BaseEntity /** 退款回调地址 */ private String refundNotifyUrl; + public BigDecimal getBalance() { + return balance; + } + + public void setBalance(BigDecimal balance) { + this.balance = balance; + } + public String getPlatformServiceFee() { return platformServiceFee; } diff --git a/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 25d57e9..bb91b72 100644 --- a/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -243,6 +243,7 @@ public class SysLoginService asUser.setWxopenid(openId); asUser.setAreaId(Long.parseLong(areaId)); asUser.setAppName(dept.getAppName()); + asUser.setRemark(dept.getAppName()); int i = asUserService.insertUser(asUser); user = asUser; }else{ diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index 265ed4a..6c49ad6 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -144,14 +144,14 @@ public class AsDeviceServiceImpl extends ServiceImpl i if (ObjectUtil.isNull(asDevice)) { throw new ServiceException("设备不存在:"+ sn); } - // 查询车辆上下线 - if(!isOnline(sn)){ - asDevice.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE); - log.info("设备不在线:"+ sn); - }else{ - asDevice.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_ONLINE); - } - int i = asDeviceMapper.updateAsDevice(asDevice); +// // 查询车辆上下线 +// if(!isOnline(sn)){ +// asDevice.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE); +// log.info("设备不在线:"+ sn); +// }else{ +// asDevice.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_ONLINE); +// } +// int i = asDeviceMapper.updateAsDevice(asDevice); Long areaId = asDevice.getAreaId(); EtOperatingArea etOperatingArea; if (ObjectUtil.isNotNull(areaId)) { @@ -472,7 +472,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i ResponseVo responseVo = sendCommandWithResp(asDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "编号开锁"); if(responseVo.getCode() != 0){ asynchronousUpdateOnlineStatus(asDevice.getMac()); - throw new ServiceException("【扫码/编号开锁骑行】更新车辆状态失败"); + throw new ServiceException("【扫码/编号开锁骑行】发送开锁命令失败"); } /** 3.更新车辆状态*/ asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); @@ -498,6 +498,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i //计算预约费 calculateAppointmentFee(order); order.setTotalFee(order.getAppointmentFee()); + order.setPayFee(order.getAppointmentFee()); int update = etOrderService.updateEtOrder(order); if(update==0){ log.info("【扫码/编号开锁骑行】更新订单失败"); @@ -881,6 +882,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i BigDecimal fee = appointmentServiceFee.multiply(new BigDecimal(area.getTimeoutMinutes()).divide(new BigDecimal(10))); order.setAppointmentFee(fee); order.setTotalFee(fee); + order.setPayFee(fee); int update = etOrderService.updateEtOrder(order); if(update==0){ throw new ServiceException("【车辆超时预约】:更新订单状态失败"); @@ -921,6 +923,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i //计算预约费 calculateAppointmentFee(order); order.setTotalFee(order.getAppointmentFee()); + order.setPayFee(order.getAppointmentFee()); order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT); int i = etOrderService.updateEtOrder(order); if(i==0){ @@ -1117,6 +1120,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i } log.info("【计算订单费用】骑行费:" + order.getRidingFee() + ",车辆管理费:" + order.getManageFee() + ",调度费:" + order.getDispatchFee() + ",预约费:" + order.getAppointmentFee() + ",总计:" + totalFee); order.setTotalFee(totalFee); + order.setPayFee(totalFee); }else { throw new ServiceException("订单类型错误"); } @@ -1148,11 +1152,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i String timeoutPrice = startingRule.getTimeoutPrice();//超时价格 Integer timeoutTime = Integer.parseInt(startingRule.getTimeoutTime());//超时时间 - //判断免费骑行时间不得大于起步时间 - if(freeRideTime>startingTime){ - throw new ServiceException("免费骑行时长不得大于起步分钟!"); - } - if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_HOURS)){//租赁单位:hours-小时 startingTime = startingTime*60; timeoutTime = timeoutTime*60; @@ -1161,6 +1160,11 @@ public class AsDeviceServiceImpl extends ServiceImpl i timeoutTime = timeoutTime*60*24; } + //判断免费骑行时间不得大于起步时间 + if(freeRideTime>startingTime){ + throw new ServiceException("免费骑行时长不得大于起步分钟!"); + } + if(ObjectUtils.isNotEmpty(returnTime) && ObjectUtils.isNotEmpty(unlockTime)){ if(minutes { // 请求分账处理 if (dividendHandle(transactionId, order, area)) return; }, 24 , TimeUnit.HOURS); - + logger.info("=================【微信支付回调】4444444=================="); }else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_APPOINTMENT)){ logger.info("【微信支付回调】取消预约支付"); // 2-取消预约支付 @@ -390,7 +391,8 @@ public class CallbackServiceImpl implements CallbackService { EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleId(order.getRuleId()); Integer autoRefundDeposit = rule.getAutoRefundDeposit(); - if(autoRefundDeposit!=null && autoRefundDeposit>0){ + logger.info("【微信支付回调】进入退还押金"); + if(autoRefundDeposit!=null){ //创建一个定时器,计算出退还时间后,执行退款操作 // 往后推autoRefundDeposit小时执行 scheduledExecutorService.schedule(() -> { @@ -399,7 +401,7 @@ public class CallbackServiceImpl implements CallbackService { if(ObjectUtil.isNotNull(refund2) && refund2.getRefundResult().equals(Constants.SUCCESS2)){ return; } - logger.info("【微信支付回调】退还押金定时任务开始"); + logger.info("【微信支付回调】退还押金定时任务开始执行!!!!!!!!"); // 退款 Long userId = order.getUserId(); EtOrder etOrder = new EtOrder(); @@ -444,6 +446,9 @@ public class CallbackServiceImpl implements CallbackService { throw new ServiceException("没有找到押金充值记录"); } }, autoRefundDeposit , TimeUnit.HOURS); + }else{ + logger.info("【微信支付回调】还车结算___小时后自动退押金参数为空"); + throw new ServiceException("还车结算___小时后自动退押金参数为空"); } } @@ -462,38 +467,49 @@ public class CallbackServiceImpl implements CallbackService { capitalFlow.setOutTradeNo(order.getOutTradeNo()); capitalFlow.setType(type); capitalFlow.setBusType(busType); - capitalFlow.setAmount(order.getTotalFee()); + capitalFlow.setAmount(order.getPayFee()); if(busType.equals(ServiceConstants.ORDER_TYPE_DEPOSIT) || busType.equals(ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND)){ capitalFlow.setOperatorDividend(BigDecimal.ZERO); capitalFlow.setPartnerDividend(BigDecimal.ZERO); }else{ - //获取所有合伙人列表 - SysUser sysUser = new SysUser(); - sysUser.setUserType("03"); - List sysUsers = userMapper.selectUserList(sysUser); - double totalDividendProportion = sysUsers.stream() - .mapToDouble(SysUser::getDividendProportion) - .sum();//算出总的分成比例 - BigDecimal decimal = new BigDecimal(totalDividendProportion).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP); - BigDecimal partnerDividend = order.getTotalFee().multiply(decimal); - BigDecimal operatorDividend = order.getTotalFee().subtract(partnerDividend); + logger.info("【微信支付回调--保存资金流水记录】 ==============业务类型=====================:"+busType); + BigDecimal partnerDividend = BigDecimal.ZERO; + BigDecimal operatorDividend = order.getPayFee(); + if(sysDept.getIsProfitSharing().equals("true")){//需要分账 + logger.info("【微信支付回调--保存资金流水记录】 ==============需要分账====================="+sysDept.getIsProfitSharing()); + //获取所有合伙人列表 + SysUser sysUser = new SysUser(); + sysUser.setUserType("03"); + sysUser.setAreaId(order.getAreaId()); + List sysUsers = userMapper.selectUserList(sysUser); + double totalDividendProportion = sysUsers.stream() + .mapToDouble(SysUser::getDividendProportion) + .sum();//算出总的分成比例 + BigDecimal decimal = new BigDecimal(totalDividendProportion).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP); + partnerDividend = order.getTotalFee().multiply(decimal); + operatorDividend = order.getTotalFee().subtract(partnerDividend); + } + logger.info("【微信支付回调--保存资金流水记录】 ==============partnerDividend=====================:"+partnerDividend); + logger.info("【微信支付回调--保存资金流水记录】 ==============operatorDividend=====================:"+operatorDividend); if(type.equals(ServiceConstants.FLOW_TYPE_INCOME)){ capitalFlow.setPartnerDividend(partnerDividend); capitalFlow.setOperatorDividend(operatorDividend); - capitalFlow.setOperatorBalance(capitalFlow.getOperatorBalance().add(operatorDividend)); + capitalFlow.setOperatorBalance(sysDept.getBalance().add(operatorDividend)); deptService.changeDeptBalance(operatorDividend,sysDept.getDeptId()); + logger.info("【微信支付回调--保存资金流水记录】 ==============收入=====================:"); }else{ capitalFlow.setPartnerDividend(partnerDividend.negate()); capitalFlow.setOperatorDividend(operatorDividend.negate()); - capitalFlow.setOperatorBalance(capitalFlow.getOperatorBalance().subtract(operatorDividend)); + capitalFlow.setOperatorBalance(sysDept.getBalance().subtract(operatorDividend)); deptService.changeDeptBalance(operatorDividend.negate(),sysDept.getDeptId()); + logger.info("【微信支付回调--保存资金流水记录】 ==============支出=====================:"); } } BigDecimal bigDecimal = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP); capitalFlow.setHandlingCharge(bigDecimal.multiply(order.getTotalFee()));//手续费 capitalFlow.setPayType(ServiceConstants.PAY_TYPE_WX); capitalFlow.setCreateTime(DateUtils.getNowDate()); - + logger.info("【微信支付回调】保存资金流水记录对象 : " + JSON.toJSONString(capitalFlow)); int i = etCapitalFlowService.insertEtCapitalFlow(capitalFlow); if(i==0){ throw new ServiceException("保存资金流水记录失败"); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index a844d35..67a2ce6 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -100,7 +100,11 @@ public class EtOrderServiceImpl implements IEtOrderService @Override public EtOrder selectEtOrderByOrderId(Long orderId) { - return etOrderMapper.selectEtOrderByOrderId(orderId); + // todo 订单详情获取行程记录、费用明细、退款明细、收费方式、终点起点、 + EtOrder order = etOrderMapper.selectEtOrderByOrderId(orderId); + AsDevice device = asDeviceMapper.selectAsDeviceBySn(order.getSn()); + order.setDevice(device); + return order; } /** @@ -414,6 +418,7 @@ public class EtOrderServiceImpl implements IEtOrderService log.info("【预下单】支付场景为:取消预约支付"); etOrder = etOrderMapper.selectEtOrderByOrderNo(order.getOrderNo()); etOrder.setTotalFee(etOrder.getAppointmentFee()); + etOrder.setPayFee(etOrder.getAppointmentFee()); int updateEtOrder = etOrderService.updateEtOrder(etOrder); if(updateEtOrder==0){ throw new ServiceException("【预下单】订单信息更新失败"); @@ -480,6 +485,7 @@ public class EtOrderServiceImpl implements IEtOrderService EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(user.getAreaId()); BigDecimal deposit = new BigDecimal(area.getDeposit()); etOrder.setTotalFee(deposit); + etOrder.setPayFee(deposit); }else { throw new ServiceException("订单类型错误"); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java index 19ff3a7..fbb6ca2 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java @@ -101,7 +101,7 @@ public class WxPayService implements IWxPayService { String isProfitSharing = sysDept.getIsProfitSharing(); // 获取JSAPI所需参数 PrepayRequest request = new PrepayRequest(); - request.setAmount(getAmount(order.getTotalFee())); + request.setAmount(getAmount(order.getPayFee())); String outTradeNo = IdUtils.getOrderNo("wx"); order.setOutTradeNo(outTradeNo); int updateEtOrder = etOrderService.updateEtOrder(order); diff --git a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java index 67c33d3..c2bf8bc 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java +++ b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java @@ -264,6 +264,7 @@ public class EtTask { BigDecimal fee = appointmentServiceFee.multiply(new BigDecimal(area.getTimeoutMinutes()).divide(new BigDecimal(10))); order.setAppointmentFee(fee); order.setTotalFee(fee); + order.setPayFee(fee); int update = etOrderService.updateEtOrder(order); if(update==0){ throw new ServiceException("【车辆超时预约】:更新订单状态失败"); diff --git a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml index 98a31a8..45a0834 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml @@ -126,7 +126,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -353,7 +387,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml b/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml index dc90efc..1e952d7 100644 --- a/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -22,6 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -38,7 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, - d.del_flag,d.platform_service_fee, d.is_profit_sharing, d.domain, d.is_use_platform_app, d.appid, d.app_name, d.app_secret, + d.del_flag,d.platform_service_fee, d.is_profit_sharing, d.domain, d.is_use_platform_app, d.appid, d.app_name, d.balance, d.app_secret, d.merchant_id, d.api_v3_key, d.notify_url, d.private_key_path,d.merchant_serial_number,d.refund_notify_url, d.create_by, d.create_time from sys_dept d @@ -76,7 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"