From 9647eb472976d8c32425f97ca9eaca7c69f5aeac Mon Sep 17 00:00:00 2001 From: wenjy Date: Sun, 15 May 2022 14:30:54 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E9=A6=96=E9=A1=B5=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=A7=92=E8=89=B2=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/iot/IndexController.java | 151 ++++++++++++++---- .../ruoyi/system/domain/BaseSensorInfo.java | 10 ++ .../com/ruoyi/system/domain/RecordAlarm.java | 10 ++ .../system/mapper/BaseSensorInfoMapper.java | 9 ++ .../system/mapper/RecordAlarmMapper.java | 4 + .../system/service/IRecordAlarmService.java | 2 + .../impl/BaseSensorInfoServiceImpl.java | 11 +- .../service/impl/RecordAlarmServiceImpl.java | 10 ++ .../mapper/system/BaseSensorInfoMapper.xml | 39 +++++ .../mapper/system/RecordAlarmMapper.xml | 36 +++++ 10 files changed, 252 insertions(+), 30 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java index f291a1f..287cef8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java @@ -149,13 +149,23 @@ public class IndexController { List baseMonitorunitTypes = baseMonitorunitTypeService.selectBaseMonitorunitTypeList(new BaseMonitorunitType()); - List baseMonitorunitInfoDtos = - baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(new BaseMonitorunitInfo()); + List baseMonitorunitInfoDtoList = new ArrayList(); + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + for (SysRole sysRole : sysRoles) { + // + BaseMonitorunitInfo baseMonitorunitInfo = new BaseMonitorunitInfo(); + baseMonitorunitInfo.setRoleId(sysRole.getRoleId()); + List baseMonitorunitInfoDtos = + baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo); + baseMonitorunitInfoDtoList.addAll(baseMonitorunitInfoDtos); + } baseMonitorunitTypes.forEach( x -> { List collect = - baseMonitorunitInfoDtos.stream() + baseMonitorunitInfoDtoList.stream() .filter( y -> !y.getParentId().isEmpty() @@ -202,8 +212,22 @@ public class IndexController { @ResponseBody public String getSensorStateCharts() { try { - List baseSensorInfoDtos = - baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo()); + + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + + List baseSensorInfoDtos = new ArrayList<>(); + for (SysRole sysRole : sysRoles) { + BaseSensorInfo baseSensorInfo = new BaseSensorInfo(); + baseSensorInfo.setEnableFlag(0L); + baseSensorInfo.setRoleId(sysRole.getRoleId()); + List baseSensorInfoDtos1 = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo); + baseSensorInfoDtos.addAll(baseSensorInfoDtos1); + } + + /*List baseSensorInfoDtos = + baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo());*/ List yAxis = new ArrayList() { { @@ -216,7 +240,7 @@ public class IndexController { List data = new ArrayList() { { - this.add( + /*this.add( baseSensorInfoDtos.stream() .filter(x -> x.getSensorStatus() == 0) .collect(Collectors.toList()) @@ -230,7 +254,10 @@ public class IndexController { baseSensorInfoDtos.stream() .filter(x -> x.getSensorStatus() == 2) .collect(Collectors.toList()) - .size()); // 告警 + .size()); // 告警*/ + this.add(0); + this.add(baseSensorInfoDtos.size()); + this.add(0); } }; @@ -254,6 +281,7 @@ public class IndexController { @ResponseBody public String getSensorStateInfo() { try { + List> data = new ArrayList<>(); List header = @@ -266,24 +294,49 @@ public class IndexController { }; List baseSensorTypeList = baseSensorTypeService.selectBaseSensorTypeList(new BaseSensorType()); + + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + + baseSensorTypeList.forEach( x -> { - List baseSensorInfoDtos = - baseSensorInfoService.selectBaseSensorInfoList( - new BaseSensorInfo(x.getSensortypeId(), 0L)); + List baseSensorInfoDtos = new ArrayList<>(); + for (SysRole sysRole : sysRoles) { + // + BaseSensorInfo baseSensorInfo = new BaseSensorInfo(); + baseSensorInfo.setEnableFlag(0L); + baseSensorInfo.setRoleId(sysRole.getRoleId()); + baseSensorInfo.setSensorType(x.getSensortypeId()); + List baseSensorInfoDtos1 = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo); + baseSensorInfoDtos.addAll(baseSensorInfoDtos1); + } + data.add( - new ArrayList() { - { - this.add(x.getSensortypeName()); - this.add(baseSensorInfoDtos.size() + ""); - this.add( - baseSensorInfoDtos.stream() - .filter(z -> z.getSensorStatus() == 1) - .collect(Collectors.toList()) - .size() - + ""); - } - }); + new ArrayList() { + { + this.add(x.getSensortypeName()); + if(baseSensorInfoDtos != null){ + this.add(baseSensorInfoDtos.size() + ""); + if(baseSensorInfoDtos.size() > 0) { + /*this.add( + baseSensorInfoDtos.stream() + .filter(z -> z.getSensorStatus() == 1) + .collect(Collectors.toList()) + .size() + + "");*/ + this.add(0+""); + }else{ + this.add(0+""); + } + }else{ + this.add(0+""); + this.add(0+""); + } + } + }); + }); return JSONArray.toJSONString(new ScrollTableDto(header, data)); } catch (Exception ex) { @@ -311,16 +364,33 @@ public class IndexController { @GetMapping("/quantityStatistics") @ResponseBody public String quantityStatistics() { - List baseSensorInfoDtos = - baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo("", 0L)); - List baseMonitorunitInfos = - baseMonitorunitInfoService.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo()); + List baseSensorInfoDtos = new ArrayList<>(); + + List baseMonitorunitInfoDtoList = new ArrayList(); + + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + for (SysRole sysRole : sysRoles) { + // + BaseSensorInfo baseSensorInfo = new BaseSensorInfo(); + baseSensorInfo.setEnableFlag(0L); + baseSensorInfo.setRoleId(sysRole.getRoleId()); + List baseSensorInfoDtos1 = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo); + baseSensorInfoDtos.addAll(baseSensorInfoDtos1); + + BaseMonitorunitInfo baseMonitorunitInfo = new BaseMonitorunitInfo(); + baseMonitorunitInfo.setRoleId(sysRole.getRoleId()); + List baseMonitorunitInfoDtos = + baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo); + baseMonitorunitInfoDtoList.addAll(baseMonitorunitInfoDtos); + } List result = new ArrayList() { { this.add(baseSensorInfoDtos.size()); this.add( - baseMonitorunitInfos.stream() + baseMonitorunitInfoDtoList.stream() .filter(x -> !x.getParentId().isEmpty() && x.getEnableFlag() == 0L) .collect(Collectors.toList()) .size()); @@ -340,7 +410,16 @@ public class IndexController { @ResponseBody public String getAlarmAmount() { List info = new ArrayList<>(); - List recordAlarms = recordAlarmService.selectRecordAlarmList(new RecordAlarm()); + List recordAlarms = new ArrayList<>(); + SysUser sysUser = ShiroUtils.getSysUser(); + + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + for (SysRole sysRole : sysRoles) { + RecordAlarm recordAlarm = new RecordAlarm(); + recordAlarm.setRoleId(sysRole.getRoleId()); + List recordAlarms1 = recordAlarmService.selectRecordAlarmList(recordAlarm); + recordAlarms.addAll(recordAlarms1); + } if (recordAlarms.size() > 0) { int size = @@ -409,7 +488,21 @@ public class IndexController { List dayByMonth = getSevenDate(); - List recordAlarmDtos = recordAlarmService.selectAlarmTrendList(""); + List recordAlarmDtos = new ArrayList<>(); + SysUser sysUser = ShiroUtils.getSysUser(); + + if(ShiroUtils.getLoginName().equals("admin")){ + List recordAlarmDtos1 = recordAlarmService.selectAlarmTrendList(""); + recordAlarmDtos.addAll(recordAlarmDtos1); + }else{ + List sysRoles = iSysRoleService.selectRolesByUserId(sysUser.getUserId()); + for (SysRole sysRole : sysRoles) { + RecordAlarm recordAlarm = new RecordAlarm(); + recordAlarm.setRoleId(sysRole.getRoleId()); + List recordAlarmDtos1 = recordAlarmService.selectAlarmTrendListByRoleId(sysRole.getRoleId()); + recordAlarmDtos.addAll(recordAlarmDtos1); + } + } dayByMonth.forEach( x -> { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/BaseSensorInfo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/BaseSensorInfo.java index 88a19f0..bf77e2a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/BaseSensorInfo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/BaseSensorInfo.java @@ -77,6 +77,8 @@ public class BaseSensorInfo extends BaseEntity @Excel(name = "是否启用") private Long enableFlag; + private Long roleId; + public void setObjId(Long objId) { this.objId = objId; @@ -177,6 +179,14 @@ public class BaseSensorInfo extends BaseEntity return enableFlag; } + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/RecordAlarm.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/RecordAlarm.java index 220d6ed..6cd5ec8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/RecordAlarm.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/RecordAlarm.java @@ -55,6 +55,8 @@ public class RecordAlarm extends BaseEntity private String endCollectTime; + private Long roleId; + public void setSensorId(String sensorId) { this.sensorId = sensorId; @@ -158,6 +160,14 @@ public class RecordAlarm extends BaseEntity this.endCollectTime = endCollectTime; } + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java index e5a7e7f..8c26cf1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java @@ -30,6 +30,15 @@ public interface BaseSensorInfoMapper */ public List selectBaseSensorInfoList(BaseSensorInfo baseSensorInfo); + /** + * 通过角色编号查询传感器信息列表 + * @author WenJY + * @date 2022-05-15 12:49 + * @param baseSensorInfo + * @return java.util.List + */ + public List selectBaseSensorInfoListByRoleId(BaseSensorInfo baseSensorInfo); + /** * 新增传感器信息 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordAlarmMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordAlarmMapper.java index 6a00578..4b5ed48 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordAlarmMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordAlarmMapper.java @@ -28,6 +28,8 @@ public interface RecordAlarmMapper */ public List selectRecordAlarmList(RecordAlarm recordAlarm); + public List selectRecordAlarmListByRoleId(RecordAlarm recordAlarm); + /** * 新增异常数据记录 * @@ -77,4 +79,6 @@ public interface RecordAlarmMapper * @return java.util.List */ public List selectAlarmTrendList(String monitorUnitTypeId); + + public List selectAlarmTrendListByRoleId(Long roleId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordAlarmService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordAlarmService.java index 19a3140..c6fac5e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordAlarmService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordAlarmService.java @@ -78,4 +78,6 @@ public interface IRecordAlarmService */ public List selectAlarmTrendList(String monitorUnitTypeId); + public List selectAlarmTrendListByRoleId(Long roleId); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java index 6645355..08f2af2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java @@ -51,7 +51,16 @@ public class BaseSensorInfoServiceImpl implements IBaseSensorInfoService @Override public List selectBaseSensorInfoList(BaseSensorInfo baseSensorInfo) { - return baseSensorInfoMapper.selectBaseSensorInfoList(baseSensorInfo); + try{ + if(baseSensorInfo.getRoleId() != null && baseSensorInfo.getRoleId() > 1){ + List baseSensorInfoDtos = baseSensorInfoMapper.selectBaseSensorInfoListByRoleId(baseSensorInfo); + return baseSensorInfoDtos; + } + return baseSensorInfoMapper.selectBaseSensorInfoList(baseSensorInfo); + }catch (Exception ex) { + System.out.println(ex.getMessage()); + return null; + } } /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordAlarmServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordAlarmServiceImpl.java index 5af45e6..312bd7b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordAlarmServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordAlarmServiceImpl.java @@ -43,6 +43,11 @@ public class RecordAlarmServiceImpl implements IRecordAlarmService @Override public List selectRecordAlarmList(RecordAlarm recordAlarm) { + + if(recordAlarm.getRoleId() != null && recordAlarm.getRoleId() > 1){ + return recordAlarmMapper.selectRecordAlarmListByRoleId(recordAlarm); + } + return recordAlarmMapper.selectRecordAlarmList(recordAlarm); } @@ -118,4 +123,9 @@ public class RecordAlarmServiceImpl implements IRecordAlarmService return recordAlarmMapper.selectAlarmTrendList(monitorUnitTypeId); } + @Override + public List selectAlarmTrendListByRoleId(Long roleId) { + return recordAlarmMapper.selectAlarmTrendListByRoleId(roleId); + } + } diff --git a/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml index a92a3c0..48a93ff 100644 --- a/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml @@ -20,6 +20,7 @@ + @@ -103,6 +104,44 @@ + + + + + + \ No newline at end of file