From 59c3ff74c871136f779182b3b2e5f09abf96be05 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Tue, 4 Jun 2024 10:36:58 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/app/AppVerifyController.java | 8 +++++ .../ruoyi/common/utils/onenet/ResponseVo.java | 21 ++++++++++++ .../system/service/IAsDeviceService.java | 12 ++++++- .../service/impl/AsDeviceServiceImpl.java | 33 ++++++++++++++++++- .../service/impl/CallbackServiceImpl.java | 21 ++++++++---- 5 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 electripper-common/src/main/java/com/ruoyi/common/utils/onenet/ResponseVo.java 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 21de10e..563e517 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 @@ -144,6 +144,10 @@ public class AppVerifyController extends BaseController if(order.getRuleId()==null){ return error("=============================================ruleId未传!!!============================================="); } + //设备是否在线 + if(!asDeviceService.isOnline(order.getSn())){ + return error("设备不在线"); + } //实名判断 if(!asUserService.checkIsAuthentication(order.getUserId())){ return error("您还未实名,请先实名"); @@ -291,6 +295,10 @@ public class AppVerifyController extends BaseController public AjaxResult deviceAppointment(EtOrderVo appointmentVo) { logger.info("【车辆预约信息】:{}", JSON.toJSON(appointmentVo)); + //设备是否在线 + if(!asDeviceService.isOnline(appointmentVo.getSn())){ + return error("设备不在线"); + } //运营时间判断 if(!asDeviceService.isOperatingTime(appointmentVo.getSn())){ return error("不在营业时间内,不得骑行"); diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/ResponseVo.java b/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/ResponseVo.java new file mode 100644 index 0000000..89b3baf --- /dev/null +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/ResponseVo.java @@ -0,0 +1,21 @@ +package com.ruoyi.common.utils.onenet; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class ResponseVo { + + @JsonProperty("data") + private Object data; + + @JsonProperty("request_id") + private String requestId; + + @JsonProperty("msg") + private String msg; + + @JsonProperty("code") + private int code; + +} 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 f55bdb3..de5a78d 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 @@ -1,9 +1,9 @@ package com.ruoyi.system.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.common.utils.onenet.ResponseVo; import com.ruoyi.system.domain.AsDevice; import com.ruoyi.system.domain.EtOperatingArea; -import com.ruoyi.system.domain.EtOrder; import com.ruoyi.system.domain.response.OrderResponse; import com.ruoyi.system.domain.vo.DeviceNumVo; import com.ruoyi.system.domain.vo.EtOrderVo; @@ -127,6 +127,11 @@ public interface IAsDeviceService extends IService */ public void sendCommand(String mac, String token,String command,String type); + /** + * 发送命令(带响应) + */ + public ResponseVo sendCommandWithResp(String mac, String token, String command, String type); + /** * 响铃寻车 */ @@ -236,6 +241,11 @@ public interface IAsDeviceService extends IService int updateLocation(AsDevice device); + /** + * 判断是否在线 + */ + boolean isOnline(String sn); + // /** // * 是否靠近运营区边界 // */ 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 7d77656..cb51654 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 @@ -17,6 +17,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.map.GeoUtils; import com.ruoyi.common.utils.onenet.IotUtil; +import com.ruoyi.common.utils.onenet.ResponseVo; import com.ruoyi.common.utils.onenet.Token; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.system.domain.*; @@ -633,6 +634,16 @@ public class AsDeviceServiceImpl extends ServiceImpl i } } + @Override + /** 发送命令*/ + public ResponseVo sendCommandWithResp(String mac, String token,String command,String type) { + String param = "device_name=" + mac + "&product_id=" + productId +"&timeout=" + timeout; + String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND + "?"+param; + String result = HttpUtils.sendPostWithToken(sendUrl, command, token); + log.info("【"+type+"】===>IOT请求调用结果:【{}】",result); + return JSON.parseObject(result,ResponseVo.class); + } + /** * 响铃寻车 * @param sn @@ -798,7 +809,14 @@ public class AsDeviceServiceImpl extends ServiceImpl i //定时取消预约 scheduledExecutorService.schedule(() -> { log.error("【车辆超时预约】系统自动取消"); - //订单更新最后预约时间,并结束订单,做超出预约时间标记 + EtOrder order1 = etOrderService.selectEtOrderByOrderNo(order.getOrderNo()); + log.info("【定时取消预约】重新获取订单信息:{}",JSON.toJSON(order1)); + if(order1.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_PAID)){//已支付订单,跳过 + log.error("【车辆超时预约】订单已支付,跳过"); + return; + } + log.error("【车辆超时预约】订单未支付,系统自动处理"); + //未支付 订单更新最后预约时间,并结束订单,做超出预约时间标记 order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT); order.setAppointmentEndTime(new Date()); order.setAppointmentTimeout("1"); @@ -1333,6 +1351,19 @@ public class AsDeviceServiceImpl extends ServiceImpl i return asDeviceMapper.update(null,wrapper); } + /** + * 判断是否在线 + */ + @SneakyThrows + @Override + public boolean isOnline(String sn) { + ResponseVo responseVo = sendCommandWithResp(asDeviceMapper.selectAsDeviceBySn(sn).getMac(), Token.getToken(), "111", "是否在线"); + if(responseVo.getCode() == 0){ + return true; + } + return false; + } + /** * 判断是否靠近边界 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java index 31c196e..a1ba4fd 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java @@ -6,7 +6,6 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.Constants; -import com.ruoyi.common.constant.IotConstants; import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.core.domain.entity.AsUser; import com.ruoyi.common.core.domain.entity.SysUser; @@ -16,7 +15,7 @@ import com.ruoyi.common.pay.wx.domain.NotifyEventType; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.http.HttpUtils; -import com.ruoyi.common.utils.onenet.Token; +import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.vo.AttachVo; import com.ruoyi.system.mapper.AsDeviceMapper; @@ -40,14 +39,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.TransactionTemplate; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; /** @@ -165,7 +162,7 @@ public class CallbackServiceImpl implements CallbackService { if(autoRefundDeposit!=null && autoRefundDeposit>0){ //创建一个定时器,计算出退还时间后,执行退款操作 // 往后推autoRefundDeposit小时执行 - scheduledExecutorService.schedule(() -> { +// scheduledExecutorService.schedule(() -> { logger.info("【微信支付回调】退还押金定时任务开始"); // 退款 Long userId = order.getUserId(); @@ -182,12 +179,13 @@ public class CallbackServiceImpl implements CallbackService { .max(Comparator.comparing(EtOrder::getPayTime)); if (latestOrder.isPresent()) { EtOrder newestOrder = latestOrder.get(); + logger.info("【微信支付回调】最后一次押金充值记录 : " + JSON.toJSONString(newestOrder)); // 处理找到的最新支付时间的订单 String deposit = area.getDeposit(); if(newestOrder.getTotalFee().compareTo(new BigDecimal(deposit))!=0){ throw new ServiceException("押金充值记录与当前运营区的押金不同"); } - Refund refund = wxPayService.refund(newestOrder,autoRefundDeposit+"个小时后自动退款", newestOrder.getTotalFee()); + Refund refund = wxPayService.refund(newestOrder,autoRefundDeposit+"个小时后自动退押金", newestOrder.getTotalFee()); EtRefund refund1= orderService.createRefund(etOrder, newestOrder.getTotalFee(), null, null, null, null, refund,ServiceConstants.REFUND_TYPE_DEPOSIT); int i = etRefundService.insertEtRefund(refund1); if(i>0){ @@ -195,10 +193,19 @@ public class CallbackServiceImpl implements CallbackService { } // 新增资金流水记录 capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND); + + // 更新用户信息,清除缓存 + asUser.setBalance(asUser.getBalance().subtract(newestOrder.getTotalFee())); + int updateUser = userService.updateUser(asUser); + Collection keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); + redisCache.deleteObject(keys); + if(updateUser>0){ + logger.info("【微信支付回调】退还押金,更新用户余额成功!"); + } } else { throw new ServiceException("没有找到押金充值记录"); } - }, autoRefundDeposit, TimeUnit.HOURS); +// }, autoRefundDeposit, TimeUnit.HOURS); } logger.info("=================【微信支付回调】开始请求分账=================="); logger.info("区域对象====="+JSON.toJSONString(area));