From b636559aec2c39f38f5c201941333855f68fda3b Mon Sep 17 00:00:00 2001 From: xins Date: Tue, 26 Sep 2023 18:23:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?3.6=201=E3=80=81job=E4=BF=AE=E6=94=B9=202=E3=80=81=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=BF=A1=E6=81=AF=E5=A2=9E=E5=8A=A0=E5=AF=B9=E6=97=B6?= =?UTF-8?q?=E5=92=8C=E6=8B=8D=E7=85=A7=E5=8A=9F=E8=83=BD=203=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0publish=E4=B8=8B=E5=8F=91=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=88=B0redis=204=E3=80=81=E5=9C=BA=E6=99=AF=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D=E5=92=8C=E5=AF=86=E7=A0=81=E8=87=AA=E5=8A=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E4=B8=8D=E8=83=BD=E4=BF=AE=E6=94=B9=205?= =?UTF-8?q?=E3=80=81=E7=9B=91=E6=8E=A7=E5=8D=95=E5=85=83=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E5=8D=95=E5=85=83=E7=B1=BB=E5=9E=8B=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=206=E3=80=81=E8=AE=A1=E7=AE=97=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E6=83=85=E5=86=B5=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tdengine/api/domain/DeviceStatus.java | 12 ++ .../common/core/constant/HwDictConstants.java | 19 ++- .../datascope/aspect/DataScopeAspect.java | 3 - .../controller/HwDeviceController.java | 15 +- .../HwMonitorPlatformController.java | 4 - .../controller/HwMonitorUnitController.java | 16 +- .../com/ruoyi/business/domain/HwDevice.java | 10 ++ .../business/service/IHwDeviceService.java | 8 + .../service/impl/HwDeviceServiceImpl.java | 150 +++++++++++++----- .../impl/HwMonitorUnitTypeServiceImpl.java | 40 +++-- .../service/impl/HwSceneServiceImpl.java | 56 ++++--- .../mapper/business/HwDeviceMapper.xml | 2 +- .../mapper/business/HwSceneMapper.xml | 2 +- .../service/impl/DeviceStatusServiceImpl.java | 13 +- .../mapper/tdengine/DeviceStatusMapper.xml | 3 +- .../main/java/com/ruoyi/job/task/RyTask.java | 2 +- ruoyi-ui/src/api/business/device.js | 12 ++ ruoyi-ui/src/api/business/monitorUnit.js | 19 +-- ruoyi-ui/src/views/business/device/index.vue | 33 +++- .../business/deviceMode/deviceModeService.vue | 4 +- .../business/deviceMode/editDeviceMode.vue | 2 +- .../src/views/business/monitorUnit/index.vue | 33 ++-- .../views/business/monitorUnitType/index.vue | 1 + ruoyi-ui/src/views/business/scene/index.vue | 15 +- 24 files changed, 326 insertions(+), 148 deletions(-) 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 2043d83..0fca5cb 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 @@ -2,6 +2,8 @@ package com.ruoyi.tdengine.api.domain; import com.ruoyi.common.core.web.domain.BaseEntity; +import java.util.List; + /** * @Description: 设备状态对象 * @ClassName: DeviceStatus @@ -26,6 +28,8 @@ public class DeviceStatus extends BaseEntity { private Long startTime; private Long endTime; + private List schemaFields; + public Long getTs() { return ts; } @@ -89,4 +93,12 @@ public class DeviceStatus extends BaseEntity { public void setEndTime(Long endTime) { this.endTime = endTime; } + + public List getSchemaFields() { + return schemaFields; + } + + public void setSchemaFields(List schemaFields) { + this.schemaFields = schemaFields; + } } 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 13da9ac..931728d 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 @@ -33,7 +33,7 @@ public class HwDictConstants { public static final String FUNCTION_MODE_SERVICE = "2";//设备模型功能模式服务 public static final String FUNCTION_MODE_EVENT = "3";//设备模型功能模式事件 - public static final String RW_FLAG_RW = "1";//读写 + public static final String RW_FLAG_RW = "1";//读写 public static final String RW_FLAG_READ = "2";//只读 public static final String DEVICE_STATUS_PUBLISH = "1";//设备状态:已发布 @@ -83,9 +83,22 @@ 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 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";//未处理 + + public static final String SCENE_STATUS_NORMAL = "1";//正常状态 + + public static final String CONTROL_COMMAND_REDIS_KEY = "mqtt:channel:down";//下发控制指令到redis的key + public static final String CONTROL_COMMAND_TOPIC_VALUE = "/v1/{}/device/command";//下发控制指令的topic + public static final String CONTROL_COMMAND_TOPIC_KEY = "TOPIC"; + public static final String CONTROL_COMMAND_PAYLOAD_KEY = "Payload"; + public static final String CONTROL_COMMAND_PAYLOAD_MID_KEY = "mid"; + public static final String CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY = "timestamp"; + public static final String CONTROL_COMMAND_PAYLOAD_TYPE_KEY = "type"; + public static final String CONTROL_COMMAND_PAYLOAD_PARAM_KEY = "param"; + + public static final String DEVICEMODE_GPS_FLAG_NO="0"; } diff --git a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java index ed41fb3..fcd0a66 100644 --- a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java +++ b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java @@ -130,8 +130,6 @@ public class DataScopeAspect { sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias)); } - - System.out.println("---"+ sqlString.toString()); Object params = joinPoint.getArgs()[0]; if (StringUtils.isNotNull(params) && params instanceof BaseEntity) { BaseEntity baseEntity = (BaseEntity) params; @@ -139,7 +137,6 @@ public class DataScopeAspect { baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); } StringBuilder tenantFilterSql = getTenantFilterSql(user, tenantAlias); - System.out.println("------"+tenantFilterSql.toString()); if (StringUtils.isNotBlank(tenantFilterSql.toString())) { baseEntity.getParams().put(TENANT_DATA_SCOPE, " AND (" + tenantFilterSql.substring(4) + ")"); } 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 734d6bc..9967c01 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 @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse; import com.ruoyi.business.domain.HwDeviceMode; import com.ruoyi.business.domain.HwMonitorUnit; import com.ruoyi.business.domain.HwScene; +import com.ruoyi.business.domain.VO.DeviceControlVo; import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.HwMonitorUnitVo; import com.ruoyi.business.service.IHwDeviceModeService; @@ -193,7 +194,19 @@ public class HwDeviceController extends BaseController { device.setUpdateBy(SecurityUtils.getUsername()); device.setUpdateTime(new Date()); - return toAjax(hwDeviceService.updateHwDevice(device)); + return toAjax(hwDeviceService.changeDeviceStatus(device)); + } + + /** + * 状态修改 + */ + @RequiresPermissions("business:device:edit") + @Log(title = "下发设备控制指令", businessType = BusinessType.UPDATE) + @PutMapping("/publishControlCommand") + public AjaxResult publishControlCommand(@RequestBody DeviceControlVo deviceControlVo) + { + hwDeviceService.publishControlCommand(deviceControlVo); + return success(); } @GetMapping("/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 bbcb88d..062663c 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 @@ -5,7 +5,6 @@ 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; @@ -16,10 +15,7 @@ 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; @RestController @RequestMapping("/monitorPlatform") diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorUnitController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorUnitController.java index 8935c84..95f2ae7 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorUnitController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorUnitController.java @@ -136,22 +136,14 @@ public class HwMonitorUnitController extends BaseController @RequiresPermissions("business:monitorUnit:list") - @GetMapping("/getMonitorUnitTypes") - public AjaxResult getMonitorUnitTypes(HwMonitorUnitType monitorUnitType) + @GetMapping(value = {"/getMonitorUnitTypes/", "/getMonitorUnitTypes/{sceneId}"}) + public AjaxResult getMonitorUnitTypes(@PathVariable(value = "sceneId", required = false) Long sceneId) { + HwMonitorUnitType monitorUnitType = new HwMonitorUnitType(); + monitorUnitType.setSceneId(sceneId); return success(monitorUnitTypeService.selectHwMonitorUnitTypeList(monitorUnitType)); } - @RequiresPermissions("business:monitorUnit:list") - @GetMapping("/getEditedMonitorUnitTypes") - public AjaxResult getEditedMonitorUnitTypes(HwMonitorUnitType monitorUnitType) - { - LoginUser loginUser = SecurityUtils.getLoginUser(); - SysUser user = loginUser.getSysUser(); - monitorUnitType.setTenantId(user.getTenantId()); - return success(monitorUnitTypeService.selectHwMonitorUnitTypeList4Select(monitorUnitType)); - } - /** * 查询监控单元列表供编辑 */ diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java index a77b95c..916fd95 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java @@ -168,6 +168,8 @@ public class HwDevice extends BaseEntity { private String deviceModeName; private String tenantName; + private String gpsFlag; + public void setDeviceId(Long deviceId) { this.deviceId = deviceId; @@ -393,6 +395,14 @@ public class HwDevice extends BaseEntity { this.tenantName = tenantName; } + public String getGpsFlag() { + return gpsFlag; + } + + public void setGpsFlag(String gpsFlag) { + this.gpsFlag = gpsFlag; + } + @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/service/IHwDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java index 1446bfd..ef2fa6e 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 @@ -73,6 +73,14 @@ public interface IHwDeviceService */ public int updateHwDevice(HwDevice hwDevice); + /** + * 修改设备状态 + * + * @param hwDevice 设备信息 + * @return 结果 + */ + public int changeDeviceStatus(HwDevice hwDevice); + /** * 批量删除设备信息 * 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 812f75b..788e7a3 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 @@ -5,6 +5,7 @@ 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.HwDeviceMode; import com.ruoyi.business.domain.HwDeviceModeFunction; import com.ruoyi.business.domain.HwScene; import com.ruoyi.business.domain.VO.DeviceControlVo; @@ -12,6 +13,7 @@ import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.HwDeviceVo; import com.ruoyi.business.mapper.HwDeviceMapper; import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper; +import com.ruoyi.business.mapper.HwDeviceModeMapper; import com.ruoyi.business.mapper.HwSceneMapper; import com.ruoyi.business.service.IHwDeviceService; import com.ruoyi.common.core.constant.Constants; @@ -46,6 +48,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService { @Autowired private HwDeviceMapper hwDeviceMapper; @Autowired + private HwDeviceModeMapper hwDeviceModeMapper; + @Autowired private HwSceneMapper hwSceneMapper; @Autowired private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper; @@ -75,7 +79,13 @@ public class HwDeviceServiceImpl implements IHwDeviceService { @Override public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId) { - return hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId); + HwDevice device = hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId); + Long deviceModeId = device.getDeviceModeId(); + if (deviceModeId != null) { + HwDeviceMode mode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId); + device.setGpsFlag(mode != null ? mode.getGpsFlag() : HwDictConstants.DEVICEMODE_GPS_FLAG_NO); + } + return device; } /** @@ -317,6 +327,58 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return rows; } + /** + * 修改设备状态 + * + * @param hwDevice 设备信息 + * @return 结果 + */ + @Override + public int changeDeviceStatus(HwDevice hwDevice) { + HwDevice dbDevice = hwDeviceMapper.selectHwDeviceByDeviceId(hwDevice.getDeviceId()); + if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) { + throw new ServiceException("已发布状态不能修改"); + } + hwDevice.setUpdateTime(DateUtils.getNowDate()); + return hwDeviceMapper.updateHwDevice(hwDevice); + } + + /** + * @param: deviceControlVo + * @description 下发当网关,主题带设备编号 + * @author xins + * @date 2023-09-25 14:56 + */ + @Override + public void publishControlCommand(DeviceControlVo deviceControlVo) { + JSONObject controlCommandJson = new JSONObject(); + StringBuilder controlCommandTopic = new StringBuilder(); + Long deviceId = deviceControlVo.getDeviceId(); + HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); + String deviceType = device.getDeviceType(); + if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) { + Long gatewayDeviceId = device.getReleatedDeviceId(); + HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId); + controlCommandTopic.append(StringUtils + .format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, gatewayDevice.getDeviceCode())); + } else { + controlCommandTopic.append(StringUtils + .format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, device.getDeviceCode())); + } + JSONObject payloadJson = new JSONObject(); + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, device.getDeviceCode()); + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位:s + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, deviceControlVo.getType()); + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, "{}"); + + controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic.toString()); + controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString()); + + System.out.println("---" + controlCommandJson.toString()); + redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString()); + } + + /** * @param: hwDevice 前端传的对象 * @param: dbDevice 目前数据库的对象 @@ -494,8 +556,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { hwDeviceVo.setDeviceName(hwDevice.getDeviceName()); hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE); hwDeviceVo.setDeviceDataMap(ddValueMap); - //TODO:去掉下边一行 - ddValueMap.put("ii", "http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg"); acquisitionDeviceVos.add(hwDeviceVo); }); @@ -553,50 +613,76 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } private Map computeDeviceCountPerDay(Long startTime, Long endTime) { + //先增加需要查询的字段名称(由于tdengine用last和last_row查询时字段显示有bug,所以需要设置要查询的字段) + List schemaFields = new ArrayList(); + TdField deviceTypeField = new TdField(); + deviceTypeField.setFieldName(TdEngineConstants.ST_TAG_DEVICETYPE); + + TdField onlineStatusField = new TdField(); + onlineStatusField.setFieldName(TdEngineConstants.ST_TAG_ONLINESTATUS); + + schemaFields.add(deviceTypeField); + schemaFields.add(onlineStatusField); + DeviceStatus queryGroupStatus = new DeviceStatus(); queryGroupStatus.setStartTime(startTime); queryGroupStatus.setEndTime(endTime); + queryGroupStatus.setSchemaFields(schemaFields); DeviceStatus queryLastStatus = new DeviceStatus(); queryLastStatus.setEndTime(startTime); + queryLastStatus.setSchemaFields(schemaFields); +// System.out.println(DateUtils.dateTime(new Date(startTime)) + "----" + DateUtils.dateTime(new Date(endTime))); Map onlineDeviceCountByDay = new HashMap(); + //先获取starttime和endtime时间范围内在线的设备状态信息 Map> groupDeviceStatuMapList = (Map>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData(); if (groupDeviceStatuMapList == null) { groupDeviceStatuMapList = new HashMap<>(); } + //获取在endtime之前最后的设备状态信息(有些设备会一直在线,没有连续的上线下线记录,所以要获取最近的设备状态信息来补齐后面的设备在线情况) 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()); + if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) { + onlineDeviceCountByDay.put(startTime, 0); + } else { + for (Map groupDeviceStatuMap : lastDeviceStatuMapList) { + DeviceStatus ds = new DeviceStatus(); + for (Map.Entry entry : groupDeviceStatuMap.entrySet()) { + switch (entry.getKey()) { + case TdEngineConstants.ST_TAG_DEVICEID: + ds.setDeviceId((long) (Integer) entry.getValue()); + break; + case TdEngineConstants.ST_TAG_DEVICETYPE: + ds.setDeviceType((Integer) entry.getValue()); + break; + case TdEngineConstants.ST_TAG_ONLINESTATUS: + ds.setOnlineStatus((Integer) entry.getValue()); + break; + default: + break; + } } - } - 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); + 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)); } - } else { - count = this.getDeviceCount(dss.get(0)); - } - if (onlineDeviceCountByDay.get(startTime) == null) { - onlineDeviceCountByDay.put(startTime, count); - } else { - onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count); + if (onlineDeviceCountByDay.get(startTime) == null) { + onlineDeviceCountByDay.put(startTime, count); + } else { + onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count); + } } } @@ -646,16 +732,4 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } - /** - * @param: deviceControlVo - * @description 下发当网关,主题带设备编号 - * @author xins - * @date 2023-09-25 14:56 - */ - @Override - public void publishControlCommand(DeviceControlVo deviceControlVo) { - String channel = ""; - String message = ""; - redisTemplate.convertAndSend(channel, message); - } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitTypeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitTypeServiceImpl.java index e553497..16e8c46 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitTypeServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitTypeServiceImpl.java @@ -2,7 +2,10 @@ package com.ruoyi.business.service.impl; import java.util.List; +import com.ruoyi.business.domain.HwMonitorUnit; import com.ruoyi.business.domain.VO.HwMonitorUnitVo; +import com.ruoyi.business.mapper.HwMonitorUnitMapper; +import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.datascope.annotation.DataScope; import org.springframework.beans.factory.annotation.Autowired; @@ -18,11 +21,13 @@ import com.ruoyi.business.service.IHwMonitorUnitTypeService; * @date 2023-08-31 */ @Service -public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService -{ +public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService { @Autowired private HwMonitorUnitTypeMapper hwMonitorUnitTypeMapper; + @Autowired + private HwMonitorUnitMapper hwMonitorUnitMapper; + /** * 查询监控单元类型 * @@ -30,8 +35,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService * @return 监控单元类型 */ @Override - public HwMonitorUnitType selectHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId) - { + public HwMonitorUnitType selectHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId) { return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeByMonitorUnitTypeId(monitorUnitTypeId); } @@ -43,8 +47,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService */ @Override @DataScope(tenantAlias = "hmut") - public List selectHwMonitorUnitTypeList(HwMonitorUnitType hwMonitorUnitType) - { + public List selectHwMonitorUnitTypeList(HwMonitorUnitType hwMonitorUnitType) { return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeList(hwMonitorUnitType); } @@ -56,8 +59,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService * @return 结果 */ @Override - public int insertHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType) - { + public int insertHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType) { hwMonitorUnitType.setCreateTime(DateUtils.getNowDate()); return hwMonitorUnitTypeMapper.insertHwMonitorUnitType(hwMonitorUnitType); } @@ -69,8 +71,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService * @return 结果 */ @Override - public int updateHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType) - { + public int updateHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType) { hwMonitorUnitType.setUpdateTime(DateUtils.getNowDate()); return hwMonitorUnitTypeMapper.updateHwMonitorUnitType(hwMonitorUnitType); } @@ -82,8 +83,15 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService * @return 结果 */ @Override - public int deleteHwMonitorUnitTypeByMonitorUnitTypeIds(Long[] monitorUnitTypeIds) - { + public int deleteHwMonitorUnitTypeByMonitorUnitTypeIds(Long[] monitorUnitTypeIds) { + for (Long monitorUnitTypeId : monitorUnitTypeIds) { + HwMonitorUnit queryMonitorUnit = new HwMonitorUnit(); + queryMonitorUnit.setMonitorUnitTypeId(monitorUnitTypeId); + List monitorUnits = hwMonitorUnitMapper.selectHwMonitorUnitList(queryMonitorUnit); + if (monitorUnits != null && monitorUnits.size() > 0) { + throw new ServiceException("所选择删除的监控单元类型已关联监控单元,不能删除"); + } + } return hwMonitorUnitTypeMapper.deleteHwMonitorUnitTypeByMonitorUnitTypeIds(monitorUnitTypeIds); } @@ -94,8 +102,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService * @return 结果 */ @Override - public int deleteHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId) - { + public int deleteHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId) { return hwMonitorUnitTypeMapper.deleteHwMonitorUnitTypeByMonitorUnitTypeId(monitorUnitTypeId); } @@ -105,7 +112,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService * @param hwMonitorUnitType 监控单元类型 * @return 监控单元类型集合 */ - public List selectHwMonitorUnitTypeList4Select(HwMonitorUnitType hwMonitorUnitType){ + public List selectHwMonitorUnitTypeList4Select(HwMonitorUnitType hwMonitorUnitType) { return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeList(hwMonitorUnitType); } @@ -117,8 +124,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService */ @Override @DataScope(tenantAlias = "hmut") - public List selectHwMonitorUnitTypeJoinList(HwMonitorUnitType hwMonitorUnitType) - { + public List selectHwMonitorUnitTypeJoinList(HwMonitorUnitType hwMonitorUnitType) { return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeJoinList(hwMonitorUnitType); } 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 cecaff3..38d9fa6 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 @@ -97,6 +97,7 @@ public class HwSceneServiceImpl implements IHwSceneService { @Override public List selectHwSceneJoinList(HwSceneVo hwScene) { + hwScene.setSceneStatus(HwDictConstants.SCENE_STATUS_NORMAL); return hwSceneMapper.selectHwSceneVoList(hwScene); } @@ -112,7 +113,6 @@ public class HwSceneServiceImpl implements IHwSceneService { LoginUser loginUser = SecurityUtils.getLoginUser(); SysUser sysUser = loginUser.getSysUser(); hwScene.setCreateBy(sysUser.getUserName()); - hwScene.setTenantId(sysUser.getTenantId()); if (hwScene.getPreserveTime() == null) { hwScene.setPreserveTime(new BigDecimal(90)); @@ -120,13 +120,16 @@ public class HwSceneServiceImpl implements IHwSceneService { if (hwScene.getTestPreserveTime() == null) { hwScene.setTestPreserveTime(new BigDecimal(30)); } -// String randomKey = RandomStringUtils.random(12, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"); -// String randomSecret = RandomStringUtils.random(16, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"); -// hwScene.setModeKey(randomKey); -// hwScene.setModeSecret(randomSecret); + + String randomAccount = RandomStringUtils.random(6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"); + String randomKey = RandomStringUtils.random(12, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"); + hwScene.setModeAccount(randomAccount); + hwScene.setModeKey(randomKey); + hwScene.setCreateTime(DateUtils.getNowDate()); int rows = hwSceneMapper.insertHwScene(hwScene); + this.updateDefaultFlag(hwScene); this.createTdDatabase(hwScene); return rows; } @@ -148,20 +151,10 @@ public class HwSceneServiceImpl implements IHwSceneService { @Override @Transactional public int updateHwScene(HwScene hwScene) { - if (hwScene.getDefaultFlag().equals(HwDictConstants.SCENE_DEFAULT_FLAG_YES)) { - HwScene queryScene = new HwScene(); - queryScene.setTenantId(hwScene.getTenantId()); - List dbScenes = hwSceneMapper.selectHwSceneList(queryScene); - if (dbScenes != null && dbScenes.isEmpty()) { - dbScenes.forEach(dbScene -> { - dbScene.setDefaultFlag(HwDictConstants.SCENE_DEFAULT_FLAG_NO); - hwSceneMapper.updateHwScene(dbScene); - }); - } - } + this.updateDefaultFlag(hwScene); hwScene.setUpdateTime(DateUtils.getNowDate()); - int rows = hwSceneMapper.updateHwScene(hwScene); + int rows = hwSceneMapper.updateHwScene(hwScene); this.updateRedisAuth(hwScene); return rows; } @@ -252,9 +245,9 @@ public class HwSceneServiceImpl implements IHwSceneService { SysUser user = loginUser.getSysUser(); hwScene.setTenantId(user.getTenantId()); - List scenes = hwSceneMapper.selectHwSceneList(hwScene); - scenes.forEach(s ->{ - if(!s.getTenantId().equals( user.getTenantId())){ + List scenes = hwSceneMapper.selectHwSceneList(hwScene); + scenes.forEach(s -> { + if (!s.getTenantId().equals(user.getTenantId())) { s.setSelectedDisable("1"); } }); @@ -262,4 +255,27 @@ public class HwSceneServiceImpl implements IHwSceneService { return scenes; } + /** + * @param: hwScene + * @description 更新场景默认标识,一个租户只能有一个默认场景 + * @author xins + * @date 2023-09-26 18:19 + */ + private void updateDefaultFlag(HwScene hwScene) { + if (hwScene.getDefaultFlag().equals(HwDictConstants.SCENE_DEFAULT_FLAG_YES)) { + HwScene queryScene = new HwScene(); + queryScene.setTenantId(hwScene.getTenantId()); + List dbScenes = hwSceneMapper.selectHwSceneList(queryScene); + if (dbScenes != null && !dbScenes.isEmpty()) { + dbScenes.forEach(dbScene -> { + if (hwScene.getSceneId()==null || (hwScene.getSceneId() != null && + !hwScene.getSceneId().equals(dbScene.getSceneId()))) { + dbScene.setDefaultFlag(HwDictConstants.SCENE_DEFAULT_FLAG_NO); + hwSceneMapper.updateHwScene(dbScene); + } + }); + } + } + } + } diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml index be36095..9a63d28 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml @@ -233,7 +233,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select hd.device_code,hd.device_name, hd.device_status,hd.online_status, hd.device_pic,hd.active_time, + select hd.device_code,hd.device_name, hd.device_status,hd.online_status, hd.device_pic,hd.active_time,hd.device_mode_id, hmu.monitor_unit_name from hw_device hd left join hw_monitor_unit hmu on hd.monitor_unit_id = hmu.monitor_unit_id 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 705156c..92c625f 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 @@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and scene_name like concat('%', #{sceneName}, '%') - and tenant_id = #{tenantId} + and tenant_id = #{tenantId} and scene_mode_id = #{sceneModeId} and scene_pic = #{scenePic} and default_flag = #{defaultFlag} 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 f07e3c0..6205fa5 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,10 +7,7 @@ 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.*; import java.util.stream.Collectors; /** @@ -68,14 +65,18 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService { 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) { + Set kk = latestMap.keySet(); + for(String k : kk){ + System.out.println(k+"==="+latestMap.get(k)); + } + 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, + m.put(v.getKey().substring(v.getKey().indexOf("(") + 1, v.getKey().indexOf(")")), v.getValue()), HashMap::putAll); filterMaps.add(filterMap); } 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 2d0757a..d1d6605 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 @@ -15,7 +15,8 @@