diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java index 1c53cfe..89fc763 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java @@ -3,7 +3,10 @@ package com.ruoyi.web.controller.iot; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.json.JsonUtils; +import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.system.domain.BaseDeviceParam; import com.ruoyi.system.domain.BaseMonitorunitInfo; import com.ruoyi.system.domain.BaseSensorInfo; @@ -12,6 +15,7 @@ import com.ruoyi.system.domain.dto.BaseSensorInfoDto; import com.ruoyi.system.service.IBaseDeviceParamService; import com.ruoyi.system.service.IBaseMonitorunitInfoService; import com.ruoyi.system.service.IBaseSensorInfoService; +import com.ruoyi.system.service.ISysRoleService; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; @@ -44,6 +48,9 @@ public class DeviceMonitorController { @Autowired private IBaseDeviceParamService baseDeviceParamService; + @Autowired + private ISysRoleService iSysRoleService; + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /** @@ -56,9 +63,26 @@ public class DeviceMonitorController { @GetMapping("/getMonitorUnitTree") @ResponseBody public String getMonitorUnitTree() { - List baseMonitorunitInfoDtos = - baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList( - new BaseMonitorunitInfo(null, null, null, null, 0L)); + List baseMonitorunitInfoDtos = new ArrayList<>(); + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + + if(ShiroUtils.getLoginName().equals("admin")){ + List baseMonitorunitInfoDtos1 = + baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList( + new BaseMonitorunitInfo(null, null, null, null, 0L)); + baseMonitorunitInfoDtos.addAll(baseMonitorunitInfoDtos1); + }else{ + for (SysRole sysRole : sysRoles) { + BaseMonitorunitInfo baseMonitorunitInfo = new BaseMonitorunitInfo(); + baseMonitorunitInfo.setEnableFlag(0L); + baseMonitorunitInfo.setRoleId(sysRole.getRoleId()); + List baseMonitorunitInfoDtos1 = + baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo); + baseMonitorunitInfoDtos.addAll(baseMonitorunitInfoDtos1); + } + } List collect = baseMonitorunitInfoDtos.stream() @@ -103,8 +127,30 @@ public class DeviceMonitorController { @GetMapping("/getFirstMonitorUnit") @ResponseBody public String getFirstMonitorUnit(){ + + List baseMonitorunitInfos = new ArrayList<>(); + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + + if(ShiroUtils.getLoginName().equals("admin")){ + List baseMonitorunitInfoDtos1 = + baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList( + new BaseMonitorunitInfo(null, null, null, null, 0L)); + baseMonitorunitInfos.addAll(baseMonitorunitInfoDtos1); + }else{ + for (SysRole sysRole : sysRoles) { + BaseMonitorunitInfo baseMonitorunitInfo = new BaseMonitorunitInfo(); + baseMonitorunitInfo.setEnableFlag(0L); + baseMonitorunitInfo.setRoleId(sysRole.getRoleId()); + List baseMonitorunitInfoDtos1 = + baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo); + baseMonitorunitInfos.addAll(baseMonitorunitInfoDtos1); + } + } + String monitorunitId = ""; - List baseMonitorunitInfos = baseMonitorunitInfoService.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo()); + //List baseMonitorunitInfos = baseMonitorunitInfoService.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo()); if(baseMonitorunitInfos.size() > 0){ BaseMonitorunitInfo baseMonitorunitInfo = baseMonitorunitInfos.stream().filter(x -> !x.getParentId().isEmpty()).collect(Collectors.toList()).get(0); monitorunitId = baseMonitorunitInfo.getMonitorunitId(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java index 5642e54..cab2050 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java @@ -62,7 +62,7 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi public List selectBaseMonitorunitInfoDtoList( BaseMonitorunitInfo baseMonitorunitInfo) { - if(baseMonitorunitInfo.getRoleId() != null){ + if(baseMonitorunitInfo.getRoleId() != null && baseMonitorunitInfo.getRoleId() > 1){ return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoDtoListByRoleId(baseMonitorunitInfo); }