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

main
wenjy 3 years ago
parent 6fad6e7bfa
commit 5cff219631

@ -1,13 +1,20 @@
package com.ruoyi.web.controller.iot;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.system.domain.BaseMonitorunitInfo;
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.BaseSensorInfoDto;
import com.ruoyi.system.domain.dto.ScrollTableDto;
import com.ruoyi.system.service.IBaseMonitorunitInfoService;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@ -30,6 +37,10 @@ public class IndexController {
@Autowired private IBaseMonitorunitInfoService baseMonitorunitInfoService;
@Autowired private IBaseSensorTypeService baseSensorTypeService;
@Autowired private IBaseSensorInfoService baseSensorInfoService;
@GetMapping()
public String index() {
return "iot-ui/index";
@ -57,7 +68,10 @@ public class IndexController {
x -> {
List<BaseMonitorunitInfoDto> collect =
baseMonitorunitInfoDtos.stream()
.filter(y -> y.getMonitorunitType().equals(x.getMonitorunittypeId()))
.filter(
y ->
!y.getParentId().isEmpty()
&& y.getMonitorunitType().equals(x.getMonitorunittypeId()))
.collect(Collectors.toList());
BaseMonitorunitInfoDto info = new BaseMonitorunitInfoDto();
info.setName(x.getMonitorunittypeName());
@ -127,14 +141,21 @@ public class IndexController {
x -> {
List<BaseMonitorunitInfoDto> collect =
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());
data.add(
new ArrayList<String>() {
{
this.add(x.getMonitorunittypeName());
this.add(collect.size() + "");
this.add(collect.size() + "");
this.add(collect2.size() + "");
}
});
});
@ -165,10 +186,46 @@ public class IndexController {
@GetMapping("/getSensorStateCharts")
@ResponseBody
public String getSensorStateCharts() {
return "{\n"
+ " \"yAxis\": [\"在线\", \"离线\", \"告警\"],\n"
+ " \"data\": [60, 132, 89]\n"
+ "}";
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"
+ " \"yAxis\": [\"在线\", \"离线\", \"告警\"],\n"
+ " \"data\": [0, 132, 89]\n"
+ "}";
}
}
/**
@ -181,17 +238,80 @@ public class IndexController {
@GetMapping("/getSensorStateInfo")
@ResponseBody
public String getSensorStateInfo() {
return "{\n"
+ " \"header\": [\"名称\", \"安装数量\", \"离线数量\"],\n"
+ " \"data\": [\n"
+ " [\"温度\", \"30\", \"30\"],\n"
+ " [\"湿度\", \"14\", \"14\"],\n"
+ " [\"振动\", \"26\", \"26\"],\n"
+ " [\"烟雾\", \"20\", \"20\"],\n"
+ " [\"倾斜\", \"10\", \"10\"],\n"
+ " [\"拉力\", \"10\", \"10\"]\n"
+ " ]\n"
+ "}";
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"
+ " \"header\": [\"名称\", \"安装数量\", \"离线数量\"],\n"
+ " \"data\": [\n"
+ " [\"温度\", \"30\", \"30\"],\n"
+ " [\"湿度\", \"14\", \"14\"],\n"
+ " [\"振动\", \"26\", \"26\"],\n"
+ " [\"烟雾\", \"20\", \"20\"],\n"
+ " [\"倾斜\", \"10\", \"10\"],\n"
+ " [\"拉力\", \"10\", \"10\"]\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,
},
boundaryGap: ['5%', '5%'],
boundaryGap: ['0%', '5%'],
},
yAxis: [{
type: 'category',

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

@ -22,6 +22,11 @@ public class BaseSensorInfo extends BaseEntity
this.sensorId = sensorId;
}
public BaseSensorInfo(String sensorType, Long enableFlag) {
this.sensorType = sensorType;
this.enableFlag = enableFlag;
}
/** 主键标识 */
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;
}

@ -19,177 +19,187 @@ import com.ruoyi.common.core.text.Convert;
/**
* Service
*
*
* @author wenjy
* @date 2022-01-27
*/
@Service
public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoService
{
@Autowired
private BaseMonitorunitInfoMapper baseMonitorunitInfoMapper;
public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoService {
@Autowired private BaseMonitorunitInfoMapper baseMonitorunitInfoMapper;
/**
*
*
* @param ObjId
* @return
*/
@Override
public BaseMonitorunitInfo selectBaseMonitorunitInfoByObjId(Long ObjId)
{
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoByObjId(ObjId);
}
/**
*
*
* @param ObjId
* @return
*/
@Override
public BaseMonitorunitInfo selectBaseMonitorunitInfoByObjId(Long ObjId) {
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoByObjId(ObjId);
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public List<BaseMonitorunitInfo> selectBaseMonitorunitInfoList(BaseMonitorunitInfo baseMonitorunitInfo)
{
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(baseMonitorunitInfo);
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public List<BaseMonitorunitInfo> selectBaseMonitorunitInfoList(
BaseMonitorunitInfo baseMonitorunitInfo) {
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(baseMonitorunitInfo);
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(BaseMonitorunitInfo baseMonitorunitInfo)
{
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo);
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(
BaseMonitorunitInfo baseMonitorunitInfo) {
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo);
}
/**
*
* @author WenJY
* @date 2022/2/7 9:53
* @param baseMonitorunitInfos
* @param updateSupport
* @return java.lang.String
*/
@Override
public String importMould(List<BaseMonitorunitInfo> baseMonitorunitInfos, boolean updateSupport) {
if (StringUtils.isNull(baseMonitorunitInfos) || baseMonitorunitInfos.size() == 0) {
throw new BusinessException("导入标准数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfos) {
try {
List<BaseMonitorunitInfo> baseMonitorunitInfoList =
baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo(baseMonitorunitInfo.getMonitorunitId()));
/**
*
*
* @author WenJY
* @date 2022/2/7 9:53
* @param baseMonitorunitInfos
* @param updateSupport
* @return java.lang.String
*/
@Override
public String importMould(List<BaseMonitorunitInfo> baseMonitorunitInfos, boolean updateSupport) {
if (StringUtils.isNull(baseMonitorunitInfos) || baseMonitorunitInfos.size() == 0) {
throw new BusinessException("导入标准数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfos) {
try {
List<BaseMonitorunitInfo> baseMonitorunitInfoList =
baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(
new BaseMonitorunitInfo(baseMonitorunitInfo.getMonitorunitId()));
if (baseMonitorunitInfoList.size() == 0) {
baseMonitorunitInfo.setCreateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setCreateTime(new Date());
baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++;
successMsg.append("<br/>" + successNum + "、 " + baseMonitorunitInfo.getMonitorunitName() + " 导入成功");
} else if (updateSupport) {
for (BaseMonitorunitInfo unitInfo : baseMonitorunitInfoList) {
baseMonitorunitInfo.setObjId(unitInfo.getObjId());
baseMonitorunitInfo.setUpdateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setUpdateTime(new Date());
baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++;
}
successMsg.append("<br/>" + successNum + "、" + baseMonitorunitInfo.getMonitorunitName() + " 更新成功");
} else {
failureNum++;
failureMsg.append("<br/>" + failureNum + "、" + baseMonitorunitInfo.getMonitorunitId() + "、" + baseMonitorunitInfo.getMonitorunitName() + " 已存在");
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、标准: " + baseMonitorunitInfo.getMonitorunitId() + "、" + baseMonitorunitInfo.getMonitorunitName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new BusinessException(failureMsg.toString());
if (baseMonitorunitInfoList.size() == 0) {
baseMonitorunitInfo.setCreateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setCreateTime(new Date());
baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++;
successMsg.append(
"<br/>" + successNum + "、 " + baseMonitorunitInfo.getMonitorunitName() + " 导入成功");
} else if (updateSupport) {
for (BaseMonitorunitInfo unitInfo : baseMonitorunitInfoList) {
baseMonitorunitInfo.setObjId(unitInfo.getObjId());
baseMonitorunitInfo.setUpdateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setUpdateTime(new Date());
baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++;
}
successMsg.append(
"<br/>" + successNum + "、" + baseMonitorunitInfo.getMonitorunitName() + " 更新成功");
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
failureNum++;
failureMsg.append(
"<br/>"
+ failureNum
+ "、"
+ baseMonitorunitInfo.getMonitorunitId()
+ "、"
+ baseMonitorunitInfo.getMonitorunitName()
+ " 已存在");
}
return successMsg.toString();
} catch (Exception e) {
failureNum++;
String msg =
"<br/>"
+ failureNum
+ "、标准: "
+ baseMonitorunitInfo.getMonitorunitId()
+ "、"
+ baseMonitorunitInfo.getMonitorunitName()
+ " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public int insertBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo)
{
baseMonitorunitInfo.setCreateTime(DateUtils.getNowDate());
return baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new BusinessException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public int updateBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo)
{
baseMonitorunitInfo.setUpdateTime(DateUtils.getNowDate());
return baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public int insertBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo) {
baseMonitorunitInfo.setCreateTime(DateUtils.getNowDate());
return baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
}
/**
*
*
* @param ObjIds
* @return
*/
@Override
public int deleteBaseMonitorunitInfoByObjIds(String ObjIds)
{
return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjIds(Convert.toStrArray(ObjIds));
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public int updateBaseMonitorunitInfo(BaseMonitorunitInfo baseMonitorunitInfo) {
baseMonitorunitInfo.setUpdateTime(DateUtils.getNowDate());
return baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
}
/**
*
*
* @param ObjId
* @return
*/
@Override
public int deleteBaseMonitorunitInfoByObjId(Long ObjId)
{
return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjId(ObjId);
}
/**
*
*
* @param ObjIds
* @return
*/
@Override
public int deleteBaseMonitorunitInfoByObjIds(String ObjIds) {
return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjIds(Convert.toStrArray(ObjIds));
}
/**
*
*
* @return
*/
@Override
public List<Ztree> selectBaseMonitorunitInfoTree()
{
List<BaseMonitorunitInfo> baseMonitorunitInfoList = baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo());
List<Ztree> ztrees = new ArrayList<Ztree>();
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfoList)
{
Ztree ztree = new Ztree();
ztree.setId(baseMonitorunitInfo.getMonitorunitId());
ztree.setpId(baseMonitorunitInfo.getParentId());
ztree.setName(baseMonitorunitInfo.getMonitorunitName());
ztree.setTitle(baseMonitorunitInfo.getMonitorunitName());
ztrees.add(ztree);
}
return ztrees;
/**
*
*
* @param ObjId
* @return
*/
@Override
public int deleteBaseMonitorunitInfoByObjId(Long ObjId) {
return baseMonitorunitInfoMapper.deleteBaseMonitorunitInfoByObjId(ObjId);
}
/**
*
*
* @return
*/
@Override
public List<Ztree> selectBaseMonitorunitInfoTree() {
List<BaseMonitorunitInfo> baseMonitorunitInfoList =
baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo());
List<Ztree> ztrees = new ArrayList<Ztree>();
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfoList) {
Ztree ztree = new Ztree();
ztree.setId(baseMonitorunitInfo.getMonitorunitId());
ztree.setpId(baseMonitorunitInfo.getParentId());
ztree.setName(baseMonitorunitInfo.getMonitorunitName());
ztree.setTitle(baseMonitorunitInfo.getMonitorunitName());
ztrees.add(ztree);
}
return ztrees;
}
}

Loading…
Cancel
Save