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 41f1603..38902cb 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 @@ -8,11 +8,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.annotation.DataScope; -import com.ruoyi.common.constant.HttpStatus; -import com.ruoyi.common.constant.IotConstants; -import com.ruoyi.common.constant.ServiceConstants; -import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.constant.*; import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.CommonUtil; import com.ruoyi.common.utils.DateUtils; @@ -110,13 +108,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i private IEtOnlineLogService etOnlineLogService; @Autowired - private IEtRefundService etRefundService; - - @Resource - private IAsUserService asUserService; - - @Autowired - private CallbackService callbackService; + private RedisCache redisCache; @Autowired private ISysConfigService sysConfigService; @@ -209,12 +201,22 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(ObjectUtil.isNotNull(model)){ asDevice.setModel(model.getModel()); } -// if(StrUtil.isNotBlank(asDevice.getLongitude()) && StrUtil.isNotBlank(asDevice.getLatitude())){ -// asDevice.setLocation(CommonUtil.getAddressByGeo(asDevice.getLongitude() + ","+asDevice.getLatitude())); -// } if(StrUtil.isNotBlank(asDevice.getVoltage())){ asDevice.setRemainingMileage(CommonUtil.getRemainingMileage(asDevice.getVoltage(),model.getFullVoltage(),model.getLowVoltage(),model.getFullEndurance())); } + String msg = redisCache.getCacheObject(CacheConstants.CACHE_DEVICE_KEY + asDevice.getSn()); + if(StrUtil.isNotBlank(msg)){ + log.info("【根据sn号查询车辆实时信息】-========redis缓存中的数据:" + msg); + LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class); + log.info("【根据sn号查询车辆实时信息】============logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry)); + LogEntry.LocationValue value = logEntry.getValue(); + // 坐标转换 WGS84 转 GCJ02 + double[] doubles = CommonUtil.coordinateConvert(value.getLon(),value.getLat()); + BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP); + BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP); + asDevice.setLongitude(lon.toString()); + asDevice.setLatitude(lat.toString()); + } //正在进行中的订单 EtOrder order = new EtOrder(); order.setSn(asDevice.getSn()); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index 8c0bca4..084488d 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -472,28 +472,31 @@ public class EtOrderServiceImpl implements IEtOrderService log.info("【押金抵扣】订单【{}】,有outTradeNo = 【{}】", order.getOrderNo(),outTradeNo); // 如果原来有outtradeno,去查询一次,查询是否支付过 Transaction transaction = wxPayService.queryOrderByOutTradeNo(outTradeNo); - if (Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) { - // 订单已支付 - order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); - order.setPayTime(DateUtils.getNowDate()); - order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); - order.setPayType(ServiceConstants.PAY_TYPE_WX); - order.setMark("主动查询-骑行支付"); - try { - int updateEtOrder = etOrderMapper.updateEtOrder(order); + try { + if (Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) { + // 订单已支付 + order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); + order.setPayTime(DateUtils.getNowDate()); + order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); + order.setPayType(ServiceConstants.PAY_TYPE_WX); + order.setMark("主动查询-骑行支付"); + int updateEtOrder = etOrderMapper.updateEtOrderByOrderNo(order); if (updateEtOrder == 0) { // 抛出自定义异常来标识订单更新失败 throw new ServiceException("押金抵扣失败,更新骑行订单失败"); } - } finally { - // 无论订单更新是否成功,一定抛出异常来终止后续操作 - throw new ServiceException("订单已支付,请勿操作"); + return 1; + }else{ + SysDept dept = wxPayService.getDeptObjByAreaId(order.getAreaId()); + // 没有支付,则关闭订单 + boolean b = wxPayService.closeOrder(outTradeNo, dept); + log.info("【押金抵扣】订单【{}】,有outTradeNo = 【{}】,查询订单未支付,关闭订单:{}", order.getOrderNo(),outTradeNo,b); } - }else{ - SysDept dept = wxPayService.getDeptObjByAreaId(order.getAreaId()); - // 没有支付,则关闭订单 - boolean b = wxPayService.closeOrder(outTradeNo, dept); - log.info("【押金抵扣】订单【{}】,有outTradeNo = 【{}】,查询订单未支付,关闭订单:{}", order.getOrderNo(),outTradeNo,b); + } catch (ServiceException e) { + log.error("异常发生: {}", e.getMessage()); + return -1; // -1 表示失败 + } finally { + log.warn("订单已支付,请勿操作"); } } EtOrder depositOrder = getDepositOrder(order.getUserId()); @@ -1924,7 +1927,7 @@ public class EtOrderServiceImpl implements IEtOrderService Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ if(!"true".equals(isBluetooth)){ - ResponseVo responseVo = asDeviceService.sendCommandWithResp(newDevice.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "换车开锁",orderNo); + ResponseVo responseVo = asDeviceService.sendCommandWithResp(newDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "换车开锁",orderNo); if(responseVo.getCode()!=0){ log.info("【换车开锁】远程关锁失败"); throw new ServiceException("换车开锁失败");