From e0afb38346d9c6ee8686b57c9ed27a981f798a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?= <14103883+leaf-phos@user.noreply.gitee.com> Date: Tue, 1 Apr 2025 21:30:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=A4=9A=E8=BD=A6=E8=BE=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/domain/entity/User.java | 8 + .../ruoyi/framework/util/DataScopeUtil.java | 9 +- .../web/service/SysLoginService.java | 9 +- .../bst/areaJoin/domain/AreaJoinQuery.java | 3 + .../bst/areaJoin/mapper/AreaJoinMapper.java | 7 + .../bst/areaJoin/mapper/AreaJoinMapper.xml | 9 + .../service/impl/AreaJoinValidatorImpl.java | 16 +- .../com/ruoyi/bst/device/domain/Device.java | 6 +- .../com/ruoyi/bst/device/domain/DeviceVO.java | 6 + .../ruoyi/bst/device/mapper/DeviceMapper.java | 4 +- .../ruoyi/bst/device/mapper/DeviceMapper.xml | 30 ++- .../bst/device/service/DeviceService.java | 8 +- .../service/impl/DeviceIotServiceImpl.java | 4 +- .../service/impl/DeviceServiceImpl.java | 12 +- .../com/ruoyi/bst/order/domain/Order.java | 20 +- .../com/ruoyi/bst/order/domain/OrderVO.java | 21 ++ .../bst/order/domain/bo/OrderCreateBO.java | 3 + .../ruoyi/bst/order/domain/bo/OrderEndBO.java | 6 +- .../bst/order/domain/enums/OrderStatus.java | 12 +- .../ruoyi/bst/order/mapper/OrderMapper.xml | 31 +-- .../ruoyi/bst/order/service/OrderService.java | 16 +- .../service/impl/OrderConverterImpl.java | 79 +++++-- .../service/impl/OrderPayHandlerImpl.java | 29 +-- .../order/service/impl/OrderServiceImpl.java | 87 +++++-- .../service/impl/OrderValidatorImpl.java | 5 +- .../com/ruoyi/bst/order/utils/OrderUtil.java | 3 + .../bst/orderDevice/domain/OrderDevice.java | 76 +++++++ .../orderDevice/domain/OrderDeviceQuery.java | 15 ++ .../bst/orderDevice/domain/OrderDeviceVO.java | 12 + .../domain/enums/OrderDeviceStatus.java | 44 ++++ .../domain/enums/OrderDeviceType.java | 14 ++ .../orderDevice/mapper/OrderDeviceMapper.java | 74 ++++++ .../orderDevice/mapper/OrderDeviceMapper.xml | 142 ++++++++++++ .../service/OrderDeviceService.java | 98 ++++++++ .../service/impl/OrderDeviceServiceImpl.java | 212 ++++++++++++++++++ .../ruoyi/bst/pay/domain/enums/PayStatus.java | 5 + .../com/ruoyi/bst/pay/mapper/PayMapper.java | 7 + .../com/ruoyi/bst/pay/mapper/PayMapper.xml | 12 +- .../com/ruoyi/bst/pay/service/PayService.java | 6 + .../bst/pay/service/impl/PayServiceImpl.java | 1 + .../ruoyi/bst/realName/domain/RealName.java | 5 + .../service/impl/RealNameServiceImpl.java | 34 +-- .../ruoyi/common/constants/ServiceCode.java | 10 + .../ruoyi/system/user/mapper/UserMapper.xml | 7 + .../java/com/ruoyi/task/order/OrderTask.java | 25 ++- .../main/java/com/ruoyi/task/pay/PayTask.java | 51 +++++ .../com/ruoyi/web/app/AppOrderController.java | 2 +- .../ruoyi/web/app/AppRealNameController.java | 1 - .../com/ruoyi/web/bst/AreaController.java | 1 + .../ruoyi/web/bst/OrderDeviceController.java | 110 +++++++++ .../com/ruoyi/web/common/LoginController.java | 2 +- .../src/main/resources/application-env.yml | 4 + ruoyi-web/src/main/resources/application.yml | 3 +- 53 files changed, 1246 insertions(+), 170 deletions(-) create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDevice.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceQuery.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceVO.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceStatus.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceType.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.xml create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/OrderDeviceService.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/impl/OrderDeviceServiceImpl.java create mode 100644 ruoyi-service/src/main/java/com/ruoyi/common/constants/ServiceCode.java create mode 100644 ruoyi-web/src/main/java/com/ruoyi/task/pay/PayTask.java create mode 100644 ruoyi-web/src/main/java/com/ruoyi/web/bst/OrderDeviceController.java diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/User.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/User.java index 6d6d022..aa96a08 100644 --- a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/User.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/User.java @@ -12,7 +12,9 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel.ColumnType; import com.ruoyi.common.annotation.Excel.Type; +import com.ruoyi.common.annotation.Sensitive; import com.ruoyi.common.core.domain.BaseEntity; +import com.ruoyi.common.enums.DesensitizedType; import com.ruoyi.common.xss.Xss; import io.swagger.annotations.ApiModelProperty; @@ -99,11 +101,17 @@ public class User extends BaseEntity private Boolean isReal; @ApiModelProperty("真实姓名") + @Sensitive(desensitizedType = DesensitizedType.USERNAME) private String realName; @ApiModelProperty("实名身份证号") + @Sensitive(desensitizedType = DesensitizedType.ID_CARD) private String realIdCard; + @ApiModelProperty("实名手机号") + @Sensitive(desensitizedType = DesensitizedType.PHONE) + private String realPhone; + @ApiModelProperty("余额") private BigDecimal balance; diff --git a/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/util/DataScopeUtil.java b/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/util/DataScopeUtil.java index 3624773..81c265f 100644 --- a/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/util/DataScopeUtil.java +++ b/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/util/DataScopeUtil.java @@ -65,10 +65,11 @@ public class DataScopeUtil { /** * Mybatis直接使用的方法 - * @param deptAlias - * @param userAlias - * @param needScope - * @return + * @param deptAlias 部门别名 + * @param userAlias 用户别名 + * @param deptSetAlias 部门逗号分隔字段别名 + * @param userSetAlias 用户逗号分隔字段别名 + * @param needScope 是否需要数据隔离 */ public static String dataScope(String deptAlias, String userAlias, String deptSetAlias, String userSetAlias, boolean needScope) { if (needScope) { diff --git a/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index bb7cb64..4555fb4 100644 --- a/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -330,9 +330,16 @@ public class SysLoginService return null; } + // 生成昵称 + String nickName = "微信" + openId.substring(openId.length() - 4); + if (StringUtils.hasText(phone)) { + nickName = "用户" + phone.substring(phone.length() - 4); + } + UserVO user = new UserVO(); - user.setNickName("微信" + openId.substring(openId.length() - 4)); + user.setNickName(nickName); user.setPhonenumber(phone); + user.setUserName(phone); return transactionTemplate.execute(status -> { int rows = userService.insertUser(user); diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/domain/AreaJoinQuery.java b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/domain/AreaJoinQuery.java index 57a3b8f..b72563c 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/domain/AreaJoinQuery.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/domain/AreaJoinQuery.java @@ -14,4 +14,7 @@ public class AreaJoinQuery extends AreaJoinVO { @ApiModelProperty("运营商ID") private Long mchId; + @ApiModelProperty("排除ID") + private Long excludeId; + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.java b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.java index 94b4d6e..513b341 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.java @@ -78,4 +78,11 @@ public interface AreaJoinMapper * @return */ BigDecimal selectMaxOfPoint(@Param("query") AreaJoinQuery query); + + /** + * 查询数量 + * @param query + * @return + */ + int selectCount(@Param("query") AreaJoinQuery query); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.xml index 276a590..1cd47cc 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/mapper/AreaJoinMapper.xml @@ -43,6 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and ba.name like concat('%', #{query.areaName}, '%') and su.phonenumber like concat('%', #{query.userPhone}, '%') and ba.user_id = #{query.mchId} + and baj.id != #{query.excludeId} and baj.id in @@ -142,4 +143,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/service/impl/AreaJoinValidatorImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/service/impl/AreaJoinValidatorImpl.java index 70ca9ce..4d92e9e 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/service/impl/AreaJoinValidatorImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/areaJoin/service/impl/AreaJoinValidatorImpl.java @@ -54,9 +54,21 @@ public class AreaJoinValidatorImpl implements AreaJoinValidator { throw new ServiceException("分成比例【" + vo.getPoint() + "】不能高于运营商【" + vo.getMchPoint() + "】"); } - // TODO 判断用户是否重复绑定到一个运营区上 - + // 校验用户是否重复绑定到一个运营区上 + this.checkRepeat(vo); } + private void checkRepeat(AreaJoinVO vo) { + if (vo == null || vo.getUserId() == null || vo.getAreaId() == null) { + return; + } + AreaJoinQuery query = new AreaJoinQuery(); + query.setUserId(vo.getUserId()); + query.setAreaId(vo.getAreaId()); + query.setExcludeId(vo.getId()); + int count = areaJoinMapper.selectCount(query); + ServiceUtil.assertion(count > 0, "用户%s已加盟运营区%s,请勿重复操作", vo.getUserId(), vo.getAreaId()); + } + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/Device.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/Device.java index 28131c8..558effd 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/Device.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/Device.java @@ -142,9 +142,9 @@ public class Device extends BaseEntity implements IotDevice @ApiModelProperty("最后在线时间") private LocalDateTime lastOnlineTime; - @Excel(name = "当前正在进行的订单ID") - @ApiModelProperty("当前正在进行的订单ID") - private Long orderId; + @Excel(name = "当前订单设备ID") + @ApiModelProperty("当前订单设备ID") + private Long orderDeviceId; @Override public String mac() { diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/DeviceVO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/DeviceVO.java index 42b4fb6..e3cf81a 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/DeviceVO.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/domain/DeviceVO.java @@ -59,12 +59,18 @@ public class DeviceVO extends Device { @ApiModelProperty("运营区代理商名称") private String areaAgentName; + @ApiModelProperty("当前订单ID") + private Long orderId; + @ApiModelProperty("当前订单状态") private String orderStatus; @ApiModelProperty("当前订单编号") private String orderNo; + @ApiModelProperty("当前订单设备状态") + private String orderDeviceStatus; + // 剩余续航(公里) public BigDecimal getRemainEndurance() { BigDecimal remainEndurance = MathUtils.mulDecimal(getRemainingPower(), getModelFullEndurance()); diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.java index 59127ad..47f1df1 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.java @@ -97,8 +97,8 @@ public interface DeviceMapper /** * 清除设备当前订单ID * @param id 设备ID - * @param orderId 订单ID + * @param orderDeviceId 订单设备ID * @return 结果 */ - int clearCurrentOrder(@Param("id") Long id, @Param("orderId") Long orderId); + int clearCurrentOrderDevice(@Param("id") Long id, @Param("orderDeviceId") Long orderDeviceId); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.xml index 83790b7..f4baf71 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/mapper/DeviceMapper.xml @@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bd.is_sound, bd.deleted, bd.last_online_time, - bd.order_id, + bd.order_device_id, mch.nick_name as mch_name, mch.point as mch_point, bm.name as model_name, @@ -60,7 +60,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" basua.point as area_agent_point, basua.nick_name as area_agent_name, bo.status as order_status, - bo.no as order_no + bo.no as order_no, + bod.status as order_device_status @@ -71,7 +72,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join bst_area ba on bd.area_id = ba.id left join sys_user basu on basu.user_id = ba.user_id left join sys_user basua on basua.user_id = basu.agent_id - left join bst_order bo on bo.id = bd.order_id + left join bst_order_device bod on bod.id = bd.order_device_id + left join bst_order bo on bo.id = bod.order_id @@ -172,7 +174,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" iot_status, is_sound, last_online_time, - order_id, + order_device_id, #{modelId}, @@ -205,7 +207,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{iotStatus}, #{isSound}, #{lastOnlineTime}, - #{orderId}, + #{orderDeviceId}, @@ -248,7 +250,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" iot_status = #{data.iotStatus}, is_sound = #{data.isSound}, last_online_time = #{data.lastOnlineTime}, - order_id = #{data.orderId}, + order_device_id = #{data.orderDeviceId}, @@ -296,27 +298,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - - update bst_device - set order_id = null - where id = #{id} - and order_id = #{orderId} + + update bst_device + set order_device_id = null + where id = #{id} and order_device_id = #{orderDeviceId} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceService.java index ceaf468..3acd967 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceService.java @@ -134,18 +134,18 @@ public interface DeviceService /** * 更新设备当前订单ID * @param id 设备ID - * @param orderId 订单ID + * @param deviceOrderId 设备订单ID * @return 结果 */ - public int updateCurrentOrderId(Long id, Long orderId); + public int updateCurrentDeviceOrderId(Long id, Long deviceOrderId); /** * 清除设备当前订单ID * @param id 设备ID - * @param orderId 订单ID + * @param orderDeviceId 订单设备ID * @return 结果 */ - public int clearCurrentOrder(Long id, Long orderId); + public int clearCurrentOrderDevice(Long id, Long orderDeviceId); /** * 根据mac更新在线状态 diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceIotServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceIotServiceImpl.java index 6137901..898f7b1 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceIotServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceIotServiceImpl.java @@ -20,7 +20,7 @@ import com.ruoyi.bst.device.domain.enums.DeviceStatus; import com.ruoyi.bst.device.mapper.DeviceMapper; import com.ruoyi.bst.device.service.DeviceIotService; import com.ruoyi.bst.device.utils.DeviceUtil; -import com.ruoyi.bst.order.domain.enums.OrderStatus; +import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceStatus; import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.collection.CollectionUtils; @@ -108,7 +108,7 @@ public class DeviceIotServiceImpl implements DeviceIotService { ServiceUtil.assertion(!DeviceStatus.canLock().contains(device.getStatus()), "设备%s当前状态不允许锁车", device.getSn()); // 是否有正在进行的订单 - boolean hasOrder = device.getOrderId() != null && OrderStatus.inUse().contains(device.getOrderStatus()); + boolean hasOrder = device.getOrderDeviceId() != null && OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus()); Integer result = transactionTemplate.execute(status -> { // 更新设备状态 diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceServiceImpl.java index 50ae069..6e42c33 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/impl/DeviceServiceImpl.java @@ -354,22 +354,22 @@ public class DeviceServiceImpl implements DeviceService } @Override - public int updateCurrentOrderId(Long id, Long orderId) { - if (id == null || orderId == null) { + public int updateCurrentDeviceOrderId(Long id, Long deviceOrderId) { + if (id == null || deviceOrderId == null) { return 0; } Device data = new Device(); - data.setOrderId(orderId); + data.setOrderDeviceId(deviceOrderId); data.setId(id); return deviceMapper.updateDevice(data); } @Override - public int clearCurrentOrder(Long id, Long orderId) { - if (id == null || orderId == null) { + public int clearCurrentOrderDevice(Long id, Long orderDeviceId) { + if (id == null || orderDeviceId == null) { return 0; } - return deviceMapper.clearCurrentOrder(id, orderId); + return deviceMapper.clearCurrentOrderDevice(id, orderDeviceId); } @Override diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/Order.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/Order.java index 85eafa4..591a3a1 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/Order.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/Order.java @@ -39,22 +39,6 @@ public class Order extends BaseEntity @ApiModelProperty("用户ID") private Long userId; - @Excel(name = "设备ID") - @ApiModelProperty("设备ID") - private Long deviceId; - - @Excel(name = "设备MAC") - @ApiModelProperty("设备MAC") - private String deviceMac; - - @Excel(name = "设备SN") - @ApiModelProperty("设备SN") - private String deviceSn; - - @Excel(name = "设备车牌号") - @ApiModelProperty("设备车牌号") - private String deviceVehicleNum; - @Excel(name = "支付成功的支付单ID") @ApiModelProperty("支付成功的支付单ID") private Long payId; @@ -212,4 +196,8 @@ public class Order extends BaseEntity @ApiModelProperty("结束原因") private String endReason; + @Excel(name = "当前订单设备ID") + @ApiModelProperty("当前订单设备ID") + private Long orderDeviceId; + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/OrderVO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/OrderVO.java index f334a86..661b7da 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/OrderVO.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/OrderVO.java @@ -3,12 +3,33 @@ package com.ruoyi.bst.order.domain; import java.math.BigDecimal; import java.time.LocalDateTime; +import com.ruoyi.common.annotation.Excel; + import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class OrderVO extends Order { + @ApiModelProperty("原始设备ID") + private Long deviceId; + + @Excel(name = "原始设备MAC") + @ApiModelProperty("原始设备MAC") + private String deviceMac; + + @Excel(name = "原始设备SN") + @ApiModelProperty("原始设备SN") + private String deviceSn; + + @Excel(name = "原始设备车牌号") + @ApiModelProperty("原始设备车牌号") + private String deviceVehicleNum; + + @Excel(name = "原始设备所属用户ID") + @ApiModelProperty("原始设备所属用户ID") + private Long deviceMchId; + @ApiModelProperty("运营区名称") private String areaName; diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderCreateBO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderCreateBO.java index 4cc79db..fd9bab8 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderCreateBO.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderCreateBO.java @@ -4,6 +4,7 @@ import com.ruoyi.bst.device.domain.DeviceVO; import com.ruoyi.bst.order.domain.Order; import com.ruoyi.bst.order.domain.dto.OrderCreateDTO; import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO; +import com.ruoyi.bst.orderDevice.domain.OrderDevice; import com.ruoyi.bst.suit.domain.SuitVO; import com.ruoyi.common.core.domain.vo.UserVO; @@ -30,4 +31,6 @@ public class OrderCreateBO { // 生成的订单 private Order order; + // 生成的订单设备 + private OrderDevice orderDevice; } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderEndBO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderEndBO.java index fe8da6c..0f4f4b2 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderEndBO.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/bo/OrderEndBO.java @@ -9,6 +9,7 @@ import com.ruoyi.bst.locationLog.domain.vo.LocationLogPositionVO; import com.ruoyi.bst.order.domain.OrderVO; import com.ruoyi.bst.order.domain.dto.OrderEndDTO; import com.ruoyi.bst.order.domain.vo.OrderInParkingVO; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; import lombok.Data; @@ -17,7 +18,10 @@ public class OrderEndBO { // 原始参数 private OrderEndDTO dto; - // 设备 + // 当前订单设备 + private OrderDeviceVO orderDevice; + + // 当前设备 private DeviceVO device; // 运营区数据 diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/enums/OrderStatus.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/enums/OrderStatus.java index 45a7b51..8e21d4d 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/enums/OrderStatus.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/domain/enums/OrderStatus.java @@ -14,7 +14,7 @@ public enum OrderStatus { WAIT_PAY("WAIT_PAY", "待支付"), PROCESSING("PROCESSING", "进行中"), FINISHED("FINISHED", "已结束"), - CANCEL("CANCEL", "已取消"), + CANCELED("CANCELED", "已取消"), WAIT_VERIFY("WAIT_VERIFY", "待审核"), REFUNDED("REFUNDED", "已退款"); @@ -46,4 +46,14 @@ public enum OrderStatus { public static List canRefund() { return CollectionUtils.map(OrderStatus::getCode, FINISHED, REFUNDED); } + + // 未支付的订单状态 + public static List unPayList() { + return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY); + } + + // 可以取消支付的订单状态 + public static List canCancelPay() { + return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY); + } } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/mapper/OrderMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/order/mapper/OrderMapper.xml index c506254..ebf74d1 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/mapper/OrderMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/mapper/OrderMapper.xml @@ -16,10 +16,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bo.suit_type, bo.area_id, bo.user_id, - bo.device_id, - bo.device_mac, - bo.device_sn, - bo.device_vehicle_num, bo.pay_id, bo.total_fee, bo.deposit_fee, @@ -57,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bo.start_area_sub_name, bo.end_area_sub_name, bo.end_reason, + bo.order_device_id, ba.name as area_name, su.nick_name as user_name, su.phonenumber as user_phone, @@ -65,13 +62,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bp.refunding as pay_refunding, bp.pay_time as pay_time, bp.channel_name as pay_channel_name, - bd.remaining_power as device_remaining_power, - bd.lock_status as device_lock_status + bod.device_id, + bod.device_mac, + bod.device_sn, + bod.device_vehicle_num, + bod.device_mch_id from bst_order bo left join bst_area ba on bo.area_id = ba.id left join sys_user su on bo.user_id = su.user_id left join bst_pay bp on bo.pay_id = bp.id - left join bst_device bd on bo.device_id = bd.id + left join bst_order_device bod on bod.id = bo.order_device_id @@ -104,7 +104,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and bo.end_area_sub_name like concat('%', #{query.endAreaSubName}, '%') and bo.max_time >= #{query.maxTimeStart} and bo.max_time <= #{query.maxTimeEnd} + and bo.device_mch_id = #{query.deviceMchId} and bo.end_reason like concat('%', #{query.endReason}, '%') + and bo.order_device_id = #{query.orderDeviceId} and date(bo.create_time) >= #{query.createDateRange[0]} and date(bo.create_time) <= #{query.createDateRange[1]} @@ -136,10 +138,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" suit_type, area_id, user_id, - device_id, - device_mac, - device_sn, - device_vehicle_num, pay_id, total_fee, deposit_fee, @@ -177,16 +175,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" start_area_sub_name, end_area_sub_name, end_reason, + order_device_id, #{no}, #{suitType}, #{areaId}, #{userId}, - #{deviceId}, - #{deviceMac}, - #{deviceSn}, - #{deviceVehicleNum}, #{payId}, #{totalFee}, #{depositFee}, @@ -224,6 +219,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{startAreaSubName}, #{endAreaSubName}, #{endReason}, + #{orderDeviceId}, @@ -240,10 +236,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" suit_type = #{data.suitType}, area_id = #{data.areaId}, user_id = #{data.userId}, - device_id = #{data.deviceId}, - device_mac = #{data.deviceMac}, - device_sn = #{data.deviceSn}, - device_vehicle_num = #{data.deviceVehicleNum}, pay_id = #{data.payId}, total_fee = #{data.totalFee}, deposit_fee = #{data.depositFee}, @@ -281,6 +273,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" start_area_sub_name = #{data.startAreaSubName}, end_area_sub_name = #{data.endAreaSubName}, end_reason = #{data.endReason}, + order_device_id = #{data.orderDeviceId}, diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/OrderService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/OrderService.java index 9284ca1..51751a4 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/OrderService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/OrderService.java @@ -108,7 +108,13 @@ public interface OrderService * @param id 订单ID * @return 结果 */ - public int cancelOrder(Long id); + public int cancelOrder(Long id, String remark); + + /** + * 取消过期订单 + * @param order 订单 + */ + public void cancelWhenExpired(Order order); /** * 支付订单 @@ -154,4 +160,12 @@ public interface OrderService * @return 结果 */ public int closeDevice(OrderVO order, boolean requiredIot); + + /** + * 更新订单设备ID + * @param id 订单ID + * @param orderDeviceId 订单设备ID + * @return 结果 + */ + public int updateOrderDeviceId(Long id, Long orderDeviceId); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderConverterImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderConverterImpl.java index 9563605..224493d 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderConverterImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderConverterImpl.java @@ -35,6 +35,11 @@ import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO; import com.ruoyi.bst.order.service.OrderConverter; import com.ruoyi.bst.order.service.OrderService; import com.ruoyi.bst.order.utils.OrderUtil; +import com.ruoyi.bst.orderDevice.domain.OrderDevice; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; +import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceStatus; +import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceType; +import com.ruoyi.bst.orderDevice.service.OrderDeviceService; import com.ruoyi.bst.suit.domain.SuitVO; import com.ruoyi.bst.suit.domain.enums.SuitType; import com.ruoyi.bst.suit.service.SuitService; @@ -82,6 +87,9 @@ public class OrderConverterImpl implements OrderConverter{ @Autowired private LocationLogService locationLogService; + @Autowired + private OrderDeviceService orderDeviceService; + @Override public OrderPrePriceVO toOrderPrePriceVO(OrderCalcPrePriceDTO dto) { if (dto == null) { @@ -120,9 +128,35 @@ public class OrderConverterImpl implements OrderConverter{ Order order = this.generateOrder(bo); bo.setOrder(order); + // 生成订单设备 + OrderDevice orderDevice = this.generateOrderDevice(bo); + bo.setOrderDevice(orderDevice); + return bo; } + // 生成订单设备 + private OrderDevice generateOrderDevice(OrderCreateBO bo) { + if (bo == null) { + return null; + } + OrderDevice orderDevice = new OrderDevice(); + + // 设备 + DeviceVO device = bo.getDevice(); + orderDevice.setType(OrderDeviceType.ORIGINAL.getCode()); + orderDevice.setStatus(OrderDeviceStatus.WAIT_USE.getCode()); + if (device != null) { + orderDevice.setDeviceId(device.getId()); + orderDevice.setDeviceMac(device.getMac()); + orderDevice.setDeviceSn(device.getSn()); + orderDevice.setDeviceVehicleNum(device.getVehicleNum()); + orderDevice.setDeviceMchId(device.getMchId()); + } + + return orderDevice; + } + // 生成订单 private Order generateOrder(OrderCreateBO bo) { if (bo == null) { @@ -141,11 +175,7 @@ public class OrderConverterImpl implements OrderConverter{ // 设备信息 DeviceVO device = bo.getDevice(); if (device != null) { - order.setDeviceId(device.getId()); order.setAreaId(device.getAreaId()); - order.setDeviceMac(device.getMac()); - order.setDeviceSn(device.getSn()); - order.setDeviceVehicleNum(device.getVehicleNum()); } // 套餐信息 @@ -259,28 +289,31 @@ public class OrderConverterImpl implements OrderConverter{ bo.setOrder(order); if (order != null) { - // 获取设备信息 - DeviceVO device = deviceService.selectDeviceById(order.getDeviceId()); - deviceIotService.refresh(device, null); - bo.setDevice(device); + // 获取当前订单设备 + OrderDeviceVO orderDevice = orderDeviceService.selectOrderDeviceById(order.getOrderDeviceId()); + bo.setOrderDevice(orderDevice); - if (device != null) { - - // 查询运营区 - AreaVO area = areaService.selectAreaById(device.getAreaId()); - bo.setArea(area); - - if (area != null) { - // 查询运营区的可还车的子区域列表 - List areaSubList = areaSubService.selectParkingAreaByAreaId(area.getId()); - bo.setParkingAreaSubList(areaSubList); - - // 停车点信息 - OrderInParkingVO inParkingVO = OrderUtil.getInParkingVO(area, areaSubList, device, dto.getLon(), dto.getLat()); - bo.setInParkingVO(inParkingVO); - } + if (orderDevice != null) { + // 获取当前设备信息 + DeviceVO device = deviceService.selectDeviceById(orderDevice.getDeviceId()); + deviceIotService.refresh(device, null); + bo.setDevice(device); } + // 查询运营区 + AreaVO area = areaService.selectAreaById(order.getAreaId()); + bo.setArea(area); + + if (area != null) { + // 查询运营区的可还车的子区域列表 + List areaSubList = areaSubService.selectParkingAreaByAreaId(area.getId()); + bo.setParkingAreaSubList(areaSubList); + } + + // 停车点信息 + OrderInParkingVO inParkingVO = OrderUtil.getInParkingVO(area, bo.getParkingAreaSubList(), bo.getDevice(), dto.getLon(), dto.getLat()); + bo.setInParkingVO(inParkingVO); + // 查询订单车辆轨迹列表 List positionList = locationLogService.selectPositionListByOrderId(order.getId()); bo.setPositionList(positionList); diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderPayHandlerImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderPayHandlerImpl.java index c1e104c..4e27479 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderPayHandlerImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderPayHandlerImpl.java @@ -6,15 +6,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.support.TransactionTemplate; -import com.ruoyi.bst.device.domain.DeviceVO; -import com.ruoyi.bst.device.service.DeviceIotService; -import com.ruoyi.bst.device.service.DeviceService; import com.ruoyi.bst.order.domain.Order; import com.ruoyi.bst.order.domain.OrderQuery; import com.ruoyi.bst.order.domain.OrderVO; import com.ruoyi.bst.order.domain.enums.OrderStatus; import com.ruoyi.bst.order.mapper.OrderMapper; import com.ruoyi.bst.order.service.OrderService; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; +import com.ruoyi.bst.orderDevice.service.OrderDeviceService; import com.ruoyi.bst.pay.domain.PayVO; import com.ruoyi.bst.pay.domain.enums.PayBstType; import com.ruoyi.bst.pay.interfaces.PayHandler; @@ -30,14 +29,11 @@ public class OrderPayHandlerImpl implements PayHandler { @Autowired private OrderMapper orderMapper; - @Autowired - private DeviceIotService deviceIotService; - @Autowired private TransactionTemplate transactionTemplate; @Autowired - private DeviceService deviceService; + private OrderDeviceService orderDeviceService; // 支付成功后操作 @Override @@ -50,9 +46,9 @@ public class OrderPayHandlerImpl implements PayHandler { OrderVO order = orderService.selectOrderById(pay.getBstId()); ServiceUtil.assertion(order == null, "ID为%s的订单不存在", pay.getBstId()); - // 查询设备 - DeviceVO device = deviceService.selectDeviceById(order.getDeviceId()); - ServiceUtil.assertion(device == null, "ID为%s的设备不存在", order.getDeviceId()); + // 查询订单设备 + OrderDeviceVO orderDevice = orderDeviceService.selectOriginByOrderId(order.getId()); + ServiceUtil.assertion(orderDevice == null, "ID为%s的订单设备不存在", order.getId()); LocalDateTime startTime = LocalDateTime.now(); @@ -69,9 +65,9 @@ public class OrderPayHandlerImpl implements PayHandler { int rows = orderMapper.updateByQuery(data, query); ServiceUtil.assertion(rows != 1, "更新ID为%s的订单失败", order.getId()); - // 操作设备解锁 - int unlock = deviceIotService.unlock(device, false, "订单支付成功:" + order.getNo(), false); - ServiceUtil.assertion(unlock <= 0, "解锁ID为%s的设备失败", device.getId()); + // 开始使用订单设备 + int start = orderDeviceService.start(orderDevice, false); + ServiceUtil.assertion(start != 1, "开始使用ID为%s的订单设备失败", orderDevice.getId()); return rows; }); @@ -79,13 +75,6 @@ public class OrderPayHandlerImpl implements PayHandler { return result != null && result == 1; } - // 支付单关单后操作 - @Override - public boolean onClose(PayVO pay) { - // TODO - return true; - } - // 支付单退款后操作,啥也不用做 @Override public boolean onRefundSuccess(RefundVO refund) { diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderServiceImpl.java index df600d2..4709b2d 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderServiceImpl.java @@ -44,8 +44,11 @@ import com.ruoyi.bst.order.service.OrderConverter; import com.ruoyi.bst.order.service.OrderService; import com.ruoyi.bst.order.service.OrderValidator; import com.ruoyi.bst.order.utils.OrderUtil; +import com.ruoyi.bst.orderDevice.domain.OrderDevice; +import com.ruoyi.bst.orderDevice.service.OrderDeviceService; import com.ruoyi.bst.pay.domain.Pay; import com.ruoyi.bst.pay.domain.dto.PayRefundDTO; +import com.ruoyi.bst.pay.domain.enums.PayBstType; import com.ruoyi.bst.pay.domain.vo.DoPayVO; import com.ruoyi.bst.pay.service.PayConverter; import com.ruoyi.bst.pay.service.PayService; @@ -109,6 +112,9 @@ public class OrderServiceImpl implements OrderService @Autowired private AreaSubService areaSubService; + @Autowired + private OrderDeviceService orderDeviceService; + /** * 查询订单 * @@ -215,15 +221,20 @@ public class OrderServiceImpl implements OrderService // 创建订单 Order order = bo.getOrder(); int rows = this.insertOrder(order); - if (rows != 1) { - return null; - } + ServiceUtil.assertion(rows != 1, "创建订单失败"); // 查询订单 OrderVO vo = this.selectOrderByNo(order.getNo()); + ServiceUtil.assertion(vo == null, "创建订单失败"); + + // 创建订单设备 + OrderDevice orderDevice = bo.getOrderDevice(); + orderDevice.setOrderId(vo.getId()); + int orderDeviceRows = orderDeviceService.insertOrderDevice(orderDevice); + ServiceUtil.assertion(orderDeviceRows != 1, "创建订单设备失败"); // 更新设备当前订单ID - int updateDevice = deviceService.updateCurrentOrderId(bo.getDevice().getId(), vo.getId()); + int updateDevice = deviceService.updateCurrentDeviceOrderId(bo.getDevice().getId(), orderDevice.getId()); ServiceUtil.assertion(updateDevice != 1, "更新设备当前订单ID失败"); // 加入延时队列,超时取消 @@ -248,7 +259,8 @@ public class OrderServiceImpl implements OrderService } // 加入延时队列,超时取消 - private void cancelWhenExpired(Order order) { + @Override + public void cancelWhenExpired(Order order) { if (order == null || order.getPayExpireTime() == null) { return; } @@ -261,19 +273,52 @@ public class OrderServiceImpl implements OrderService scheduledExecutorService.schedule(() -> { // 尝试取消订单 - this.cancelOrder(order.getId()); + this.cancelOrder(order.getId(), "订单超时取消"); }, delay, TimeUnit.SECONDS); } - // TODO 取消订单 + // 取消订单 @Override - public int cancelOrder(Long id) { + public int cancelOrder(Long id, String remark) { if (id == null) { return 0; } - // TODO - return 0; + // 查询订单 + OrderVO order = this.selectOrderById(id); + ServiceUtil.assertion(order == null, "ID为%s的订单不存在", id); + ServiceUtil.assertion(!OrderStatus.canCancelPay().contains(order.getStatus()), "ID为%s的订单当前状态不允许取消", id); + + // 刷新支付结果 + if (order.getPayNo() != null) { + payService.refreshPayResult(order.getPayNo()); + } + + // 查询最新订单状态 + order = this.selectOrderById(id); + ServiceUtil.assertion(order == null, "ID为%s的订单不存在", id); + ServiceUtil.assertion(!OrderStatus.canCancelPay().contains(order.getStatus()), "ID为%s的订单当前状态不允许取消", id); + + // 取消订单 + Integer result = transactionTemplate.execute(status -> { + // 更新订单状态 + Order data = new Order(); + data.setStatus(OrderStatus.CANCELED.getCode()); + data.setCancelRemark(remark); + OrderQuery query = new OrderQuery(); + query.setId(id); + query.setStatusList(OrderStatus.canCancelPay()); + int rows = orderMapper.updateByQuery(data, query); + ServiceUtil.assertion(rows != 1, "ID为%s的订单取消失败,状态已发生变化", id); + + // 取消支付单 + boolean cancelPay = payService.closeByBstId(PayBstType.ORDER.getType(), id); + ServiceUtil.assertion(!cancelPay, "ID为%s的订单取消支付单失败", id); + + return rows; + }); + + return result == null ? 0 : result; } @@ -316,7 +361,6 @@ public class OrderServiceImpl implements OrderService OrderVO order = bo.getOrder(); OrderInParkingVO inParkingVO = bo.getInParkingVO(); AreaVO area = bo.getArea(); - DeviceVO device = bo.getDevice(); // 设置订单数据 order.setEndTime(LocalDateTime.now()); // 结束时间 @@ -370,13 +414,9 @@ public class OrderServiceImpl implements OrderService ServiceUtil.assertion(!after, "订单完成处理失败"); } - // 清除设备当前订单ID - int clear = deviceService.clearCurrentOrder(device.getId(), order.getId()); - ServiceUtil.assertion(clear != 1, "清除设备当前订单ID失败"); - - // 设备上锁(必须放最后,因为会操作设备) - int lock = deviceIotService.lock(device.getId(), false, "订单结束:" + order.getNo(), false); - ServiceUtil.assertion(lock != 1, "设备上锁失败"); + // 结束订单设备 + int finish = orderDeviceService.finish(bo.getOrderDevice(), false); + ServiceUtil.assertion(finish != 1, "结束订单设备失败"); return rows; }); @@ -504,4 +544,15 @@ public class OrderServiceImpl implements OrderService return deviceIotService.lock(order.getDeviceId(), false, "订单锁车:" + order.getNo(), requiredIot); } + + @Override + public int updateOrderDeviceId(Long id, Long orderDeviceId) { + if (id == null || orderDeviceId == null) { + return 0; + } + Order order = new Order(); + order.setId(id); + order.setOrderDeviceId(orderDeviceId); + return orderMapper.updateOrder(order); + } } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderValidatorImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderValidatorImpl.java index 15c2674..e700aee 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderValidatorImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/service/impl/OrderValidatorImpl.java @@ -21,6 +21,7 @@ import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO; import com.ruoyi.bst.order.service.OrderValidator; import com.ruoyi.bst.order.utils.OrderUtil; import com.ruoyi.bst.suit.domain.SuitVO; +import com.ruoyi.common.constants.ServiceCode; import com.ruoyi.common.core.domain.vo.UserVO; import com.ruoyi.common.utils.MathUtils; import com.ruoyi.common.utils.ServiceUtil; @@ -52,7 +53,9 @@ public class OrderValidatorImpl implements OrderValidator{ // 用户 UserVO user = bo.getUser(); ServiceUtil.assertion(user == null, "ID为%s的用户不存在", dto.getUserId()); - // TODO 实名认证 + boolean needRealName = device.getAreaAuthentication() != null && device.getAreaAuthentication(); + boolean isReal = user.getIsReal() != null && user.getIsReal(); + ServiceUtil.assertion(needRealName && !isReal, "用户%s未实名认证", user.getNickName(), ServiceCode.USER_NOT_REAL_NAME); // 价格 OrderPrePriceVO prePrice = bo.getPrePrice(); diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/order/utils/OrderUtil.java b/ruoyi-service/src/main/java/com/ruoyi/bst/order/utils/OrderUtil.java index 7a2c2c3..5c03132 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/order/utils/OrderUtil.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/order/utils/OrderUtil.java @@ -107,6 +107,9 @@ public class OrderUtil { * @return */ public static OrderInParkingVO getInParkingVO(AreaVO area, List areaSubList, DeviceVO device, BigDecimal lon, BigDecimal lat) { + if (area == null || areaSubList == null || device == null) { + return null; + } OrderInParkingVO vo = new OrderInParkingVO(); // 通过设备定位获取所在区域 diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDevice.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDevice.java new file mode 100644 index 0000000..0a6156a --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDevice.java @@ -0,0 +1,76 @@ +package com.ruoyi.bst.orderDevice.domain; + +import java.time.LocalDateTime; + +import org.springframework.format.annotation.DateTimeFormat; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 订单设备对象 bst_order_device + * + * @author ruoyi + * @date 2025-04-01 + */ +@Data +public class OrderDevice extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + private Long id; + + @Excel(name = "订单ID") + @ApiModelProperty("订单ID") + private Long orderId; + + @Excel(name = "设备ID") + @ApiModelProperty("设备ID") + private Long deviceId; + + @Excel(name = "类型", readConverterExp = "1=原始车辆,2=替换车辆") + @ApiModelProperty("类型") + private String type; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("开始时间") + private LocalDateTime startTime; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("结束时间") + private LocalDateTime endTime; + + @Excel(name = "换车原因") + @ApiModelProperty("换车原因") + private String reason; + + @Excel(name = "对应故障ID") + @ApiModelProperty("对应故障ID") + private Long faultId; + + @Excel(name = "状态") + @ApiModelProperty("状态") + private String status; + + @Excel(name = "设备MAC") + @ApiModelProperty("设备MAC") + private String deviceMac; + + @Excel(name = "设备SN") + @ApiModelProperty("设备SN") + private String deviceSn; + + @Excel(name = "设备车牌号") + @ApiModelProperty("设备车牌号") + private String deviceVehicleNum; + + @Excel(name = "设备所属用户ID") + @ApiModelProperty("设备所属用户ID") + private Long deviceMchId; + +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceQuery.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceQuery.java new file mode 100644 index 0000000..af55458 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceQuery.java @@ -0,0 +1,15 @@ +package com.ruoyi.bst.orderDevice.domain; + +import java.util.List; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class OrderDeviceQuery extends OrderDeviceVO { + + @ApiModelProperty("状态列表") + private List statusList; + + +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceVO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceVO.java new file mode 100644 index 0000000..d9bf246 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/OrderDeviceVO.java @@ -0,0 +1,12 @@ +package com.ruoyi.bst.orderDevice.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class OrderDeviceVO extends OrderDevice{ + + @ApiModelProperty("订单编号") + private String orderNo; + +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceStatus.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceStatus.java new file mode 100644 index 0000000..b843ad9 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceStatus.java @@ -0,0 +1,44 @@ +package com.ruoyi.bst.orderDevice.domain.enums; + +import java.util.List; + +import com.ruoyi.common.utils.collection.CollectionUtils; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum OrderDeviceStatus { + + WAIT_USE("WAIT_USE", "待使用"), + USING("USING", "使用中"), + FINISHED("FINISHED", "已完成"); + + private String code; + private String name; + + /** + * 允许开始的订单设备状态 + * @return + */ + public static List canStart() { + return CollectionUtils.map(OrderDeviceStatus::getCode, WAIT_USE); + } + + /** + * 允许结束的订单设备状态 + * @return + */ + public static List canFinish() { + return CollectionUtils.map(OrderDeviceStatus::getCode, USING); + } + + /** + * 在使用的订单设备状态 + * @return + */ + public static List inUse() { + return CollectionUtils.map(OrderDeviceStatus::getCode, USING); + } +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceType.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceType.java new file mode 100644 index 0000000..47aa5c3 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/domain/enums/OrderDeviceType.java @@ -0,0 +1,14 @@ +package com.ruoyi.bst.orderDevice.domain.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum OrderDeviceType { + ORIGINAL("1", "原始车辆"), + REPLACE("2", "替换车辆"); + + private String code; + private String name; +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.java new file mode 100644 index 0000000..d738e59 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.java @@ -0,0 +1,74 @@ +package com.ruoyi.bst.orderDevice.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Param; + +import com.ruoyi.bst.orderDevice.domain.OrderDevice; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceQuery; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; + +/** + * 订单设备Mapper接口 + * + * @author ruoyi + * @date 2025-04-01 + */ +public interface OrderDeviceMapper +{ + /** + * 查询订单设备 + * + * @param id 订单设备主键 + * @return 订单设备 + */ + OrderDeviceVO selectOrderDeviceById(Long id); + + /** + * 查询订单设备列表 + * + * @param query 订单设备 + * @return 订单设备集合 + */ + List selectOrderDeviceList(@Param("query")OrderDeviceQuery query); + + /** + * 新增订单设备 + * + * @param orderDevice 订单设备 + * @return 结果 + */ + int insertOrderDevice(OrderDevice orderDevice); + + /** + * 修改订单设备 + * + * @param orderDevice 订单设备 + * @return 结果 + */ + public int updateOrderDevice(@Param("data") OrderDevice orderDevice); + + /** + * 删除订单设备 + * + * @param id 订单设备主键 + * @return 结果 + */ + int deleteOrderDeviceById(Long id); + + /** + * 批量删除订单设备 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteOrderDeviceByIds(Long[] ids); + + /** + * 根据条件更新订单设备 + * @param data 订单设备 + * @param query 查询条件 + * @return 结果 + */ + int updateByQuery(@Param("data") OrderDevice data, @Param("query") OrderDeviceQuery query); +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.xml new file mode 100644 index 0000000..7a801d5 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/mapper/OrderDeviceMapper.xml @@ -0,0 +1,142 @@ + + + + + + + + select + bod.id, + bod.order_id, + bod.device_id, + bod.type, + bod.start_time, + bod.end_time, + bod.reason, + bod.fault_id, + bod.status, + bod.device_mac, + bod.device_sn, + bod.device_vehicle_num, + bod.device_mch_id, + bo.no as order_no + from bst_order_device bod + left join bst_order bo on bo.id = bod.order_id + + + + and bod.id = #{query.id} + and bod.order_id = #{query.orderId} + and bod.device_id = #{query.deviceId} + and bod.type = #{query.type} + and bod.reason like concat('%', #{query.reason}, '%') + and bod.fault_id = #{query.faultId} + and bod.status = #{query.status} + and bod.device_mac like concat('%', #{query.deviceMac}, '%') + and bod.device_sn like concat('%', #{query.deviceSn}, '%') + and bod.device_vehicle_num like concat('%', #{query.deviceVehicleNum}, '%') + and bod.device_mch_id = #{query.deviceMchId} + + and bod.status in + + #{item} + + + ${query.params.dataScope} + + + + + + + + insert into bst_order_device + + id, + order_id, + device_id, + type, + start_time, + end_time, + reason, + fault_id, + status, + device_mac, + device_sn, + device_vehicle_num, + device_mch_id, + + + #{id}, + #{orderId}, + #{deviceId}, + #{type}, + #{startTime}, + #{endTime}, + #{reason}, + #{faultId}, + #{status}, + #{deviceMac}, + #{deviceSn}, + #{deviceVehicleNum}, + #{deviceMchId}, + + + + + update bst_order_device + + + + where id = #{data.id} + + + + order_id = #{data.orderId}, + device_id = #{data.deviceId}, + type = #{data.type}, + start_time = #{data.startTime}, + end_time = #{data.endTime}, + reason = #{data.reason}, + fault_id = #{data.faultId}, + status = #{data.status}, + device_mac = #{data.deviceMac}, + device_sn = #{data.deviceSn}, + device_vehicle_num = #{data.deviceVehicleNum}, + device_mch_id = #{data.deviceMchId}, + + + + delete from bst_order_device where id = #{id} + + + + delete from bst_order_device where id in + + #{id} + + + + + + + update bst_order_device bod + + + + + + + + + diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/OrderDeviceService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/OrderDeviceService.java new file mode 100644 index 0000000..68eccd1 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/OrderDeviceService.java @@ -0,0 +1,98 @@ +package com.ruoyi.bst.orderDevice.service; + +import java.util.List; + +import com.ruoyi.bst.orderDevice.domain.OrderDevice; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceQuery; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; + +/** + * 订单设备Service接口 + * + * @author ruoyi + * @date 2025-04-01 + */ +public interface OrderDeviceService +{ + /** + * 查询订单设备 + * + * @param id 订单设备主键 + * @return 订单设备 + */ + public OrderDeviceVO selectOrderDeviceById(Long id); + + /** + * 查询订单设备列表 + * + * @param orderDevice 订单设备 + * @return 订单设备集合 + */ + public List selectOrderDeviceList(OrderDeviceQuery orderDevice); + + /** + * 新增订单设备 + * + * @param orderDevice 订单设备 + * @return 结果 + */ + public int insertOrderDevice(OrderDevice orderDevice); + + /** + * 修改订单设备 + * + * @param orderDevice 订单设备 + * @return 结果 + */ + public int updateOrderDevice(OrderDevice orderDevice); + + /** + * 批量删除订单设备 + * + * @param ids 需要删除的订单设备主键集合 + * @return 结果 + */ + public int deleteOrderDeviceByIds(Long[] ids); + + /** + * 删除订单设备信息 + * + * @param id 订单设备主键 + * @return 结果 + */ + public int deleteOrderDeviceById(Long id); + + /** + * 根据订单ID查询原始设备 + * + * @param id 订单ID + * @return 订单设备 + */ + public OrderDeviceVO selectOriginByOrderId(Long orderId); + + /** + * 开始使用订单设备 + * + * @param orderDevice 订单设备 + * @param requiredIot Iot是否强制成功 + * @return 结果 + */ + public int start(OrderDeviceVO orderDevice, boolean requiredIot); + + /** + * 根据订单ID查询订单设备列表 + * + * @param id 订单ID + * @return 订单设备列表 + */ + public List selectOrderDeviceListByOrderId(Long orderId); + + /** + * 结束订单设备 + * + * @param orderDevice 订单设备 + * @param requiredIot Iot是否强制成功 + * @return 结果 + */ + public int finish(OrderDeviceVO orderDevice, boolean requiredIot); +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/impl/OrderDeviceServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/impl/OrderDeviceServiceImpl.java new file mode 100644 index 0000000..4efad49 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/orderDevice/service/impl/OrderDeviceServiceImpl.java @@ -0,0 +1,212 @@ +package com.ruoyi.bst.orderDevice.service.impl; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.support.TransactionTemplate; + +import com.github.pagehelper.PageHelper; +import com.ruoyi.bst.device.service.DeviceIotService; +import com.ruoyi.bst.device.service.DeviceService; +import com.ruoyi.bst.order.service.OrderService; +import com.ruoyi.bst.orderDevice.domain.OrderDevice; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceQuery; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; +import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceStatus; +import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceType; +import com.ruoyi.bst.orderDevice.mapper.OrderDeviceMapper; +import com.ruoyi.bst.orderDevice.service.OrderDeviceService; +import com.ruoyi.common.utils.ServiceUtil; +import com.ruoyi.common.utils.collection.CollectionUtils; + +/** + * 订单设备Service业务层处理 + * + * @author ruoyi + * @date 2025-04-01 + */ +@Service +public class OrderDeviceServiceImpl implements OrderDeviceService +{ + @Autowired + private OrderDeviceMapper orderDeviceMapper; + + @Autowired + private DeviceIotService deviceIotService; + + @Autowired + private TransactionTemplate transactionTemplate; + + @Autowired + private DeviceService deviceService; + + @Autowired + private OrderService orderService; + + /** + * 查询订单设备 + * + * @param id 订单设备主键 + * @return 订单设备 + */ + @Override + public OrderDeviceVO selectOrderDeviceById(Long id) + { + return orderDeviceMapper.selectOrderDeviceById(id); + } + + /** + * 查询订单设备列表 + * + * @param orderDevice 订单设备 + * @return 订单设备 + */ + @Override + public List selectOrderDeviceList(OrderDeviceQuery orderDevice) + { + return orderDeviceMapper.selectOrderDeviceList(orderDevice); + } + + /** + * 新增订单设备 + * + * @param orderDevice 订单设备 + * @return 结果 + */ + @Override + public int insertOrderDevice(OrderDevice orderDevice) + { + return orderDeviceMapper.insertOrderDevice(orderDevice); + } + + /** + * 修改订单设备 + * + * @param orderDevice 订单设备 + * @return 结果 + */ + @Override + public int updateOrderDevice(OrderDevice orderDevice) + { + return orderDeviceMapper.updateOrderDevice(orderDevice); + } + + /** + * 批量删除订单设备 + * + * @param ids 需要删除的订单设备主键 + * @return 结果 + */ + @Override + public int deleteOrderDeviceByIds(Long[] ids) + { + return orderDeviceMapper.deleteOrderDeviceByIds(ids); + } + + /** + * 删除订单设备信息 + * + * @param id 订单设备主键 + * @return 结果 + */ + @Override + public int deleteOrderDeviceById(Long id) + { + return orderDeviceMapper.deleteOrderDeviceById(id); + } + + /** + * 根据订单ID查询原始设备 + * + * @param id 订单ID + * @return 订单设备 + */ + @Override + public OrderDeviceVO selectOriginByOrderId(Long orderId) { + if (orderId == null) { + return null; + } + OrderDeviceQuery query = new OrderDeviceQuery(); + query.setOrderId(orderId); + query.setType(OrderDeviceType.ORIGINAL.getCode()); + return selectOne(query); + } + + private OrderDeviceVO selectOne(OrderDeviceQuery query) { + PageHelper.startPage(1, 1); + List list = orderDeviceMapper.selectOrderDeviceList(query); + return CollectionUtils.firstElement(list); + } + + @Override + public int start(OrderDeviceVO orderDevice, boolean requiredIot) { + ServiceUtil.assertion(orderDevice == null, "订单设备不能为空"); + ServiceUtil.assertion(!OrderDeviceStatus.canStart().contains(orderDevice.getStatus()), "订单设备状态不允许开始"); + + Integer result = transactionTemplate.execute(status -> { + // 修改订单设备状态 + OrderDevice data = new OrderDevice(); + data.setStatus(OrderDeviceStatus.USING.getCode()); + data.setStartTime(LocalDateTime.now()); + OrderDeviceQuery query = new OrderDeviceQuery(); + query.setId(orderDevice.getId()); + query.setStatusList(OrderDeviceStatus.canStart()); + int rows = orderDeviceMapper.updateByQuery(data, query); + + // 修改订单信息 + int updateOrder = orderService.updateOrderDeviceId(orderDevice.getOrderId(), orderDevice.getId()); + ServiceUtil.assertion(updateOrder != 1, "更新订单信息失败"); + + // 操作设备解锁 + if (rows > 0) { + int unlock = deviceIotService.unlock(orderDevice.getDeviceId(), false, "订单开锁:" + orderDevice.getOrderNo(), requiredIot); + ServiceUtil.assertion(unlock <= 0, "解锁ID为%s的设备失败", orderDevice.getDeviceId()); + } + + return rows; + }); + + return result == null ? 0 : result; + } + + @Override + public List selectOrderDeviceListByOrderId(Long orderId) { + if (orderId == null) { + return null; + } + OrderDeviceQuery query = new OrderDeviceQuery(); + query.setOrderId(orderId); + return orderDeviceMapper.selectOrderDeviceList(query); + } + + @Override + public int finish(OrderDeviceVO orderDevice, boolean requiredIot) { + ServiceUtil.assertion(orderDevice == null, "订单设备不能为空"); + ServiceUtil.assertion(!OrderDeviceStatus.canFinish().contains(orderDevice.getStatus()), "订单设备状态不允许结束"); + + Integer result = transactionTemplate.execute(status -> { + // 修改状态 + OrderDevice data = new OrderDevice(); + data.setStatus(OrderDeviceStatus.FINISHED.getCode()); + data.setEndTime(LocalDateTime.now()); + OrderDeviceQuery query = new OrderDeviceQuery(); + query.setId(orderDevice.getId()); + query.setStatusList(OrderDeviceStatus.canFinish()); + int rows = orderDeviceMapper.updateByQuery(data, query); + + // 清除设备当前订单设备ID + int clear = deviceService.clearCurrentOrderDevice(orderDevice.getDeviceId(), orderDevice.getId()); + ServiceUtil.assertion(clear != 1, "清除设备当前订单ID失败"); + + // 设备上锁(必须放最后,因为会操作设备) + int lock = deviceIotService.lock(orderDevice.getDeviceId(), false, "订单上锁:" + orderDevice.getOrderNo(), requiredIot); + ServiceUtil.assertion(lock != 1, "设备上锁失败"); + + return rows; + }); + + return result == null ? 0 : result; + } +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/domain/enums/PayStatus.java b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/domain/enums/PayStatus.java index 06cabeb..7d81a4d 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/domain/enums/PayStatus.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/domain/enums/PayStatus.java @@ -39,6 +39,11 @@ public enum PayStatus { return asList(PAYED, REFUNDED); } + // 未支付的状态 + public static List unPayList() { + return asList(WAIT_PAY, PAYING); + } + // 允许退款的状态 public static List canRefund() { return payedList(); diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.java b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.java index aa7de2a..7c960a7 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.java @@ -92,4 +92,11 @@ public interface PayMapper * @return 结果 */ int recordRefundAmount(@Param("id") Long id, @Param("amount") BigDecimal amount); + + /** + * 查询支付单号列表 + * @param query + * @return + */ + List selectNoList(@Param("query") PayQuery query); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.xml index 277633b..febbaa6 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/mapper/PayMapper.xml @@ -182,5 +182,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" refunded = refunded + #{amount} where id = #{id} and refunding - #{amount} >= 0 - + + + + + diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/PayService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/PayService.java index 4d170a4..95801d6 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/PayService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/PayService.java @@ -106,4 +106,10 @@ public interface PayService * @return */ int refund(PayRefundDTO dto); + + /** + * 刷新支付结果 + */ + void refreshPayResultBeforeExpire(String no); + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/impl/PayServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/impl/PayServiceImpl.java index 1f0b2b1..55eaf40 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/impl/PayServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/pay/service/impl/PayServiceImpl.java @@ -353,6 +353,7 @@ public class PayServiceImpl implements PayService { return vo; } + @Override public void refreshPayResultBeforeExpire(String no) { if (StringUtils.isBlank(no)) { return; diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/realName/domain/RealName.java b/ruoyi-service/src/main/java/com/ruoyi/bst/realName/domain/RealName.java index 52cd73d..2441e13 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/realName/domain/RealName.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/realName/domain/RealName.java @@ -8,6 +8,8 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import javax.validation.constraints.NotBlank; + /** * 实名认证信息对象 bst_real_name * @@ -27,10 +29,12 @@ public class RealName extends BaseEntity @Excel(name = "用户姓名") @ApiModelProperty("用户姓名") + @NotBlank(message = "用户姓名不允许为空") private String userName; @Excel(name = "身份证") @ApiModelProperty("身份证") + @NotBlank(message = "身份证不允许为空") private String idCard; @Excel(name = "人脸图像") @@ -43,6 +47,7 @@ public class RealName extends BaseEntity @Excel(name = "手机号") @ApiModelProperty("手机号") + @NotBlank(message = "手机号不允许为空") private String mobile; @Excel(name = "实名认证状态:0-未实名 1-已实名") diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/realName/service/impl/RealNameServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/realName/service/impl/RealNameServiceImpl.java index 81e3020..ee33b71 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/realName/service/impl/RealNameServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/realName/service/impl/RealNameServiceImpl.java @@ -1,18 +1,25 @@ package com.ruoyi.bst.realName.service.impl; -import java.time.Instant; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; + +import com.ruoyi.bst.realName.domain.RealName; +import com.ruoyi.bst.realName.domain.RealNameQuery; +import com.ruoyi.bst.realName.domain.RealNameVO; import com.ruoyi.bst.realName.domain.Face.Face; import com.ruoyi.bst.realName.domain.Refresh.RealNameRefreshVO; import com.ruoyi.bst.realName.domain.enums.RealNameStatus; +import com.ruoyi.bst.realName.mapper.RealNameMapper; +import com.ruoyi.bst.realName.service.RealNameService; import com.ruoyi.common.constant.CacheConstants; -import com.ruoyi.common.core.domain.entity.User; import com.ruoyi.common.core.domain.vo.UserVO; import com.ruoyi.common.core.redis.RedisCache; -import com.ruoyi.common.enums.UserStatus; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServiceUtil; @@ -27,20 +34,7 @@ import com.ruoyi.common.valid.liveness.LivenessResponseQueryData; import com.ruoyi.common.valid.liveness.LivenessResponseTokenData; import com.ruoyi.common.valid.liveness.LivenessUtils; import com.ruoyi.common.valid.liveness.enums.LivenessQueryResult; -import com.ruoyi.system.user.mapper.UserMapper; import com.ruoyi.system.user.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.ruoyi.bst.realName.mapper.RealNameMapper; -import com.ruoyi.bst.realName.domain.RealName; -import com.ruoyi.bst.realName.domain.RealNameVO; -import com.ruoyi.bst.realName.domain.RealNameQuery; -import com.ruoyi.bst.realName.service.RealNameService; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.TransactionTemplate; - -import static net.sf.jsqlparser.parser.feature.Feature.insert; -import static net.sf.jsqlparser.parser.feature.Feature.use; /** * 实名认证信息Service业务层处理 @@ -174,9 +168,6 @@ public class RealNameServiceImpl implements RealNameService public RealNameVO realName(RealName realName) { UserVO user = userService.selectUserById(realName.getUserId()); ServiceUtil.assertion(user == null,"用户信息不存在"); - ServiceUtil.assertion(StringUtils.isBlank(realName.getUserName()), "用户姓名不允许为空"); - ServiceUtil.assertion(StringUtils.isBlank(realName.getIdCard()), "用户身份证不允许为空"); - Boolean flag = realNameMapper.checkIdCard(realName.getIdCard()); ServiceUtil.assertion(flag,"用户身份证重复"); @@ -185,8 +176,6 @@ public class RealNameServiceImpl implements RealNameService LivenessResponseTokenData tokenData = LivenessUtils.getToken(LIVENESS_RETURN_URL, null, null); ServiceUtil.assertion(tokenData == null || StringUtils.isBlank(tokenData.getToken()), "获取活体检测token失败"); - - // 存入缓存:10分钟 String cacheKey = CacheConstants.LIVENESS_TOKEN + realName.getUserId(); Face face = new Face(); @@ -202,7 +191,6 @@ public class RealNameServiceImpl implements RealNameService vo.setFaceToken(tokenData.getToken()); vo.setJumpUrl(LivenessUtils.JUMP_URL + "?token=" + tokenData.getToken()); return vo; - } /** @@ -272,7 +260,7 @@ public class RealNameServiceImpl implements RealNameService data.setUserId(realName.getUserId()); data.setRealName(realName.getUserName()); data.setRealIdCard(realName.getIdCard()); - data.setPhonenumber(realName.getMobile()); + data.setRealPhone(realName.getMobile()); data.setIsReal(true); // 数据库操作 diff --git a/ruoyi-service/src/main/java/com/ruoyi/common/constants/ServiceCode.java b/ruoyi-service/src/main/java/com/ruoyi/common/constants/ServiceCode.java new file mode 100644 index 0000000..e7fdea8 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/common/constants/ServiceCode.java @@ -0,0 +1,10 @@ +package com.ruoyi.common.constants; + +/** + * 业务状态码 + */ +public class ServiceCode { + + // 用户未实名 + public static final Integer USER_NOT_REAL_NAME = 10001; +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/system/user/mapper/UserMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/system/user/mapper/UserMapper.xml index 04ba4b4..a420825 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/system/user/mapper/UserMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/system/user/mapper/UserMapper.xml @@ -61,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" u.is_real, u.real_name, u.real_id_card, + u.real_phone, u.balance, d.dept_id, d.parent_id, @@ -128,6 +129,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and u.real_id_card like concat('%', #{realIdCard}, '%') + + and u.real_phone like concat('%', #{realPhone}, '%') + and u.user_id in ( select user_id from bst_user_app where app_id = #{appId} @@ -268,6 +272,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" is_real, real_name, real_id_card, + real_phone, create_time )values( #{userId}, @@ -288,6 +293,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{isReal}, #{realName}, #{realIdCard}, + #{realPhone}, sysdate() ) @@ -314,6 +320,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" is_real = #{isReal}, real_name = #{realName}, real_id_card = #{realIdCard}, + real_phone = #{realPhone}, update_time = sysdate() where user_id = #{userId} diff --git a/ruoyi-web/src/main/java/com/ruoyi/task/order/OrderTask.java b/ruoyi-web/src/main/java/com/ruoyi/task/order/OrderTask.java index 8b33fe9..e9f5477 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/task/order/OrderTask.java +++ b/ruoyi-web/src/main/java/com/ruoyi/task/order/OrderTask.java @@ -4,12 +4,15 @@ import java.time.LocalDateTime; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; import com.ruoyi.bst.order.domain.OrderQuery; import com.ruoyi.bst.order.domain.OrderVO; import com.ruoyi.bst.order.domain.dto.OrderEndDTO; import com.ruoyi.bst.order.domain.enums.OrderStatus; +import com.ruoyi.bst.order.mapper.OrderMapper; import com.ruoyi.bst.order.service.OrderService; import com.ruoyi.common.utils.collection.CollectionUtils; @@ -17,11 +20,31 @@ import lombok.extern.slf4j.Slf4j; @Component @Slf4j -public class OrderTask { +public class OrderTask implements ApplicationRunner { @Autowired private OrderService orderService; + @Autowired + private OrderMapper orderMapper; + + + @Override + public void run(ApplicationArguments args) throws Exception { + // 查询所有未支付的订单 + OrderQuery query = new OrderQuery(); + query.setStatusList(OrderStatus.unPayList()); + List orderList = orderMapper.selectOrderList(query); + + for (OrderVO order : orderList) { + try { + orderService.cancelWhenExpired(order); + } catch (Exception e) { + log.error("取消订单失败,订单ID:{}", order.getId(), e); + } + } + } + /** * 关闭超过最大可用时间的订单 */ diff --git a/ruoyi-web/src/main/java/com/ruoyi/task/pay/PayTask.java b/ruoyi-web/src/main/java/com/ruoyi/task/pay/PayTask.java new file mode 100644 index 0000000..c0d5514 --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/task/pay/PayTask.java @@ -0,0 +1,51 @@ +package com.ruoyi.task.pay; + +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import com.ruoyi.bst.pay.domain.PayQuery; +import com.ruoyi.bst.pay.domain.enums.PayStatus; +import com.ruoyi.bst.pay.mapper.PayMapper; +import com.ruoyi.bst.pay.service.PayService; + +import lombok.extern.slf4j.Slf4j; + +@Component +@Slf4j +public class PayTask implements ApplicationRunner { + + @Autowired + private PayService payService; + + @Autowired + private PayMapper payMapper; + + @Autowired + private ScheduledExecutorService scheduledExecutorService; + + @Override + public void run(ApplicationArguments args) throws Exception { + // 查询所有未支付的支付单 + PayQuery query = new PayQuery(); + query.setStatusList(PayStatus.unPayList()); + List payList = payMapper.selectNoList(query); + + log.info("查询到{}条未支付的支付单", payList.size()); + for (String no : payList) { + scheduledExecutorService.schedule(() -> { + try { + payService.refreshPayResultBeforeExpire(no); + } catch (Exception e) { + log.error("刷新支付结果失败,支付单号:{}", no, e); + } + }, 0, TimeUnit.SECONDS); + } + } + +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/app/AppOrderController.java b/ruoyi-web/src/main/java/com/ruoyi/web/app/AppOrderController.java index 011fd11..ec93046 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/app/AppOrderController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/app/AppOrderController.java @@ -2,7 +2,6 @@ package com.ruoyi.web.app; import java.util.List; -import com.ruoyi.bst.order.domain.vo.OrderFeeVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -19,6 +18,7 @@ import com.ruoyi.bst.order.domain.dto.OrderCreateDTO; import com.ruoyi.bst.order.domain.dto.OrderEndDTO; import com.ruoyi.bst.order.domain.dto.OrderPayDTO; import com.ruoyi.bst.order.domain.enums.OrderStatus; +import com.ruoyi.bst.order.domain.vo.OrderFeeVO; import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO; import com.ruoyi.bst.order.service.OrderConverter; import com.ruoyi.bst.order.service.OrderService; diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/app/AppRealNameController.java b/ruoyi-web/src/main/java/com/ruoyi/web/app/AppRealNameController.java index c3f60bd..17b8139 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/app/AppRealNameController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/app/AppRealNameController.java @@ -24,7 +24,6 @@ public class AppRealNameController extends BaseController { return success(realNameService.realName(realName)); } - @ApiOperation("刷新用户实名认证结果") @GetMapping("/refreshRealName") public AjaxResult refreshRealName() { diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/bst/AreaController.java b/ruoyi-web/src/main/java/com/ruoyi/web/bst/AreaController.java index 19e0898..38c407c 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/bst/AreaController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/bst/AreaController.java @@ -4,6 +4,7 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.annotation.DataScope; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/bst/OrderDeviceController.java b/ruoyi-web/src/main/java/com/ruoyi/web/bst/OrderDeviceController.java new file mode 100644 index 0000000..fafed51 --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/web/bst/OrderDeviceController.java @@ -0,0 +1,110 @@ +package com.ruoyi.web.bst; + +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.ruoyi.bst.orderDevice.domain.OrderDevice; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceQuery; +import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO; +import com.ruoyi.bst.orderDevice.service.OrderDeviceService; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; + +/** + * 订单设备Controller + * + * @author ruoyi + * @date 2025-04-01 + */ +@RestController +@RequestMapping("/bst/orderDevice") +public class OrderDeviceController extends BaseController +{ + @Autowired + private OrderDeviceService orderDeviceService; + + /** + * 查询订单设备列表 + */ + @PreAuthorize("@ss.hasPermi('bst:orderDevice:list')") + @GetMapping("/list") + public TableDataInfo list(OrderDeviceQuery query) + { + startPage(); + startOrderBy(); + List list = orderDeviceService.selectOrderDeviceList(query); + return getDataTable(list); + } + + /** + * 导出订单设备列表 + */ + @PreAuthorize("@ss.hasPermi('bst:orderDevice:export')") + @Log(title = "订单设备", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, OrderDeviceQuery query) + { + List list = orderDeviceService.selectOrderDeviceList(query); + ExcelUtil util = new ExcelUtil(OrderDeviceVO.class); + util.exportExcel(response, list, "订单设备数据"); + } + + /** + * 获取订单设备详细信息 + */ + @PreAuthorize("@ss.hasPermi('bst:orderDevice:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(orderDeviceService.selectOrderDeviceById(id)); + } + + /** + * 新增订单设备 + */ + @PreAuthorize("@ss.hasPermi('bst:orderDevice:add')") + @Log(title = "订单设备", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody OrderDevice orderDevice) + { + return toAjax(orderDeviceService.insertOrderDevice(orderDevice)); + } + + /** + * 修改订单设备 + */ + @PreAuthorize("@ss.hasPermi('bst:orderDevice:edit')") + @Log(title = "订单设备", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody OrderDevice orderDevice) + { + return toAjax(orderDeviceService.updateOrderDevice(orderDevice)); + } + + /** + * 删除订单设备 + */ + @PreAuthorize("@ss.hasPermi('bst:orderDevice:remove')") + @Log(title = "订单设备", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(orderDeviceService.deleteOrderDeviceByIds(ids)); + } +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/common/LoginController.java b/ruoyi-web/src/main/java/com/ruoyi/web/common/LoginController.java index 7a183c2..b99c91b 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/common/LoginController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/common/LoginController.java @@ -3,13 +3,13 @@ package com.ruoyi.web.common; import java.util.List; import java.util.Set; -import com.ruoyi.common.annotation.Anonymous; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.Menu; diff --git a/ruoyi-web/src/main/resources/application-env.yml b/ruoyi-web/src/main/resources/application-env.yml index 7f4d303..3a8096b 100644 --- a/ruoyi-web/src/main/resources/application-env.yml +++ b/ruoyi-web/src/main/resources/application-env.yml @@ -41,3 +41,7 @@ ruoyi: pay: # 支付回调主机地址 notifyHost: https://60.215.128.117:49553 + +# 活体检测 +liveness: + returnUrl: http://192.168.2.99:4100/liveness diff --git a/ruoyi-web/src/main/resources/application.yml b/ruoyi-web/src/main/resources/application.yml index 55380b8..4d29b0f 100644 --- a/ruoyi-web/src/main/resources/application.yml +++ b/ruoyi-web/src/main/resources/application.yml @@ -148,9 +148,8 @@ liveness: appCode: 32b6c6445b1a42ed862dd4202392c47d appSecret: td0vlGZRy9GxlrpinlrxSXFXVW34JxDh jumpUrl: https://liveness.shumaidata.com/index - returnUrl: https://market.aliyun.com/apimarket/detail/cmapi00064393?spm=5176.730005.result.10.2271414a01R1ZI#sku=yuncode5839300001 # 人像比对 face: appKey: 204590328 appCode: 32b6c6445b1a42ed862dd4202392c47d - appSecret: td0vlGZRy9GxlrpinlrxSXFXVW34JxDh \ No newline at end of file + appSecret: td0vlGZRy9GxlrpinlrxSXFXVW34JxDh