From 473bbdf8091c6214cc890437249d05ababfdd6c0 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: Fri, 6 Jun 2025 15:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E2=80=9C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E2=80=9D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/domain/enums/ChannelApiType.java | 4 ++-- .../bst/device/service/DeviceIotService.java | 10 ++++++++++ .../service/impl/DeviceIotServiceImpl.java | 12 ++++++++++++ .../bst/pay/service/impl/PayServiceImpl.java | 19 +++++++++++++------ .../com/ruoyi/iot/constants/IotConstants.java | 2 ++ .../com/ruoyi/iot/service/IotService.java | 8 ++++++++ .../service/impl/IotReceiveServiceImpl.java | 8 ++++---- .../iot/service/impl/IotServiceImpl.java | 5 +++++ .../ruoyi/web/bst/DeviceIotController.java | 8 ++++++++ 9 files changed, 64 insertions(+), 12 deletions(-) diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/channel/domain/enums/ChannelApiType.java b/ruoyi-service/src/main/java/com/ruoyi/bst/channel/domain/enums/ChannelApiType.java index 51812bc..05a55f3 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/channel/domain/enums/ChannelApiType.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/channel/domain/enums/ChannelApiType.java @@ -27,7 +27,7 @@ public enum ChannelApiType { WECHAT("WX", "微信支付",WxPayService.class, false, true), ALI("ALI", "支付宝", AliPayService.class, true, true), BANK("BANK", "银行卡", null, false, true), - BALANCE("BALANCE", "余额支付", null, true, true), + BALANCE("BALANCE", "余额支付", null, true, false), TM_WX("TM_WX", "太米微信支付", TmPayService.class, true, true), CREDIT("CREDIT", "挂账", CreditPayServiceImpl.class, true, false); @@ -35,7 +35,7 @@ public enum ChannelApiType { private final String name; private final Class payApi; private final Boolean isRefundSync; // 退款是否同步通知 - private final Boolean needPay; // 是否需要前端调起支付 + private final Boolean needPay; // 是否需要前端调起支付,也可作为刷新支付结果是否为异步的凭据 public static ChannelApiType parse(String type) { for (ChannelApiType value : ChannelApiType.values()) { diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceIotService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceIotService.java index acb55b3..939d7bf 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceIotService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/device/service/DeviceIotService.java @@ -182,4 +182,14 @@ public interface DeviceIotService { */ Map getIotInfo(String mac); + /** + * 升级设备 + * + * @param device 设备 + * @param reason 原因 + * @param requiredIot 是否IOT操作必须成功 + * @return 结果 + */ + boolean update(DeviceVO device, String reason, boolean requiredIot); + } 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 374f0bf..29e9b79 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 @@ -449,4 +449,16 @@ public class DeviceIotServiceImpl implements DeviceIotService { return redisCache.getCacheMap(key); } + + @Override + public boolean update(DeviceVO device, String reason, boolean requiredIot) { + if (device == null) { + return false; + } + CommandResponse res = iotService.update(device, reason); + boolean success = IotUtil.isSuccess(res); + ServiceUtil.assertion(requiredIot && !success, IotUtil.getMsg(res), ServiceCode.IOT_FAILED); + return success; + } + } 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 cda3fc7..c2aaa47 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 @@ -344,10 +344,6 @@ public class PayServiceImpl implements PayService { // 若支付金额为0,则不调起支付 if (pay.getAmount().compareTo(BigDecimal.ZERO) == 0) { vo.setNeedPay(false); - // 异步处理支付成功 - scheduledExecutorService.schedule(() -> { - this.handleSuccess(pay.getNo(), LocalDateTime.now()); - }, 1L, TimeUnit.SECONDS); } else { // 获取渠道信息 ChannelVO channel = channelService.selectChannelByChannelId(pay.getChannelId()); @@ -376,9 +372,19 @@ public class PayServiceImpl implements PayService { log.error("更新渠道订单号失败,支付单ID为{}", pay.getId()); } + } + + // 根据是否需要前端调起支付来判断 + if (vo.getNeedPay()) { // 异步刷新支付结果 - scheduledExecutorService.execute( ()-> { + scheduledExecutorService.schedule( ()-> { + log.info("异步刷新支付结果:pay.getNo() = {}", pay.getNo()); this.refreshPayResultBeforeExpire(pay.getNo()); + }, 10, TimeUnit.SECONDS); + } else { + // 异步处理支付成功 + scheduledExecutorService.execute(() -> { + this.handleSuccess(pay.getNo(), LocalDateTime.now()); }); } @@ -394,6 +400,7 @@ public class PayServiceImpl implements PayService { this.refreshPayResult(no); // 获取刷新后的订单 PayVO pay = this.selectByNo(no); + log.info("异步刷新支付结果:pay = {}", pay); if (pay == null) { return; } @@ -427,6 +434,7 @@ public class PayServiceImpl implements PayService { } PayVO pay = this.selectByNo(no); + log.info("刷新支付结果 pay = {}", pay); if (pay == null) { return; } @@ -448,7 +456,6 @@ public class PayServiceImpl implements PayService { // 获取支付结果,若成功则处理支付成功 Object result = this.queryPayInfo(payApi, pay, channel, app); boolean isPaySuccess = payApi.isPaySuccess(result); - log.info("刷新支付结果:{}, {}, {}", pay.getNo(), isPaySuccess, result); if (isPaySuccess) { this.handleSuccess(pay, payApi.getPayTime(result)); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/iot/constants/IotConstants.java b/ruoyi-service/src/main/java/com/ruoyi/iot/constants/IotConstants.java index 7bb6f8f..1d6c2a0 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/iot/constants/IotConstants.java +++ b/ruoyi-service/src/main/java/com/ruoyi/iot/constants/IotConstants.java @@ -36,6 +36,7 @@ public class IotConstants { public static final String COMMAND_PLAY = "play"; // 播放语音 public static final String VOLTAGE_CHECK = "check"; // 电压校准 public static final String COMMAND_REBOOT = "reboot"; // 重启设备 + public static final String COMMAND_UPDATE = "update"; // 升级设备 // 语音列表 public static final String PLAY_WELCOME = "0";// 欢迎 @@ -64,5 +65,6 @@ public class IotConstants { public static final String DS_SYS_LON = "lon"; // 经度 public static final String DS_SYS_LAT = "lat"; // 纬度 public static final String DS_CSQ = "CSQ"; // 信号强度 + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/iot/service/IotService.java b/ruoyi-service/src/main/java/com/ruoyi/iot/service/IotService.java index 198f3d4..da36c38 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/iot/service/IotService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/iot/service/IotService.java @@ -122,4 +122,12 @@ public interface IotService { * @return 结果 */ CommandResponse uploadData(IotDevice device, String reason); + + /** + * 升级设备 + * @param device 设备 + * @param reason 原因 + * @return 结果 + */ + CommandResponse update(IotDevice device, String reason); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotReceiveServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotReceiveServiceImpl.java index faa625d..c096b69 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotReceiveServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotReceiveServiceImpl.java @@ -118,10 +118,10 @@ public class IotReceiveServiceImpl implements IotReceiveService { } // 处理设备定位BUG,若出现BUG则重启设备 - int handle = this.handleDeviceLocationBug(device, at, lastLocationTime, oldLon, oldLat); - if (handle == 1) { - return; - } +// int handle = this.handleDeviceLocationBug(device, at, lastLocationTime, oldLon, oldLat); +// if (handle == 1) { +// return; +// } // 处理运营区 this.handleArea(device); diff --git a/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java index 2fd37b6..7939b1f 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java @@ -383,6 +383,11 @@ public class IotServiceImpl implements IotService { return sendCommand(device, IotConstants.COMMAND_PLAY + type, reason); } + @Override + public CommandResponse update(IotDevice device, String reason) { + return sendCommand(device, IotConstants.COMMAND_UPDATE, reason); + } + @Override public CommandResponse reboot(IotDevice device, String reason) { return sendCommand(device, IotConstants.COMMAND_REBOOT, reason); diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/bst/DeviceIotController.java b/ruoyi-web/src/main/java/com/ruoyi/web/bst/DeviceIotController.java index 1d1a24c..d0fbc4f 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/bst/DeviceIotController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/bst/DeviceIotController.java @@ -134,4 +134,12 @@ public class DeviceIotController extends BaseController { DeviceVO device = this.getDevice(id, sn); return executeWithLock(device, () -> success(deviceIotService.setMusic(device, music, "管理员设置声音", true))); } + + @PreAuthorize("@ss.hasPermi('bst:device:update')") + @Log(title = "管理员升级设备", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.DEVICE) + @PutMapping("/update") + public AjaxResult update(@RequestParam(required = false) Long id, @RequestParam(required = false) String sn) { + DeviceVO device = this.getDevice(id, sn); + return executeWithLock(device, () -> success(deviceIotService.update(device, "管理员升级设备", true))); + } }