change - 监控主页后端接口处理

main
wenjy 3 years ago
parent 6fad6e7bfa
commit 5cff219631

@ -1,13 +1,20 @@
package com.ruoyi.web.controller.iot; package com.ruoyi.web.controller.iot;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.system.domain.BaseMonitorunitInfo; import com.ruoyi.system.domain.BaseMonitorunitInfo;
import com.ruoyi.system.domain.BaseMonitorunitType; import com.ruoyi.system.domain.BaseMonitorunitType;
import com.ruoyi.system.domain.BaseSensorInfo;
import com.ruoyi.system.domain.BaseSensorType;
import com.ruoyi.system.domain.dto.BarChatsDto;
import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto; import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto;
import com.ruoyi.system.domain.dto.BaseSensorInfoDto;
import com.ruoyi.system.domain.dto.ScrollTableDto; import com.ruoyi.system.domain.dto.ScrollTableDto;
import com.ruoyi.system.service.IBaseMonitorunitInfoService; import com.ruoyi.system.service.IBaseMonitorunitInfoService;
import com.ruoyi.system.service.IBaseMonitorunitTypeService; import com.ruoyi.system.service.IBaseMonitorunitTypeService;
import com.ruoyi.system.service.IBaseSensorInfoService;
import com.ruoyi.system.service.IBaseSensorTypeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -30,6 +37,10 @@ public class IndexController {
@Autowired private IBaseMonitorunitInfoService baseMonitorunitInfoService; @Autowired private IBaseMonitorunitInfoService baseMonitorunitInfoService;
@Autowired private IBaseSensorTypeService baseSensorTypeService;
@Autowired private IBaseSensorInfoService baseSensorInfoService;
@GetMapping() @GetMapping()
public String index() { public String index() {
return "iot-ui/index"; return "iot-ui/index";
@ -57,7 +68,10 @@ public class IndexController {
x -> { x -> {
List<BaseMonitorunitInfoDto> collect = List<BaseMonitorunitInfoDto> collect =
baseMonitorunitInfoDtos.stream() baseMonitorunitInfoDtos.stream()
.filter(y -> y.getMonitorunitType().equals(x.getMonitorunittypeId())) .filter(
y ->
!y.getParentId().isEmpty()
&& y.getMonitorunitType().equals(x.getMonitorunittypeId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
BaseMonitorunitInfoDto info = new BaseMonitorunitInfoDto(); BaseMonitorunitInfoDto info = new BaseMonitorunitInfoDto();
info.setName(x.getMonitorunittypeName()); info.setName(x.getMonitorunittypeName());
@ -127,14 +141,21 @@ public class IndexController {
x -> { x -> {
List<BaseMonitorunitInfoDto> collect = List<BaseMonitorunitInfoDto> collect =
baseMonitorunitInfoDtos.stream() baseMonitorunitInfoDtos.stream()
.filter(y -> y.getMonitorunitType().equals(x.getMonitorunittypeId())) .filter(
y ->
!y.getParentId().isEmpty()
&& y.getMonitorunitType().equals(x.getMonitorunittypeId()))
.collect(Collectors.toList());
List<BaseMonitorunitInfoDto> collect2 =
collect.stream()
.filter(z -> z.getMonitorunitStatus().equals(0))
.collect(Collectors.toList()); .collect(Collectors.toList());
data.add( data.add(
new ArrayList<String>() { new ArrayList<String>() {
{ {
this.add(x.getMonitorunittypeName()); this.add(x.getMonitorunittypeName());
this.add(collect.size() + ""); this.add(collect.size() + "");
this.add(collect.size() + ""); this.add(collect2.size() + "");
} }
}); });
}); });
@ -165,11 +186,47 @@ public class IndexController {
@GetMapping("/getSensorStateCharts") @GetMapping("/getSensorStateCharts")
@ResponseBody @ResponseBody
public String getSensorStateCharts() { public String getSensorStateCharts() {
try {
List<BaseSensorInfoDto> baseSensorInfoDtos =
baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo());
List<String> yAxis =
new ArrayList<String>() {
{
this.add("在线");
this.add("离线");
this.add("告警");
}
};
List<Integer> data =
new ArrayList<Integer>() {
{
this.add(
baseSensorInfoDtos.stream()
.filter(x -> x.getSensorStatus() == 0)
.collect(Collectors.toList())
.size()); // 在线
this.add(
baseSensorInfoDtos.stream()
.filter(x -> x.getSensorStatus() == 1)
.collect(Collectors.toList())
.size()); // 离线
this.add(
baseSensorInfoDtos.stream()
.filter(x -> x.getSensorStatus() == 2)
.collect(Collectors.toList())
.size()); // 告警
}
};
return JSONArray.toJSONString(new BarChatsDto(yAxis, data));
} catch (Exception ex) {
return "{\n" return "{\n"
+ " \"yAxis\": [\"在线\", \"离线\", \"告警\"],\n" + " \"yAxis\": [\"在线\", \"离线\", \"告警\"],\n"
+ " \"data\": [60, 132, 89]\n" + " \"data\": [0, 132, 89]\n"
+ "}"; + "}";
} }
}
/** /**
* *
@ -181,6 +238,40 @@ public class IndexController {
@GetMapping("/getSensorStateInfo") @GetMapping("/getSensorStateInfo")
@ResponseBody @ResponseBody
public String getSensorStateInfo() { public String getSensorStateInfo() {
try {
List<List<String>> data = new ArrayList<>();
List<String> header =
new ArrayList<String>() {
{
this.add("名称");
this.add("安装数量");
this.add("离线数量");
}
};
List<BaseSensorType> baseSensorTypeList =
baseSensorTypeService.selectBaseSensorTypeList(new BaseSensorType());
baseSensorTypeList.forEach(
x -> {
List<BaseSensorInfoDto> baseSensorInfoDtos =
baseSensorInfoService.selectBaseSensorInfoList(
new BaseSensorInfo(x.getSensortypeId(), 0L));
data.add(
new ArrayList<String>() {
{
this.add(x.getSensortypeName());
this.add(baseSensorInfoDtos.size() + "");
this.add(
baseSensorInfoDtos.stream()
.filter(z -> z.getSensorStatus() == 1)
.collect(Collectors.toList())
.size()
+ "");
}
});
});
return JSONArray.toJSONString(new ScrollTableDto(header, data));
} catch (Exception ex) {
return "{\n" return "{\n"
+ " \"header\": [\"名称\", \"安装数量\", \"离线数量\"],\n" + " \"header\": [\"名称\", \"安装数量\", \"离线数量\"],\n"
+ " \"data\": [\n" + " \"data\": [\n"
@ -193,6 +284,35 @@ public class IndexController {
+ " ]\n" + " ]\n"
+ "}"; + "}";
} }
}
/**
* :
*
* @author WenJY
* @date 2022/3/11 17:08
* @return java.lang.String
*/
@GetMapping("/quantityStatistics")
@ResponseBody
public String quantityStatistics() {
List<BaseSensorInfoDto> baseSensorInfoDtos =
baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo("", 0L));
List<BaseMonitorunitInfo> baseMonitorunitInfos =
baseMonitorunitInfoService.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo());
List<Integer> result =
new ArrayList<Integer>() {
{
this.add(baseSensorInfoDtos.size());
this.add(
baseMonitorunitInfos.stream()
.filter(x -> !x.getParentId().isEmpty() && x.getEnableFlag() == 0L)
.collect(Collectors.toList())
.size());
}
};
return JSONArray.toJSONString(result);
}
/** /**
* *

@ -1,3 +1,19 @@
//数量统计,传感器数量、监控单元数量
$(() => {
$.ajax({
url: '/iot/index/quantityStatistics',
type: 'GET',
dataType: 'JSON',
success: function (datas) {
$("#sensorAmount").text(datas[0]);
$("#monitorunitAmount").text(datas[1]);
},
error: function (e) {
console.log("异常:" + e)
}
})
})
//监控单元列表 //监控单元列表
$(() => { $(() => {
@ -181,7 +197,7 @@ function barChats(datas, id) {
}, },
show: true, show: true,
}, },
boundaryGap: ['5%', '5%'], boundaryGap: ['0%', '5%'],
}, },
yAxis: [{ yAxis: [{
type: 'category', type: 'category',

@ -24,11 +24,11 @@
<!--传感器数量--> <!--传感器数量-->
<div class="center monitorInfo"> <div class="center monitorInfo">
<span>123</span> <span id="sensorAmount">123</span>
</div> </div>
<!--监控单元数量--> <!--监控单元数量-->
<div class="center monitorUnit"> <div class="center monitorUnit">
<span>123</span> <span id="monitorunitAmount">123</span>
</div> </div>
<!--监控单元告警--未确认数--> <!--监控单元告警--未确认数-->

@ -22,6 +22,11 @@ public class BaseSensorInfo extends BaseEntity
this.sensorId = sensorId; this.sensorId = sensorId;
} }
public BaseSensorInfo(String sensorType, Long enableFlag) {
this.sensorType = sensorType;
this.enableFlag = enableFlag;
}
/** 主键标识 */ /** 主键标识 */
private Long objId; private Long objId;

@ -0,0 +1,25 @@
package com.ruoyi.system.domain.dto;
import lombok.Data;
import java.util.List;
/**
* @author WenJY
* @date 20220311 16:41
*/
@Data
public class BarChatsDto {
public BarChatsDto() {
}
public BarChatsDto(List<String> yAxis, List<Integer> data) {
this.yAxis = yAxis;
this.data = data;
}
private List<String> yAxis;
private List<Integer> data;
}

@ -24,10 +24,8 @@ import com.ruoyi.common.core.text.Convert;
* @date 2022-01-27 * @date 2022-01-27
*/ */
@Service @Service
public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoService public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoService {
{ @Autowired private BaseMonitorunitInfoMapper baseMonitorunitInfoMapper;
@Autowired
private BaseMonitorunitInfoMapper baseMonitorunitInfoMapper;
/** /**
* *
@ -36,8 +34,7 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public BaseMonitorunitInfo selectBaseMonitorunitInfoByObjId(Long ObjId) public BaseMonitorunitInfo selectBaseMonitorunitInfoByObjId(Long ObjId) {
{
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoByObjId(ObjId); return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoByObjId(ObjId);
} }
@ -48,8 +45,8 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public List<BaseMonitorunitInfo> selectBaseMonitorunitInfoList(BaseMonitorunitInfo baseMonitorunitInfo) public List<BaseMonitorunitInfo> selectBaseMonitorunitInfoList(
{ BaseMonitorunitInfo baseMonitorunitInfo) {
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(baseMonitorunitInfo); return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(baseMonitorunitInfo);
} }
@ -60,13 +57,14 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(BaseMonitorunitInfo baseMonitorunitInfo) public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(
{ BaseMonitorunitInfo baseMonitorunitInfo) {
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo); return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo);
} }
/** /**
* *
*
* @author WenJY * @author WenJY
* @date 2022/2/7 9:53 * @date 2022/2/7 9:53
* @param baseMonitorunitInfos * @param baseMonitorunitInfos
@ -85,14 +83,16 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfos) { for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfos) {
try { try {
List<BaseMonitorunitInfo> baseMonitorunitInfoList = List<BaseMonitorunitInfo> baseMonitorunitInfoList =
baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo(baseMonitorunitInfo.getMonitorunitId())); baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(
new BaseMonitorunitInfo(baseMonitorunitInfo.getMonitorunitId()));
if (baseMonitorunitInfoList.size() == 0) { if (baseMonitorunitInfoList.size() == 0) {
baseMonitorunitInfo.setCreateBy(ShiroUtils.getLoginName()); baseMonitorunitInfo.setCreateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setCreateTime(new Date()); baseMonitorunitInfo.setCreateTime(new Date());
baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo); baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++; successNum++;
successMsg.append("<br/>" + successNum + "、 " + baseMonitorunitInfo.getMonitorunitName() + " 导入成功"); successMsg.append(
"<br/>" + successNum + "、 " + baseMonitorunitInfo.getMonitorunitName() + " 导入成功");
} else if (updateSupport) { } else if (updateSupport) {
for (BaseMonitorunitInfo unitInfo : baseMonitorunitInfoList) { for (BaseMonitorunitInfo unitInfo : baseMonitorunitInfoList) {
baseMonitorunitInfo.setObjId(unitInfo.getObjId()); baseMonitorunitInfo.setObjId(unitInfo.getObjId());
@ -101,14 +101,29 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo); baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++; successNum++;
} }
successMsg.append("<br/>" + successNum + "、" + baseMonitorunitInfo.getMonitorunitName() + " 更新成功"); successMsg.append(
"<br/>" + successNum + "、" + baseMonitorunitInfo.getMonitorunitName() + " 更新成功");
} else { } else {
failureNum++; failureNum++;
failureMsg.append("<br/>" + failureNum + "、" + baseMonitorunitInfo.getMonitorunitId() + "、" + baseMonitorunitInfo.getMonitorunitName() + " 已存在"); failureMsg.append(
"<br/>"
+ failureNum
+ "、"
+ baseMonitorunitInfo.getMonitorunitId()
+ "、"
+ baseMonitorunitInfo.getMonitorunitName()
+ " 已存在");
} }
} catch (Exception e) { } catch (Exception e) {
failureNum++; failureNum++;
String msg = "<br/>" + failureNum + "、标准: " + baseMonitorunitInfo.getMonitorunitId() + "、" + baseMonitorunitInfo.getMonitorunitName() + " 导入失败:"; String msg =
"<br/>"
+ failureNum
+ "、标准: "
+ baseMonitorunitInfo.getMonitorunitId()
+ "、"
+ baseMonitorunitInfo.getMonitorunitName()
+ " 导入失败:";
failureMsg.append(msg + e.getMessage()); failureMsg.append(msg + e.getMessage());
} }
} }
@ -128,8 +143,7 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public int insertBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo) public int insertBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo) {
{
baseMonitorunitInfo.setCreateTime(DateUtils.getNowDate()); baseMonitorunitInfo.setCreateTime(DateUtils.getNowDate());
return baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo); return baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
} }
@ -141,8 +155,7 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public int updateBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo) public int updateBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo) {
{
baseMonitorunitInfo.setUpdateTime(DateUtils.getNowDate()); baseMonitorunitInfo.setUpdateTime(DateUtils.getNowDate());
return baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo); return baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
} }
@ -154,8 +167,7 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public int deleteBaseMonitorunitInfoByObjIds(String ObjIds) public int deleteBaseMonitorunitInfoByObjIds(String ObjIds) {
{
return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjIds(Convert.toStrArray(ObjIds)); return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjIds(Convert.toStrArray(ObjIds));
} }
@ -166,8 +178,7 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public int deleteBaseMonitorunitInfoByObjId(Long ObjId) public int deleteBaseMonitorunitInfoByObjId(Long ObjId) {
{
return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjId(ObjId); return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjId(ObjId);
} }
@ -177,12 +188,11 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
* @return * @return
*/ */
@Override @Override
public List<Ztree> selectBaseMonitorunitInfoTree() public List<Ztree> selectBaseMonitorunitInfoTree() {
{ List<BaseMonitorunitInfo> baseMonitorunitInfoList =
List<BaseMonitorunitInfo> baseMonitorunitInfoList = baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo()); baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo());
List<Ztree> ztrees = new ArrayList<Ztree>(); List<Ztree> ztrees = new ArrayList<Ztree>();
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfoList) for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfoList) {
{
Ztree ztree = new Ztree(); Ztree ztree = new Ztree();
ztree.setId(baseMonitorunitInfo.getMonitorunitId()); ztree.setId(baseMonitorunitInfo.getMonitorunitId());
ztree.setpId(baseMonitorunitInfo.getParentId()); ztree.setpId(baseMonitorunitInfo.getParentId());

Loading…
Cancel
Save