From d9e8887a60c8a52956575c07207f6996936effb4 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Thu, 30 May 2024 11:48:16 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=9C=A8=E8=BF=90=E8=90=A5=E5=8C=BA?= =?UTF-8?q?=E5=A4=96X=E7=A7=92=E5=90=8E=E6=96=AD=E7=94=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/receive/ReceiveController.java | 267 ++++++++++-------- .../com/ruoyi/system/domain/AsDevice.java | 3 + .../mapper/system/AsDeviceMapper.xml | 7 +- 3 files changed, 161 insertions(+), 116 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 8890edb..06a6c9d 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 @@ -32,6 +32,10 @@ import javax.annotation.Resource; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * 接收硬件参数 @@ -66,6 +70,9 @@ public class ReceiveController { @Autowired private IEtOrderService etOrderService; + @Autowired + private ScheduledExecutorService scheduledExecutorService; + /** * 功能描述:第三方平台数据接收。

@@ -125,133 +132,162 @@ public class ReceiveController { lat = new BigDecimal(doubles[0]).setScale(4, RoundingMode.HALF_UP); lon = new BigDecimal(doubles[1]).setScale(4, RoundingMode.HALF_UP); log.info("转换后的GCJ02经纬度:" + lon + "---" + lat); - device.setLatitude(lat.toString()); - device.setLongitude(lon.toString()); - Integer bat = value.getBat(); - 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()); - 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()); - /** 2. 判断是否在禁行区内 - * 如果在, 根据配置‘禁行区内断电配置’进行断电 - **/ - boolean noRidingArea = asDeviceService.isNoRidingArea(device.getSn(), device.getAreaId()); - if(noRidingArea){ - String noRidingOutage = area.getNoRidingOutage(); - //发送播报指令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"禁行区内播报"); - if(noRidingOutage.equals("1")){//禁行区内断电 - //发送断电命令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_QLOSE,"禁行区内断电"); - log.info("禁行区内发送断电命令:" +logEntry.getDevName()); + if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){ + device.setLatitude(lat.toString()); + device.setLongitude(lon.toString()); + Integer bat = value.getBat(); + 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()); + 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()); + /** 2. 判断是否在禁行区内 + * 如果在, 根据配置‘禁行区内断电配置’进行断电 + **/ + boolean noRidingArea = asDeviceService.isNoRidingArea(device.getSn(), device.getAreaId()); + if(noRidingArea){ + String noRidingOutage = area.getNoRidingOutage(); + //发送播报指令 + asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"禁行区内播报"); + if(noRidingOutage.equals("1") && !device.getIsAreaOutOutage().equals("1")){//禁行区内断电 + //x秒后发送断电命令 + scheduledExecutorService.schedule(() -> { + try { + asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_QLOSE,"超出营运区断电"); + device.setIsAreaOutOutage("0"); + asDeviceService.updateAsDevice(device); + log.info("禁行区内发送断电命令:" +logEntry.getDevName()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } + }, area.getOutage(), TimeUnit.SECONDS); + device.setIsAreaOutOutage("1"); + asDeviceService.updateAsDevice(device); + } } - } - /** 3.超出运营区外断电*/ - boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area); - if(isAreaZone){ - String areaOutOutage = area.getAreaOutOutage(); - //发送超出营运区播报指令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"超出营运区播报"); - if(areaOutOutage.equals("1")){//超出营运区断电 - //发送断电命令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_QLOSE,"超出营运区断电"); - log.info("超出营运区发送断电命令:" +logEntry.getDevName()); + /** 3.超出运营区外断电*/ + boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area); + if(isAreaZone){ + String areaOutOutage = area.getAreaOutOutage(); + //发送超出营运区播报指令 + asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"超出营运区播报"); + if(areaOutOutage.equals("1") && !device.getIsAreaOutOutage().equals("1")){//超出营运区断电 + //x秒后发送断电命令 + scheduledExecutorService.schedule(() -> { + try { + asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_QLOSE,"超出营运区断电"); + device.setIsAreaOutOutage("0"); + asDeviceService.updateAsDevice(device); + log.info("超出营运区发送断电命令:" +logEntry.getDevName()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } + }, area.getOutage(), TimeUnit.SECONDS); + device.setIsAreaOutOutage("1"); + asDeviceService.updateAsDevice(device); + } } - } - /** 4.行程线路添加,更新订单中的trip_route字段 */ - Integer status = value.getStatus(); - if(status == 1){//上电运行 - log.info("上电运行:" +logEntry.getDevName()); - if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){ - //获取当前正在骑行中的订单 - EtOrder etOrder = etOrderService.getCurrentOrder(device.getSn()); - if(ObjectUtil.isNotNull(etOrder)){ - JSONArray jsonArray; - if(StrUtil.isNotBlank(etOrder.getTripRouteStr())){ - jsonArray = JSON.parseArray(etOrder.getTripRouteStr()); - }else{ - jsonArray = new JSONArray(); - } - JSONArray newPoint = new JSONArray(); - newPoint.add(lon); - newPoint.add(lat); + /** 4.行程线路添加,更新订单中的trip_route字段 */ + Integer status = value.getStatus(); + if(status == 1){//上电运行 + log.info("上电运行:" +logEntry.getDevName()); + if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){ + //获取当前正在骑行中的订单 + EtOrder etOrder = etOrderService.getCurrentOrder(device.getSn()); + if(ObjectUtil.isNotNull(etOrder)){ + JSONArray jsonArray; + if(StrUtil.isNotBlank(etOrder.getTripRouteStr())){ + jsonArray = JSON.parseArray(etOrder.getTripRouteStr()); + }else{ + jsonArray = new JSONArray(); + } + JSONArray newPoint = new JSONArray(); + newPoint.add(lon); + newPoint.add(lat); - // 优化轨迹,如果获取到的定位与最后一个定位相同,则不添加 - if(jsonArray.size() > 0){ - JSONArray lastPoint = (JSONArray) jsonArray.get(jsonArray.size() - 1); - if(lastPoint.get(0).equals(lon) && lastPoint.get(1).equals(lat)){ - log.info("获取到的定位与最后一个定位相同,不添加线路"); + // 优化轨迹,如果获取到的定位与最后一个定位相同,则不添加 + if(jsonArray.size() > 0){ + JSONArray lastPoint = (JSONArray) jsonArray.get(jsonArray.size() - 1); + if(lastPoint.get(0).equals(lon) && lastPoint.get(1).equals(lat)){ + log.info("获取到的定位与最后一个定位相同,不添加线路"); + }else{ + jsonArray.add(newPoint); + jsonArray.toJSONString(); + } }else{ jsonArray.add(newPoint); jsonArray.toJSONString(); } - }else{ - jsonArray.add(newPoint); - jsonArray.toJSONString(); - } - log.info("更新行程jsonArray:" +jsonArray.toJSONString()); - etOrder.setTripRouteStr(jsonArray.toJSONString()); - Geometry geometry = GeoUtils.toGeometryByLinearRing(jsonArray.toJSONString()); - String wkt = GeoUtils.wkt(geometry); - etOrder.setTripRoute(wkt); - int updateEtOrder = etOrderService.updateEtOrder(etOrder); - if (updateEtOrder > 0) { - log.info("更新行程线路成功==========================>" +logEntry.getDevName()); - }else{ - log.info("更新行程线路失败==========================>" +logEntry.getDevName()); + log.info("更新行程jsonArray:" +jsonArray.toJSONString()); + etOrder.setTripRouteStr(jsonArray.toJSONString()); + Geometry geometry = GeoUtils.toGeometryByLinearRing(jsonArray.toJSONString()); + String wkt = GeoUtils.wkt(geometry); + etOrder.setTripRoute(wkt); + int updateEtOrder = etOrderService.updateEtOrder(etOrder); + if (updateEtOrder > 0) { + log.info("更新行程线路成功==========================>" +logEntry.getDevName()); + }else{ + log.info("更新行程线路失败==========================>" +logEntry.getDevName()); + } } } } - } - /** 5.低于电量(%)不得骑行,声音播报 */ - 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("生成换电工单失败"); + log.info("低电量播报:" +logEntry.getDevName()); } - /** 改变车辆状态 */ - device.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE); - if (asDeviceService.updateAsDevice(device) > 0) { - log.info("车辆状态改成换电中"); - }else{ - throw new ServiceException("车辆状态更新失败"); + /** 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("车辆状态更新失败"); + } } - } // /** TODO 7.运营边界判断 几米判断? 3 播报运营边界 play2@ 是否靠近运营区边界*/ // boolean isCloseToTheBoundary = asDeviceService.isCloseToTheBoundary(device.getSn(), area); // if(isCloseToTheBoundary){ @@ -259,8 +295,9 @@ public class ReceiveController { // asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY2,"靠近营运边界播报"); // } - }else{ - log.info("更新定位失败:" +logEntry.getDevName()); + }else{ + log.info("更新定位失败:" +logEntry.getDevName()); + } } }else{ log.info("未找到车辆对象:" +logEntry.getDevName()); diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java b/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java index a0f9506..863d880 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/AsDevice.java @@ -136,6 +136,9 @@ public class AsDevice implements Serializable{ /** 车牌号 */ private String vehicleNum; + /** 是否发送过断电指令 */ + private String isAreaOutOutage; + /** 正在进行中的订单 */ @TableField(exist = false) private List etOrders; diff --git a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml index 18f7021..655db0e 100644 --- a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml @@ -29,10 +29,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select device_id, picture, device_name, mac, sn, model_id, vehicle_num, area_id, activation_time, online_status, create_by, create_time, update_by, update_time, last_time, remark, status, lock_status, location, remaining_power, voltage, qrcode, longitude, latitude from et_device + select device_id, picture, device_name, mac, sn, model_id, vehicle_num, area_id, activation_time, online_status, create_by, create_time, update_by, update_time, last_time, remark, status, lock_status, location, remaining_power, voltage, qrcode, longitude, latitude, is_area_out_outage from et_device