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,10 +186,46 @@ public class IndexController {
@GetMapping("/getSensorStateCharts") @GetMapping("/getSensorStateCharts")
@ResponseBody @ResponseBody
public String getSensorStateCharts() { public String getSensorStateCharts() {
return "{\n" try {
+ " \"yAxis\": [\"在线\", \"离线\", \"告警\"],\n" List<BaseSensorInfoDto> baseSensorInfoDtos =
+ " \"data\": [60, 132, 89]\n" 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") @GetMapping("/getSensorStateInfo")
@ResponseBody @ResponseBody
public String getSensorStateInfo() { public String getSensorStateInfo() {
return "{\n" try {
+ " \"header\": [\"名称\", \"安装数量\", \"离线数量\"],\n" List<List<String>> data = new ArrayList<>();
+ " \"data\": [\n"
+ " [\"温度\", \"30\", \"30\"],\n" List<String> header =
+ " [\"湿度\", \"14\", \"14\"],\n" new ArrayList<String>() {
+ " [\"振动\", \"26\", \"26\"],\n" {
+ " [\"烟雾\", \"20\", \"20\"],\n" this.add("名称");
+ " [\"倾斜\", \"10\", \"10\"],\n" this.add("安装数量");
+ " [\"拉力\", \"10\", \"10\"]\n" this.add("离线数量");
+ " ]\n" }
+ "}"; };
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, 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;
}

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