From daaba224af151a4b9f61b93d90bdbdfc0b8ca704 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Wed, 29 May 2024 14:10:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/receive/ReceiveController.java | 13 +++- .../com/ruoyi/common/utils/CommonUtil.java | 22 +++--- .../java/com/ruoyi/system/domain/EtModel.java | 4 +- .../service/impl/AsDeviceServiceImpl.java | 74 +++++++++---------- .../system/service/impl/WxPayService.java | 3 + .../mapper/system/AsDeviceMapper.xml | 4 + 6 files changed, 68 insertions(+), 52 deletions(-) diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java index 5f5badb..e2979e7 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java @@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; /** * 接收硬件参数 @@ -105,13 +106,17 @@ public class ReceiveController { * */ /** 1.更新车辆定位、电压;计算续航里程 */ AsDevice device = asDeviceService.selectAsDeviceByMac(logEntry.getDevName()); + if(ObjectUtil.isNull(device)){ + throw new ServiceException("未找到车辆信息"); + } EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(device.getAreaId()); if(ObjectUtil.isNotNull(device)){ device.setLatitude(value.getLon()); device.setLongitude(value.getLat()); Integer bat = value.getBat(); - double voltage = (double) bat / 10;//电压 - device.setVoltage(String.valueOf(voltage));//电压 + BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10)); + log.info("保存电压:" + divide); + device.setVoltage(divide.toString());//电压 // 根据电压计算续航里程 EtModel model = etModelService.selectEtModelByModelId(device.getModelId()); Integer remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance()); @@ -120,7 +125,7 @@ public class ReceiveController { device.setRemainingPower(electricQuantity.toString()); int i = asDeviceService.updateAsDeviceBySn(device); if(i>0){ - log.info("更新定位成功:" +logEntry.getDevName()); + log.info("更新定位成功==========================>" +logEntry.getDevName()); /** 2. 判断是否在禁行区内 * 如果在, 根据配置‘禁行区内断电配置’进行断电 **/ @@ -153,7 +158,7 @@ public class ReceiveController { /** 5.低于电量(%)不得骑行,声音播报 */ if(electricQuantity <= model.getLowBatteryReminder()){ //发送低电量播报指令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY6,"低电量播报"); +// asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY6,"低电量播报"); log.info("低电量播报:" +logEntry.getDevName()); } /** 6.低电量 生成换电工单*/ diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java b/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java index 76367eb..ba28a94 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java @@ -9,6 +9,7 @@ import com.ruoyi.common.utils.spring.SpringUtils; import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; +import java.math.RoundingMode; /** * 业务工具类 @@ -110,11 +111,13 @@ public class CommonUtil { * @param fullEndurance 满电续航里程 * @author qzz */ - public static Integer getRemainingMileage(String voltage,Integer fullVoltage,Integer lowVoltage,Integer fullEndurance) { + public static Integer getRemainingMileage(String voltage,Double fullVoltage,Double lowVoltage,Integer fullEndurance) { // 满电电压减去亏电电压 乘以 满电续航里程 除以 满电电压 - int current = (fullVoltage - Integer.parseInt(voltage)) ; - int full = (fullVoltage - lowVoltage) ; - BigDecimal divide = new BigDecimal(current).divide(new BigDecimal(full));//当前电量百分百 + log.info(" 电压--voltage:{},满电电压--fullVoltage:{},亏电电压--lowVoltage:{},满电续航--fullEndurance:{}",voltage,fullVoltage,lowVoltage,fullEndurance); + BigDecimal vol = new BigDecimal(voltage); + BigDecimal current = new BigDecimal(fullVoltage).subtract(vol); + BigDecimal full = new BigDecimal(fullVoltage).subtract(new BigDecimal(lowVoltage)); + BigDecimal divide = full.subtract(current).divide(full,2, RoundingMode.HALF_UP);//当前电量百分百 log.info("当前电量百分百:{}%",divide.multiply(new BigDecimal(100))); BigDecimal multiply = divide.multiply(new BigDecimal(fullEndurance)); log.info("当前剩余续航里程:{}km",multiply); @@ -129,13 +132,14 @@ public class CommonUtil { * @param lowVoltage 亏电电压 * @author qzz */ - public static Integer getElectricQuantity(String voltage,Integer fullVoltage,Integer lowVoltage) { + public static Integer getElectricQuantity(String voltage,Double fullVoltage,Double lowVoltage) { // 满电电压减去亏电电压 乘以 满电续航里程 除以 满电电压 - int current = (fullVoltage - Integer.parseInt(voltage)) ; - int full = (fullVoltage - lowVoltage) ; - BigDecimal divide = new BigDecimal(current).divide(new BigDecimal(full));//当前电量百分百 + BigDecimal vol = new BigDecimal(voltage); + BigDecimal current = new BigDecimal(fullVoltage).subtract(vol); + BigDecimal full = new BigDecimal(fullVoltage).subtract(new BigDecimal(lowVoltage)); + BigDecimal divide = full.subtract(current).divide(full,2, RoundingMode.HALF_UP);//当前电量百分百 BigDecimal multiply = divide.multiply(new BigDecimal(100)); - log.info("当前电量百分百:{}%",multiply); +// log.info("当前电量百分百:{}%",multiply); return multiply.intValue(); } } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java index 764abca..4b917c4 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java @@ -34,11 +34,11 @@ public class EtModel extends BaseEntity /** 满电电压 */ @Excel(name = "满电电压") - private Integer fullVoltage; + private Double fullVoltage; /** 亏电电压 */ @Excel(name = "亏电电压") - private Integer lowVoltage; + private Double lowVoltage; /** 满电续航 */ @Excel(name = "满电续航") 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 6902532..cbd5032 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 @@ -406,12 +406,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** 2.发送命令*/ sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN,"编号开锁"); //间隔1秒 - try { - Thread.sleep(500); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"编号开锁播报"); +// try { +// Thread.sleep(1000); +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } +// sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"编号开锁播报"); /** 3.更新车辆状态*/ asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING); @@ -475,12 +475,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** 2.发送命令*/ sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN,"管理员开锁"); //间隔1秒 - try { - Thread.sleep(500); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"管理员开锁播报"); +// try { +// Thread.sleep(500); +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } +// sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"管理员开锁播报"); return Boolean.TRUE; }); if(!execute)throw new ServiceException("管理员开锁失败"); @@ -657,12 +657,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** 2.发送命令*/ sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_LLOSE,"临时锁车"); //间隔1秒 - try { - Thread.sleep(500); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY7,"临时锁车播报"); +// try { +// Thread.sleep(500); +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } +// sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY7,"临时锁车播报"); if(StrUtil.isNotBlank(orderNo)){//有订单号,则是用户临时锁车 /** 改变车辆状态:4-临时锁车 */ asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK);//临时锁车 @@ -713,12 +713,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** 2.发送命令*/ sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN,"临时解锁"); //间隔1秒 - try { - Thread.sleep(500); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"临时解锁播报"); +// try { +// Thread.sleep(500); +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } +// sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"临时解锁播报"); if(StrUtil.isNotBlank(orderNo)){//有订单号,则是用户骑行中解锁 /** 改变车辆状态:3-骑行中 */ asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING);//骑行中 @@ -789,13 +789,13 @@ public class AsDeviceServiceImpl extends ServiceImpl i //1.发送开锁命令并更新车辆状态 String token = Token.getToken(); sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_CLOSE,"取消预约关锁"); - //间隔1秒 - try { - Thread.sleep(500); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY8,"取消预约关锁播报"); +// //间隔1秒 +// try { +// Thread.sleep(500); +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } +// sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY8,"取消预约关锁播报"); /** 5.记录行程*/ int tripLog = tripLogService.tripLog(order.getOrderNo(),order.getSn(),ServiceConstants.TRIP_LOG_TYPE_UNLOCK_RIDE); if(tripLog==0){ @@ -883,12 +883,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** 2. 车辆远程关锁*/ sendCommand(device.getMac(), token,IotConstants.COMMAND_CLOSE,"还车关锁"); //间隔1秒 - try { - Thread.sleep(500); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - sendCommand(device.getMac(), token,IotConstants.COMMAND_PLAY8,"还车关锁播报"); +// try { +// Thread.sleep(500); +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } +// sendCommand(device.getMac(), token,IotConstants.COMMAND_PLAY8,"还车关锁播报"); /** 4. 更新车辆状态*/ device.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL); device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); 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 b7062be..fbeab1a 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 @@ -112,6 +112,9 @@ public class WxPayService implements IWxPayService { request.setDescription(description); request.setNotifyUrl(wxPayConfig.getNotifyUrl()); request.setPayer(getPayer(user.getWxopenid())); + SettleInfo settleInfo = new SettleInfo(); + settleInfo.setProfitSharing(Boolean.TRUE); + request.setSettleInfo(settleInfo); PrepayWithRequestPaymentResponse res = jsapiServiceExtension.prepayWithRequestPayment(request); return res; } finally { diff --git a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml index 72d6ee4..18f7021 100644 --- a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml @@ -120,6 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" lock_status, location, remaining_power, + voltage, qrcode, longitude, latitude, @@ -144,6 +145,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{lockStatus}, #{location}, #{remainingPower}, + #{voltage}, #{qrcode}, #{longitude}, #{latitude}, @@ -172,6 +174,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" lock_status = #{lockStatus}, location = #{location}, remaining_power = #{remainingPower}, + voltage = #{voltage}, qrcode = #{qrcode}, longitude = #{longitude}, latitude = #{latitude}, @@ -201,6 +204,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" lock_status = #{lockStatus}, location = #{location}, remaining_power = #{remainingPower}, + voltage = #{voltage}, qrcode = #{qrcode}, longitude = #{longitude}, latitude = #{latitude},