Merge remote-tracking branch 'origin/master'

master
suixy 4 days ago
commit 5b2047b7f9

@ -0,0 +1,57 @@
package com.ruoyi.web.controller.system;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TVibrationSensorHourlyReport;
import com.ruoyi.system.service.ITVibrationSensorHourlyReportService;
/**
*
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/TVibrationSensorHourlyReport")
public class TVibrationSensorHourlyReportController extends BaseController {
private final String prefix = "system/TVibrationSensorHourlyReport";
@Autowired
private ITVibrationSensorHourlyReportService tVibrationSensorHourlyReportService;
@GetMapping()
public String index() {
return prefix + "/TVibrationSensorHourlyReport";
}
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(TVibrationSensorHourlyReport query) {
startPage();
List<TVibrationSensorHourlyReport> list = tVibrationSensorHourlyReportService.selectTVibrationSensorHourlyReportList(query);
return getDataTable(list);
}
@Log(title = "振动传感器整点报表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(TVibrationSensorHourlyReport query) {
List<TVibrationSensorHourlyReport> list = tVibrationSensorHourlyReportService.selectTVibrationSensorHourlyReportList(query);
ExcelUtil<TVibrationSensorHourlyReport> util = new ExcelUtil<>(TVibrationSensorHourlyReport.class);
return util.exportExcel(list, "振动传感器整点报表");
}
}

@ -0,0 +1,229 @@
<!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('振动传感器整点报表')" />
<th:block th:include="include :: layout-latest-css"/>
<th:block th:include="include :: ztree-css"/>
<th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
<div class="box box-main">
<div class="box-header">
<div class="box-title">
<i class="fa icon-grid"></i> 测控点信息
</div>
<div class="box-tools pull-right">
<a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="测控点信息"><i
class="fa fa-edit"></i></a>
<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
class="fa fa-chevron-up"></i></button>
<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
class="fa fa-chevron-down"></i></button>
<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i>
</button>
</div>
</div>
<div class="ui-layout-content">
<div id="tree" class="ztree"></div>
</div>
</div>
</div>
<div class="ui-layout-center">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<input type="hidden" id="sensorId" name="sensorId">
<div class="select-list">
<ul>
<li class="select-time">
<label>采集时间:</label>
<input type="text" style="width: 150px" class="form-control" id="laydate-demo-3" placeholder="开始时间" name="params[beginCollectTime]"/>
<span>-</span>
<input type="text" style="width: 150px" class="form-control" id="laydate-demo-4" placeholder="结束时间" name="params[endCollectTime]"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><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-warning" onclick="$.table.exportExcel()" >
<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>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
var prefix = ctx + "system/TVibrationSensorHourlyReport";
$(function () {
var panehHidden = false;
if ($(this).width() < 769) {
panehHidden = true;
}
$('body').layout({initClosed: panehHidden, west__size: 245});
initDefaultCollectTime();
queryUserList();
queryDeptTree();
$.table.search();
});
function initDefaultCollectTime() {
var now = new Date();
var start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
var end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 0, 0);
$("#laydate-demo-3").val(formatDateTime(start));
$("#laydate-demo-4").val(formatDateTime(end));
}
function formatDateTime(date) {
var y = date.getFullYear();
var m = String(date.getMonth() + 1).padStart(2, '0');
var d = String(date.getDate()).padStart(2, '0');
var hh = String(date.getHours()).padStart(2, '0');
var mm = String(date.getMinutes()).padStart(2, '0');
var ss = String(date.getSeconds()).padStart(2, '0');
return y + '-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss;
}
function queryUserList() {
var options = {
url: prefix + "/list",
exportUrl: prefix + "/export",
modalName: "振动传感器整点报表",
columns: [{
field: 'objId',
title: '主键',
visible: false
},
{
field: 'monitorName',
title: '测点名称'
},
{
field: 'sensorId',
title: '传感器ID'
},
{
field: 'reportTime',
title: '报表小时',
formatter: function (value, row, index) {
if (!value) {
return '';
}
var dt = new Date(value.replace(/-/g, '/'));
if (isNaN(dt.getTime())) {
return value;
}
var y = dt.getFullYear();
var m = String(dt.getMonth() + 1).padStart(2, '0');
var d = String(dt.getDate()).padStart(2, '0');
var hh = String(dt.getHours()).padStart(2, '0');
return y + '-' + m + '-' + d + ' ' + hh + ':00:00';
}
},
{
field: 'collectTime',
title: '采集时间',
visible: false
},
{
field: 'speed',
title: '速度(mm/s)'
},
{
field: 'displacement',
title: '位移(um)'
},
{
field: 'acceleration',
title: '加速度(g)'
},
{
field: 'temperature',
title: '温度(℃)'
},
{
field: 'recodeTime',
title: '写入时间',
visible: false
},
{
field: 'remark',
title: '备注'
}]
};
$.table.init(options);
}
function queryDeptTree() {
var url = ctx + "system/Monitor/treeData?monitorType=" + 20;
var options = {
url: url,
expandLevel: 1,
onClick: zOnClick
};
$.tree.init(options);
function zOnClick(event, treeId, treeNode) {
$("#sensorId").val(treeNode.id);
$.table.search();
}
}
$('#btnExpand').click(function () {
$._tree.expandAll(true);
$(this).hide();
$('#btnCollapse').show();
});
$('#btnCollapse').click(function () {
$._tree.expandAll(false);
$(this).hide();
$('#btnExpand').show();
});
$('#btnRefresh').click(function () {
queryDeptTree();
});
function dept() {
var url = ctx + "system/Monitor?id=20";
$.modal.openTab("测控点信息", url);
}
layui.use('laydate', function () {
var laydate = layui.laydate;
laydate.render({
elem: '#laydate-demo-3',
type: 'datetime',
trigger: 'click'
});
laydate.render({
elem: '#laydate-demo-4',
type: 'datetime',
trigger: 'click'
});
});
</script>
</body>
</html>

@ -6,6 +6,7 @@
<th:block th:include="include :: ztree-css"/>
<th:block th:include="include :: datetimepicker-css"/>
</head>
<style>
.chartDiv {
width: 16%;
@ -132,7 +133,6 @@
});
let time1 = null
let time2 = null
function queryDeptTree() {
var url = ctx + "system/Monitor/treeData?monitorType=" + 20;
@ -151,7 +151,8 @@
function onCheck(event, treeId, treeNode) {
const intervalFun = () => {
$.post(ctx + 'system/TVibrationsensorData/realTimeMonitor', {sensorId: $.tree.getCheckedNodes()}, (e) => {
var checkedIds = getCheckedSensorIds();
$.post(ctx + 'system/TVibrationsensorData/realTimeMonitor', {sensorId: checkedIds}, (e) => {
let data = e.data || []
// let data = [{}, {}, {}]
@ -173,13 +174,13 @@
}
intervalFun()
if (time2) {
clearInterval(time2)
time2 = null
if (time1) {
clearInterval(time1)
time1 = null
}
time1 = setInterval(() => {
intervalFun()
}, 1000 * 60)
}, 10000)
}
function zOnClick(event, treeId, treeNode) {
@ -374,10 +375,26 @@
})
}
})
}, 5000 * 1000)
}, 10000)
}
}
// 兼容后端逗号分隔参数将选中的树节点ID拼成 "id1,id2,id3"
function getCheckedSensorIds() {
var treeObj = $.fn.zTree.getZTreeObj("tree");
if (!treeObj) {
return "";
}
var checkedNode = treeObj.getCheckedNodes(true);
var ids = [];
checkedNode.forEach(function (node) {
if (node && node.id !== undefined && node.id !== null && node.id !== "") {
ids.push(node.id);
}
});
return ids.join(",");
}
</script>
</body>

@ -0,0 +1,146 @@
package com.ruoyi.system.domain;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* T_VibrationSensor_Hourly_Report
*
* @author ruoyi
*/
public class TVibrationSensorHourlyReport extends BaseEntity {
private static final long serialVersionUID = 1L;
private Long objId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "报表小时", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date reportTime;
@Excel(name = "振动传感器ID")
private String sensorId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "采集时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date collectTime;
@Excel(name = "速度(mm/s)")
private BigDecimal speed;
@Excel(name = "位移(um)")
private BigDecimal displacement;
@Excel(name = "加速度(g)")
private BigDecimal acceleration;
@Excel(name = "温度(℃)")
private BigDecimal temperature;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "记录时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date recodeTime;
private String monitorName;
public String getMonitorName() {
return monitorName;
}
public void setMonitorName(String monitorName) {
this.monitorName = monitorName;
}
public Long getObjId() {
return objId;
}
public void setObjId(Long objId) {
this.objId = objId;
}
public Date getReportTime() {
return reportTime;
}
public void setReportTime(Date reportTime) {
this.reportTime = reportTime;
}
public String getSensorId() {
return sensorId;
}
public void setSensorId(String sensorId) {
this.sensorId = sensorId;
}
public Date getCollectTime() {
return collectTime;
}
public void setCollectTime(Date collectTime) {
this.collectTime = collectTime;
}
public BigDecimal getSpeed() {
return speed;
}
public void setSpeed(BigDecimal speed) {
this.speed = speed;
}
public BigDecimal getDisplacement() {
return displacement;
}
public void setDisplacement(BigDecimal displacement) {
this.displacement = displacement;
}
public BigDecimal getAcceleration() {
return acceleration;
}
public void setAcceleration(BigDecimal acceleration) {
this.acceleration = acceleration;
}
public BigDecimal getTemperature() {
return temperature;
}
public void setTemperature(BigDecimal temperature) {
this.temperature = temperature;
}
public Date getRecodeTime() {
return recodeTime;
}
public void setRecodeTime(Date recodeTime) {
this.recodeTime = recodeTime;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("objId", getObjId())
.append("reportTime", getReportTime())
.append("sensorId", getSensorId())
.append("collectTime", getCollectTime())
.append("speed", getSpeed())
.append("displacement", getDisplacement())
.append("acceleration", getAcceleration())
.append("temperature", getTemperature())
.append("recodeTime", getRecodeTime())
.append("remark", getRemark())
.toString();
}
}

@ -0,0 +1,24 @@
package com.ruoyi.system.mapper;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.system.domain.TVibrationSensorHourlyReport;
/**
* Mapper
*
* @author ruoyi
*/
public interface TVibrationSensorHourlyReportMapper {
List<TVibrationSensorHourlyReport> selectTVibrationSensorHourlyReportList(TVibrationSensorHourlyReport query);
/**
* SQL Server 便
*
* @param hourEnd null
*/
void insertHourlyReportByProcedure(@Param("hourEnd") Date hourEnd);
}

@ -0,0 +1,17 @@
package com.ruoyi.system.service;
import java.util.Date;
import java.util.List;
import com.ruoyi.system.domain.TVibrationSensorHourlyReport;
/**
* Service
*
* @author ruoyi
*/
public interface ITVibrationSensorHourlyReportService {
List<TVibrationSensorHourlyReport> selectTVibrationSensorHourlyReportList(TVibrationSensorHourlyReport query);
}

@ -0,0 +1,30 @@
package com.ruoyi.system.service.impl;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.domain.TVibrationSensorHourlyReport;
import com.ruoyi.system.mapper.TVibrationSensorHourlyReportMapper;
import com.ruoyi.system.service.ITVibrationSensorHourlyReportService;
/**
* Service
*
* @author ruoyi
*/
@Service
public class TVibrationSensorHourlyReportServiceImpl implements ITVibrationSensorHourlyReportService {
@Autowired
private TVibrationSensorHourlyReportMapper tVibrationSensorHourlyReportMapper;
@Override
public List<TVibrationSensorHourlyReport> selectTVibrationSensorHourlyReportList(TVibrationSensorHourlyReport query) {
return tVibrationSensorHourlyReportMapper.selectTVibrationSensorHourlyReportList(query);
}
}

@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
import java.util.*;
import java.text.SimpleDateFormat;
import java.util.stream.Collectors;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
@ -91,6 +92,14 @@ public class TVibrationsensorDataServiceImpl implements ITVibrationsensorDataSer
@Override
public List<TVibrationsensorData> selectRealTimeMonitor(TVibrationsensorData tVibrationsensorData) {
String sensorId = tVibrationsensorData.getSensorId();
if (StringUtils.isNotBlank(sensorId)) {
List<String> sensorIdList = Arrays.stream(sensorId.split(","))
.map(String::trim)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
tVibrationsensorData.getParams().put("sensorIdList", sensorIdList);
}
return tVibrationsensorDataMapper.selectRealTimeMonitor(tVibrationsensorData);
}

@ -0,0 +1,55 @@
<?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.TVibrationSensorHourlyReportMapper">
<resultMap type="TVibrationSensorHourlyReport" id="TVibrationSensorHourlyReportResult">
<result property="objId" column="objId"/>
<result property="reportTime" column="reportTime"/>
<result property="sensorId" column="sensor_id"/>
<result property="collectTime" column="collectTime"/>
<result property="speed" column="speed"/>
<result property="displacement" column="displacement"/>
<result property="acceleration" column="acceleration"/>
<result property="temperature" column="temperature"/>
<result property="recodeTime" column="recodeTime"/>
<result property="remark" column="remark"/>
<result property="monitorName" column="monitorName"/>
</resultMap>
<select id="selectTVibrationSensorHourlyReportList" parameterType="TVibrationSensorHourlyReport"
resultMap="TVibrationSensorHourlyReportResult">
select m.monitorName,
r.objId,
r.reportTime,
r.sensor_id,
r.collectTime,
r.speed,
r.displacement,
r.acceleration,
r.temperature,
r.recodeTime,
r.remark
from T_VibrationSensor_Hourly_Report r
left join T_Monitor m on m.monitorId = r.sensor_id
<where>
<if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
and r.collectTime between #{params.beginCollectTime} and #{params.endCollectTime}
</if>
<if test="params.beginReportTime != null and params.beginReportTime != '' and params.endReportTime != null and params.endReportTime != ''">
and r.reportTime between #{params.beginReportTime} and #{params.endReportTime}
</if>
<if test="sensorId != null and sensorId != ''">and r.sensor_id = #{sensorId}</if>
<if test="speed != null">and r.speed = #{speed}</if>
<if test="displacement != null">and r.displacement = #{displacement}</if>
<if test="acceleration != null">and r.acceleration = #{acceleration}</if>
<if test="temperature != null">and r.temperature = #{temperature}</if>
</where>
order by r.reportTime desc, r.sensor_id
</select>
<select id="insertHourlyReportByProcedure" statementType="CALLABLE">
{call dbo.sp_InsertVibrationSensorHourlyReport(#{hourEnd, jdbcType=TIMESTAMP, mode=IN})}
</select>
</mapper>

@ -114,8 +114,11 @@
FROM T_VibrationSensor_Data
WHERE 1=1
-- AND collectTime > (GETDATE() - 1)
<if test="sensorId != null and sensorId != ''">
and sensor_id in (select monitorId from T_Monitor where monitorId like concat(#{sensorId}, '%'))
<if test="params.sensorIdList != null and params.sensorIdList.size() > 0">
and sensor_id in
<foreach collection="params.sensorIdList" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
)
SELECT m.monitorName, t.*

@ -0,0 +1,238 @@
/*
1. dbo.sp_InsertVibrationSensorHourlyReport
sensor_id T_VibrationSensor_Data collectTime objId
2. reportTime 2025-03-23 09:00:00 [09:00, 10:00)
3. 使 SQL Server Quartz
-
- [DATEADD(hour,-1,@EndExclusive), @EndExclusive)
*/
IF OBJECT_ID(N'dbo.T_VibrationSensor_Hourly_Report', N'U') IS NULL
BEGIN
CREATE TABLE dbo.T_VibrationSensor_Hourly_Report
(
objId BIGINT IDENTITY
CONSTRAINT PK_T_VibrationSensor_Hourly_Report PRIMARY KEY,
reportTime DATETIME NOT NULL,
sensor_id NVARCHAR(64) NOT NULL,
collectTime DATETIME NULL,
speed DECIMAL(18, 2) NULL,
displacement DECIMAL(18, 2) NULL,
acceleration DECIMAL(18, 2) NULL,
temperature DECIMAL(18, 2) NULL,
recodeTime DATETIME NOT NULL CONSTRAINT DF_T_VibrationSensor_Hourly_Report_recodeTime DEFAULT GETDATE(),
remark VARCHAR(64) NULL,
CONSTRAINT UQ_T_VibrationSensor_Hourly_Report_hour_sensor UNIQUE (reportTime, sensor_id)
);
CREATE NONCLUSTERED INDEX IX_T_VibrationSensor_Hourly_Report_reportTime
ON dbo.T_VibrationSensor_Hourly_Report (reportTime DESC);
EXEC sp_addextendedproperty N'MS_Description', N'振动传感器整点报表(每小时末条采集)', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report';
EXEC sp_addextendedproperty N'MS_Description', N'主键', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'objId';
EXEC sp_addextendedproperty N'MS_Description', N'报表归属小时(该小时起点)', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'reportTime';
EXEC sp_addextendedproperty N'MS_Description', N'振动传感器ID', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'sensor_id';
EXEC sp_addextendedproperty N'MS_Description', N'该小时内末条记录的采集时间', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'collectTime';
EXEC sp_addextendedproperty N'MS_Description', N'速度(mm/s)', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'speed';
EXEC sp_addextendedproperty N'MS_Description', N'位移(um)', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'displacement';
EXEC sp_addextendedproperty N'MS_Description', N'加速度(g)', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'acceleration';
EXEC sp_addextendedproperty N'MS_Description', N'温度(℃)', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'temperature';
EXEC sp_addextendedproperty N'MS_Description', N'写入报表时间', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'recodeTime';
EXEC sp_addextendedproperty N'MS_Description', N'备注', N'SCHEMA', N'dbo', N'TABLE', N'T_VibrationSensor_Hourly_Report', N'COLUMN', N'remark';
END
GO
IF OBJECT_ID(N'dbo.sp_InsertVibrationSensorHourlyReport', N'P') IS NOT NULL
DROP PROCEDURE dbo.sp_InsertVibrationSensorHourlyReport;
GO
CREATE PROCEDURE dbo.sp_InsertVibrationSensorHourlyReport
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
DECLARE @EndExclusive DATETIME = DATEADD(HOUR, DATEDIFF(HOUR, 0, GETDATE()), 0);
DECLARE @StartInclusive DATETIME = DATEADD(HOUR, -1, @EndExclusive);
DECLARE @ReportTime DATETIME = @StartInclusive;
;WITH Ranked AS (
SELECT d.objId,
d.sensor_id,
d.collectTime,
d.speed,
d.displacement,
d.acceleration,
d.temperature,
d.remark,
ROW_NUMBER() OVER (
PARTITION BY d.sensor_id
ORDER BY d.collectTime DESC, d.objId DESC
) AS rn
FROM dbo.T_VibrationSensor_Data d
WHERE d.collectTime >= @StartInclusive
AND d.collectTime < @EndExclusive
)
INSERT INTO dbo.T_VibrationSensor_Hourly_Report (reportTime, sensor_id, collectTime, speed, displacement,
acceleration, temperature, recodeTime, remark)
SELECT @ReportTime,
r.sensor_id,
@ReportTime,
r.speed,
r.displacement,
r.acceleration,
r.temperature,
@ReportTime,
r.remark
FROM Ranked r
WHERE r.rn = 1
AND NOT EXISTS (
SELECT 1
FROM dbo.T_VibrationSensor_Hourly_Report x
WHERE x.reportTime = @ReportTime
AND x.sensor_id = r.sensor_id
);
-- 清理原始明细:删除 recodeTime 三个月前的数据
DELETE FROM dbo.T_VibrationSensor_Data
WHERE recodeTime < DATEADD(MONTH, -3, @EndExclusive);
END
GO
IF NOT EXISTS (
SELECT 1
FROM sys.extended_properties ep
WHERE ep.class = 1
AND ep.major_id = OBJECT_ID(N'dbo.sp_InsertVibrationSensorHourlyReport')
AND ep.minor_id = 0
AND ep.name = N'MS_Description'
)
EXEC sp_addextendedproperty N'MS_Description',
N'按小时汇总振动温度:无入参,固定按当前整点回算上一小时,取各传感器 collectTime 最后一条写入整点报表。',
N'SCHEMA', N'dbo', N'PROCEDURE', N'sp_InsertVibrationSensorHourlyReport';
ELSE
EXEC sp_updateextendedproperty N'MS_Description',
N'按小时汇总振动温度:无入参,固定按当前整点回算上一小时,取各传感器 collectTime 最后一条写入整点报表。',
N'SCHEMA', N'dbo', N'PROCEDURE', N'sp_InsertVibrationSensorHourlyReport';
GO
/*
--------------------------------------------------------------------
menu_id / parent_id
-- 目录或菜单 Curl = /system/TVibrationSensorHourlyReport
-- perms: system:TVibrationSensorHourlyReport:view / list / export
INSERT INTO sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, remark)
VALUES (N'振动整点报表', <ID>, 10, N'/system/TVibrationSensorHourlyReport', N'C', N'0', N'system:TVibrationSensorHourlyReport:view', N'fa fa-table', N'admin', GETDATE(), N'');
-- 将返回的 menu_id 记入 @mid再插入按钮权限 F
-- system:TVibrationSensorHourlyReport:list
-- system:TVibrationSensorHourlyReport:export
--------------------------------------------------------------------
*/
/*
--------------------------------------------------------------------
SQL Server SSMS
USE msdb;
GO
EXEC dbo.sp_add_job
@job_name = N'振动传感器整点报表',
@enabled = 1,
@description = N'每小时执行 sp_InsertVibrationSensorHourlyReport';
GO
EXEC dbo.sp_add_jobstep
@job_name = N'振动传感器整点报表',
@step_name = N'写入整点报表',
@subsystem = N'TSQL',
@database_name = N'你的数据库名',
@command = N'EXEC dbo.sp_InsertVibrationSensorHourlyReport;',
@retry_attempts = 2,
@retry_interval = 5;
GO
EXEC dbo.sp_add_schedule
@schedule_name = N'每小时整点',
@freq_type = 4,
@freq_interval = 1,
@freq_subday_type = 8,
@freq_subday_interval = 1,
@active_start_time = 0;
GO
EXEC dbo.sp_attach_schedule
@job_name = N'振动传感器整点报表',
@schedule_name = N'每小时整点';
GO
EXEC dbo.sp_add_jobserver
@job_name = N'振动传感器整点报表';
GO
@active_start_time = 0 00:00:00 1 freq_subday
SSMS EXEC
--------------------------------------------------------------------
*/
/*
--------------------------------------------------------------------
1) 00:00 ~ 2 1
2) reportTime + sensor_id
--------------------------------------------------------------------
*/
DECLARE @TodayStart DATETIME = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0);
DECLARE @CurrentHour DATETIME = DATEADD(HOUR, DATEDIFF(HOUR, 0, GETDATE()), 0);
;WITH H AS (
SELECT @TodayStart AS reportTime
UNION ALL
SELECT DATEADD(HOUR, 1, reportTime)
FROM H
WHERE DATEADD(HOUR, 1, reportTime) < @CurrentHour
),
S AS (
SELECT N'VS-001' AS sensor_id
UNION ALL
SELECT N'VS-002'
),
R AS (
SELECT
h.reportTime,
s.sensor_id,
h.reportTime AS collectTime,
CAST((ABS(CHECKSUM(NEWID())) % 1200) / 100.0 AS DECIMAL(18, 2)) AS speed,
CAST((ABS(CHECKSUM(NEWID())) % 5000) / 100.0 AS DECIMAL(18, 2)) AS displacement,
CAST((ABS(CHECKSUM(NEWID())) % 300) / 100.0 AS DECIMAL(18, 2)) AS acceleration,
CAST((ABS(CHECKSUM(NEWID())) % 7000) / 100.0 AS DECIMAL(18, 2)) AS temperature
FROM H h
CROSS JOIN S s
)
INSERT INTO dbo.T_VibrationSensor_Hourly_Report
(
reportTime, sensor_id, collectTime, speed, displacement, acceleration, temperature, recodeTime, remark
)
SELECT
r.reportTime,
r.sensor_id,
r.collectTime,
r.speed,
r.displacement,
r.acceleration,
r.temperature,
r.reportTime,
N'随机测试数据'
FROM R r
WHERE NOT EXISTS (
SELECT 1
FROM dbo.T_VibrationSensor_Hourly_Report x
WHERE x.reportTime = r.reportTime
AND x.sensor_id = r.sensor_id
)
OPTION (MAXRECURSION 1000);
GO
Loading…
Cancel
Save