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 7bb5fb1..b14a75e 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 @@ -49,4 +49,10 @@ public class HwDictConstants { public static final Long ADMINISTRATOR_TENANT_ID = 0L;//金瑞铭租户ID + + public static final String DEVICE_TYPE_GATEWAY_DEVICE = "1";//网关设备 + public static final String DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT = "2";//网关子设备 + public static final String DEVICE_TYPE_DIRECT_CONNECT_DEVICE = "3";//直连设备 + + } 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 a529867..dc74dd0 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 @@ -1,14 +1,22 @@ package com.ruoyi.business.controller; +import java.util.Date; import java.util.List; import java.util.Map; 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.DeviceModeVo; import com.ruoyi.business.domain.VO.HwMonitorUnitVo; +import com.ruoyi.business.service.IHwDeviceModeService; import com.ruoyi.business.service.IHwMonitorUnitService; +import com.ruoyi.business.service.IHwSceneService; +import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysDept; +import com.ruoyi.system.api.domain.SysRole; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -43,6 +51,13 @@ public class HwDeviceController extends BaseController @Autowired private IHwMonitorUnitService hwMonitorUnitService; + + @Autowired + private IHwDeviceModeService hwDeviceModeService; + + @Autowired + private IHwSceneService hwSceneService; + /** * 查询设备信息列表 */ @@ -51,7 +66,7 @@ public class HwDeviceController extends BaseController public TableDataInfo list(HwDevice hwDevice) { startPage(); - List list = hwDeviceService.selectHwDeviceList(hwDevice); + List list = hwDeviceService.selectHwDeviceJoinList(hwDevice); return getDataTable(list); } @@ -115,14 +130,56 @@ public class HwDeviceController extends BaseController } + @RequiresPermissions("business:device:list") + @GetMapping("/getScenes") + public AjaxResult getScenes(HwScene scene) + { + return success(hwSceneService.selectHwSceneList(scene)); + } + /** * 获取监控单元树列表 */ -// @RequiresPermissions("business:device:list") - @GetMapping("/monitorUnitTree") - public AjaxResult monitorUnitTree(HwMonitorUnit monitorUnit) + @RequiresPermissions("business:device:list") + @GetMapping(value = {"/monitorUnitTree/", "/monitorUnitTree/{sceneId}"}) + public AjaxResult monitorUnitTree(@PathVariable(value = "sceneId", required = false) Long sceneId) + { + HwMonitorUnit queryMonitorUnit = new HwMonitorUnit(); + queryMonitorUnit.setSceneId(sceneId); + return success(hwMonitorUnitService.selectMonitorTreeList(queryMonitorUnit)); + } + + @RequiresPermissions("business:device:list") + @GetMapping(value = {"/getDeviceModes/", "/getDeviceModes/{sceneId}"}) + public AjaxResult getDeviceModes(@PathVariable(value = "sceneId", required = false) Long sceneId) + { + HwDeviceMode queryDeviceMode = new HwDeviceMode(); + queryDeviceMode.setSceneId(sceneId); + return success(hwDeviceModeService.selectHwDeviceModeList(queryDeviceMode)); + } + + @RequiresPermissions("business:device:list") + @GetMapping(value = {"/getGatewayDevices/", "/getGatewayDevices/{sceneId}"}) + public AjaxResult getGatewayDevices(@PathVariable(value = "sceneId", required = false) Long sceneId) + { + HwDevice queryHwDevice = new HwDevice(); + queryHwDevice.setSceneId(sceneId); + queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE); + return success(hwDeviceService.selectHwDeviceList(queryHwDevice)); + } + + + /** + * 状态修改 + */ + @RequiresPermissions("business:device:edit") + @Log(title = "设备管理", businessType = BusinessType.UPDATE) + @PutMapping("/changeDeviceStatus") + public AjaxResult changeDeviceStatus(@RequestBody HwDevice device) { - return success(hwMonitorUnitService.selectMonitorTreeList(monitorUnit)); + device.setUpdateBy(SecurityUtils.getUsername()); + device.setUpdateTime(new Date()); + return toAjax(hwDeviceService.updateHwDevice(device)); } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java index ebd0089..72800c6 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java @@ -16,6 +16,7 @@ import com.ruoyi.common.core.enums.DataTypeEnums; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.RemoteConfigService; import com.ruoyi.tdengine.api.RemoteTdEngineService; @@ -72,6 +73,7 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { * @return 设备模型 */ @Override + @DataScope(tenantAlias = "hdm") public List selectHwDeviceModeList(HwDeviceMode hwDeviceMode) { return hwDeviceModeMapper.selectHwDeviceModeList(hwDeviceMode); } 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 baf9f35..bac0b7e 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 @@ -16,6 +16,7 @@ import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.common.core.enums.DataTypeEnums; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.NumberUtils; +import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.domain.TdHistorySelectDto; import com.ruoyi.tdengine.api.domain.TdSelectDto; @@ -48,6 +49,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { */ @Override public HwDevice selectHwDeviceByDeviceId(Long deviceId) { + return hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); } @@ -69,6 +71,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { * @return 设备信息 */ @Override + @DataScope(tenantAlias = "hd") public List selectHwDeviceList(HwDevice hwDevice) { return hwDeviceMapper.selectHwDeviceList(hwDevice); } @@ -93,6 +96,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { @Override public int insertHwDevice(HwDevice hwDevice) { hwDevice.setCreateTime(DateUtils.getNowDate()); + return hwDeviceMapper.insertHwDevice(hwDevice); } @@ -233,4 +237,16 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return devicesMap; } + + /** + * 查询设备信息列表,join监控单元、设备模型等表 + * + * @param hwDevice 设备信息 + * @return 设备信息 + */ + @Override + @DataScope(tenantAlias = "hd") + public List selectHwDeviceJoinList(HwDevice hwDevice) { + return hwDeviceMapper.selectHwDeviceJoinList(hwDevice); + } } 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 3ab6b52..d6af569 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 @@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.R; 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; @@ -299,6 +300,7 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { * @return 监控单元树信息集合 */ @Override + @DataScope(tenantAlias = "hmu") public List selectMonitorTreeList(HwMonitorUnit hwMonitorUnit) { List hwMonitorUnits = this.selectHwMonitorUnitList(hwMonitorUnit); return buildMonitorUnitTreeSelect(hwMonitorUnits); 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 491dcbb..3969905 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 @@ -9,6 +9,7 @@ import com.ruoyi.business.domain.HwSceneMode; import com.ruoyi.business.domain.VO.HwSceneVo; import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysUser; @@ -59,14 +60,8 @@ public class HwSceneServiceImpl implements IHwSceneService { * @return 场景信息 */ @Override + @DataScope(tenantAlias = "hs") public List selectHwSceneList(HwScene hwScene) { -// LoginUser loginUser = SecurityUtils.getLoginUser(); -// SysUser sysUser = loginUser.getSysUser(); -// Long tenantId = sysUser.getTenantId(); - Long tenantId = 1L; - if (tenantId != 0L) {//如果不是金瑞铭,则只能返回租户自己的场景 - hwScene.setTenantId(tenantId); - } List scenes = hwSceneMapper.selectHwSceneList(hwScene); boolean defaultFlag = false; for (HwScene scene : scenes) { 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 3072448..2bb9624 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 @@ -34,6 +34,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -74,13 +77,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select device_id, device_code, device_name, scene_id, monitor_unit_id, device_type, networking_mode, access_protocol, data_format, releated_device_id, device_mode_id, access_gw_protocol, active_status, device_status, active_time, device_pic, ip_address, area_id, device_location, current_module_version, current_singlechip_version, remark, create_by, create_time, update_by, update_time, device_field, tenant_id, online_status from hw_device + select device_id, device_code, device_name, scene_id, monitor_unit_id, device_type, networking_mode, access_protocol, data_format, releated_device_id, device_mode_id, access_gw_protocol, active_status, device_status, active_time, device_pic, ip_address, area_id, device_location, current_module_version, current_singlechip_version, remark, create_by, create_time, update_by, update_time, device_field, tenant_id, online_status from hw_device hd @@ -242,4 +247,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and har.device_id = #{deviceId}) + + + + \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceModeMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceModeMapper.xml index 6d1e984..dd765c6 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceModeMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceModeMapper.xml @@ -67,7 +67,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select device_mode_id, device_mode_name, tenant_id, scene_id, language_code, gps_flag, device_mode_status, common_flag, mode_classfication, device_mode_pic, data_verify_level, remark, create_by, create_time, update_by, update_time, device_mode_field from hw_device_mode + select device_mode_id, device_mode_name, tenant_id, scene_id, language_code, gps_flag, device_mode_status, common_flag, mode_classfication, device_mode_pic, data_verify_level, remark, create_by, create_time, update_by, update_time, device_mode_field from hw_device_mode hdm @@ -88,6 +88,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and device_mode_pic = #{deviceModePic} and data_verify_level = #{dataVerifyLevel} and device_mode_field = #{deviceModeField} + + ${params.tenantDataScope} 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 67aa83a..ea9a0ea 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 @@ -58,7 +58,7 @@ - select monitor_unit_id, monitor_unit_name, scene_id, parent_id, monitor_unit_type_id, area_id, monitor_address, monitor_pic, preserve_time, remark, monitor_unit_status, create_by, create_time, update_by, update_time, monitor_unit_field from hw_monitor_unit + select monitor_unit_id, monitor_unit_name, scene_id, parent_id, monitor_unit_type_id, area_id, monitor_address, monitor_pic, preserve_time, remark, monitor_unit_status, create_by, create_time, update_by, update_time, monitor_unit_field from hw_monitor_unit hmu @@ -96,14 +96,16 @@ and preserve_time = #{preserveTime} and monitor_unit_status = #{monitorUnitStatus} and monitor_unit_field = #{monitorUnitField} - - + + + + - - + + diff --git a/ruoyi-ui/src/api/business/device.js b/ruoyi-ui/src/api/business/device.js index 431679c..ac9c932 100644 --- a/ruoyi-ui/src/api/business/device.js +++ b/ruoyi-ui/src/api/business/device.js @@ -1,4 +1,5 @@ import request from '@/utils/request' +import {parseStrEmpty} from "@/utils/ruoyi"; // 查询设备信息列表 export function listDevice(query) { @@ -43,10 +44,52 @@ export function delDevice(deviceId) { }) } + +// 查询场景信息列表供选择使用(例如下拉列表) +export function getScenes(query) { + return request({ + url: '/business/device/getScenes', + method: 'get', + params: query + }) +} + + // 查询监控单元树 -export function getMonitorTree() { +export function getMonitorTree(sceneId) { + return request({ + url: '/business/device/monitorUnitTree/' + parseStrEmpty(sceneId), + method: 'get' + }) +} + + +// 查询设备模型 +export function getDeviceModes(sceneId) { return request({ - url: '/business/device/monitorUnitTree', + url: '/business/device/getDeviceModes/' + parseStrEmpty(sceneId), method: 'get' }) } + +// 查询网关设备 +export function getGatewayDevices(sceneId) { + return request({ + url: '/business/device/getGatewayDevices/' + parseStrEmpty(sceneId), + method: 'get' + }) +} + + +// 设备状态修改 +export function changeDeviceStatus(deviceId, deviceStatus) { + const data = { + deviceId, + deviceStatus + } + return request({ + url: '/business/device/changeDeviceStatus', + method: 'put', + data: data + }) +} diff --git a/ruoyi-ui/src/api/business/scene.js b/ruoyi-ui/src/api/business/scene.js index 5c89883..b202ad6 100644 --- a/ruoyi-ui/src/api/business/scene.js +++ b/ruoyi-ui/src/api/business/scene.js @@ -43,13 +43,3 @@ export function delScene(sceneId) { }) } - -// 查询场景信息列表供选择使用(例如下拉列表) -export function getScenes(query) { - return request({ - url: '/business/scene/getScenes', - method: 'get', - params: query - }) -} - diff --git a/ruoyi-ui/src/views/business/device/index.vue b/ruoyi-ui/src/views/business/device/index.vue index 047a58d..70270a8 100644 --- a/ruoyi-ui/src/views/business/device/index.vue +++ b/ruoyi-ui/src/views/business/device/index.vue @@ -17,89 +17,81 @@ @keyup.enter.native="handleQuery" /> - - - - - + + + + + + + + - - - - + + + - - - - - - - - + + + + - - + + + + + + - - + + + + + - - + + + + + + + 搜索 重置 @@ -160,25 +152,42 @@ - - - - - - - - - - + + + + + + + + + + + - - - - + + + + + + +