add - 传感器历史数据查询

main
wenjy 3 years ago
parent 41aa48aa17
commit 3f051af871

@ -0,0 +1,65 @@
package com.ruoyi.web.controller.record;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.system.domain.dto.BaseSensorInfoDto;
import com.ruoyi.system.service.IRecordSensorDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
*
*
* @author WenJY
* @date 20220407 16:20
*/
@Controller
@RequestMapping("/record/recordSensorData")
public class RecordSensorDataController {
@Autowired private IRecordSensorDataService iRecordSensorDataService;
private String prefix = "record/recordSensorData";
@GetMapping("/getPage")
public String recordSensorData(@RequestParam("id") String id, ModelMap mmap) {
mmap.put("sensorId", id);
return prefix + "/recordSensorData";
}
@PostMapping("/list")
@ResponseBody
public String _getList(BaseSensorInfoDto baseSensorInfoDto) {
baseSensorInfoDto.setTableName("record_" + baseSensorInfoDto.getSensorType());
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, -5);
date = calendar.getTime();
Map<String, Object> paramMap = new HashMap<String, Object>();
if (baseSensorInfoDto.getBeginCollectTime() == null) {
paramMap.put("beginCollectTime", date);
} else {
paramMap.put("beginCollectTime", baseSensorInfoDto.getBeginCollectTime());
}
if (baseSensorInfoDto.getEndCollectTime() == null) {
paramMap.put("endCollectTime", new Date());
} else {
paramMap.put("endCollectTime", baseSensorInfoDto.getEndCollectTime());
}
baseSensorInfoDto.setParams(paramMap);
List<Map<String, Object>> maps =
iRecordSensorDataService.selectSensorDataList(baseSensorInfoDto);
return JSONArray.toJSONString(maps);
}
}

@ -53,6 +53,20 @@ const sensorInfoList = function (sensorTypeId) {
});
columnsArray.push({field: "edgeId", title: "边设备ID", width: 180,height: 60, colspan: 1, rowspan: 1, align: "center"});
columnsArray.push({
title: "操作",
width: 100,
colspan: 1,
rowspan: 1,
align: "center",
height: 60,
formatter: function(value, row, index) {
var actions = [];
actions.push('<button style="width: 70px;height: 22px;background-color: #1C84C6;border: 1px solid #1C84C6;border-radius:3px;color: white;" onclick="historyButton(\'' + row.sensorId+","+row.datatype + '\')" ><i class="fa fa-edit"></i>历史数据</button> ');
return actions.join('');
}
});
}
$('#table').bootstrapTable('destroy');
@ -106,7 +120,7 @@ const onSearchByMonitorLocation = function (obj) {
var storeId = document.getElementById('table');
var rowsLength = storeId.rows.length;
var key = obj.value;
var searchCol = storeId.rows.item(0).cells.length-3;
var searchCol = storeId.rows.item(0).cells.length-4;
for (var i = 1; i < rowsLength; i++) {
var searchText = storeId.rows[i].cells[searchCol].innerHTML;
if (searchText.match(key)) {
@ -140,7 +154,7 @@ const onSearchByCollectTime = function (obj) {
var storeId = document.getElementById('table');
var rowsLength = storeId.rows.length;
var key = obj.value;
var searchCol = storeId.rows.item(0).cells.length-2;
var searchCol = storeId.rows.item(0).cells.length-3;
for (var i = 1; i < rowsLength; i++) {
var searchText = storeId.rows[i].cells[searchCol].innerHTML;
if (searchText.match(key)) {
@ -151,3 +165,7 @@ const onSearchByCollectTime = function (obj) {
}
}, 500);
}
const historyButton = function(id) {
location.href = '/record/recordSensorData/getPage?id='+id;
}

@ -0,0 +1,142 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('历史记录')" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
<input type="hidden" id="sensorId" name="sensorId"/>
</li>
<li class="select-time">
<label>采集时间:</label>
<input type="text" class="time-input" id="startTime" placeholder="开始时间"
name="beginCollectTime"/>
<span>-</span>
<input type="text" class="time-input" id="endTime" placeholder="结束时间"
name="endCollectTime"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="tableRefresh()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<!-- <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="record:recordAlarm:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="record:recordAlarm:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="record:recordAlarm:remove">
<i class="fa fa-remove"></i> 删除
</a>-->
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="record:recordAlarm:export">
<i class="fa fa-download"></i> 导出
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
var prefix = ctx + "record/recordSensorData";
$(()=>{
tableRefresh();
})
const tableRefresh = function() {
let sensorId = [[${sensorId}]].split(",");
let formData = new FormData();
formData.append("sensorId",sensorId[0]);
formData.append("sensorType",sensorId[1]);
formData.append("beginCollectTime",$("#startTime").val());
formData.append("endCollectTime",$("#endTime").val());
$.ajax({
type: "post",
url: "/record/recordSensorData/list",
contentType: "application/json;charset=utf-8",
dataType: "json",
data: formData,
json: 'callback',
processData: false,
contentType: false,
success: function (json) {
const columnsArray = [];
if (json.length > 0) {
const jsonObj = Object.keys(json[0]);
for (let i = 0; i < jsonObj.length; i++) {//Object.keys(obj) key
let property = jsonObj[i];
if(property != "设备编号" && property != "采集时间"){
columnsArray.push({
field: property,
title: property,
width: 140,
align: "center"
});
}
}
}
$('#bootstrap-table').bootstrapTable('destroy');
$('#bootstrap-table').bootstrapTable({
data: json,
striped:true,
cache:false,
pageNumber: 1,
pagination: true,
showColumns:true,
sidePagination: 'client',
pageSize: 10,
pageList: [5, 10, 15, 20, 25, 50],
showRefresh: true,
columns: columnsArray
});
columnsArray.push();
},
error: function () {
alert("错误");
}
})
}
<!-- laydate示例 -->
layui.use('laydate', function () {
var laydate = layui.laydate;
laydate.render({
elem: '#startTime',
type: 'datetime',
trigger: 'click'
});
laydate.render({
elem: '#endTime',
type: 'datetime',
trigger: 'click'
});
});
</script>
</body>
</html>

@ -2,8 +2,10 @@ package com.ruoyi.system.domain.dto;
import com.ruoyi.system.domain.BaseSensorInfo;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author WenJY
@ -23,4 +25,13 @@ public class BaseSensorInfoDto extends BaseSensorInfo {
private String reportParam;
/** 数据采集时间 */
private String collectTime;
private String tableName;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date beginCollectTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endCollectTime;
}

@ -0,0 +1,16 @@
package com.ruoyi.system.mapper;
import com.ruoyi.system.domain.dto.BaseSensorInfoDto;
import java.util.List;
import java.util.Map;
/**
*
* @author WenJY
* @date 20220407 16:24
*/
public interface RecordSensorDataMapper {
List<Map<String, Object>> selectSensorDataList(BaseSensorInfoDto baseSensorInfoDto);
}

@ -0,0 +1,16 @@
package com.ruoyi.system.service;
import com.ruoyi.system.domain.dto.BaseSensorInfoDto;
import java.util.List;
import java.util.Map;
/**
* @author WenJY
* @date 20220407 16:23
*/
public interface IRecordSensorDataService {
List<Map<String, Object>> selectSensorDataList(BaseSensorInfoDto baseSensorInfoDto);
}

@ -0,0 +1,28 @@
package com.ruoyi.system.service.impl;
import com.ruoyi.system.domain.dto.BaseSensorInfoDto;
import com.ruoyi.system.mapper.RecordSensorDataMapper;
import com.ruoyi.system.service.IRecordSensorDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
*
* @author WenJY
* @date 20220407 16:23
*/
@Service
public class RecordSensorDataServiceImpl implements IRecordSensorDataService {
@Autowired
private RecordSensorDataMapper recordSensorDataMapper;
@Override
public List<Map<String, Object>> selectSensorDataList(BaseSensorInfoDto baseSensorInfoDto) {
System.out.println("打印表名:"+baseSensorInfoDto.getTableName());
return recordSensorDataMapper.selectSensorDataList(baseSensorInfoDto);
}
}

@ -0,0 +1,39 @@
<?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">
<mapper namespace="com.ruoyi.system.mapper.RecordSensorDataMapper">
<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="reportParam" column="Param"/>
<result property="collectTime" column="CollectTime"/>
<result property="tableName" column="tableName"/>
</resultMap>
<select id="selectSensorDataList" fetchSize="50000" parameterType="BaseSensorInfoDto" resultType="map">
select * from ${tableName}
<where>
<if test="sensorId != null and sensorId != ''">and sensorId = #{sensorId}</if>
<if test="params.beginCollectTime != null and params.endCollectTime != null ">and collectTime between #{params.beginCollectTime} and #{params.endCollectTime}
</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save