From 1abf528d608c49f6a78636cd200464040a6cd5c6 Mon Sep 17 00:00:00 2001
From: 18650502300 <18650502300@163.com>
Date: Tue, 28 May 2024 17:33:11 +0800
Subject: [PATCH] =?UTF-8?q?1.=E4=BD=8E=E7=94=B5=E9=87=8F=E4=B8=8D=E5=BE=97?=
=?UTF-8?q?=E9=AA=91=E8=A1=8C=E5=88=A4=E6=96=AD=202.=E4=BD=8E=E7=94=B5?=
=?UTF-8?q?=E9=87=8F=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E6=8D=A2=E7=94=B5?=
=?UTF-8?q?=E5=B7=A5=E5=8D=95=EF=BC=8C=E9=80=BB=E8=BE=91=E7=A7=BB=E5=88=B0?=
=?UTF-8?q?=E5=BF=83=E8=B7=B3=E9=80=BB=E8=BE=91=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/app/AppVerifyController.java | 4 +
.../iot/receive/ReceiveController.java | 57 ++++++++++++--
.../ruoyi/common/utils/SendAliSmsUtil.java | 1 -
.../system/service/IAsDeviceService.java | 5 ++
.../service/impl/AsDeviceServiceImpl.java | 76 ++++---------------
5 files changed, 75 insertions(+), 68 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 9a9b4ed..be2f67f 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
@@ -148,6 +148,10 @@ public class AppVerifyController extends BaseController
if(!asUserService.checkIsDeposit(order.getUserId())){
return error("您还未充值押金,请先充值押金");
}
+ //低电量不得骑行判断
+ if(asDeviceService.isLowBattery(order.getSn())){
+ return error("低电量不得骑行");
+ }
OrderResponse orderResponse =asDeviceService.snSwitch(order);
return success(orderResponse);
}
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 5fcc438..f1dabff 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
@@ -4,16 +4,17 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.IotConstants;
+import com.ruoyi.common.constant.ServiceConstants;
+import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.onenet.Token;
+import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.AsDevice;
+import com.ruoyi.system.domain.EtAdminOrder;
import com.ruoyi.system.domain.EtModel;
import com.ruoyi.system.domain.EtOperatingArea;
-import com.ruoyi.system.mapper.AsDeviceMapper;
-import com.ruoyi.system.service.IAsDeviceService;
-import com.ruoyi.system.service.IEtModelService;
-import com.ruoyi.system.service.IEtOperatingAreaService;
+import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.iot.domain.BodyObj;
import com.ruoyi.web.controller.iot.domain.LogEntry;
import com.ruoyi.web.controller.iot.util.Util;
@@ -52,6 +53,13 @@ public class ReceiveController {
@Resource
private IEtOperatingAreaService etOperatingAreaService;
+ @Autowired
+ private IEtAdminOrderService etAdminOrderService;
+
+ @Autowired
+ private ISysUserService sysUserService;
+
+
/**
* 功能描述:第三方平台数据接收。
*
注:
@@ -105,7 +113,9 @@ public class ReceiveController {
// 根据电压计算续航里程
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
Integer remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
+ Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage);
+ device.setRemainingPower(electricQuantity.toString());
int i = asDeviceService.updateAsDeviceBySn(device);
if(i>0){
log.info("更新定位成功:" +logEntry.getDevName());
@@ -138,13 +148,46 @@ public class ReceiveController {
/** todo 4.行程线路添加,更新订单中的trip_route字段 */
- /** 5.低电量不能骑行,如果电量低则声音播报 */
- Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());
- if(electricQuantity <=model.getLowBatteryReminder()){
+ /** 5.低于电量(%)不得骑行,声音播报 */
+ if(electricQuantity <= model.getLowBatteryReminder()){
//发送低电量播报指令
asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY6,"低电量播报");
log.info("低电量播报:" +logEntry.getDevName());
}
+ /** 6.低电量 生成换电工单*/
+ Integer replacementOrder = area.getAutoReplacementOrder();
+ Boolean aBoolean = etAdminOrderService.checkOrderUnique(device.getSn());
+ if (Integer.parseInt(device.getRemainingPower()) < replacementOrder && !aBoolean) {
+ /** 生成换电工单 */
+ EtAdminOrder adminOrder = new EtAdminOrder();
+ adminOrder.setDeviceMac(device.getMac());
+ adminOrder.setSn(device.getSn());
+ adminOrder.setBeforeElectric(Integer.parseInt(device.getRemainingPower()));
+ adminOrder.setOrderNo(IdUtils.randomUUID2());
+ adminOrder.setStatus(ServiceConstants.REPLACEMENT_ELECTRICITY_STATUS_UNDER_WAY);
+ adminOrder.setIsEffective(ServiceConstants.REPLACEMENT_ELECTRICITY_IS_EFFECTIVE_YES);
+ SysUser sysUser = sysUserService.selectUserByUserName("wx");//获取用户名为“wx”的维修人员
+ adminOrder.setAdminId(sysUser.getUserId());
+ adminOrder.setAdminName(sysUser.getUserName());
+ adminOrder.setLatitude(device.getLatitude());
+ adminOrder.setLongitude(device.getLongitude());
+ adminOrder.setType("2");
+ String location = device.getLongitude() + ","+device.getLatitude();
+ adminOrder.setAddress(CommonUtil.getAddressByGeo(location));
+ int i1 = etAdminOrderService.insertEtAdminOrder(adminOrder);
+ if (i1 > 0) {
+ log.info("生成换电工单成功");
+ }else{
+ throw new ServiceException("生成换电工单失败");
+ }
+ /** 改变车辆状态 */
+ device.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE);
+ if (asDeviceService.updateAsDevice(device) > 0) {
+ log.info("车辆状态改成换电中");
+ }else{
+ throw new ServiceException("车辆状态更新失败");
+ }
+ }
}else{
log.info("更新定位失败:" +logEntry.getDevName());
}
diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/SendAliSmsUtil.java b/electripper-common/src/main/java/com/ruoyi/common/utils/SendAliSmsUtil.java
index cad5598..74d4656 100644
--- a/electripper-common/src/main/java/com/ruoyi/common/utils/SendAliSmsUtil.java
+++ b/electripper-common/src/main/java/com/ruoyi/common/utils/SendAliSmsUtil.java
@@ -25,7 +25,6 @@ public class SendAliSmsUtil {
// 产品域名,开发者无需替换
static final String domain = "dysmsapi.aliyuncs.com";
- // TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
private static final String accessKeyId = "LTAI5tR5PUDLcBxZskXhYaar";//需要替换
private static final String accessKeySecret = "qCziuzsKPwCY6SD0cTr1Gau5dOjHnb";//需要替换
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 00c8d58..772000f 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
@@ -204,4 +204,9 @@ public interface IAsDeviceService extends IService
* 判断是否在禁行区内
*/
public boolean isNoRidingArea(String sn,Long areaId);
+
+ /**
+ * 低电量不得骑行判断
+ */
+ boolean isLowBattery(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 74e0101..38ea9a6 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
@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.constant.IotConstants;
import com.ruoyi.common.constant.ServiceConstants;
-import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.DateUtils;
@@ -79,9 +78,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i
@Autowired
private IEtParkingAreaService parkingAreaService;
- @Autowired
- private ISysUserService userService;
-
@Resource
private ISysDictDataService sysDictDataService;
@@ -138,16 +134,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i
if (ObjectUtil.isNull(asDevice)) {
throw new ServiceException("设备不存在");
}
- /** TODO 获取车辆实时信息 电量、定位、状态*/
-// if (ObjectUtil.isNotNull(asDevice)) {
-// /** 获取车辆实时信息 */
-// String url = iotUrl + "/v1.0/devices/" + asDevice.getMac() + "/datapoints?product_id=" + productId + "&timeout=" + timeout;
-// String result = HttpUtils.sendGet(url, Token.getToken());
-// JSONObject jsonObject = JSON.parseObject(result);
-// if (jsonObject.getInteger("code") == 200) {
-// JSONObject data =jsonObject.getJSONObject("data");
-// }
-// }
Long areaId = asDevice.getAreaId();
EtOperatingArea etOperatingArea;
if (ObjectUtil.isNotNull(areaId)) {
@@ -155,51 +141,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i
}else{
throw new ServiceException("区域信息不存在");
}
- /** TODO 电量低于系统设置值时,自动生成换电工单 唯一 */
- Integer replacementOrder = etOperatingArea.getAutoReplacementOrder();
- Boolean aBoolean = etAdminOrderService.checkOrderUnique(asDevice.getSn());
- if (Integer.parseInt(asDevice.getRemainingPower()) < replacementOrder && !aBoolean) {
- Boolean execute = transactionTemplate.execute(e -> {
- /** 生成换电工单 */
- EtAdminOrder adminOrder = new EtAdminOrder();
- adminOrder.setDeviceMac(asDevice.getMac());
- adminOrder.setSn(asDevice.getSn());
- adminOrder.setBeforeElectric(Integer.parseInt(asDevice.getRemainingPower()));
- adminOrder.setOrderNo(IdUtils.randomUUID2());
- adminOrder.setStatus(ServiceConstants.REPLACEMENT_ELECTRICITY_STATUS_UNDER_WAY);
- adminOrder.setIsEffective(ServiceConstants.REPLACEMENT_ELECTRICITY_IS_EFFECTIVE_YES);
- SysUser sysUser = userService.selectUserByUserName("wx");//获取用户名为“wx”的维修人员
- adminOrder.setAdminId(sysUser.getUserId());
- adminOrder.setAdminName(sysUser.getUserName());
- adminOrder.setLatitude(asDevice.getLatitude());
- adminOrder.setLongitude(asDevice.getLongitude());
- adminOrder.setType("2");
- String location = asDevice.getLongitude() + ","+asDevice.getLatitude();
- adminOrder.setAddress(CommonUtil.getAddressByGeo(location));
- int i = etAdminOrderService.insertEtAdminOrder(adminOrder);
- if (i > 0) {
- log.info("生成换电工单成功");
- }else{
- return Boolean.FALSE;
- }
- /** 改变车辆状态 */
- asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE);
- int i1 = asDeviceMapper.updateAsDevice(asDevice);
-
- if (i1 > 0) {
- log.info("车辆状态改成换电中");
- }else{
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
- });
- if (!execute)throw new ServiceException("生成换电工单失败");
- }
- String vehicleMileage = sysConfigService.selectConfigByKey("vehicle.mileage");//车辆里程数
- Integer mileage = Integer.parseInt(vehicleMileage);
- Integer remainingPower = Integer.parseInt(asDevice.getRemainingPower());
- // mileage与remainingPower相乘
- asDevice.setRemainingMileage(mileage * remainingPower/100);//剩余里程
if(ObjectUtil.isNotNull(etOperatingArea)){
asDevice.setAreaName(etOperatingArea.getAreaName());
}
@@ -458,7 +399,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i
}
String sessionId = IdUtils.randomUUIDByDigit(8);
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(orderVo.getSn());
- /** TODO 远程开锁*/
/** 1.获取token*/
String token = Token.getToken();
String finalOrderNo = orderNo;
@@ -1301,4 +1241,20 @@ public class AsDeviceServiceImpl extends ServiceImpl i
}
return isNoRiding;
}
+
+ /**
+ * 是否低电量
+ */
+ @Override
+ public boolean isLowBattery(String sn) {
+ AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
+ String remainingPower = device.getRemainingPower();
+ log.info("车辆【{}】电量为【{}】",sn,remainingPower);
+ EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(device.getAreaId());
+ if(Integer.parseInt(remainingPower) < Integer.parseInt(area.getUndercharge())){
+ log.info("车辆【{}】电量为【{}】低于【{}】",sn,remainingPower,area.getUndercharge());
+ return true;
+ }
+ return false;
+ }
}