From fa7f3d2fb45461bae32b54154d51c4ea3db19595 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Fri, 3 Jan 2025 13:52:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/app/AppVerifyController.java | 14 +++++++++++--- .../common/core/redis/enums/RedisLockKey.java | 3 ++- .../com/ruoyi/system/service/IAsDeviceService.java | 2 +- .../system/service/impl/AsDeviceServiceImpl.java | 14 +++++++++++--- .../ruoyi/system/service/impl/WxPayService.java | 8 ++++++-- 5 files changed, 31 insertions(+), 10 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 e1a8433..1266103 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 @@ -261,7 +261,15 @@ public class AppVerifyController extends BaseController if(asDeviceService.isLowBattery(order.getSn())){ return error("低电量不得骑行"); } - OrderResponse orderResponse =asDeviceService.snSwitch(order); + OrderResponse orderResponse; + // 加锁 + ServiceUtil.assertion(!redisLock.lock(RedisLockKey.SNSWITCH, order.getSn()), "当前车辆使用人数较多,请稍后再试!"); + try { + orderResponse =asDeviceService.snSwitch(order); + } finally { + // 解锁 + redisLock.unlock(RedisLockKey.SNSWITCH, order.getSn()); + } return success(orderResponse); } @@ -705,9 +713,9 @@ public class AppVerifyController extends BaseController * 所有车辆定位 */ @GetMapping(value = "/allVehicleInfo") - public AjaxResult allVehicleInfo(String powerStart,String powerEnd, String status,String sort,String areaId,String onlineStatus) + public AjaxResult allVehicleInfo(String powerStart,String powerEnd, String status,String sort,String areaId,String onlineStatus,String typeSort) { - List asDevices = asDeviceService.allVehicleInfo(powerStart,powerEnd,status,sort,areaId,onlineStatus); + List asDevices = asDeviceService.allVehicleInfo(powerStart,powerEnd,status,sort,areaId,onlineStatus,typeSort); return success(asDevices); } diff --git a/electripper-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java b/electripper-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java index 6af2bc6..cb9457a 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java +++ b/electripper-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java @@ -13,7 +13,8 @@ public enum RedisLockKey { DEDUCTION("deduction", "押金抵扣"), EDITPRICE("editPrice", "改价"), - PAYCALLBACK("payCallback", "支付回调"); + PAYCALLBACK("payCallback", "支付回调"), + SNSWITCH("snSwitch", "扫码开锁"); private final String key; private final String name; diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java index f1e9c6c..7bfb106 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java @@ -170,7 +170,7 @@ public interface IAsDeviceService extends IService /** * 所有车辆定位 */ - List allVehicleInfo(String powerStart, String powerEnd, String status,String sort,String areaId,String onlineStatus); + List allVehicleInfo(String powerStart, String powerEnd, String status,String sort,String areaId,String onlineStatus,String typeSort); /** * 查询车辆数量 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 d02edda..c796dfe 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 @@ -719,7 +719,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i * 所有车辆定位 */ @Override - public List allVehicleInfo(String powerStart, String powerEnd, String status,String sort,String areaId,String onlineStatus) { + public List allVehicleInfo(String powerStart, String powerEnd, String status,String sort,String areaId,String onlineStatus,String typeSort) { QueryWrapper wrapper = new QueryWrapper<>(); if(StrUtil.isNotBlank(areaId)){ wrapper.eq("area_id",areaId); @@ -737,8 +737,16 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(StrUtil.isNotBlank(onlineStatus)){ wrapper.in("online_status",onlineStatus); } - if(StrUtil.isNotBlank(sort)){ - wrapper.orderBy(true,!StrUtil.equals(sort, "desc"),"remaining_power"); + if(StrUtil.isNotBlank(typeSort)){ + if(StrUtil.equals(typeSort,"1")){ + wrapper.orderBy(true,!StrUtil.equals(sort, "desc"),"sn"); + }else if(StrUtil.equals(typeSort,"2")){ + wrapper.orderBy(true,!StrUtil.equals(sort, "desc"),"model_id"); + }else if(StrUtil.equals(typeSort,"3")){ + wrapper.orderBy(true,!StrUtil.equals(sort, "desc"),"vehicle_num"); + }else{ + wrapper.orderBy(true,!StrUtil.equals(sort, "desc"),"remaining_power"); + } } List asDevices = asDeviceMapper.selectList(wrapper); for (AsDevice asDevice:asDevices){ 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 5cb32b3..d34bf46 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 @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSON; import com.alipay.api.response.AlipayTradeRefundResponse; +import com.aliyuncs.exceptions.ClientException; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.ServiceConstants; @@ -488,8 +489,11 @@ public class WxPayService implements IWxPayService { request.setNotifyUrl(channelVO.getRefundNotifyUrl()); log.info("【退款】请求微信参数:【{}】",JSON.toJSONString(request)); RefundService refundService = getRefundService(channelVO); - Refund refund = refundService.create(request); - log.info("【退款】微信返回结果:【{}】",JSON.toJSONString(refund)); + try { + refundService.create(request); + } catch (com.wechat.pay.java.core.exception.ServiceException e) { + throw new ServiceException("【退款】微信退款失败:" + e.getErrorMessage()); + } }else if(PayChannel.TM_WX.equalsCode(channelVO.getCode())){ log.info("----------{}-------------","太米微信退款"); RefundAble refundAble = new RefundAble();