diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/AlarmInfoController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/AlarmInfoController.java index 0a98160..3210fb3 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/AlarmInfoController.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/AlarmInfoController.java @@ -3,6 +3,7 @@ package com.aiit.xiuos.controller; import com.aiit.xiuos.Utils.Constant; import com.aiit.xiuos.Utils.ResultRespons; import com.aiit.xiuos.model.AlarmInfo; +import com.aiit.xiuos.model.UserInfo; import com.aiit.xiuos.service.AlarmInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/alarmInfo") @@ -18,6 +20,11 @@ public class AlarmInfoController { AlarmInfoService alarmInfoService; @GetMapping("/select") public ResultRespons getAllInfo(AlarmInfo alarmInfo,HttpServletRequest request){ + UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user"); + if(userInfo==null){ + return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!"); + } + alarmInfo.setOrg(userInfo.getOrg()); List lists = alarmInfoService.selectByParam(alarmInfo); if(lists!=null && lists.size()>=0){ @@ -37,4 +44,28 @@ public class AlarmInfoController { } return new ResultRespons(Constant.ERROR_CODE,"更新告警信息失败!"); } + + @GetMapping("/getAlarmLevelCount") + public ResultRespons getAlarmLevelCount(HttpServletRequest request){ + UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user"); + if(userInfo==null){ + return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!"); + } + List> list=alarmInfoService.getAlarmLevelCount(userInfo.getOrg()); + if(list!=null){ + return new ResultRespons(Constant.SUCCESS_CODE,"查询成功!",list); + } + return new ResultRespons(Constant.ERROR_CODE,"查询失败!"); + } + + @GetMapping("/getCount") + public ResultRespons getCount(HttpServletRequest request){ + UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user"); + if(userInfo==null){ + return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!"); + } + int res= alarmInfoService.getCount(userInfo.getOrg()); + return new ResultRespons(Constant.SUCCESS_CODE,"查询成功!",res); + + } } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DeviceController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DeviceController.java index e7dee95..fe5aae9 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DeviceController.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DeviceController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/device") @@ -32,6 +33,7 @@ public class DeviceController { String id =GenerateIdUtil.getId(userInfo.getUsername(),userInfo.getOrg()); deviceInfo.setId(id); deviceInfo.setUpdatetime(MyUtils.getTime()); + deviceInfo.setOrg(userInfo.getOrg()); int res=deviceInfoService.addDevice(deviceInfo); if(1==res){ return new ResultRespons(Constant.SUCCESS_CODE,"新增设备成功!"); @@ -40,11 +42,15 @@ public class DeviceController { } @GetMapping("/select") public ResultRespons selectDevice(@RequestParam("activestatus") int activestatus, HttpServletRequest request){ + UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user"); + if(userInfo==null){ + return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!"); + } List deviceInfoList =null; if(1==activestatus){ - deviceInfoList=deviceInfoService.selectActiveDevice(); + deviceInfoList=deviceInfoService.selectActiveDevice(userInfo.getOrg()); }else if(0==activestatus){ - deviceInfoList=deviceInfoService.selectUnActiveDevice(); + deviceInfoList=deviceInfoService.selectUnActiveDevice(userInfo.getOrg()); } return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",deviceInfoList); } @@ -60,10 +66,37 @@ public class DeviceController { @PostMapping("/active") public ResultRespons activeDevice(@RequestBody DeviceInfo deviceInfo, HttpServletRequest request){ + int res=deviceInfoService.activeDeviceByNo(deviceInfo.getNo()); if(1==res){ return new ResultRespons(Constant.SUCCESS_CODE,"激活设备成功!"); } return new ResultRespons(Constant.ERROR_CODE,"激活设备失败!"); } + + @GetMapping("/getTypeCount") + public ResultRespons getTypeCount(HttpServletRequest request){ + UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user"); + if(userInfo==null){ + return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!"); + } + List> list=deviceInfoService.getDeviceTypeCount(userInfo.getOrg()); + if(list!=null){ + return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",list); + } + return new ResultRespons(Constant.ERROR_CODE,"查询设备失败!"); + } + + @GetMapping("/getRunStatusCount") + public ResultRespons getRunStatusCount(HttpServletRequest request){ + UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user"); + if(userInfo==null){ + return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!"); + } + List> list=deviceInfoService.getDeviceRunStautsCount(userInfo.getOrg()); + if(list!=null){ + return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",list); + } + return new ResultRespons(Constant.ERROR_CODE,"查询设备失败!"); + } } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/AlarmInfoMapper.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/AlarmInfoMapper.java index 23dd8af..e7e4b58 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/AlarmInfoMapper.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/AlarmInfoMapper.java @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Map; @Repository public interface AlarmInfoMapper { @@ -29,5 +30,9 @@ public interface AlarmInfoMapper { List selectByParam(AlarmInfo alarmInfo); + @Select("select alarm_level,count(alarm_level) from alarm_info where org = #{org}GROUP BY alarm_level") + List> getAlarmLevelCount(@Param("org") String org); + @Select("select count(1) as 未处理 from alarm_info where org =#{org} and alarm_status =1") + int getCount(@Param("org") String org); } \ No newline at end of file diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/DeviceInfoMapper.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/DeviceInfoMapper.java index 4baaeb9..4b1ec8e 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/DeviceInfoMapper.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/DeviceInfoMapper.java @@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Update; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Map; @Repository public interface DeviceInfoMapper { @@ -26,15 +27,19 @@ public interface DeviceInfoMapper { @Update("update device_info set activestatus=1,updatetime=#{time} where no =#{no}") int updateStatusByNo(@Param("time") String updateTime, @Param("no") String no); - @Select("select * from device_info where activestatus=1") - List selectActiveDevices(); + @Select("select * from device_info where activestatus=1 and org=#{org}") + List selectActiveDevices(@Param("org") String org); - @Select("select * from device_info where activestatus=0") - List selectUnActiveDevices(); + @Select("select * from device_info where activestatus=0 and org=#{org}" ) + List selectUnActiveDevices(@Param("org") String org); @Delete("delete from device_info where no =#{no}") int deleteByNo(@Param("no") String no); @Select("select * from device_info where no=#{no}") List selectByNo(@Param("no") String no); + + List> getDeviceTypeCount(@Param("org") String org); + + List> getDeviceRunStatusCount(@Param("org") String org); } \ No newline at end of file diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/AlarmInfo.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/AlarmInfo.java index 427cfa4..554de91 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/AlarmInfo.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/AlarmInfo.java @@ -12,7 +12,7 @@ public class AlarmInfo { private String deviceNo; private String alarmName; - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date alarmTime; private String deviceType; @@ -23,7 +23,9 @@ public class AlarmInfo { private String alarmRes; - public AlarmInfo(String deviceNo, String alarmName, Date alarmTime, String deviceType, Integer alarmStatus, Integer alarmLevel, String alarmRes) { + private String org; + + public AlarmInfo(String deviceNo, String alarmName, Date alarmTime, String deviceType, Integer alarmStatus, Integer alarmLevel, String alarmRes, String org) { this.deviceNo = deviceNo; this.alarmName = alarmName; this.alarmTime = alarmTime; @@ -31,6 +33,7 @@ public class AlarmInfo { this.alarmStatus = alarmStatus; this.alarmLevel = alarmLevel; this.alarmRes = alarmRes; + this.org = org; } public AlarmInfo() { diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/DeviceInfo.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/DeviceInfo.java index f67f0ba..2f1d021 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/DeviceInfo.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/DeviceInfo.java @@ -1,6 +1,5 @@ package com.aiit.xiuos.model; - import lombok.Builder; import lombok.Data; @@ -55,7 +54,9 @@ public class DeviceInfo { private String privateserverusername; - public DeviceInfo(String id, String no, String productname, String type, Integer activestatus, String updatetime, String devicedesc, Integer runstatus, String statusdesc, String kernel, String webversion, String ipaddr, String netmask, String gateway, String dnsserver0, String dnsserver1, String topic, String serveraddr, String serverport, String username, String clientid, String privateserveraddr, String privateserverport, String privateserverusername) { + private String org; + + public DeviceInfo(String id, String no, String productname, String type, Integer activestatus, String updatetime, String devicedesc, Integer runstatus, String statusdesc, String kernel, String webversion, String ipaddr, String netmask, String gateway, String dnsserver0, String dnsserver1, String topic, String serveraddr, String serverport, String username, String clientid, String privateserveraddr, String privateserverport, String privateserverusername, String org) { this.id = id; this.no = no; this.productname = productname; @@ -80,6 +81,7 @@ public class DeviceInfo { this.privateserveraddr = privateserveraddr; this.privateserverport = privateserverport; this.privateserverusername = privateserverusername; + this.org = org; } public DeviceInfo() { diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/AlarmInfoService.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/AlarmInfoService.java index 466ffe2..868174c 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/AlarmInfoService.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/AlarmInfoService.java @@ -3,10 +3,14 @@ package com.aiit.xiuos.service; import com.aiit.xiuos.model.AlarmInfo; import java.util.List; +import java.util.Map; public interface AlarmInfoService { List selectAll(); List selectByLevel(int level); int updateAlarmInfo(AlarmInfo alarmInfo); List selectByParam(AlarmInfo alarmInfo); + List> getAlarmLevelCount(String org); + //获取未处理得告警数量 + int getCount(String org); } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/DeviceInfoService.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/DeviceInfoService.java index 28b9345..084b2c5 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/DeviceInfoService.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/DeviceInfoService.java @@ -3,12 +3,16 @@ package com.aiit.xiuos.service; import com.aiit.xiuos.model.DeviceInfo; import java.util.List; +import java.util.Map; public interface DeviceInfoService { int addDevice(DeviceInfo deviceInfo); int deleteDeviceByNo(String no); int activeDeviceByNo(String no); - List selectActiveDevice(); - List selectUnActiveDevice(); + List selectActiveDevice(String org); + List selectUnActiveDevice(String org); List selectbyNo(String no); + List> getDeviceTypeCount(String org); + List> getDeviceRunStautsCount(String org); + } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/AlarmInfoServiceImpl.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/AlarmInfoServiceImpl.java index 159207d..da1c5ab 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/AlarmInfoServiceImpl.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/AlarmInfoServiceImpl.java @@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Map; + @Service public class AlarmInfoServiceImpl implements AlarmInfoService { @Autowired @@ -32,4 +34,14 @@ public class AlarmInfoServiceImpl implements AlarmInfoService { return alarmInfoMapper.selectByParam(alarmInfo); } + @Override + public List> getAlarmLevelCount(String org) { + return alarmInfoMapper.getAlarmLevelCount(org); + } + + @Override + public int getCount(String org) { + return alarmInfoMapper.getCount(org); + } + } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/DeviceInfoServiceImpl.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/DeviceInfoServiceImpl.java index cd77d9c..b1c8a61 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/DeviceInfoServiceImpl.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/DeviceInfoServiceImpl.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Map; @Service public class DeviceInfoServiceImpl implements DeviceInfoService { @@ -30,17 +31,27 @@ public class DeviceInfoServiceImpl implements DeviceInfoService { } @Override - public List selectActiveDevice() { - return deviceInfoMapper.selectActiveDevices(); + public List selectActiveDevice(String org) { + return deviceInfoMapper.selectActiveDevices(org); } @Override - public List selectUnActiveDevice() { - return deviceInfoMapper.selectUnActiveDevices(); + public List selectUnActiveDevice(String org) { + return deviceInfoMapper.selectUnActiveDevices(org); } @Override public List selectbyNo(String no) { return deviceInfoMapper.selectByNo(no); } + + @Override + public List> getDeviceTypeCount(String org) { + return deviceInfoMapper.getDeviceTypeCount(org); + } + + @Override + public List> getDeviceRunStautsCount(String org) { + return deviceInfoMapper.getDeviceRunStatusCount(org); + } } diff --git a/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml b/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml index c15ac5f..14fe9a2 100644 --- a/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml +++ b/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml @@ -10,10 +10,12 @@ + - device_no, alarm_name, alarm_time, device_type, alarm_status, alarm_level, alarm_res + device_no, alarm_name, alarm_time, device_type, alarm_status, alarm_level, alarm_res, + org - select * from alarm_info where 1=1 - - and device_no = #{deviceNo,jdbcType=VARCHAR} - - - and alarm_name = #{alarmName,jdbcType=VARCHAR} - - - and alarm_time = #{alarmTime,jdbcType=TIMESTAMP} - - - and device_type = #{deviceType,jdbcType=VARCHAR} - - - and alarm_status = #{alarmStatus,jdbcType=INTEGER} - - - and alarm_level = #{alarmLevel,jdbcType=INTEGER} - - order by alarm_time desc; + select * from alarm_info where org= #{org,jdbcType=VARCHAR} + + and device_no = #{deviceNo,jdbcType=VARCHAR} + + + and alarm_name = #{alarmName,jdbcType=VARCHAR} + + + and alarm_time = #{alarmTime,jdbcType=TIMESTAMP} + + + and device_type = #{deviceType,jdbcType=VARCHAR} + + + and alarm_status = #{alarmStatus,jdbcType=INTEGER} + + + and alarm_level = #{alarmLevel,jdbcType=INTEGER} + + order by alarm_time desc; \ No newline at end of file diff --git a/xiuosiot-backend/src/main/resources/mappers/DeviceInfoMapper.xml b/xiuosiot-backend/src/main/resources/mappers/DeviceInfoMapper.xml index 89a8576..0fc5dfb 100644 --- a/xiuosiot-backend/src/main/resources/mappers/DeviceInfoMapper.xml +++ b/xiuosiot-backend/src/main/resources/mappers/DeviceInfoMapper.xml @@ -27,23 +27,25 @@ + id, no, productname, type, activestatus, updatetime, devicedesc, runstatus, statusdesc, kernel, webversion, ipaddr, netmask, gateway, dnsserver0, dnsserver1, topic, serveraddr, - serverport, username, clientid, privateserveraddr, privateserverport, privateserverusername + serverport, username, clientid, privateserveraddr, privateserverport, privateserverusername, + org delete from device_info - where id = #{id,jdbcType=INTEGER} + where id = #{id,jdbcType=VARCHAR} and no = #{no,jdbcType=VARCHAR} @@ -54,17 +56,17 @@ netmask, gateway, dnsserver0, dnsserver1, topic, serveraddr, serverport, username, clientid, - privateserveraddr, privateserverport, privateserverusername - ) - values (#{id,jdbcType=INTEGER}, #{no,jdbcType=VARCHAR}, #{productname,jdbcType=VARCHAR}, + privateserveraddr, privateserverport, privateserverusername, + org) + values (#{id,jdbcType=VARCHAR}, #{no,jdbcType=VARCHAR}, #{productname,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{activestatus,jdbcType=INTEGER}, #{updatetime,jdbcType=VARCHAR}, #{devicedesc,jdbcType=VARCHAR}, #{runstatus,jdbcType=INTEGER}, #{statusdesc,jdbcType=VARCHAR}, #{kernel,jdbcType=VARCHAR}, #{webversion,jdbcType=VARCHAR}, #{ipaddr,jdbcType=VARCHAR}, #{netmask,jdbcType=VARCHAR}, #{gateway,jdbcType=VARCHAR}, #{dnsserver0,jdbcType=VARCHAR}, #{dnsserver1,jdbcType=VARCHAR}, #{topic,jdbcType=VARCHAR}, #{serveraddr,jdbcType=VARCHAR}, - #{serverport,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{clientid,jdbcType=INTEGER}, - #{privateserveraddr,jdbcType=VARCHAR}, #{privateserverport,jdbcType=VARCHAR}, #{privateserverusername,jdbcType=VARCHAR} - ) + #{serverport,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{clientid,jdbcType=VARCHAR}, + #{privateserveraddr,jdbcType=VARCHAR}, #{privateserverport,jdbcType=VARCHAR}, #{privateserverusername,jdbcType=VARCHAR}, + #{org,jdbcType=VARCHAR}) insert into device_info @@ -141,10 +143,13 @@ privateserverusername, + + org, + - #{id,jdbcType=INTEGER}, + #{id,jdbcType=VARCHAR}, #{no,jdbcType=VARCHAR}, @@ -204,7 +209,7 @@ #{username,jdbcType=VARCHAR}, - #{clientid,jdbcType=INTEGER}, + #{clientid,jdbcType=VARCHAR}, #{privateserveraddr,jdbcType=VARCHAR}, @@ -215,6 +220,9 @@ #{privateserverusername,jdbcType=VARCHAR}, + + #{org,jdbcType=VARCHAR}, + @@ -275,7 +283,7 @@ username = #{username,jdbcType=VARCHAR}, - clientid = #{clientid,jdbcType=INTEGER}, + clientid = #{clientid,jdbcType=VARCHAR}, privateserveraddr = #{privateserveraddr,jdbcType=VARCHAR}, @@ -286,8 +294,11 @@ privateserverusername = #{privateserverusername,jdbcType=VARCHAR}, + + org = #{org,jdbcType=VARCHAR}, + - where id = #{id,jdbcType=INTEGER} + where id = #{id,jdbcType=VARCHAR} and no = #{no,jdbcType=VARCHAR} @@ -310,11 +321,20 @@ serveraddr = #{serveraddr,jdbcType=VARCHAR}, serverport = #{serverport,jdbcType=VARCHAR}, username = #{username,jdbcType=VARCHAR}, - clientid = #{clientid,jdbcType=INTEGER}, + clientid = #{clientid,jdbcType=VARCHAR}, privateserveraddr = #{privateserveraddr,jdbcType=VARCHAR}, privateserverport = #{privateserverport,jdbcType=VARCHAR}, - privateserverusername = #{privateserverusername,jdbcType=VARCHAR} - where id = #{id,jdbcType=INTEGER} + privateserverusername = #{privateserverusername,jdbcType=VARCHAR}, + org = #{org,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} and no = #{no,jdbcType=VARCHAR} + + + + \ No newline at end of file