change - 传感器汇总数据查询修改

main
wenjy 3 years ago
parent 76e96bb28c
commit 298f07888f

@ -64,38 +64,31 @@ public class SensorSummaryController extends BaseController {
List<Map<String, Object>> result = new ArrayList<>();
List<BaseSensorInfoDto> baseSensorInfoDtos =
baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(sensorTypeId, 0L));
baseSensorInfoService.selectSensorDataListBySensorType(sensorTypeId);
baseSensorInfoDtos.forEach(
x -> {
Map<String, Object> info = new HashMap<>();
for (BaseSensorInfoDto baseSensorInfoDto : baseSensorInfoDtos) {
Map<String, Object> info = new HashMap<>();
if (baseSensorInfoDto.getReportParam() != null) {
JSONObject jsonObject = JSON.parseObject(baseSensorInfoDto.getReportParam());
Object jrm = redisTemplate.opsForHash().get(x.getSensorType(), x.getSensorId());
JSONObject datavalue = JSON.parseObject(jsonObject.get("datavalue").toString());
if (jrm != null) {
JSONObject jsonObject = JSON.parseObject(jrm.toString());
info = JsonUtils.JSONObjectToMap(datavalue);
Object param = jsonObject.get("param");
info.put("datatype", jsonObject.get("datatype"));
}
info.put("id", 1);
JSONObject data = JSON.parseObject(param.toString());
info.put("sensorId", baseSensorInfoDto.getSensorId());
JSONObject datavalue = JSON.parseObject(data.get("datavalue").toString());
info.put("edgeId", baseSensorInfoDto.getEdgeId());
info = JsonUtils.JSONObjectToMap(datavalue);
info.put("sensorLocation", baseSensorInfoDto.getSensorLocation());
info.put("datatype", data.get("datatype"));
}
info.put("collectTime", baseSensorInfoDto.getCollectTime());
info.put("id", 1);
info.put("sensorId", x.getSensorId());
info.put("edgeId", x.getEdgeId());
info.put("sensorLocation", x.getSensorLocation());
result.add(info);
});
result.add(info);
}
String s = JSONArray.toJSONString(result);
System.out.println("传感器数据展示" + s);
@ -128,86 +121,4 @@ public class SensorSummaryController extends BaseController {
System.out.println("key为" + item + "值为:" + children.get(item));
}
}
}
class sensorTableModel {
private int id;
private String edgeId;
private String sensorId;
private BigDecimal sensorData;
private BigDecimal rssi;
private BigDecimal voltage;
private String collectTime;
private String monitorLocation;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEdgeId() {
return edgeId;
}
public void setEdgeId(String edgeId) {
this.edgeId = edgeId;
}
public String getSensorId() {
return sensorId;
}
public void setSensorId(String sensorId) {
this.sensorId = sensorId;
}
public BigDecimal getSensorData() {
return sensorData;
}
public void setSensorData(BigDecimal sensorData) {
this.sensorData = sensorData;
}
public BigDecimal getRssi() {
return rssi;
}
public void setRssi(BigDecimal rssi) {
this.rssi = rssi;
}
public BigDecimal getVoltage() {
return voltage;
}
public void setVoltage(BigDecimal voltage) {
this.voltage = voltage;
}
public String getCollectTime() {
return collectTime;
}
public void setCollectTime(String collectTime) {
this.collectTime = collectTime;
}
public String getMonitorLocation() {
return monitorLocation;
}
public void setMonitorLocation(String monitorLocation) {
this.monitorLocation = monitorLocation;
}
}
}

@ -2,26 +2,6 @@ const sensorInfoList = function (sensorTypeId) {
let formData = new FormData();
formData.append("sensorTypeId", sensorTypeId);
let sensorTypeArray = [];
$.ajax({
type: "post",
url: "/base/sysParamConfig/getParameter",
data: formData,
contentType: "application/json;charset=utf-8",
dataType: "json",
json: 'callback',
processData: false,
contentType: false,
success: function (json) {
sensorTypeArray = json;
},
error: function () {
alert("错误");
}
});
$.ajax({
type: "post",
url: "/iot/sensorSummary/getSensorInfo",
@ -32,10 +12,13 @@ const sensorInfoList = function (sensorTypeId) {
processData: false,
contentType: false,
success: function (json) {
let sensorTypeArray = getparamsFunction(sensorTypeId);
const columnsArray = [];
columnsArray.push({field: "id", title: "序号", width: 60, colspan: 1, rowspan: 1, align: "center"});
columnsArray.push({field: "edgeId", title: "边设备ID", width: 145, colspan: 1, rowspan: 1, align: "center"});
columnsArray.push({field: "sensorId", title: "传感器ID", width: 145, colspan: 1, rowspan: 1, align: "center"});
columnsArray.push({field: "edgeId", title: "边设备ID", width: 160, colspan: 1, rowspan: 1, align: "center"});
columnsArray.push({field: "sensorId", title: "传感器ID", width: 160, colspan: 1, rowspan: 1, align: "center"});
columnsArray.push({
field: "sensorLocation",
title: "监测位置",
@ -45,10 +28,19 @@ const sensorInfoList = function (sensorTypeId) {
align: "center"
});
columnsArray.push({
field: "collectTime",
title: "时间",
width: 160,
colspan: 1,
rowspan: 1,
align: "center"
});
if (json.length > 0) {
for (let i = 0; i < (Object.keys(json[0])).length; i++) {//Object.keys(obj) 获取key名称
let property = (Object.keys(json[0]))[i];
if (property != "id" && property != "edgeId" && property != "sensorId" && property != 'sensorLocation' && property != 'datatype') {
if (property != "id" && property != "edgeId" && property != "sensorId" && property != 'sensorLocation' && property != 'datatype' && property != 'collectTime') {
columnsArray.push({
field: property,
title: sensorTypeArray.length == 0 ? property : sensorTypeArray.find(array => array.paramTitle === property).paramText,
@ -81,6 +73,30 @@ const sensorInfoList = function (sensorTypeId) {
})
}
const getparamsFunction = function (sensorTypeId) {
var returnData;
let formData = new FormData();
formData.append("sensorTypeId", sensorTypeId);
$.ajax({
type: "post",
url: "/base/sysParamConfig/getParameter",
data: formData,
contentType: "application/json;charset=utf-8",
dataType: "json",
json: 'callback',
processData: false,
contentType: false,
async: false,
success: function (json) {
returnData = json;
},
error: function () {
alert("错误");
}
});
return returnData;
}
const onSearchByMonitorLocation = function (obj) {
setTimeout(function () {
var storeId = document.getElementById('table');
@ -113,4 +129,21 @@ const onSearchBySensorId = function (obj) {
}
}
}, 500);
}
const onSearchByCollectTime = function (obj) {
setTimeout(function () {
var storeId = document.getElementById('table');
var rowsLength = storeId.rows.length;
var key = obj.value;
var searchCol = 4;
for (var i = 1; i < rowsLength; i++) {
var searchText = storeId.rows[i].cells[searchCol].innerHTML;
if (searchText.match(key)) {
storeId.rows[i].style.display = '';
} else {
storeId.rows[i].style.display = 'none';
}
}
}, 500);
}

@ -9,29 +9,6 @@
<link rel="stylesheet" th:href="@{/css/lot-ui/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/lot-ui/bootstrap-table.css}"/>
<link rel="stylesheet" th:href="@{/css/lot-ui/Iot-sensorSummaryStyle.css}"/>
<!--<style type="text/css">
div::-webkit-scrollbar {
/*滚动条整体样式*/
width: 5px;
/*高宽分别对应横竖滚动条的尺寸*/
height: 1px;
}
div::-webkit-scrollbar-thumb {
/*滚动条里面小方块*/
border-radius: 10px;
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
background: #004EA1;
}
div::-webkit-scrollbar-track {
/*滚动条里面轨道*/
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
border-radius: 10px;
background: #EDEDED;
}
</style>-->
</head>
<body>
<!--传感器类型-->
@ -53,8 +30,8 @@
<input type="text" class="form-control" onkeydown="onSearchBySensorId(this)" id="sensorId" name="sensorId"
placeholder="请输入传感器编号">
<!--<label class="search-label">传感器名称:</label>
<input type="text" class="form-control" id="sensor-name" name="sensor-name" placeholder="请输入传感器名称">-->
<label class="search-label">采集时间:</label>
<input type="text" class="form-control" onkeydown="onSearchByCollectTime(this)" id="collectTime" name="collectTime" placeholder="请输入采集时间">
</div>
</form>
</div>

@ -18,4 +18,9 @@ public class BaseSensorInfoDto extends BaseSensorInfo {
private BigDecimal[] maxValue;
private BigDecimal[] minValue;
/** 传感器实时上传数据 */
private String reportParam;
/** 数据采集时间 */
private String collectTime;
}

@ -59,4 +59,13 @@ public interface BaseSensorInfoMapper
* @return
*/
public int deleteBaseSensorInfoByObjIds(String[] objIds);
/**
*
* @author WenJY
* @date 2022/3/25 9:27
* @param sensorType
* @return java.util.List<com.ruoyi.system.domain.dto.BaseSensorInfoDto>
*/
public List<BaseSensorInfoDto> selectSensorDataListBySensorType(String sensorType);
}

@ -69,4 +69,13 @@ public interface IBaseSensorInfoService
* @return
*/
public int deleteBaseSensorInfoByObjId(Long objId);
/**
*
* @author WenJY
* @date 2022/3/25 9:27
* @param sensorType
* @return java.util.List<com.ruoyi.system.domain.dto.BaseSensorInfoDto>
*/
public List<BaseSensorInfoDto> selectSensorDataListBySensorType(String sensorType);
}

@ -157,4 +157,16 @@ public class BaseSensorInfoServiceImpl implements IBaseSensorInfoService
{
return baseSensorInfoMapper.deleteBaseSensorInfoByObjId(objId);
}
/**
*
* @author WenJY
* @date 2022/3/25 9:37
* @param sensorType
* @return java.util.List<com.ruoyi.system.domain.dto.BaseSensorInfoDto>
*/
@Override
public List<BaseSensorInfoDto> selectSensorDataListBySensorType(String sensorType) {
return baseSensorInfoMapper.selectSensorDataListBySensorType(sensorType);
}
}

@ -1,48 +1,65 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.BaseSensorInfoMapper">
<resultMap type="BaseSensorInfo" id="BaseSensorInfoResult">
<result property="objId" column="ObjId" />
<result property="edgeId" column="EdgeId" />
<result property="sensorId" column="Sensor_Id" />
<result property="sensorName" column="Sensor_Name" />
<result property="sensorType" column="Sensor_Type" />
<result property="sensorStatus" column="Sensor_Status" />
<result property="monitorunitId" column="MonitorUnit_Id" />
<result property="sensorLocation" column="Sensor_Location" />
<result property="sensorAddress" column="Sensor_Address" />
<result property="orderNum" column="Order_Num" />
<result property="enableFlag" column="Enable_Flag" />
<result property="createBy" column="Create_By" />
<result property="createTime" column="Create_Time" />
<result property="updateBy" column="Update_By" />
<result property="updateTime" column="Update_Time" />
<result property="objId" column="ObjId"/>
<result property="edgeId" column="EdgeId"/>
<result property="sensorId" column="Sensor_Id"/>
<result property="sensorName" column="Sensor_Name"/>
<result property="sensorType" column="Sensor_Type"/>
<result property="sensorStatus" column="Sensor_Status"/>
<result property="monitorunitId" column="MonitorUnit_Id"/>
<result property="sensorLocation" column="Sensor_Location"/>
<result property="sensorAddress" column="Sensor_Address"/>
<result property="orderNum" column="Order_Num"/>
<result property="enableFlag" column="Enable_Flag"/>
<result property="createBy" column="Create_By"/>
<result property="createTime" column="Create_Time"/>
<result property="updateBy" column="Update_By"/>
<result property="updateTime" column="Update_Time"/>
</resultMap>
<resultMap type="BaseSensorInfoDto" id="BaseSensorInfoDtoResult">
<result property="objId" column="ObjId" />
<result property="edgeId" column="EdgeId" />
<result property="sensorId" column="Sensor_Id" />
<result property="sensorName" column="Sensor_Name" />
<result property="sensorType" column="Sensor_Type" />
<result property="sensorStatus" column="Sensor_Status" />
<result property="monitorunitId" column="MonitorUnit_Id" />
<result property="sensorLocation" column="Sensor_Location" />
<result property="sensorAddress" column="Sensor_Address" />
<result property="orderNum" column="Order_Num" />
<result property="enableFlag" column="Enable_Flag" />
<result property="createBy" column="Create_By" />
<result property="createTime" column="Create_Time" />
<result property="updateBy" column="Update_By" />
<result property="updateTime" column="Update_Time" />
<result property="monitorunitName" column="MonitorUnit_Name" />
<result property="objId" column="ObjId"/>
<result property="edgeId" column="EdgeId"/>
<result property="sensorId" column="Sensor_Id"/>
<result property="sensorName" column="Sensor_Name"/>
<result property="sensorType" column="Sensor_Type"/>
<result property="sensorStatus" column="Sensor_Status"/>
<result property="monitorunitId" column="MonitorUnit_Id"/>
<result property="sensorLocation" column="Sensor_Location"/>
<result property="sensorAddress" column="Sensor_Address"/>
<result property="orderNum" column="Order_Num"/>
<result property="enableFlag" column="Enable_Flag"/>
<result property="createBy" column="Create_By"/>
<result property="createTime" column="Create_Time"/>
<result property="updateBy" column="Update_By"/>
<result property="updateTime" column="Update_Time"/>
<result property="monitorunitName" column="MonitorUnit_Name"/>
<result property="reportParam" column="Param"/>
<result property="collectTime" column="CollectTime"/>
</resultMap>
<sql id="selectBaseSensorInfoVo">
select ObjId, EdgeId, Sensor_Id, Sensor_Name, Sensor_Type, Sensor_Status, MonitorUnit_Id, Sensor_Location, Sensor_Address, Order_Num, Enable_Flag, Create_By, Create_Time, Update_By, Update_Time from base_sensor_info
select ObjId,
EdgeId,
Sensor_Id,
Sensor_Name,
Sensor_Type,
Sensor_Status,
MonitorUnit_Id,
Sensor_Location,
Sensor_Address,
Order_Num,
Enable_Flag,
Create_By,
Create_Time,
Update_By,
Update_Time
from base_sensor_info
</sql>
<select id="selectBaseSensorInfoList" parameterType="BaseSensorInfo" resultMap="BaseSensorInfoDtoResult">
@ -64,20 +81,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
t1.Update_Time
from base_sensor_info t1
left join base_monitorunit_info t2 on t1.MonitorUnit_Id = t2.MonitorUnit_Id
<where>
<if test="EdgeId != null and EdgeId != ''"> and t1.EdgeId = #{EdgeId}</if>
<if test="sensorId != null and sensorId != ''"> and t1.Sensor_Id = #{sensorId}</if>
<if test="sensorName != null and sensorName != ''"> and t1.Sensor_Name like concat('%', #{sensorName}, '%')</if>
<if test="sensorType != null and sensorType != ''"> and t1.Sensor_Type = #{sensorType}</if>
<if test="sensorStatus != null "> and t1.Sensor_Status = #{sensorStatus}</if>
<if test="monitorunitId != null and monitorunitId != ''"> and t1.MonitorUnit_Id = #{monitorunitId}</if>
<if test="sensorLocation != null and sensorLocation != ''"> and t1.Sensor_Location = #{sensorLocation}</if>
<if test="sensorAddress != null and sensorAddress != ''"> and t1.Sensor_Address = #{sensorAddress}</if>
<if test="orderNum != null "> and t1.Order_Num = #{orderNum}</if>
<if test="enableFlag != null "> and t1.Enable_Flag = #{enableFlag}</if>
<where>
<if test="EdgeId != null and EdgeId != ''">and t1.EdgeId = #{EdgeId}</if>
<if test="sensorId != null and sensorId != ''">and t1.Sensor_Id = #{sensorId}</if>
<if test="sensorName != null and sensorName != ''">and t1.Sensor_Name like concat('%', #{sensorName},
'%')
</if>
<if test="sensorType != null and sensorType != ''">and t1.Sensor_Type = #{sensorType}</if>
<if test="sensorStatus != null ">and t1.Sensor_Status = #{sensorStatus}</if>
<if test="monitorunitId != null and monitorunitId != ''">and t1.MonitorUnit_Id = #{monitorunitId}</if>
<if test="sensorLocation != null and sensorLocation != ''">and t1.Sensor_Location = #{sensorLocation}</if>
<if test="sensorAddress != null and sensorAddress != ''">and t1.Sensor_Address = #{sensorAddress}</if>
<if test="orderNum != null ">and t1.Order_Num = #{orderNum}</if>
<if test="enableFlag != null ">and t1.Enable_Flag = #{enableFlag}</if>
</where>
</select>
<select id="selectBaseSensorInfoByObjId" parameterType="Long" resultMap="BaseSensorInfoDtoResult">
select t1.ObjId,
t1.EdgeId,
@ -99,7 +118,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join base_monitorunit_info t2 on t1.MonitorUnit_Id = t2.MonitorUnit_Id
where t1.ObjId = #{objId}
</select>
<select id="selectSensorDataListBySensorType" parameterType="String" resultMap="BaseSensorInfoDtoResult">
select t1.EdgeId, t1.Sensor_Id, t1.Sensor_Type, t1.Sensor_Name, t2.Param, t2.CollectTime,t1.Sensor_Location
from base_sensor_info t1
left join record_upload t2 on t2.Sensor_Id = t1.Sensor_Id
where t1.Sensor_Type = #{sensorType}
and t2.Type = 'CMD_REPORTDATA'
and t2.Param is not null
and t2.CollectTime between DATE_FORMAT(now(), '%Y-%m-%d 00:00:00') and DATE_FORMAT(now(), '%Y-%m-%d 23:59:59');
</select>
<insert id="insertBaseSensorInfo" parameterType="BaseSensorInfo" useGeneratedKeys="true" keyProperty="objId">
insert into base_sensor_info
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -117,7 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">Create_Time,</if>
<if test="updateBy != null">Update_By,</if>
<if test="updateTime != null">Update_Time,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="EdgeId != null">#{EdgeId},</if>
<if test="sensorId != null">#{sensorId},</if>
@ -133,7 +162,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</trim>
</insert>
<update id="updateBaseSensorInfo" parameterType="BaseSensorInfo">
@ -158,11 +187,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteBaseSensorInfoByObjId" parameterType="Long">
delete from base_sensor_info where ObjId = #{objId}
delete
from base_sensor_info
where ObjId = #{objId}
</delete>
<delete id="deleteBaseSensorInfoByObjIds" parameterType="String">
delete from base_sensor_info where ObjId in
delete from base_sensor_info where ObjId in
<foreach item="objId" collection="array" open="(" separator="," close=")">
#{objId}
</foreach>

Loading…
Cancel
Save