From 3aa79b1438b5d04948e3513b3f72374d8b36c885 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Tue, 11 Jun 2024 13:37:43 +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 --- .../web/controller/app/AppController.java | 6 +-- .../iot/receive/ReceiveController.java | 50 +++++++++++++++---- .../ruoyi/common/constant/IotConstants.java | 16 ++++++ .../ruoyi/system/domain/EtOperatingArea.java | 4 ++ .../service/IEtOperatingAreaService.java | 3 +- .../service/impl/AsDeviceServiceImpl.java | 15 +++--- .../impl/EtOperatingAreaServiceImpl.java | 36 +++++++------ .../mapper/system/EtOperatingAreaMapper.xml | 1 + .../resources/mapper/system/SysDeptMapper.xml | 2 +- 9 files changed, 97 insertions(+), 36 deletions(-) diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java index 4936c7c..1b3e705 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java @@ -99,16 +99,16 @@ public class AppController extends BaseController /** - * 根据定位获取运营区详细信息 + * 根据定位获取运营区详细信息 device not subscribed */ @GetMapping(value = "/area/info") - public AjaxResult areaInfo(String longitude,String latitude) + public AjaxResult areaInfo(String longitude,String latitude, String deptId) { if(StrUtil.isBlank(longitude) || StrUtil.isBlank(latitude)){ logger.info("没有经纬度参数:【longitude={}】,【latitude={}】",longitude,latitude); return error("请传经纬度参数"+"【longitude="+longitude+"】,【latitude="+latitude+"】"); } - EtOperatingArea area = etOperatingAreaService.getAreaInfoByLocation(longitude,latitude); + EtOperatingArea area = etOperatingAreaService.getAreaInfoByLocation(longitude,latitude,deptId); return success(area); } 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 0dbac07..bd9b700 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 @@ -77,6 +77,8 @@ public class ReceiveController { @Autowired private ScheduledExecutorService scheduledExecutorService; + private final Object lock = new Object(); + /** * 功能描述:第三方平台数据接收。
@@ -97,16 +99,37 @@ public class ReceiveController {
log.info("receive方法接收到参数: body String --- " +body);
/************************************************
* 解析数据推送请求,非加密模式。
- * 如果是明文模式使用以下代码
+ * 如果是明文模式使用以下代码 hangdleBody(body, false); ChatGPT is under heavy load
**************************************************/
/*************明文模式 start****************/
BodyObj obj = Util.resolveBody(body, false);
log.info("receive方法解析对象: body Object --- " + JSON.toJSONString(obj));
+ // 起一个异步线程处理数据
+ scheduledExecutorService.schedule(() -> {
+ new Thread(() -> {
+ synchronized (lock) {
+ try {
+ handleBody(obj);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }, 0, TimeUnit.SECONDS);
+ /*************明文模式 end****************/
+ return "ok";
+ }
+
+ private void handleBody(BodyObj obj) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
if (obj != null){
boolean dataRight = Util.checkSignature(obj, token);
if (dataRight){
log.info("receive方法验证签名正确: content" + JSON.toJSONString(obj));
- String msg = (String)obj.getMsg();
+ String msg = (String) obj.getMsg();
log.info("receive方法-获取到消息体: msg---" +msg);
JSONObject jsonObject = JSONObject.parseObject(msg, JSONObject.class);
if(IotConstants.ONENET_LOCATION.equals(jsonObject.get("ds_id")) && ObjectUtil.isNotNull(jsonObject.get("value"))){
@@ -161,17 +184,26 @@ public class ReceiveController {
String noRidingOutage = area.getNoRidingOutage();
if (noRidingOutage.equals("1") && value.getStatus() != 3) { // 禁行区内断电
log.info("禁行区内断电命令--SN:" + device.getSn());
- asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE, "禁行区内断电");
+ asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "禁行区内断电");
}
}
/** 3.超出运营区外断电*/
boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area);
if(!isAreaZone){
- String isAdminUnlocking = device.getIsAdminUnlocking();// 是否管理员开锁
- String areaOutOutage = area.getAreaOutOutage();
- if (areaOutOutage.equals("1") && value.getStatus() != 3 && !isAdminUnlocking.equals("1")) { // 超出营运区断电
- log.info("超出营运区断电命令--SN:" + device.getSn());
- asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE, "超出营运区断电");
+ //是否在20米范围内
+ boolean inPolygon = GeoUtils.isInPolygonWithTolerance(lon.toString(), lat.toString(), GeoUtils.fromWkt(area.getBoundary()), 20);
+ if(inPolygon){
+ //在20米范围内,发报警
+ log.info("超出运营区20米内发送警告命令--SN:" + device.getSn());
+ asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "超出运营区20米内");
+ }else{
+ //超出运营区外断电
+ String isAdminUnlocking = device.getIsAdminUnlocking();// 是否管理员开锁
+ String areaOutOutage = area.getAreaOutOutage();
+ if (areaOutOutage.equals("1") && value.getStatus() != 3 && !isAdminUnlocking.equals("1")) { // 超出营运区断电
+ log.info("超出营运区断电命令--SN:" + device.getSn());
+ asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "超出营运区断电");
+ }
}
}
/** 4.行程线路添加,更新订单中的trip_route字段 */
@@ -254,8 +286,6 @@ public class ReceiveController {
}else {
log.info("receive方法参数为空: body empty error");
}
- /*************明文模式 end****************/
- return "ok";
}
private boolean isLastPointSame(JSONArray jsonArray, BigDecimal lon, BigDecimal lat) {
diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java
index e9ec82b..a108622 100644
--- a/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java
+++ b/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java
@@ -116,6 +116,22 @@ public class IotConstants {
*/
public static final String COMMAND_PLAY8 = "play8@";
+ /**
+ * 命令 频率:5秒
+ */
+ public static final String COMMAND_FREQUENCY_5 = "sub10@";
+
+ /**
+ * 命令 频率:20秒
+ */
+ public static final String COMMAND_FREQUENCY_20 = "sub20@";
+
+ /**
+ * 命令 频率:一个小时
+ */
+ public static final String COMMAND_FREQUENCY_3600 = "sub3600@";
+
+
/**----------------------------命令end----------------------------*/
diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java
index 624c655..4d9efab 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOperatingArea.java
@@ -30,6 +30,10 @@ public class EtOperatingArea extends BaseEntityPlus implements Serializable
@TableId(value = "area_id", type = IdType.AUTO)
private Long areaId;
+ /** 运营商id */
+ @TableField(exist = false)
+ private Long deptId;
+
/** 区域名称 */
@Excel(name = "区域名称")
private String areaName;
diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java
index 687a47a..81fa979 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java
@@ -92,9 +92,10 @@ public interface IEtOperatingAreaService extends IService