diff --git a/docker/copy.sh b/docker/copy.sh index 318efb2..8a984f2 100644 --- a/docker/copy.sh +++ b/docker/copy.sh @@ -36,6 +36,28 @@ cp ../ruoyi-modules/ruoyi-file/target/ruoyi-modules-file.jar ./ruoyi/modules/fil echo "begin copy ruoyi-modules-job " cp ../ruoyi-modules/ruoyi-job/target/ruoyi-modules-job.jar ./ruoyi/modules/job/jar -echo "begin copy ruoyi-modules-gen " -cp ../ruoyi-modules/ruoyi-gen/target/ruoyi-modules-gen.jar ./ruoyi/modules/gen/jar +echo "begin copy ruoyi-modules-basic " +cp ../ruoyi-modules/hw-basic/target/ruoyi-modules-basic.jar ./ruoyi/modules/basic/jar + +echo "begin copy ruoyi-modules-business " +cp ../ruoyi-modules/hw-business/target/ruoyi-modules-business.jar ./ruoyi/modules/business/jar + +echo "begin copy ruoyi-modules-dataprocess " +cp ../ruoyi-modules/hw-data-process/target/ruoyi-modules-dataprocess.jar ./ruoyi/modules/dataprocess/jar + +echo "begin copy ruoyi-modules-mqttbroker" +cp ../ruoyi-modules/hw-mqtt-broker/target/ruoyi-modules-mqttbroker.jar ./ruoyi/modules/mqttbroker/jar + +echo "begin copy ruoyi-modules-tdengine" +cp ../ruoyi-modules/hw-tdengine/target/ruoyi-modules-tdengine.jar ./ruoyi/modules/tdengine/jar + + + + + + + + + + diff --git a/docker/deploy.sh b/docker/deploy.sh index 0248909..c2884dc 100644 --- a/docker/deploy.sh +++ b/docker/deploy.sh @@ -21,6 +21,18 @@ port(){ firewall-cmd --add-port=9202/tcp --permanent firewall-cmd --add-port=9203/tcp --permanent firewall-cmd --add-port=9300/tcp --permanent + firewall-cmd --add-port=9600/tcp --permanent + firewall-cmd --add-port=9601/tcp --permanent + firewall-cmd --add-port=9603/tcp --permanent + firewall-cmd --add-port=9605/tcp --permanent + firewall-cmd --add-port=9602/tcp --permanent + firewall-cmd --add-port=9080/tcp --permanent + firewall-cmd --add-port=9660/tcp --permanent + firewall-cmd --add-port=9661/tcp --permanent + firewall-cmd --add-port=9663/tcp --permanent + firewall-cmd --add-port=9665/tcp --permanent + firewall-cmd --add-port=9666/tcp --permanent + firewall-cmd --add-port=9080/tcp --permanent service firewalld restart } @@ -31,9 +43,10 @@ base(){ # 启动程序模块(必须) modules(){ - docker-compose up -d ruoyi-nginx ruoyi-gateway ruoyi-auth ruoyi-modules-system + docker-compose up -d ruoyi-nginx ruoyi-gateway ruoyi-auth ruoyi-modules-system ruoyi-modules-business ruoyi-modules-basic ruoyi-modules-mqttbroker ruoyi-modules-tdengine ruoyi-modules-dataprocess } + # 关闭所有环境/模块 stop(){ docker-compose stop diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 321d097..5c937d4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,56 +1,7 @@ version : '3.8' services: - ruoyi-nacos: - container_name: ruoyi-nacos - image: nacos/nacos-server - build: - context: ./nacos - environment: - - MODE=standalone - volumes: - - ./nacos/logs/:/home/nacos/logs - - ./nacos/conf/application.properties:/home/nacos/conf/application.properties - ports: - - "8848:8848" - - "9848:9848" - - "9849:9849" - depends_on: - - ruoyi-mysql - ruoyi-mysql: - container_name: ruoyi-mysql - image: mysql:5.7 - build: - context: ./mysql - ports: - - "3306:3306" - volumes: - - ./mysql/conf:/etc/mysql/conf.d - - ./mysql/logs:/logs - - ./mysql/data:/var/lib/mysql - command: [ - 'mysqld', - '--innodb-buffer-pool-size=80M', - '--character-set-server=utf8mb4', - '--collation-server=utf8mb4_unicode_ci', - '--default-time-zone=+8:00', - '--lower-case-table-names=1' - ] - environment: - MYSQL_DATABASE: 'ry-cloud' - MYSQL_ROOT_PASSWORD: 123456 - ruoyi-redis: - container_name: ruoyi-redis - image: redis - build: - context: ./redis - ports: - - "6379:6379" - volumes: - - ./redis/conf/redis.conf:/home/ruoyi/redis/redis.conf - - ./redis/data:/data - command: redis-server /home/ruoyi/redis/redis.conf ruoyi-nginx: - container_name: ruoyi-nginx + container_name: hwsaas-nginx image: nginx build: context: ./nginx @@ -71,70 +22,74 @@ services: context: ./ruoyi/gateway dockerfile: dockerfile ports: - - "8080:8080" - depends_on: - - ruoyi-redis - links: - - ruoyi-redis + - "9080:9080" ruoyi-auth: container_name: ruoyi-auth build: context: ./ruoyi/auth dockerfile: dockerfile ports: - - "9200:9200" - depends_on: - - ruoyi-redis - links: - - ruoyi-redis + - "9660:9660" ruoyi-modules-system: container_name: ruoyi-modules-system build: context: ./ruoyi/modules/system dockerfile: dockerfile ports: - - "9201:9201" - depends_on: - - ruoyi-redis - - ruoyi-mysql - links: - - ruoyi-redis - - ruoyi-mysql - ruoyi-modules-gen: - container_name: ruoyi-modules-gen - build: - context: ./ruoyi/modules/gen - dockerfile: dockerfile - ports: - - "9202:9202" - depends_on: - - ruoyi-mysql - links: - - ruoyi-mysql + - "9661:9661" ruoyi-modules-job: container_name: ruoyi-modules-job build: context: ./ruoyi/modules/job dockerfile: dockerfile ports: - - "9203:9203" - depends_on: - - ruoyi-mysql - links: - - ruoyi-mysql + - "9663:9663" ruoyi-modules-file: container_name: ruoyi-modules-file build: context: ./ruoyi/modules/file dockerfile: dockerfile ports: - - "9300:9300" + - "9665:9665" volumes: - - ./ruoyi/uploadPath:/home/ruoyi/uploadPath - ruoyi-visual-monitor: - container_name: ruoyi-visual-monitor + - ./ruoyi/uploadPath:/home/ruoyi/uploadPath + ruoyi-modules-basic: + container_name: ruoyi-modules-basic + build: + context: ./ruoyi/modules/basic + dockerfile: dockerfile + ports: + - "9600:9600" + ruoyi-modules-business: + container_name: ruoyi-modules-business + build: + context: ./ruoyi/modules/business + dockerfile: dockerfile + ports: + - "9601:9601" + ruoyi-modules-mqttbroker: + container_name: ruoyi-modules-mqttbroker + build: + context: ./ruoyi/modules/mqttbroker + dockerfile: dockerfile + ports: + - "9605:9605" + ruoyi-modules-dataprocess: + container_name: ruoyi-modules-dataprocess + build: + context: ./ruoyi/modules/dataprocess + dockerfile: dockerfile + ports: + - "9603:9603" + depends_on: + - ruoyi-modules-mqttbroker + links: + - ruoyi-modules-mqttbroker + ruoyi-modules-tdengine: + container_name: ruoyi-modules-tdengine build: - context: ./ruoyi/visual/monitor + context: ./ruoyi/modules/tdengine dockerfile: dockerfile ports: - - "9100:9100" + - "9602:9602" + diff --git a/docker/nginx/conf/nginx.conf b/docker/nginx/conf/nginx.conf index 83de2a3..54208fc 100644 --- a/docker/nginx/conf/nginx.conf +++ b/docker/nginx/conf/nginx.conf @@ -11,8 +11,8 @@ http { keepalive_timeout 65; server { - listen 80; - server_name localhost; + listen 8018; + server_name 175.27.215.92; location / { root /home/ruoyi/projects/ruoyi-ui; diff --git a/logs/hw-mqtt-broker/all.log.2023-09-05.0.gz b/logs/hw-mqtt-broker/all.log.2023-09-05.0.gz deleted file mode 100644 index a0cb698..0000000 Binary files a/logs/hw-mqtt-broker/all.log.2023-09-05.0.gz and /dev/null differ diff --git a/logs/hw-mqtt-broker/all.log.2023-09-06.0.gz b/logs/hw-mqtt-broker/all.log.2023-09-06.0.gz deleted file mode 100644 index 7b46268..0000000 Binary files a/logs/hw-mqtt-broker/all.log.2023-09-06.0.gz and /dev/null differ diff --git a/logs/hw-mqtt-broker/error.log.2023-09-06.0.gz b/logs/hw-mqtt-broker/error.log.2023-09-06.0.gz deleted file mode 100644 index 1c4d7b9..0000000 Binary files a/logs/hw-mqtt-broker/error.log.2023-09-06.0.gz and /dev/null differ diff --git a/pom.xml b/pom.xml index c30e4a6..4f86d95 100644 --- a/pom.xml +++ b/pom.xml @@ -227,6 +227,14 @@ ${ruoyi.version} + + + com.ruoyi + hw-api-business + ${ruoyi.version} + + + diff --git a/ruoyi-api/hw-api-business/pom.xml b/ruoyi-api/hw-api-business/pom.xml new file mode 100644 index 0000000..c1fcc50 --- /dev/null +++ b/ruoyi-api/hw-api-business/pom.xml @@ -0,0 +1,28 @@ + + + + com.ruoyi + ruoyi-api + 3.6.3 + + 4.0.0 + + hw-api-business + + + hw-api-business平台业务模块 + + + + + + + com.ruoyi + ruoyi-common-core + + + + + \ No newline at end of file diff --git a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java new file mode 100644 index 0000000..073d200 --- /dev/null +++ b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java @@ -0,0 +1,21 @@ +package com.ruoyi.business.api; + +import com.ruoyi.business.api.factory.RemoteBusinessFallbackFactory; +import com.ruoyi.common.core.constant.ServiceNameConstants; +import com.ruoyi.common.core.domain.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient(contextId = "remoteBusinessService", value = ServiceNameConstants.BUSINESS_SERVICE, fallbackFactory = RemoteBusinessFallbackFactory.class) +public interface RemoteBusinessService { + + /** + * 通过用户名查询用户信息 + * + * @param days 几天前的 + * @return 结果 + */ + @GetMapping("/device/computeOnlineDevicecCount/{days}") + public R computeOnlineDevicecCount(@PathVariable("days") int days); +} diff --git a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java new file mode 100644 index 0000000..f4bbc62 --- /dev/null +++ b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java @@ -0,0 +1,26 @@ +package com.ruoyi.business.api.factory; + +import com.ruoyi.business.api.RemoteBusinessService; +import com.ruoyi.common.core.domain.R; +import org.springframework.cloud.openfeign.FallbackFactory; + +import java.util.List; + +/** + * @Description: 平台业务模块服务降级处理 + * @ClassName: RemoteBusinessFallbackFactory + * @Author : xins + * @Date :2023-09-20 20:25 + * @Version :1.0 + */ +public class RemoteBusinessFallbackFactory implements FallbackFactory { + @Override + public RemoteBusinessService create(Throwable throwable) { + return new RemoteBusinessService() { + @Override + public R computeOnlineDevicecCount(int days) { + return R.fail("获取租户信息失败:" + throwable.getMessage()); + } + }; + } +} diff --git a/ruoyi-api/hw-api-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-api/hw-api-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..5a193bc --- /dev/null +++ b/ruoyi-api/hw-api-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +com.ruoyi.business.api.factory.RemoteBusinessFallbackFactory + diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java index 8cfe757..abe1207 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java @@ -20,7 +20,7 @@ import java.util.Map; public interface RemoteTdEngineService { @PostMapping("/tdengine/createDatabase") - R createDataBase(@RequestParam("databaseName") String databaseName); + R createDataBase(@RequestBody String databaseName); @PostMapping("/tdengine/createSuperTable") R createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo); @@ -54,4 +54,7 @@ public interface RemoteTdEngineService { @PostMapping("/tdengine/getOnlineDevicesGroupByDay") R getOnlineDevicesGroupByDay(@Validated @RequestBody DeviceStatus queryDeviceStatus); + + @PostMapping("/tdengine/getLastOnlineDevices") + R getLastOnlineDevices(@Validated @RequestBody DeviceStatus queryDeviceStatus); } diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/DeviceStatus.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/DeviceStatus.java index 25182b6..2043d83 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/DeviceStatus.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/DeviceStatus.java @@ -23,6 +23,9 @@ public class DeviceStatus extends BaseEntity { private Long sceneId; + private Long startTime; + private Long endTime; + public Long getTs() { return ts; } @@ -70,4 +73,20 @@ public class DeviceStatus extends BaseEntity { public void setSceneId(Long sceneId) { this.sceneId = sceneId; } + + public Long getStartTime() { + return startTime; + } + + public void setStartTime(Long startTime) { + this.startTime = startTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } } diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java index d8a386c..dbdfa28 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java @@ -86,6 +86,11 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory getLastOnlineDevices(DeviceStatus queryDeviceStatus) { + return R.fail("获取最近设备状态失败:" + throwable.getMessage()); + } + }; } } diff --git a/ruoyi-api/pom.xml b/ruoyi-api/pom.xml index cda19ca..f39e950 100644 --- a/ruoyi-api/pom.xml +++ b/ruoyi-api/pom.xml @@ -12,6 +12,7 @@ ruoyi-api-system hw-api-tdengine hw-api-basic + hw-api-business ruoyi-api diff --git a/ruoyi-auth/src/main/resources/bootstrap.yml b/ruoyi-auth/src/main/resources/bootstrap.yml index 43c2e63..afee82b 100644 --- a/ruoyi-auth/src/main/resources/bootstrap.yml +++ b/ruoyi-auth/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 9200 + port: 9660 # Spring spring: diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java index 2a72035..11e622d 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java @@ -58,6 +58,8 @@ public class HwDictConstants { public static final String REDIS_KEY_DEVICE_INFO = "hw_device_info";//保存设备用户名和密码等信息的redis的key + public static final String REDIS_KEY_ONLINE_DEVICE_COUNT_INFO = "online_device_count";//按照天存放每天设备在线数量 + public static final String DEVICE_MODE_STATUS_NORMAL = "1";//设备模型正常状态 public static final String SCENE_DEFAULT_FLAG_YES = "1";//场景是否默认标识:是 @@ -77,4 +79,9 @@ public class HwDictConstants { SCENE_MODE_ROUTER_MAP.put(SCENE_MODE_GPS, ROUTER_GPS); } + public static final String DEVICE_ONLINE_STATUS_ONLINE="1";//在线状态 + public static final String DEVICE_ONLINE_STATUS_OFFLINE="0"; //离线状态 + + public static final String ALARM_HANDLE_STATUS_YES = "1";//已处理 + public static final String ALARM_HANDLE_STATUS_NO = "0";//未处理 } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceNameConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceNameConstants.java index 3e3afe9..c7cf548 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceNameConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceNameConstants.java @@ -31,4 +31,9 @@ public class ServiceNameConstants * basic服务的serviceid */ public static final String BASIC_SERVICE = "hw-basic"; + + /** + * business服务的serviceid + */ + public static final String BUSINESS_SERVICE = "hw-business"; } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java index 28df6da..3d9a3a3 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java @@ -39,6 +39,9 @@ public class TdEngineConstants { public static final int ST_TAG_DEVICECODE_SIZE=50; public static final String ST_TAG_DEVICENAME = "devicename"; + + public static final String ST_TAG_DEVICETYPE = "devicetype"; + public static final String ST_TAG_ONLINESTATUS = "onlinestatus"; public static final int ST_TAG_DEVICENAME_TYPE = 10; public static final int ST_TAG_DEVICENAME_SIZE=200; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java index 137eccb..015c6af 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java @@ -28,6 +28,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + public static final String MM_DD = "MM-dd"; + private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", diff --git a/ruoyi-gateway/src/main/resources/bootstrap.yml b/ruoyi-gateway/src/main/resources/bootstrap.yml index bc2cc57..20652b5 100644 --- a/ruoyi-gateway/src/main/resources/bootstrap.yml +++ b/ruoyi-gateway/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 8080 + port: 9080 # Spring spring: diff --git a/ruoyi-modules/hw-business/pom.xml b/ruoyi-modules/hw-business/pom.xml index a473a61..7385159 100644 --- a/ruoyi-modules/hw-business/pom.xml +++ b/ruoyi-modules/hw-business/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - rouyi-modules-business + ruoyi-modules-business 海威物联网平台业务模块 @@ -104,6 +104,12 @@ junit junit + + org.glassfish + javax.json + 1.0.4 + compile + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java index 350d673..734d6bc 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java @@ -196,4 +196,8 @@ public class HwDeviceController extends BaseController return toAjax(hwDeviceService.updateHwDevice(device)); } + @GetMapping("/computeOnlineDevicecCount/{days}") + public void computeOnlineDevicecCount(@PathVariable("days") int days){ + hwDeviceService.computeOnlineDevicecCount(days); + } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java index ae75e84..c6c92b8 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java @@ -4,15 +4,19 @@ import com.alibaba.fastjson.JSONObject; import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.VO.*; import com.ruoyi.business.service.*; +import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; +import com.ruoyi.common.security.annotation.RequiresPermissions; +import com.ruoyi.common.security.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; @@ -39,6 +43,7 @@ public class HwMonitorPlatformController extends BaseController { /** * 查询3. 设备各类型占所有设备数量百分比饼状图(首页左下角) */ + @RequiresPermissions("business:monitor:index") @GetMapping("/monitorUnitPercentage") public TableDataInfo monitorUnitPercentage() { List maps = hwDeviceService.selectDeviceModeNameVo(); @@ -48,6 +53,7 @@ public class HwMonitorPlatformController extends BaseController { /** * 各场景监控单元数量占监控单元总数量百分比图(首页左上) */ + @RequiresPermissions("business:monitor:index") @GetMapping("/monitorPercentage") public TableDataInfo monitorPercentage() { List maps = hwMonitorUnitService.selectMonitorPercentage(); @@ -57,6 +63,7 @@ public class HwMonitorPlatformController extends BaseController { /** *  展示总的设备数量和总的监控单元数量(首页中间上方) */ + @RequiresPermissions("business:monitor:index") @GetMapping("/allNums") public AllNumsVo allNums() { AllNumsVo allNumsVos = hwMonitorUnitService.selectAllNums(null); @@ -72,33 +79,37 @@ public class HwMonitorPlatformController extends BaseController { * @date 2023-09-15 11:03 */ @GetMapping("/getAlarmInfos") + @RequiresPermissions("business:monitor:alarm") public TableDataInfo getAlarmInfos(HwAlarmInfo hwAlarmInfo) { - startPage(); + //startPage(); + hwAlarmInfo.setHandleStatus(HwDictConstants.ALARM_HANDLE_STATUS_NO); List alarmInfos = hwAlarmInfoService.selectHwAlarmInfoList(hwAlarmInfo); return getDataTable(alarmInfos); } + @PutMapping("/handleAlarmInfo") + @RequiresPermissions("business:monitor:alarm") + public AjaxResult handleAlarmInfo(@RequestBody HwAlarmInfo hwAlarmInfo){ + hwAlarmInfo.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(hwAlarmInfoService.updateHwAlarmInfo(hwAlarmInfo)); + } + /** * 2. 设备实时在运数量曲线图(首页右上角) * * @param sceneId 场景id */ + @RequiresPermissions("business:monitor:index") @GetMapping("/getDeviceOperations/{sceneId}") public AjaxResult selectDeviceStatus(@PathVariable("sceneId") Long sceneId) { - JSONObject data = new JSONObject(); - data.put("10-01", 10); - data.put("10-02", 20); - data.put("10-03", 30); - data.put("10-04", 40); - data.put("10-05", 16); - - return AjaxResult.success(data); + return AjaxResult.success(hwDeviceService.getOnlineDevicesCount(sceneId)); } /** - *  按场景展示总的设备数量和总的监控单元数量 + *  按场景展示总的设备数量和总的监控单元数量(标准场景) */ + @RequiresPermissions("business:monitor:standard") @GetMapping("/sceneAllNums/{sceneId}") public AllNumsVo sceneAllNums(@PathVariable("sceneId") Long sceneId) { AllNumsVo allNumsVos = hwMonitorUnitService.selectAllNums(sceneId); @@ -108,14 +119,24 @@ public class HwMonitorPlatformController extends BaseController { /** * 分页获取最子集监控单元列表(标准场景右侧) */ + @RequiresPermissions("business:monitor:standard") @GetMapping("/limitSubMonitorUnit/{sceneId}") public TableDataInfo limitSubMonitorUnit(@PathVariable("sceneId") Long sceneId) { - //todo sceneid should be + HwMonitorUnit hwMonitorUnit = new HwMonitorUnit(); + hwMonitorUnit.setSceneId(sceneId); startPage(); - List hwMonitorUnits = hwMonitorUnitService.selectLimitSubMonitorUnit(); + List hwMonitorUnits = hwMonitorUnitService.selectLimitSubMonitorUnit(hwMonitorUnit); return getDataTable(hwMonitorUnits); } + /** + * @return AjaxResult + * @param: sceneId + * @description 标准场景按报警类型返回其报警数量 + * @author xins + * @date 2023-09-21 11:35 + */ + @RequiresPermissions("business:monitor:standard") @GetMapping("/getAlarmCountGroupAlarmType/{sceneId}") public AjaxResult getAlarmCountGroupAlarmType(@PathVariable("sceneId") Long sceneId) { return success(hwAlarmInfoService.selectAlarmsByAlarmType(sceneId)); @@ -126,25 +147,10 @@ public class HwMonitorPlatformController extends BaseController { * * @param sceneId */ + @RequiresPermissions("business:monitor:gps") @GetMapping("/ElectronicNumVo/{sceneId}") public AjaxResult ElectronicNumVo(@PathVariable("sceneId") Long sceneId) { -// { -// type:'多边形', -// children:[{ -// latitude:'', -// longtitude:'' -// }] -// } - -// { -// type:'圆形', -// centerpoint:{ -// 'lantitude':, -// 'longtitude':, -// } -// } -// } return success(hwElectronicFenceService.selectEleTypeNums(sceneId)); } @@ -159,10 +165,11 @@ public class HwMonitorPlatformController extends BaseController { } /** - * 获取最子级监控单元数量、设备数量和在线设备数量 + * 获取最子级监控单元数量、设备数量和在线设备数量(定位场景) * * @param sceneId 场景id */ + @RequiresPermissions("business:monitor:gps") @GetMapping("/subDevice/{sceneId}") public SubDeviceSumVo subDevice(@PathVariable("sceneId") Long sceneId) { @@ -179,9 +186,9 @@ public class HwMonitorPlatformController extends BaseController { * @return list * @throws */ + @RequiresPermissions("business:monitor:deviceMonitor") @GetMapping("/treeList/{sceneId}") - public AjaxResult monitorUnitTree(@PathVariable("sceneId") Long sceneId) - { + public AjaxResult monitorUnitTree(@PathVariable("sceneId") Long sceneId) { HwMonitorUnit queryMonitorUnit = new HwMonitorUnit(); queryMonitorUnit.setSceneId(sceneId); return success(hwMonitorUnitService.selectMonitorTreeList(queryMonitorUnit)); @@ -207,9 +214,10 @@ public class HwMonitorPlatformController extends BaseController { * 获取监控单元详细信息 */ // @RequiresPermissions("business:monitorUnit:query") + @RequiresPermissions("business:monitor:deviceMonitor") @GetMapping(value = "/getMonitorById/{monitorUnitId}") public AjaxResult getMonitorById(@PathVariable("monitorUnitId") Long monitorUnitId) { - return success(hwMonitorUnitService.selectHwMonitorUnitByMonitorUnitId(monitorUnitId)); + return success(hwMonitorUnitService.selectHwMonitorUnitJoinByMonitorUnitId(monitorUnitId)); } /** @@ -217,6 +225,7 @@ public class HwMonitorPlatformController extends BaseController { * * @param monitorUnitId 监控单元id */ + @RequiresPermissions("business:monitor:deviceMonitor") @GetMapping("/selectDevicesByMonitorUnitId/{monitorUnitId}/{sceneId}") public AjaxResult selectDeviceByDeviceModeByMonitorUnitId(@PathVariable("monitorUnitId") Long monitorUnitId, @PathVariable("sceneId") Long sceneId) { @@ -229,10 +238,11 @@ public class HwMonitorPlatformController extends BaseController { /** - * @description 根据场景ID获取设备模型列表 + * @description 根据场景ID获取设备模型列表(设备汇总页面) * @author xins * @date 2023-09-16 12:44 */ + @RequiresPermissions("business:monitor:deviceList") @PostMapping("/getDeviceModesBySceneId") public AjaxResult getDeviceModesBySceneId(@RequestBody HwDeviceMode queryHwDeviceMode) { return success(hwDeviceModeService.selectHwDeviceModeList(queryHwDeviceMode)); @@ -241,10 +251,11 @@ public class HwMonitorPlatformController extends BaseController { /** * @return AjaxResult * @param: monitorUnitId - * @description 根据设备模型获取最新数据 + * @description 根据设备模型获取最新数据(设备汇总页面) * @author xins * @date 2023-09-16 12:45 */ + @RequiresPermissions("business:monitor:deviceList") @PostMapping("/selectLatestDataByDeviceMode") public AjaxResult selectLatestDataByDeviceMode(@Validated @RequestBody DeviceLatestDataVo deviceLatestData) { JSONObject returnObj = new JSONObject(); @@ -255,16 +266,16 @@ public class HwMonitorPlatformController extends BaseController { returnObj.put("latestData", latestDataMaps); return success(returnObj); } - - + @RequiresPermissions("business:monitor:deviceInfo") @GetMapping("/getDeviceInfo/{deviceId}") - public AjaxResult getDeviceInfo(@PathVariable("deviceId") Long deviceId){ + public AjaxResult getDeviceInfo(@PathVariable("deviceId") Long deviceId) { HwDevice device = hwDeviceService.selectHwDeviceJoinByDeviceId(deviceId); return success(device); } + @RequiresPermissions("business:monitor:deviceInfo") @GetMapping("/getLinkDevices/{deviceId}") - public AjaxResult getLinkDevices(@PathVariable("deviceId")Long deviceId){ + public AjaxResult getLinkDevices(@PathVariable("deviceId") Long deviceId) { return success(hwDeviceService.selectLinkDeviceList(deviceId)); } @@ -275,6 +286,7 @@ public class HwMonitorPlatformController extends BaseController { * @author xins * @date 2023-09-16 15:15 */ + @RequiresPermissions("business:monitor:deviceInfo") @PostMapping("/getHistoryData") public AjaxResult getHistoryData(@Validated @RequestBody DeviceHistoryDataVo deviceHistoryData) { // startPage(); @@ -288,7 +300,7 @@ public class HwMonitorPlatformController extends BaseController { } - private List getDeviceDataColumns(List> latestDataMaps){ + private List getDeviceDataColumns(List> latestDataMaps) { List deviceDataColumnVos = new ArrayList(); if (latestDataMaps != null && latestDataMaps.size() > 0) { Map latestDataMap = latestDataMaps.get(0); diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java index cf20fc8..885517d 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java @@ -68,7 +68,7 @@ public class HwMonitorUnit extends BaseEntity private String sceneName; private String monitorUnitTypeName; private String tenantName; - + private boolean normalFlag;//是否正常(如果有报警未处理的则为异常) private List child = new ArrayList(); @@ -224,6 +224,14 @@ public class HwMonitorUnit extends BaseEntity this.tenantName = tenantName; } + public boolean isNormalFlag() { + return normalFlag; + } + + public void setNormalFlag(boolean normalFlag) { + this.normalFlag = normalFlag; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoVo.java new file mode 100644 index 0000000..e0f282d --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoVo.java @@ -0,0 +1,11 @@ +package com.ruoyi.business.domain.VO; + +import lombok.Data; + +@Data +public class AlarmInfoVo { + + private Integer alarmCount; + + +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java index bc7d488..20d16b5 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.business.mapper; import java.util.List; import com.ruoyi.business.domain.HwAlarmInfo; +import com.ruoyi.business.domain.VO.AlarmInfoVo; import com.ruoyi.business.domain.VO.AlarmTypeVo; /** @@ -62,4 +63,7 @@ public interface HwAlarmInfoMapper public List selectAlarmsByAlarmType(Long sceneId); + + public AlarmInfoVo selectAlarmCountByFenceArea(Long fenceAreaId); + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java index 054cff2..ebf9580 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java @@ -38,7 +38,7 @@ public interface HwMonitorUnitMapper /** * 分页获取最子集监控单元列表 * */ - public List selectLimitSubMonitorUnit(); + public List selectLimitSubMonitorUnit(HwMonitorUnit hwMonitorUnit); Integer selectReleatedDeviceIdNums(Long deviceCode); Integer selectDeviceNums(Long sceneId); Integer selectSubDeviceSum(Long sceneId); @@ -130,4 +130,12 @@ public interface HwMonitorUnitMapper */ public List selectHwMonitorUnitJoinList(HwMonitorUnit hwMonitorUnit); + /** + * 查询监控单元Join monitorunittypename + * + * @param monitorUnitId 监控单元主键 + * @return 监控单元 + */ + public HwMonitorUnit selectHwMonitorUnitJoinByMonitorUnitId(Long monitorUnitId); + } \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java index 517869f..a862bc6 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java @@ -3,6 +3,7 @@ package com.ruoyi.business.service; import java.util.List; import java.util.Map; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.HwDeviceVo; @@ -104,4 +105,21 @@ public interface IHwDeviceService */ public List selectHwDeviceJoinList(HwDevice hwDevice); + + /** + * @param: days + * @description 计算前几天的设备在线数量 + * @author xins + * @date 2023-09-20 19:28 + */ + public void computeOnlineDevicecCount(int days); + + /** + * @param: sceneId + * @description 获取最近几天在线设备数量 + * @author xins + * @date 2023-09-21 9:09 + * @return JSONObject + */ + public JSONObject getOnlineDevicesCount(Long sceneId); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorUnitService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorUnitService.java index f73fa15..4b57930 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorUnitService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorUnitService.java @@ -38,7 +38,7 @@ public interface IHwMonitorUnitService /** * 分页获取最子集监控单元列表 * */ - public List selectLimitSubMonitorUnit(); + public List selectLimitSubMonitorUnit(HwMonitorUnit hwMonitorUnit); /** * 报警信息列表 @@ -139,4 +139,11 @@ public interface IHwMonitorUnitService */ public List selectHwMonitorUnitJoinList(HwMonitorUnit hwMonitorUnit); + /** + * 查询监控单元,Join monitorunittype + * + * @param monitorUnitId 监控单元主键 + * @return 监控单元 + */ + public HwMonitorUnit selectHwMonitorUnitJoinByMonitorUnitId(Long monitorUnitId); } \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java index 97e611a..312d082 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java @@ -8,7 +8,9 @@ import java.util.stream.Collectors; import com.ruoyi.business.domain.HwAlarmType; import com.ruoyi.business.domain.VO.AlarmTypeVo; import com.ruoyi.business.mapper.HwAlarmTypeMapper; +import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.datascope.annotation.DataScope; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.business.mapper.HwAlarmInfoMapper; @@ -47,6 +49,7 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService { * @return 报警信息 */ @Override + @DataScope(tenantAlias = "hai") public List selectHwAlarmInfoList(HwAlarmInfo hwAlarmInfo) { return hwAlarmInfoMapper.selectHwAlarmInfoList(hwAlarmInfo); } @@ -72,6 +75,7 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService { @Override public int updateHwAlarmInfo(HwAlarmInfo hwAlarmInfo) { hwAlarmInfo.setUpdateTime(DateUtils.getNowDate()); + hwAlarmInfo.setHandleStatus(HwDictConstants.ALARM_HANDLE_STATUS_YES); return hwAlarmInfoMapper.updateHwAlarmInfo(hwAlarmInfo); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java index bae9b71..8faa0a3 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.business.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.shaded.com.google.gson.JsonObject; import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.HwDeviceModeFunction; import com.ruoyi.business.domain.HwScene; @@ -23,20 +24,14 @@ import com.ruoyi.common.core.utils.NumberUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.tdengine.api.RemoteTdEngineService; -import com.ruoyi.tdengine.api.domain.AlterTagVo; -import com.ruoyi.tdengine.api.domain.TdField; -import com.ruoyi.tdengine.api.domain.TdSelectDto; -import com.ruoyi.tdengine.api.domain.TdTableVo; +import com.ruoyi.tdengine.api.domain.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -156,7 +151,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { for (Object deviceInfoObj : deviceInfoJsonArr) { JSONObject deviceInfoJson = (JSONObject) deviceInfoObj; if (deviceInfoJson.getString("deviceCode").equals(hwDevice.getDeviceCode())) { - deviceInfoJson.put("username", modeAccount); + deviceInfoJson.put("userName", modeAccount); deviceInfoJson.put("password", modeKey); redisUpdated = true; } @@ -468,4 +463,131 @@ public class HwDeviceServiceImpl implements IHwDeviceService { public List selectHwDeviceJoinList(HwDevice hwDevice) { return hwDeviceMapper.selectHwDeviceJoinList(hwDevice); } + + + /** + * @param: days + * @description 计算前几天的设备在线数量 + * @author xins + * @date 2023-09-20 19:28 + */ + @Override + public void computeOnlineDevicecCount(int days) { + JSONObject jsonObject = new JSONObject(); + for (int i = 1; i <= days; i++) { + + Date currentDate = new Date(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(currentDate); + calendar.add(Calendar.DAY_OF_MONTH, -i); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + Long startTime = calendar.getTimeInMillis();//先是昨天 00:00 + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + Long endTime = calendar.getTimeInMillis();//23:59.59 + Map onlineDeviceCountPerDay = computeDeviceCountPerDay(startTime, endTime); + Set times = onlineDeviceCountPerDay.keySet(); + for (Long key : times) { + jsonObject.put(String.valueOf(key), onlineDeviceCountPerDay.get(key)); + } + } + redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO,jsonObject.toString()); + } + + private Map computeDeviceCountPerDay(Long startTime, Long endTime) { + DeviceStatus queryGroupStatus = new DeviceStatus(); + queryGroupStatus.setStartTime(startTime); + queryGroupStatus.setEndTime(endTime); + + DeviceStatus queryLastStatus = new DeviceStatus(); + queryLastStatus.setEndTime(startTime); + + Map onlineDeviceCountByDay = new HashMap(); + + Map> groupDeviceStatuMapList = + (Map>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData(); + if (groupDeviceStatuMapList == null) { + groupDeviceStatuMapList = new HashMap<>(); + } + + List> lastDeviceStatuMapList = + (List>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData(); + for (Map groupDeviceStatuMap : lastDeviceStatuMapList) { + DeviceStatus ds = new DeviceStatus(); + for (Map.Entry entry : groupDeviceStatuMap.entrySet()) { + if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICEID)) { + ds.setDeviceId((long) (Integer) entry.getValue()); + } else if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICETYPE)) { + ds.setDeviceType((Integer) entry.getValue()); + } else if (entry.getKey().equals(TdEngineConstants.ST_TAG_ONLINESTATUS)) { + ds.setOnlineStatus((Integer) entry.getValue()); + } + } + + List dss = groupDeviceStatuMapList.get(ds.getDeviceId()); + int count = 0; + if (dss == null) { + if (String.valueOf(ds.getOnlineStatus()) + .equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) { + count = this.getDeviceCount(ds); + } + } else { + count = this.getDeviceCount(dss.get(0)); + } + + if (onlineDeviceCountByDay.get(startTime) == null) { + onlineDeviceCountByDay.put(startTime, count); + } else { + onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count); + } + } + + return onlineDeviceCountByDay; + } + + private int getDeviceCount(DeviceStatus ds) { + String deviceType = String.valueOf(ds.getDeviceType()); + if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE)) { + HwDevice queryDevice = new HwDevice(); + queryDevice.setReleatedDeviceId(ds.getDeviceId()); + List deviceList = hwDeviceMapper.selectHwDeviceList(queryDevice); + return deviceList == null ? 0 : deviceList.size(); + } else { + return 1; + } + } + + + /** + * @param: sceneId + * @description 获取最近几天在线设备数量 + * @author xins + * @date 2023-09-21 9:09 + * @return String + */ + @Override + public JSONObject getOnlineDevicesCount(Long sceneId){ + JSONObject returnObj = new JSONObject(); + int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId); + + String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO); + JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr); + + JSONObject sortedJsonObject = new JSONObject(); + jsonObject.forEach((key,value) ->{ + String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD,new Date(Long.parseLong(key))); + sortedJsonObject.put(dateStrKey,value); + }); + returnObj.put("onlineDevicesTrend",sortedJsonObject); + returnObj.put("onlineDevicesCount",onlineDevicesCount); + return returnObj; + } + + + public void publishContrlCommand(String channel,String message){ + redisTemplate.convertAndSend(channel,message); + } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwElectronicFenceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwElectronicFenceServiceImpl.java index 372079a..a4ba245 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwElectronicFenceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwElectronicFenceServiceImpl.java @@ -11,8 +11,10 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.business.domain.HwFenceArea; import com.ruoyi.business.domain.HwFenceTarget; +import com.ruoyi.business.domain.VO.AlarmInfoVo; import com.ruoyi.business.domain.VO.EleMonitorDeviceSumVo; import com.ruoyi.business.domain.VO.ElectronicFenceVo; +import com.ruoyi.business.mapper.HwAlarmInfoMapper; import com.ruoyi.business.mapper.HwFenceAreaMapper; import com.ruoyi.business.mapper.HwFenceTargetMapper; import com.ruoyi.common.core.constant.HwDictConstants; @@ -42,6 +44,9 @@ public class HwElectronicFenceServiceImpl implements IHwElectronicFenceService { @Autowired private HwFenceAreaMapper hwFenceAreaMapper; + @Autowired + private HwAlarmInfoMapper hwAlarmInfoMapper; + /** * 查询电子围栏 * @@ -101,7 +106,7 @@ public class HwElectronicFenceServiceImpl implements IHwElectronicFenceService { @Override public List selectEleTypeNums(Long sceneId) { - List electronicFenceVos = new ArrayList(); + List electronicFenceVos = new ArrayList<>(); HwElectronicFence queryElectronicFence = new HwElectronicFence(); queryElectronicFence.setSceneId(sceneId); List electronicFenceList = hwElectronicFenceMapper.selectHwElectronicFenceList(queryElectronicFence); @@ -149,7 +154,8 @@ public class HwElectronicFenceServiceImpl implements IHwElectronicFenceService { e.setRadius(Double.valueOf(areaRangeArr[2])); } - e.setAbnormalCount(2);//todo 异常数量获取 + AlarmInfoVo alarmInfoVo = hwAlarmInfoMapper.selectAlarmCountByFenceArea(fenceArea.getFenceAreaId()); + e.setAbnormalCount(alarmInfoVo.getAlarmCount()); e.setAreaShapeFlag(areaShapeFlag); e.setDeviceCount(deviceCount); electronicFenceVos.add(e); diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java index ed47593..c75d35d 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java @@ -9,26 +9,18 @@ import com.ruoyi.business.mapper.HwDeviceMapper; import com.ruoyi.business.mapper.HwElectronicFenceMapper; import com.ruoyi.business.mapper.HwMonitorUnitMapper; import com.ruoyi.business.service.IHwMonitorUnitService; -import com.ruoyi.common.core.constant.TdEngineConstants; -import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.NumberUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.tdengine.api.RemoteTdEngineService; -import com.ruoyi.tdengine.api.domain.DeviceStatus; -import com.ruoyi.tdengine.api.domain.TdSelectDto; -import com.ruoyi.tdengine.api.domain.TdSuperTableSelectVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.stream.Collectors; /** @@ -129,10 +121,11 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { return list; } - //获取总的设备数量与监控单元数量 + //获取总的设备数量与监控单元数量(标准场景使用) @Override public AllNumsVo selectAllNums(Long sceneId) { //监控单元 + //查询设备数量包括网关 Integer monitor = hwMonitorUnitMapper.selectSubSetNums(sceneId) == null ? 0 : hwMonitorUnitMapper.selectSubSetNums(sceneId); Integer integer = hwMonitorUnitMapper.selectDeviceNums(sceneId) == null ? 0 @@ -159,9 +152,9 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { // } @Override - public List selectLimitSubMonitorUnit() { + public List selectLimitSubMonitorUnit(HwMonitorUnit hwMonitorUnit) { - List hwMonitorUnits = hwMonitorUnitMapper.selectLimitSubMonitorUnit(); + List hwMonitorUnits = hwMonitorUnitMapper.selectLimitSubMonitorUnit(hwMonitorUnit); return hwMonitorUnits; } @@ -405,4 +398,15 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { } } + /** + * 查询监控单元,Join monitorunittype + * + * @param monitorUnitId 监控单元主键 + * @return 监控单元 + */ + @Override + public HwMonitorUnit selectHwMonitorUnitJoinByMonitorUnitId(Long monitorUnitId) { + return hwMonitorUnitMapper.selectHwMonitorUnitJoinByMonitorUnitId(monitorUnitId); + } + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java index d9ff8b7..cecaff3 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java @@ -190,7 +190,7 @@ public class HwSceneServiceImpl implements IHwSceneService { for (Object deviceInfoObj : deviceInfoJsonArr) { JSONObject deviceInfoJson = (JSONObject) deviceInfoObj; if (deviceInfoJson.getString("deviceCode").equals(device.getDeviceCode())) { - deviceInfoJson.put("username", modeAccount); + deviceInfoJson.put("userName", modeAccount); deviceInfoJson.put("password", modeKey); redisUpdated = true; } @@ -199,7 +199,7 @@ public class HwSceneServiceImpl implements IHwSceneService { if (!redisUpdated) { JSONObject deviceInfoJson = new JSONObject(); deviceInfoJson.put("deviceCode", device.getDeviceCode()); - deviceInfoJson.put("username", modeAccount); + deviceInfoJson.put("userName", modeAccount); deviceInfoJson.put("password", modeKey); deviceInfoJsonArr.add(deviceInfoJson); } diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml index 43a69d5..37c15c2 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml @@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -36,6 +37,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + select hai.alarm_info_id, hai.alarm_info_type, hai.alarm_releated_id, hai.device_id, @@ -68,7 +73,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and handle_status = #{handleStatus} and alarm_time = #{alarmTime} and alarm_info_field = #{alarmInfoField} + + ${params.tenantDataScope} + order by alarm_info_id desc + + \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmTypeMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmTypeMapper.xml index 9028571..d8edf93 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmTypeMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmTypeMapper.xml @@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select alarm_type_id, alarm_type_name, tenant_id, scene_id, language_code, common_flag, handle_mode, type_status, remark, create_by, create_time, update_by, update_time, alarm_type_field from hw_alarm_type + select alarm_type_id, alarm_type_name, tenant_id, scene_id, language_code, common_flag, handle_mode, type_status, remark, create_by, create_time, update_by, update_time, alarm_type_field from hw_alarm_type hat SELECT b.device_mode_name ,a.sum FROM hw_device_mode b - LEFT JOIN (SELECT device_mode_id,count(*) as sum FROM hw_device GROUP BY device_mode_id order by sum desc + LEFT JOIN (SELECT device_mode_id,count(*) as sum FROM hw_device GROUP BY device_mode_id order by sum desc ) a on a.device_mode_id = b.device_mode_id + - select count(*) as count from hw_device where - scene_id = #{sceneId} and device_status=1 and online_status=1 + SELECT count(1) as count FROM hw_device hd where hd.scene_id=#{sceneId} and hd.device_type=2 and hd.device_status=1 + and exists (select 1 from hw_device hdd where hd.releated_device_id=hdd.device_id and hdd.online_status=1) diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml index f7c5fc9..f910fc1 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml @@ -150,39 +150,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - delete from hw_fence_target where electronic_fence_id = #{electronicFenceId} - - - - insert into hw_fence_target( electronic_fence_id, target_type, target_id) values - - ( #{item.electronicFenceId}, #{item.targetType}, #{item.targetId}) - - + + - + select count(*) as count + from hw_device hd where hd.device_status=1 and (hd.device_type=2 or hd.device_type=3) and hd.scene_id = #{sceneId} \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml index c46770a..9fb0b4e 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml @@ -109,6 +109,7 @@ where monitor_unit_id = #{monitorUnitId} + select count(*) as sum from hw_device where device_status = '1' - and scene_id = #{sceneId} + and scene_id = #{sceneId} select * from hw_monitor_unit where monitor_unit_id not in (select parent_id from hw_monitor_unit where parent_id is not null) + and tenant_id = #{tenantId} + and scene_id = #{sceneId} + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml index 280cd55..705156c 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml @@ -192,7 +192,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update hw_scene set scene_status = '9' where scene_id = in + update hw_scene set scene_status = '9' where scene_id in #{sceneId} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java deleted file mode 100644 index 08644c6..0000000 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.ruoyi.business.controller; - -import java.util.List; -import java.io.IOException; -import javax.servlet.http.HttpServletResponse; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import com.ruoyi.common.log.annotation.Log; -import com.ruoyi.common.log.enums.BusinessType; -import com.ruoyi.common.security.annotation.RequiresPermissions; -import com.ruoyi.business.domain.HwAlarmRule; -import com.ruoyi.business.service.IHwAlarmRuleService; -import com.ruoyi.common.core.web.controller.BaseController; -import com.ruoyi.common.core.web.domain.AjaxResult; -import com.ruoyi.common.core.utils.poi.ExcelUtil; -import com.ruoyi.common.core.web.page.TableDataInfo; - -/** - * 报警规则Controller - * - * @author xins - * @date 2023-09-16 - */ -@RestController -@RequestMapping("/alarmRule") -public class HwAlarmRuleController extends BaseController -{ - @Autowired - private IHwAlarmRuleService hwAlarmRuleService; - - /** - * 查询报警规则列表 - */ - @RequiresPermissions("business:alarmRule:list") - @GetMapping("/list") - public TableDataInfo list(HwAlarmRule hwAlarmRule) - { - startPage(); - List list = hwAlarmRuleService.selectHwAlarmRuleList(hwAlarmRule); - return getDataTable(list); - } - - /** - * 导出报警规则列表 - */ - @RequiresPermissions("business:alarmRule:export") - @Log(title = "报警规则", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, HwAlarmRule hwAlarmRule) - { - List list = hwAlarmRuleService.selectHwAlarmRuleList(hwAlarmRule); - ExcelUtil util = new ExcelUtil(HwAlarmRule.class); - util.exportExcel(response, list, "报警规则数据"); - } - - /** - * 获取报警规则详细信息 - */ - @RequiresPermissions("business:alarmRule:query") - @GetMapping(value = "/{alarmRuleId}") - public AjaxResult getInfo(@PathVariable("alarmRuleId") Long alarmRuleId) - { - return success(hwAlarmRuleService.selectHwAlarmRuleByAlarmRuleId(alarmRuleId)); - } - - /** - * 新增报警规则 - */ - @RequiresPermissions("business:alarmRule:add") - @Log(title = "报警规则", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@RequestBody HwAlarmRule hwAlarmRule) - { - return toAjax(hwAlarmRuleService.insertHwAlarmRule(hwAlarmRule)); - } - - /** - * 修改报警规则 - */ - @RequiresPermissions("business:alarmRule:edit") - @Log(title = "报警规则", businessType = BusinessType.UPDATE) - @PutMapping - public AjaxResult edit(@RequestBody HwAlarmRule hwAlarmRule) - { - return toAjax(hwAlarmRuleService.updateHwAlarmRule(hwAlarmRule)); - } - - /** - * 删除报警规则 - */ - @RequiresPermissions("business:alarmRule:remove") - @Log(title = "报警规则", businessType = BusinessType.DELETE) - @DeleteMapping("/{alarmRuleIds}") - public AjaxResult remove(@PathVariable Long[] alarmRuleIds) - { - return toAjax(hwAlarmRuleService.deleteHwAlarmRuleByAlarmRuleIds(alarmRuleIds)); - } -} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java deleted file mode 100644 index d9988d1..0000000 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java +++ /dev/null @@ -1,392 +0,0 @@ -package com.ruoyi.business.domain; - -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.core.annotation.Excel; -import com.ruoyi.common.core.web.domain.BaseEntity; - -/** - * 报警规则对象 hw_alarm_rule - * - * @author xins - * @date 2023-09-16 - */ -public class HwAlarmRule extends BaseEntity -{ - private static final long serialVersionUID = 1L; - - /** 报警规则ID */ - private Long alarmRuleId; - - /** 规则名称 */ - @Excel(name = "规则名称") - private String alarmRuleName; - - /** 租户ID,关联hw_tenant的tenant_id */ - @Excel(name = "租户ID,关联hw_tenant的tenant_id") - private Long tenantId; - - /** 所属场景,关联hw_scene表的scene_id字段 */ - @Excel(name = "所属场景,关联hw_scene表的scene_id字段") - private Long sceneId; - - /** 报警级别,关联表hw_alarm_level字段alarm_level_id */ - @Excel(name = "报警级别,关联表hw_alarm_level字段alarm_level_id") - private Long alarmLevelId; - - /** 报警类型,关联表hw_alarm_type字段alarm_type_id */ - @Excel(name = "报警类型,关联表hw_alarm_type字段alarm_type_id") - private Long alarmTypeId; - - /** 规则类型(1、设备模型,2、设备) */ - @Excel(name = "规则类型", readConverterExp = "1=、设备模型,2、设备") - private String ruleType; - - /** 设备,关联表hw_device字段device_id */ - @Excel(name = "设备,关联表hw_device字段device_id") - private Long deviceId; - - /** 设备模型,关联表hw_device_mode字段device_mode_id */ - @Excel(name = "设备模型,关联表hw_device_mode字段device_mode_id") - private Long deviceModeId; - - /** 设备属性,关联表hw_device_mode_function字段mode_function_id */ - @Excel(name = "设备属性,关联表hw_device_mode_function字段mode_function_id") - private Long modeFunctionId; - - /** 触发条件(1、数值大于A,2、数值小于B,3、数值大于A且小于B,4、数值小于A或大于B,5、数值等于A) */ - @Excel(name = "触发条件", readConverterExp = "1=、数值大于A,2、数值小于B,3、数值大于A且小于B,4、数值小于A或大于B,5、数值等于A") - private String triggerCondition; - - /** 触发定义A值 */ - @Excel(name = "触发定义A值") - private String triggerDataA; - - /** 触发定义B值 */ - @Excel(name = "触发定义B值") - private String triggerDataB; - - /** 触发死区 */ - @Excel(name = "触发死区") - private String triggerDeadzone; - - /** 触发阈值次数 */ - @Excel(name = "触发阈值次数") - private Long triggerNumber; - - /** 时间范围(单位:分钟) */ - @Excel(name = "时间范围", readConverterExp = "单=位:分钟") - private Long triggerTimeFrame; - - /** 联动标识(1、是,0、否) */ - @Excel(name = "联动标识", readConverterExp = "1=、是,0、否") - private String linkFlag; - - /** 联动类型(1、控制,2、采集) */ - @Excel(name = "联动类型", readConverterExp = "1=、控制,2、采集") - private String linkType; - - /** 联动设备,关联表hw_device字段device_id */ - @Excel(name = "联动设备,关联表hw_device字段device_id") - private Long linkDeviceId; - - /** 联动设备功能,关联表hw_device_mode_function字段mode_function_id */ - @Excel(name = "联动设备功能,关联表hw_device_mode_function字段mode_function_id") - private Long linkDeviceFunctionId; - - /** 联动设备属性值 */ - @Excel(name = "联动设备属性值") - private String linkDeviceFunctionData; - - /** 报警启用状态(1、是,2、否) */ - @Excel(name = "报警启用状态(1、是,2、否)") - private String alarmRuleStatus; - - /** 报警推送标识(1、是,2、否) */ - @Excel(name = "报警推送标识(1、是,2、否)") - private String alarmPushFlag; - - /** 报警推送内容 */ - @Excel(name = "报警推送内容") - private String alarmPushContent; - - /** 恢复正常推送内容 */ - @Excel(name = "恢复正常推送内容") - private String alarmRecoverContent; - - /** 预留字段 */ - @Excel(name = "预留字段") - private String alarmRuleField; - - public void setAlarmRuleId(Long alarmRuleId) - { - this.alarmRuleId = alarmRuleId; - } - - public Long getAlarmRuleId() - { - return alarmRuleId; - } - public void setAlarmRuleName(String alarmRuleName) - { - this.alarmRuleName = alarmRuleName; - } - - public String getAlarmRuleName() - { - return alarmRuleName; - } - public void setTenantId(Long tenantId) - { - this.tenantId = tenantId; - } - - public Long getTenantId() - { - return tenantId; - } - public void setSceneId(Long sceneId) - { - this.sceneId = sceneId; - } - - public Long getSceneId() - { - return sceneId; - } - public void setAlarmLevelId(Long alarmLevelId) - { - this.alarmLevelId = alarmLevelId; - } - - public Long getAlarmLevelId() - { - return alarmLevelId; - } - public void setAlarmTypeId(Long alarmTypeId) - { - this.alarmTypeId = alarmTypeId; - } - - public Long getAlarmTypeId() - { - return alarmTypeId; - } - public void setRuleType(String ruleType) - { - this.ruleType = ruleType; - } - - public String getRuleType() - { - return ruleType; - } - public void setDeviceId(Long deviceId) - { - this.deviceId = deviceId; - } - - public Long getDeviceId() - { - return deviceId; - } - public void setDeviceModeId(Long deviceModeId) - { - this.deviceModeId = deviceModeId; - } - - public Long getDeviceModeId() - { - return deviceModeId; - } - public void setModeFunctionId(Long modeFunctionId) - { - this.modeFunctionId = modeFunctionId; - } - - public Long getModeFunctionId() - { - return modeFunctionId; - } - public void setTriggerCondition(String triggerCondition) - { - this.triggerCondition = triggerCondition; - } - - public String getTriggerCondition() - { - return triggerCondition; - } - public void setTriggerDataA(String triggerDataA) - { - this.triggerDataA = triggerDataA; - } - - public String getTriggerDataA() - { - return triggerDataA; - } - public void setTriggerDataB(String triggerDataB) - { - this.triggerDataB = triggerDataB; - } - - public String getTriggerDataB() - { - return triggerDataB; - } - public void setTriggerDeadzone(String triggerDeadzone) - { - this.triggerDeadzone = triggerDeadzone; - } - - public String getTriggerDeadzone() - { - return triggerDeadzone; - } - public void setTriggerNumber(Long triggerNumber) - { - this.triggerNumber = triggerNumber; - } - - public Long getTriggerNumber() - { - return triggerNumber; - } - public void setTriggerTimeFrame(Long triggerTimeFrame) - { - this.triggerTimeFrame = triggerTimeFrame; - } - - public Long getTriggerTimeFrame() - { - return triggerTimeFrame; - } - public void setLinkFlag(String linkFlag) - { - this.linkFlag = linkFlag; - } - - public String getLinkFlag() - { - return linkFlag; - } - public void setLinkType(String linkType) - { - this.linkType = linkType; - } - - public String getLinkType() - { - return linkType; - } - public void setLinkDeviceId(Long linkDeviceId) - { - this.linkDeviceId = linkDeviceId; - } - - public Long getLinkDeviceId() - { - return linkDeviceId; - } - public void setLinkDeviceFunctionId(Long linkDeviceFunctionId) - { - this.linkDeviceFunctionId = linkDeviceFunctionId; - } - - public Long getLinkDeviceFunctionId() - { - return linkDeviceFunctionId; - } - public void setLinkDeviceFunctionData(String linkDeviceFunctionData) - { - this.linkDeviceFunctionData = linkDeviceFunctionData; - } - - public String getLinkDeviceFunctionData() - { - return linkDeviceFunctionData; - } - public void setAlarmRuleStatus(String alarmRuleStatus) - { - this.alarmRuleStatus = alarmRuleStatus; - } - - public String getAlarmRuleStatus() - { - return alarmRuleStatus; - } - public void setAlarmPushFlag(String alarmPushFlag) - { - this.alarmPushFlag = alarmPushFlag; - } - - public String getAlarmPushFlag() - { - return alarmPushFlag; - } - public void setAlarmPushContent(String alarmPushContent) - { - this.alarmPushContent = alarmPushContent; - } - - public String getAlarmPushContent() - { - return alarmPushContent; - } - public void setAlarmRecoverContent(String alarmRecoverContent) - { - this.alarmRecoverContent = alarmRecoverContent; - } - - public String getAlarmRecoverContent() - { - return alarmRecoverContent; - } - public void setAlarmRuleField(String alarmRuleField) - { - this.alarmRuleField = alarmRuleField; - } - - public String getAlarmRuleField() - { - return alarmRuleField; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("alarmRuleId", getAlarmRuleId()) - .append("alarmRuleName", getAlarmRuleName()) - .append("tenantId", getTenantId()) - .append("sceneId", getSceneId()) - .append("alarmLevelId", getAlarmLevelId()) - .append("alarmTypeId", getAlarmTypeId()) - .append("ruleType", getRuleType()) - .append("deviceId", getDeviceId()) - .append("deviceModeId", getDeviceModeId()) - .append("modeFunctionId", getModeFunctionId()) - .append("triggerCondition", getTriggerCondition()) - .append("triggerDataA", getTriggerDataA()) - .append("triggerDataB", getTriggerDataB()) - .append("triggerDeadzone", getTriggerDeadzone()) - .append("triggerNumber", getTriggerNumber()) - .append("triggerTimeFrame", getTriggerTimeFrame()) - .append("linkFlag", getLinkFlag()) - .append("linkType", getLinkType()) - .append("linkDeviceId", getLinkDeviceId()) - .append("linkDeviceFunctionId", getLinkDeviceFunctionId()) - .append("linkDeviceFunctionData", getLinkDeviceFunctionData()) - .append("alarmRuleStatus", getAlarmRuleStatus()) - .append("alarmPushFlag", getAlarmPushFlag()) - .append("alarmPushContent", getAlarmPushContent()) - .append("alarmRecoverContent", getAlarmRecoverContent()) - .append("remark", getRemark()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("alarmRuleField", getAlarmRuleField()) - .toString(); - } -} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java deleted file mode 100644 index d805c36..0000000 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.ruoyi.business.mapper; - -import java.util.List; -import com.ruoyi.business.domain.HwAlarmRule; - -/** - * 报警规则Mapper接口 - * - * @author xins - * @date 2023-09-16 - */ -public interface HwAlarmRuleMapper -{ - /** - * 查询报警规则 - * - * @param alarmRuleId 报警规则主键 - * @return 报警规则 - */ - public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId); - - /** - * 查询报警规则列表 - * - * @param hwAlarmRule 报警规则 - * @return 报警规则集合 - */ - public List selectHwAlarmRuleList(HwAlarmRule hwAlarmRule); - - /** - * 新增报警规则 - * - * @param hwAlarmRule 报警规则 - * @return 结果 - */ - public int insertHwAlarmRule(HwAlarmRule hwAlarmRule); - - /** - * 修改报警规则 - * - * @param hwAlarmRule 报警规则 - * @return 结果 - */ - public int updateHwAlarmRule(HwAlarmRule hwAlarmRule); - - /** - * 删除报警规则 - * - * @param alarmRuleId 报警规则主键 - * @return 结果 - */ - public int deleteHwAlarmRuleByAlarmRuleId(Long alarmRuleId); - - /** - * 批量删除报警规则 - * - * @param alarmRuleIds 需要删除的数据主键集合 - * @return 结果 - */ - public int deleteHwAlarmRuleByAlarmRuleIds(Long[] alarmRuleIds); -} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java deleted file mode 100644 index 73c42cc..0000000 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.ruoyi.business.service; - -import java.util.List; -import com.ruoyi.business.domain.HwAlarmRule; - -/** - * 报警规则Service接口 - * - * @author xins - * @date 2023-09-16 - */ -public interface IHwAlarmRuleService -{ - /** - * 查询报警规则 - * - * @param alarmRuleId 报警规则主键 - * @return 报警规则 - */ - public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId); - - /** - * 查询报警规则列表 - * - * @param hwAlarmRule 报警规则 - * @return 报警规则集合 - */ - public List selectHwAlarmRuleList(HwAlarmRule hwAlarmRule); - - /** - * 新增报警规则 - * - * @param hwAlarmRule 报警规则 - * @return 结果 - */ - public int insertHwAlarmRule(HwAlarmRule hwAlarmRule); - - /** - * 修改报警规则 - * - * @param hwAlarmRule 报警规则 - * @return 结果 - */ - public int updateHwAlarmRule(HwAlarmRule hwAlarmRule); - - /** - * 批量删除报警规则 - * - * @param alarmRuleIds 需要删除的报警规则主键集合 - * @return 结果 - */ - public int deleteHwAlarmRuleByAlarmRuleIds(Long[] alarmRuleIds); - - /** - * 删除报警规则信息 - * - * @param alarmRuleId 报警规则主键 - * @return 结果 - */ - public int deleteHwAlarmRuleByAlarmRuleId(Long alarmRuleId); -} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java deleted file mode 100644 index bdf057d..0000000 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.ruoyi.business.service.impl; - -import java.util.List; -import com.ruoyi.common.core.utils.DateUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.ruoyi.business.mapper.HwAlarmRuleMapper; -import com.ruoyi.business.domain.HwAlarmRule; -import com.ruoyi.business.service.IHwAlarmRuleService; - -/** - * 报警规则Service业务层处理 - * - * @author xins - * @date 2023-09-16 - */ -@Service -public class HwAlarmRuleServiceImpl implements IHwAlarmRuleService -{ - @Autowired - private HwAlarmRuleMapper hwAlarmRuleMapper; - - /** - * 查询报警规则 - * - * @param alarmRuleId 报警规则主键 - * @return 报警规则 - */ - @Override - public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId) - { - return hwAlarmRuleMapper.selectHwAlarmRuleByAlarmRuleId(alarmRuleId); - } - - /** - * 查询报警规则列表 - * - * @param hwAlarmRule 报警规则 - * @return 报警规则 - */ - @Override - public List selectHwAlarmRuleList(HwAlarmRule hwAlarmRule) - { - return hwAlarmRuleMapper.selectHwAlarmRuleList(hwAlarmRule); - } - - /** - * 新增报警规则 - * - * @param hwAlarmRule 报警规则 - * @return 结果 - */ - @Override - public int insertHwAlarmRule(HwAlarmRule hwAlarmRule) - { - hwAlarmRule.setCreateTime(DateUtils.getNowDate()); - return hwAlarmRuleMapper.insertHwAlarmRule(hwAlarmRule); - } - - /** - * 修改报警规则 - * - * @param hwAlarmRule 报警规则 - * @return 结果 - */ - @Override - public int updateHwAlarmRule(HwAlarmRule hwAlarmRule) - { - hwAlarmRule.setUpdateTime(DateUtils.getNowDate()); - return hwAlarmRuleMapper.updateHwAlarmRule(hwAlarmRule); - } - - /** - * 批量删除报警规则 - * - * @param alarmRuleIds 需要删除的报警规则主键 - * @return 结果 - */ - @Override - public int deleteHwAlarmRuleByAlarmRuleIds(Long[] alarmRuleIds) - { - return hwAlarmRuleMapper.deleteHwAlarmRuleByAlarmRuleIds(alarmRuleIds); - } - - /** - * 删除报警规则信息 - * - * @param alarmRuleId 报警规则主键 - * @return 结果 - */ - @Override - public int deleteHwAlarmRuleByAlarmRuleId(Long alarmRuleId) - { - return hwAlarmRuleMapper.deleteHwAlarmRuleByAlarmRuleId(alarmRuleId); - } -} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwAlarmInfo.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwAlarmInfo.java index 14df473..eee9846 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwAlarmInfo.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwAlarmInfo.java @@ -30,6 +30,8 @@ public class HwAlarmInfo extends BaseEntity @Excel(name = "报警信息类型") private Long alarmReleatedId; + private Long fenceAreaId; + /** 报警设备ID,关联hw_device表的device_id字段 */ @Excel(name = "报警设备ID,关联hw_device表的device_id字段") private Long deviceId; @@ -114,7 +116,16 @@ public class HwAlarmInfo extends BaseEntity { return alarmReleatedId; } - public void setDeviceId(Long deviceId) + + public Long getFenceAreaId() { + return fenceAreaId; + } + + public void setFenceAreaId(Long fenceAreaId) { + this.fenceAreaId = fenceAreaId; + } + + public void setDeviceId(Long deviceId) { this.deviceId = deviceId; } diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwElectronicFence.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwElectronicFence.java index 13ead56..c8031bc 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwElectronicFence.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwElectronicFence.java @@ -36,14 +36,6 @@ public class HwElectronicFence extends BaseEntity @Excel(name = "触发状态", readConverterExp = "0=、关闭,1、出界,2、入界,3、双向") private String triggerStatus; - /** 区域形状(1、多边形,2、圆形) */ - @Excel(name = "区域形状", readConverterExp = "1=、多边形,2、圆形") - private String areaShapeFlag; - - /** 区域范围:为多边形时保存格式,经度_纬度,多个以|隔开;为圆形时的中心点和半径,下划线隔开 */ - @Excel(name = "区域范围", readConverterExp = "为多边形时保存格式为经度_纬度,多个以|隔开;为圆形时的中心点和半径,下划线") - private String areaRange; - /** 报警推送标识(1、是,0、否) */ @Excel(name = "报警推送标识(1、是,0、否)") private Long fencePushFlag; @@ -123,24 +115,6 @@ public class HwElectronicFence extends BaseEntity { return triggerStatus; } - public void setAreaShapeFlag(String areaShapeFlag) - { - this.areaShapeFlag = areaShapeFlag; - } - - public String getAreaShapeFlag() - { - return areaShapeFlag; - } - public void setAreaRange(String areaRange) - { - this.areaRange = areaRange; - } - - public String getAreaRange() - { - return areaRange; - } public void setFencePushFlag(Long fencePushFlag) { @@ -189,8 +163,6 @@ public class HwElectronicFence extends BaseEntity .append("effectiveTimeFlag", getEffectiveTimeFlag()) .append("effectiveTime", getEffectiveTime()) .append("triggerStatus", getTriggerStatus()) - .append("areaShapeFlag", getAreaShapeFlag()) - .append("areaRange", getAreaRange()) .append("fencePushFlag", getFencePushFlag()) .append("fencePushContent", getFencePushContent()) .append("fenceRecoverContent", getFenceRecoverContent()) diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwFenceArea.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwFenceArea.java new file mode 100644 index 0000000..77a871f --- /dev/null +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/domain/HwFenceArea.java @@ -0,0 +1,79 @@ +package com.ruoyi.dataprocess.domain; + +import com.ruoyi.common.core.annotation.Excel; +import com.ruoyi.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 电子围栏区域对象 hw_fence_area + * + * @author xins + * @date 2023-09-19 + */ +public class HwFenceArea extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 电子围栏区域ID */ + private Long fenceAreaId; + + /** 电子围栏ID */ + @Excel(name = "电子围栏ID") + private Long electronicFenceId; + + /** 区域形状(1、多边形,2、圆形) */ + @Excel(name = "区域形状", readConverterExp = "1=、多边形,2、圆形") + private String areaShapeFlag; + + /** 区域范围:为多边形时保存格式,经度,纬度,多个以_隔开;为圆形时的中心点和半径,,隔开 */ + @Excel(name = "区域范围:为多边形时保存格式,经度,纬度,多个以_隔开;为圆形时的中心点和半径,,隔开") + private String areaRange; + + public void setFenceAreaId(Long fenceAreaId) + { + this.fenceAreaId = fenceAreaId; + } + + public Long getFenceAreaId() + { + return fenceAreaId; + } + public void setElectronicFenceId(Long electronicFenceId) + { + this.electronicFenceId = electronicFenceId; + } + + public Long getElectronicFenceId() + { + return electronicFenceId; + } + public void setAreaShapeFlag(String areaShapeFlag) + { + this.areaShapeFlag = areaShapeFlag; + } + + public String getAreaShapeFlag() + { + return areaShapeFlag; + } + public void setAreaRange(String areaRange) + { + this.areaRange = areaRange; + } + + public String getAreaRange() + { + return areaRange; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("fenceAreaId", getFenceAreaId()) + .append("electronicFenceId", getElectronicFenceId()) + .append("areaShapeFlag", getAreaShapeFlag()) + .append("areaRange", getAreaRange()) + .toString(); + } +} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mapper/HwFenceAreaMapper.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mapper/HwFenceAreaMapper.java new file mode 100644 index 0000000..b1ec208 --- /dev/null +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mapper/HwFenceAreaMapper.java @@ -0,0 +1,62 @@ +package com.ruoyi.dataprocess.mapper; + +import com.ruoyi.dataprocess.domain.HwFenceArea; + +import java.util.List; + +/** + * 电子围栏区域Mapper接口 + * + * @author xins + * @date 2023-09-19 + */ +public interface HwFenceAreaMapper +{ + /** + * 查询电子围栏区域 + * + * @param fenceAreaId 电子围栏区域主键 + * @return 电子围栏区域 + */ + public HwFenceArea selectHwFenceAreaByFenceAreaId(Long fenceAreaId); + + /** + * 查询电子围栏区域列表 + * + * @param hwFenceArea 电子围栏区域 + * @return 电子围栏区域集合 + */ + public List selectHwFenceAreaList(HwFenceArea hwFenceArea); + + /** + * 新增电子围栏区域 + * + * @param hwFenceArea 电子围栏区域 + * @return 结果 + */ + public int insertHwFenceArea(HwFenceArea hwFenceArea); + + /** + * 修改电子围栏区域 + * + * @param hwFenceArea 电子围栏区域 + * @return 结果 + */ + public int updateHwFenceArea(HwFenceArea hwFenceArea); + + /** + * 删除电子围栏区域 + * + * @param fenceAreaId 电子围栏区域主键 + * @return 结果 + */ + public int deleteHwFenceAreaByFenceAreaId(Long fenceAreaId); + + /** + * 批量删除电子围栏区域 + * + * @param fenceAreaIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteHwFenceAreaByFenceAreaIds(Long[] fenceAreaIds); +} diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java index 9e9431a..c76f91c 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java @@ -46,6 +46,10 @@ import java.nio.charset.StandardCharsets; public class MqttConfiguration { private static final Logger logger = LoggerFactory.getLogger(MqttConfiguration.class); + public static final String TOPIC_TYPE_DATA_POSTFIX = "data"; + public static final String TOPIC_TYPE_COMMAND_POSTFIX = "command"; + public static final String TOPIC_TYPE_REPLY_POSTFIX = "reply"; + @Value("${mqtt.client.ip}") String ip; @Value("${mqtt.client.port}") @@ -120,17 +124,21 @@ public class MqttConfiguration { @Override public void onMessage(ChannelContext channelContext, String topic, MqttPublishMessage mqttPublishMessage, ByteBuffer payload) { - System.out.println("dataprocessservice:" + dataProcessService); String payloadString = new String(payload.array(), StandardCharsets.UTF_8); System.out.println("paa:" + topic); logger.info("topic:{} payload:{}", topic, payloadString); - System.out.println(topic+"----"+dataTopicFilter); - System.out.println(topic.startsWith(dataTopicFilter)); - if (topic.startsWith(dataTopicFilter.replace("#",""))) { - dataProcessService.processBusinessData(payloadString, imagePath, imagePatterns); - } else if (topic.equals(deviceStatusTopic)) { - deviceStatusService.handleDeviceStatus(payloadString,clientId); + try{ + if (topic.startsWith(dataTopicFilter.replace("#","")) && topic.endsWith(TOPIC_TYPE_DATA_POSTFIX)) { + System.out.println("rrrrrr"); + dataProcessService.processBusinessData(payloadString, imagePath, imagePatterns); + } else if (topic.equals(deviceStatusTopic)) { + deviceStatusService.handleDeviceStatus(payloadString,clientId); + } + }catch(Exception e){ + e.printStackTrace(); + logger.error("Error processing business data:"+e.getMessage()); } + } }); diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/listener/MqttClientConnectListener.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/listener/MqttClientConnectListener.java index ba274d6..6e3713a 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/listener/MqttClientConnectListener.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/listener/MqttClientConnectListener.java @@ -43,6 +43,8 @@ public class MqttClientConnectListener implements IMqttClientConnectListener { @Override public void onDisconnect(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) { logger.error("mqtt 链接断开 remark:{} isRemove:{}", remark, isRemove, throwable); + + } } diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java index 2baca61..53eef7f 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java @@ -15,9 +15,11 @@ import com.ruoyi.dataprocess.common.ImageUtils; import com.ruoyi.dataprocess.domain.HwAlarmInfo; import com.ruoyi.dataprocess.domain.HwDevice; import com.ruoyi.dataprocess.domain.HwElectronicFence; +import com.ruoyi.dataprocess.domain.HwFenceArea; import com.ruoyi.dataprocess.mapper.HwAlarmInfoMapper; import com.ruoyi.dataprocess.mapper.HwDeviceMapper; import com.ruoyi.dataprocess.mapper.HwElectronicFenceMapper; +import com.ruoyi.dataprocess.mapper.HwFenceAreaMapper; import com.ruoyi.dataprocess.service.IDataProcessService; import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.domain.TdField; @@ -55,6 +57,10 @@ public class DataProcessServiceImpl implements IDataProcessService { @Autowired private HwElectronicFenceMapper hwElectronicFenceMapper; + @Autowired + private HwFenceAreaMapper hwFenceAreaMapper; + + @Autowired private HwAlarmInfoMapper hwAlarmInfoMapper; @@ -194,75 +200,86 @@ public class DataProcessServiceImpl implements IDataProcessService { } if (StringUtils.isNotEmpty(hwElectronicFences)) { - hwElectronicFences.forEach(hwElectronicFence -> { + for (HwElectronicFence hwElectronicFence : hwElectronicFences) { + HwFenceArea queryFenceArea = new HwFenceArea(); + queryFenceArea.setElectronicFenceId(hwElectronicFence.getElectronicFenceId()); + List fenceAreas = hwFenceAreaMapper.selectHwFenceAreaList(queryFenceArea); String effectiveTimeFlag = hwElectronicFence.getEffectiveTimeFlag(); String triggerStatus = hwElectronicFence.getTriggerStatus(); - boolean isAlarmed = false;//是否报警 - if (effectiveTimeFlag.equals(HwDictConstants.EFFECTIVE_TIME_FLAG_LONG)) { - String areaShapeFlag = hwElectronicFence.getAreaShapeFlag(); - String areaRange = hwElectronicFence.getAreaRange(); - if (areaShapeFlag.equals(HwDictConstants.AREA_SHAPE_FLAG_POLYGN)) { - LocationVo polygonVo = new LocationVo(); - polygonVo.setMarkerType(LocationVo.MARKER_TYPE_POLYGON); - List> polygonList = new ArrayList<>(); - List postionList = new ArrayList<>(); - String[] areaRangeArr = areaRange.split("_");//多个点,每个点的经纬度信息(经度_纬度) - for (String areaRange1 : areaRangeArr) { - String[] areaRange1Arr = areaRange1.split(","); - String longitudeStr = areaRange1Arr[0]; - String latitudeStr = areaRange1Arr[1]; - postionList.add(new PositionVo(new BigDecimal(longitudeStr), new BigDecimal(latitudeStr))); - polygonList.add(postionList); - } + if (fenceAreas != null && !fenceAreas.isEmpty()) { + fenceAreas.forEach(fenceArea -> { + boolean isAlarmed = false;//是否报警 + if (effectiveTimeFlag.equals(HwDictConstants.EFFECTIVE_TIME_FLAG_LONG)) { + String areaShapeFlag = fenceArea.getAreaShapeFlag(); + String areaRange = fenceArea.getAreaRange(); + if (areaShapeFlag.equals(HwDictConstants.AREA_SHAPE_FLAG_POLYGN)) { + LocationVo polygonVo = new LocationVo(); + polygonVo.setMarkerType(LocationVo.MARKER_TYPE_POLYGON); + List> polygonList = new ArrayList<>(); + List postionList = new ArrayList<>(); + String[] areaRangeArr = areaRange.split("_");//多个点,每个点的经纬度信息(经度_纬度) + for (String areaRange1 : areaRangeArr) { + String[] areaRange1Arr = areaRange1.split(","); + String longitudeStr = areaRange1Arr[0]; + String latitudeStr = areaRange1Arr[1]; + postionList.add(new PositionVo(new BigDecimal(longitudeStr), new BigDecimal(latitudeStr))); + polygonList.add(postionList); + } - polygonVo.setPolygonList(polygonList); + polygonVo.setPolygonList(polygonList); - /** - * 传入的longitude和latitude是object类型,本身有可能是BigDecimal,Double,Long和Integer,先转成String再转成Double - */ - boolean isWithin = PositionUtils.checkAddressInLocation(polygonVo, Double.valueOf(String.valueOf(longitude)), Double.valueOf(String.valueOf(latitude))); - if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_EXIT) && !isWithin) {//如果电子围栏配置是出界,而此设备出界则报警 - isAlarmed = true; - } else if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_ENTRY) && isWithin) {//如果电子围栏配置是入界,而此设备入界则报警 - isAlarmed = true; + /** + * 传入的longitude和latitude是object类型,本身有可能是BigDecimal,Double,Long和Integer,先转成String再转成Double + */ + boolean isWithin = PositionUtils.checkAddressInLocation(polygonVo, Double.valueOf(String.valueOf(longitude)), Double.valueOf(String.valueOf(latitude))); + if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_EXIT) && !isWithin) {//如果电子围栏配置是出界,而此设备出界则报警 + isAlarmed = true; + } else if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_ENTRY) && isWithin) {//如果电子围栏配置是入界,而此设备入界则报警 + isAlarmed = true; + } + System.out.println("iswithin" + isWithin); + + } else if (areaShapeFlag.equals(HwDictConstants.AREA_SHAPE_FLAG_CIRCULA)) { + String[] areaRangeArr = areaRange.split(","); + String longitudeStr = areaRangeArr[0]; + String latitudeStr = areaRangeArr[1]; + String radiusStr = areaRangeArr[2]; + LocationVo circulrVo = new LocationVo(); + circulrVo.setRadius(Double.valueOf(radiusStr)); + circulrVo.setLongitude(Double.valueOf(longitudeStr)); + circulrVo.setLatitude(Double.valueOf(latitudeStr)); + circulrVo.setMarkerType(LocationVo.MARKER_TYPE_CIRCULAR); + boolean isWithin = PositionUtils.checkAddressInLocation(circulrVo, Double.valueOf(String.valueOf(longitude)), Double.valueOf(String.valueOf(latitude))); + System.out.println("iswithin:" + isWithin); + if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_EXIT) && !isWithin) {//如果电子围栏配置是出界,而此设备出界则报警 + isAlarmed = true; + } else if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_ENTRY) && isWithin) {//如果电子围栏配置是入界,而此设备入界则报警 + isAlarmed = true; + } + } } - System.out.println("iswithin" + isWithin); - - } else if (areaShapeFlag.equals(HwDictConstants.AREA_SHAPE_FLAG_CIRCULA)) { - String[] areaRangeArr = areaRange.split(","); - String longitudeStr = areaRangeArr[0]; - String latitudeStr = areaRangeArr[1]; - String radiusStr = areaRangeArr[2]; - LocationVo circulrVo = new LocationVo(); - circulrVo.setRadius(Double.valueOf(radiusStr)); - circulrVo.setLongitude(Double.valueOf(longitudeStr)); - circulrVo.setLatitude(Double.valueOf(latitudeStr)); - circulrVo.setMarkerType(LocationVo.MARKER_TYPE_CIRCULAR); - boolean isWithin = PositionUtils.checkAddressInLocation(circulrVo, Double.valueOf(String.valueOf(longitude)), Double.valueOf(String.valueOf(latitude))); - System.out.println("iswithin:" + isWithin); - if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_EXIT) && !isWithin) {//如果电子围栏配置是出界,而此设备出界则报警 - isAlarmed = true; - } else if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_ENTRY) && isWithin) {//如果电子围栏配置是入界,而此设备入界则报警 - isAlarmed = true; + + if (isAlarmed) { + HwAlarmInfo hwAralmInfo = new HwAlarmInfo(); + hwAralmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_ELECTRONIC_FENCE); + hwAralmInfo.setAlarmReleatedId(hwElectronicFence.getElectronicFenceId()); + hwAralmInfo.setDeviceId(deviceId); + hwAralmInfo.setMonitorUnitId(monitorUnitId); + hwAralmInfo.setTenantId(tenantId); + hwAralmInfo.setSceneId(sceneId); + hwAralmInfo.setFunctionValue(longitude + "_" + latitude); + hwAralmInfo.setTriggerStatus(triggerStatus); + hwAralmInfo.setAlarmTime(new Date(ts)); + hwAralmInfo.setCreateTime(new Date()); + hwAralmInfo.setFenceAreaId(fenceArea.getFenceAreaId()); + hwAlarmInfoMapper.insertHwAlarmInfo(hwAralmInfo); } - } + }); } - if (isAlarmed) { - HwAlarmInfo hwAralmInfo = new HwAlarmInfo(); - hwAralmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_ELECTRONIC_FENCE); - hwAralmInfo.setAlarmReleatedId(hwElectronicFence.getElectronicFenceId()); - hwAralmInfo.setDeviceId(deviceId); - hwAralmInfo.setMonitorUnitId(monitorUnitId); - hwAralmInfo.setTenantId(tenantId); - hwAralmInfo.setSceneId(sceneId); - hwAralmInfo.setFunctionValue(longitude + "_" + latitude); - hwAralmInfo.setTriggerStatus(triggerStatus); - hwAralmInfo.setAlarmTime(new Date(ts)); - hwAralmInfo.setCreateTime(new Date()); - hwAlarmInfoMapper.insertHwAlarmInfo(hwAralmInfo); - } - }); + + } + } } diff --git a/ruoyi-modules/hw-data-process/src/main/resources/bootstrap.yml b/ruoyi-modules/hw-data-process/src/main/resources/bootstrap.yml index 856d7d0..861f2c0 100644 --- a/ruoyi-modules/hw-data-process/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/hw-data-process/src/main/resources/bootstrap.yml @@ -2,6 +2,21 @@ server: port: 9603 +mqtt: + client: + ip: 127.0.0.1 # mqtt server ip地址 + port: 1883 # mqtt server 端口 + clientId: hw-data-process-1 # 客户端ID,保证唯一 + username: mica # mqtt server 认证用户名 + password: mica # mqtt server 认证密码 + timeout: 10 + keepalive: 20 + qos : 1 # qos服务质量等级,0最多交付一次,1至少交付一次,2只交付一次 + dataTopicFilter: /v1/# # 订阅的处理设备上报数据的topic + deviceStatusTopic: /device/status/v1 # 订阅的处理设备状态的topic + imagePath: images # base64图片转换保存的路径 + imagePatterns: jpg,jpeg,png #支持的图片格式 + # Spring spring: application: diff --git a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmInfoMapper.xml b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmInfoMapper.xml index af0318a..6d8ca2a 100644 --- a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmInfoMapper.xml +++ b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmInfoMapper.xml @@ -2,12 +2,13 @@ - + + @@ -33,6 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" alarm_info_type, alarm_releated_id, + fence_area_id, device_id, monitor_unit_id, tenant_id, @@ -54,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{alarmInfoType}, #{alarmReleatedId}, + #{fenceAreaId}, #{deviceId}, #{monitorUnitId}, #{tenantId}, diff --git a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmRuleMapper.xml b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmRuleMapper.xml deleted file mode 100644 index 5982648..0000000 --- a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwAlarmRuleMapper.xml +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select alarm_rule_id, alarm_rule_name, tenant_id, scene_id, alarm_level_id, alarm_type_id, rule_type, device_id, device_mode_id, mode_function_id, trigger_condition, trigger_data_a, trigger_data_b, trigger_deadzone, trigger_number, trigger_time_frame, link_flag, link_type, link_device_id, link_device_function_id, link_device_function_data, alarm_rule_status, alarm_push_flag, alarm_push_content, alarm_recover_content, remark, create_by, create_time, update_by, update_time, alarm_rule_field from hw_alarm_rule - - - - - - - - insert into hw_alarm_rule - - alarm_rule_name, - tenant_id, - scene_id, - alarm_level_id, - alarm_type_id, - rule_type, - device_id, - device_mode_id, - mode_function_id, - trigger_condition, - trigger_data_a, - trigger_data_b, - trigger_deadzone, - trigger_number, - trigger_time_frame, - link_flag, - link_type, - link_device_id, - link_device_function_id, - link_device_function_data, - alarm_rule_status, - alarm_push_flag, - alarm_push_content, - alarm_recover_content, - remark, - create_by, - create_time, - update_by, - update_time, - alarm_rule_field, - - - #{alarmRuleName}, - #{tenantId}, - #{sceneId}, - #{alarmLevelId}, - #{alarmTypeId}, - #{ruleType}, - #{deviceId}, - #{deviceModeId}, - #{modeFunctionId}, - #{triggerCondition}, - #{triggerDataA}, - #{triggerDataB}, - #{triggerDeadzone}, - #{triggerNumber}, - #{triggerTimeFrame}, - #{linkFlag}, - #{linkType}, - #{linkDeviceId}, - #{linkDeviceFunctionId}, - #{linkDeviceFunctionData}, - #{alarmRuleStatus}, - #{alarmPushFlag}, - #{alarmPushContent}, - #{alarmRecoverContent}, - #{remark}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - #{alarmRuleField}, - - - - - update hw_alarm_rule - - alarm_rule_name = #{alarmRuleName}, - tenant_id = #{tenantId}, - scene_id = #{sceneId}, - alarm_level_id = #{alarmLevelId}, - alarm_type_id = #{alarmTypeId}, - rule_type = #{ruleType}, - device_id = #{deviceId}, - device_mode_id = #{deviceModeId}, - mode_function_id = #{modeFunctionId}, - trigger_condition = #{triggerCondition}, - trigger_data_a = #{triggerDataA}, - trigger_data_b = #{triggerDataB}, - trigger_deadzone = #{triggerDeadzone}, - trigger_number = #{triggerNumber}, - trigger_time_frame = #{triggerTimeFrame}, - link_flag = #{linkFlag}, - link_type = #{linkType}, - link_device_id = #{linkDeviceId}, - link_device_function_id = #{linkDeviceFunctionId}, - link_device_function_data = #{linkDeviceFunctionData}, - alarm_rule_status = #{alarmRuleStatus}, - alarm_push_flag = #{alarmPushFlag}, - alarm_push_content = #{alarmPushContent}, - alarm_recover_content = #{alarmRecoverContent}, - remark = #{remark}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, - alarm_rule_field = #{alarmRuleField}, - - where alarm_rule_id = #{alarmRuleId} - - - - delete from hw_alarm_rule where alarm_rule_id = #{alarmRuleId} - - - - delete from hw_alarm_rule where alarm_rule_id in - - #{alarmRuleId} - - - \ No newline at end of file diff --git a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwElectronicFenceMapper.xml b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwElectronicFenceMapper.xml index 01f3d5a..7440055 100644 --- a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwElectronicFenceMapper.xml +++ b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwElectronicFenceMapper.xml @@ -12,16 +12,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - select electronic_fence_id, electronic_fence_name, scene_id, fence_type, effective_time_flag, effective_time, trigger_status, area_shape_flag, - area_range, fence_push_flag, fence_push_content, fence_recover_content + select electronic_fence_id, electronic_fence_name, scene_id, fence_type, effective_time_flag, effective_time, trigger_status, + fence_push_flag, fence_push_content, fence_recover_content from hw_electronic_fence hef diff --git a/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwFenceAreaMapper.xml b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwFenceAreaMapper.xml new file mode 100644 index 0000000..e8161e5 --- /dev/null +++ b/ruoyi-modules/hw-data-process/src/main/resources/mapper/dataprocess/HwFenceAreaMapper.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + select fence_area_id, electronic_fence_id, area_shape_flag, area_range from hw_fence_area + + + + + + + + insert into hw_fence_area + + electronic_fence_id, + area_shape_flag, + area_range, + + + #{electronicFenceId}, + #{areaShapeFlag}, + #{areaRange}, + + + + + update hw_fence_area + + electronic_fence_id = #{electronicFenceId}, + area_shape_flag = #{areaShapeFlag}, + area_range = #{areaRange}, + + where fence_area_id = #{fenceAreaId} + + + + delete from hw_fence_area where fence_area_id = #{fenceAreaId} + + + + delete from hw_fence_area where fence_area_id in + + #{fenceAreaId} + + + \ No newline at end of file diff --git a/ruoyi-modules/hw-mqtt-broker/src/main/resources/bootstrap.yml b/ruoyi-modules/hw-mqtt-broker/src/main/resources/bootstrap.yml index dfdd7fd..cd1bc61 100644 --- a/ruoyi-modules/hw-mqtt-broker/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/hw-mqtt-broker/src/main/resources/bootstrap.yml @@ -11,7 +11,7 @@ mqtt: #broker相关配置 broker: #客户端ClientId白名单,不进行接入校验,多个ClientId用逗号隔开 - whitelist: Test123,Test234,Test256 + whitelist: hw-data-process-1 #设备接入状态推送 connectStatus: enable: true #是否启用设备连接状态推送 @@ -29,7 +29,7 @@ spring: nacos: config: # 配置中心地址 - server-addr: localhost:8848 + server-addr: 127.0.0.1:8848 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java index 86ce794..d0bd86b 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java @@ -385,7 +385,7 @@ public class TdEngineController { try { List deviceStatuses = this.deviceStatusService.getOnlineDevicesGroupByDay(queryDeviceStatus); Map> deviceStatusMap = deviceStatuses.stream() - .collect(Collectors.groupingBy(DeviceStatus::getTs)); + .collect(Collectors.groupingBy(DeviceStatus::getDeviceId)); return R.ok(deviceStatusMap); } catch (UncategorizedSQLException e) { String message = e.getCause().getMessage(); @@ -401,4 +401,31 @@ public class TdEngineController { } } + + /** + * @return R + * @param: tdSelectDto + * @description 获取最近一次在线设备信息 + * @author xins + * @date 2023-08-29 11:26 + */ + @PostMapping("/getLastOnlineDevices") + public R getLastOnlineDevices(@RequestBody DeviceStatus queryDeviceStatus) { + try { + List> deviceStatusMapList = this.deviceStatusService.getLastOnlineDevices(queryDeviceStatus); + return R.ok(deviceStatusMapList); + } catch (UncategorizedSQLException e) { + String message = e.getCause().getMessage(); + try { + message = message.substring(message.lastIndexOf("invalid operation")); + } catch (Exception ex) { + } + log.error(message); + return R.fail(message); + } catch (Exception e) { + log.error(e.getMessage()); + return R.fail(e.getMessage()); + } + } + } diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/DeviceStatusMapper.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/DeviceStatusMapper.java index c306225..877ed15 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/DeviceStatusMapper.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/DeviceStatusMapper.java @@ -3,6 +3,7 @@ package com.ruoyi.tdengine.mapper; import com.ruoyi.tdengine.api.domain.DeviceStatus; import java.util.List; +import java.util.Map; /** * @Description:TDengine设备状态信息交互接口 @@ -21,4 +22,14 @@ public interface DeviceStatusMapper { * @return List */ List getOnlineDevicesGroupByDay(DeviceStatus deviceStatus); + + /** + * @param: deviceStatus + * @description 获取最近的在线设备列表 + * @author xins + * @date 2023-09-05 11:43 + * @return List + */ + List> getLastOnlineDevices(DeviceStatus deviceStatus); + } diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/IDeviceStatusService.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/IDeviceStatusService.java index b039129..d45fcb4 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/IDeviceStatusService.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/IDeviceStatusService.java @@ -3,6 +3,7 @@ package com.ruoyi.tdengine.service; import com.ruoyi.tdengine.api.domain.DeviceStatus; import java.util.List; +import java.util.Map; public interface IDeviceStatusService { @@ -14,4 +15,13 @@ public interface IDeviceStatusService { * @return List */ public List getOnlineDevicesGroupByDay(DeviceStatus queryDeviceStatus); + + /** + * @return List> + * @param: DeviceStatus + * @description 获取某个事件前最新的在线设备 + * @author xins + * @date 2023-09-05 13:23 + */ + public List> getLastOnlineDevices(DeviceStatus queryDeviceStatus); } diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/DeviceStatusServiceImpl.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/DeviceStatusServiceImpl.java index 6154076..f07e3c0 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/DeviceStatusServiceImpl.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/DeviceStatusServiceImpl.java @@ -7,9 +7,11 @@ import com.ruoyi.tdengine.service.IDeviceStatusService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @Description: 设备状态信息业务服务 @@ -49,4 +51,36 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService { return deviceStatuses; } + + + /** + * @return List> + * @param: DeviceStatus + * @description 获取某个事件前最新的在线设备 + * @author xins + * @date 2023-09-05 13:23 + */ + @Override + public List> getLastOnlineDevices(DeviceStatus queryDeviceStatus) { + + Map params = queryDeviceStatus.getParams(); + params.put("databaseName", TdEngineConstants.PLATFORM_DB_NAME); + params.put("superTableName", TdEngineConstants.DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME); + List> deviceStatusMap = deviceStatusMapper.getLastOnlineDevices(queryDeviceStatus); + List> filterMaps = new ArrayList<>(); + String i18nKey = "";//todo:国际化看在哪处理 + + for (Map latestMap : deviceStatusMap) { + Map filterMap = latestMap.entrySet() + .stream() + .filter(entry -> entry.getValue() != null) + .collect(HashMap::new, (m, v) -> + m.put(i18nKey + v.getKey().substring(v.getKey().indexOf("(") + 1, + v.getKey().indexOf(")")), v.getValue()), HashMap::putAll); + filterMaps.add(filterMap); + } + + return filterMaps; + } + } diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java index 857faec..a68de48 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java @@ -303,4 +303,5 @@ public class TdEngineServiceImpl implements ITdEngineService { // return maps; // } + } diff --git a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/DeviceStatusMapper.xml b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/DeviceStatusMapper.xml index 2b5b813..2d0757a 100644 --- a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/DeviceStatusMapper.xml +++ b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/DeviceStatusMapper.xml @@ -6,13 +6,24 @@ + + + + diff --git a/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml index c73fb0e..9094995 100644 --- a/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 9300 + port: 9665 # Spring spring: diff --git a/ruoyi-modules/ruoyi-job/pom.xml b/ruoyi-modules/ruoyi-job/pom.xml index 932b0cf..9397601 100644 --- a/ruoyi-modules/ruoyi-job/pom.xml +++ b/ruoyi-modules/ruoyi-job/pom.xml @@ -81,6 +81,12 @@ com.ruoyi hw-api-tdengine + + com.ruoyi + hw-api-business + 3.6.3 + compile + diff --git a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/task/RyTask.java b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/task/RyTask.java index 26dc409..d32938e 100644 --- a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/task/RyTask.java +++ b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/task/RyTask.java @@ -1,16 +1,10 @@ package com.ruoyi.job.task; -import com.ruoyi.common.core.constant.TdEngineConstants; -import com.ruoyi.tdengine.api.RemoteTdEngineService; -import com.ruoyi.tdengine.api.domain.DeviceStatus; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Component; +import com.ruoyi.business.api.RemoteBusinessService; import com.ruoyi.common.core.utils.StringUtils; +import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.List; -import java.util.Map; /** * 定时任务调度测试 @@ -20,11 +14,7 @@ import java.util.Map; @Component("ryTask") public class RyTask { @Resource - private RemoteTdEngineService remoteTdEngineService; - - @Autowired - private StringRedisTemplate redisTemplate; - + private RemoteBusinessService remoteBusinessService; public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); @@ -39,38 +29,7 @@ public class RyTask { } - public void updateDeviceStatusData(Long days) { - Long startTime = 0L;//先是昨天 - Long endTime = 1L; - DeviceStatus queryGroupStatus = new DeviceStatus(); - queryGroupStatus.setStartTime(startTime); - queryGroupStatus.setEndTime(endTime); - - DeviceStatus queryLastStatus = new DeviceStatus(); - queryLastStatus.setEndTime(startTime); - - - Map> groupDeviceStatuMapList = - (Map>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData(); - List> lastDeviceStatuMapList = - (List>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData(); - for (Map groupDeviceStatuMap : lastDeviceStatuMapList) { - DeviceStatus ds = new DeviceStatus(); - for (Map.Entry entry : groupDeviceStatuMap.entrySet()) { - if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICEID)) { - ds.setDeviceId((Long) entry.getValue()); - } else if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICETYPE)) { - ds.setDeviceType((Integer) entry.getValue()); - } else if (entry.getKey().equals(TdEngineConstants.ST_TAG_ONLINESTATUS)) { - ds.setOnlineStatus((Integer) entry.getValue()); - } - } - - if(groupDeviceStatuMapList.get(ds.getDeviceId())==null){ -// groupDeviceStatuMapList.put(ds.getDeviceId(), Lists.newArrayList()); - } - - } - + public void computeOnlineDevicecCount(int days) { + this.remoteBusinessService.computeOnlineDevicecCount(days); } } diff --git a/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml index 817a429..c2aa059 100644 --- a/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 9203 + port: 9663 # Spring spring: diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java index 93d47ef..17b1752 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java @@ -1,5 +1,6 @@ package com.ruoyi.system; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import com.ruoyi.common.security.annotation.EnableCustomConfig; @@ -17,9 +18,14 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @SpringBootApplication public class RuoYiSystemApplication { + @Value("${spring.nacos.config.server-addr}") + public static String dd; public static void main(String[] args) { + + System.out.println("---"+dd); SpringApplication.run(RuoYiSystemApplication.class, args); + System.out.println("-----"+dd); System.out.println("(♥◠‿◠)ノ゙ 系统模块启动成功 ლ(´ڡ`ლ)゙ \n" + " .-------. ____ __ \n" + " | _ _ \\ \\ \\ / / \n" + diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml index ca94b42..3af593e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 9201 + port: 9661 # Spring spring: diff --git a/ruoyi-ui/src/api/board/GPS.js b/ruoyi-ui/src/api/board/GPS.js index 1c724ce..1c02395 100644 --- a/ruoyi-ui/src/api/board/GPS.js +++ b/ruoyi-ui/src/api/board/GPS.js @@ -22,6 +22,7 @@ export function getAlarmInfos(query) { // baseURL:'/monitoring-api', url: '/business/monitorPlatform/getAlarmInfos', method: 'get', + params: query }) } // 右下 diff --git a/ruoyi-ui/src/api/board/smartScene.js b/ruoyi-ui/src/api/board/smartScene.js index dd0a7d2..b3c5523 100644 --- a/ruoyi-ui/src/api/board/smartScene.js +++ b/ruoyi-ui/src/api/board/smartScene.js @@ -33,5 +33,6 @@ export function getAlarmInfos(query) { // baseURL:'/monitoring-api', url: '/business/monitorPlatform/getAlarmInfos', method: 'get', + params: query }) } diff --git a/ruoyi-ui/src/views/board/GPS/index.vue b/ruoyi-ui/src/views/board/GPS/index.vue index c51ee56..c6f048a 100644 --- a/ruoyi-ui/src/views/board/GPS/index.vue +++ b/ruoyi-ui/src/views/board/GPS/index.vue @@ -12,7 +12,7 @@ 告警类型
- 告警位置 + 告警单元
操作 @@ -274,12 +274,12 @@ export default { this.num3 = data.onlineDeviceNum }, async setAlarmInfos() { - const {rows: data} = await getAlarmInfos() + const {rows: data} = await getAlarmInfos({"sceneId": this.sceneId}) console.log(data) this.table1Data = data.map((e, i) => { return { - value1: i, - value2: '高温预警', + value1: e.alarmInfoId, + value2: e.alarmTypeName, value3: e.monitorUnitName, status: e.handleStatus } diff --git a/ruoyi-ui/src/views/board/equipment/index.vue b/ruoyi-ui/src/views/board/equipment/index.vue index 0fbd3ad..d63ef4b 100644 --- a/ruoyi-ui/src/views/board/equipment/index.vue +++ b/ruoyi-ui/src/views/board/equipment/index.vue @@ -3,7 +3,7 @@
监控单元
-
物联网平台
+
监控单元

- 设备名称: + 名称: {{ MonitorInfo.monitorUnitName }}

- 设备id: + ID: {{ MonitorInfo.monitorUnitId }}

- 设备状态: + 状态: {{ MonitorInfo.monitorUnitStatus === 1 ? '正常' : '异常' }}

- 设备类型: - {{ MonitorInfo.monitorUnitTypeId }} + 类型: + {{ MonitorInfo.monitorUnitTypeName }}

- +
@@ -63,7 +63,7 @@
{{ i.deviceName }}
-
+
{{ val }}:
{{ i.deviceDataMaps[0][val] }}
@@ -162,7 +162,7 @@ export default { } }, async getDevice(e) { - const {data} = await selectDevicesByMonitorUnitId(this.$store.getters.sceneId, e) + const {data} = await selectDevicesByMonitorUnitId(e, this.$store.getters.sceneId) console.log(data) this.deviceId = e this.controlList = data.control @@ -190,7 +190,7 @@ export default { };