Browse Source

1、主机系统参数报表导出、查询、编辑、定时执行存储过程

dev_mz
25604 2 weeks ago
parent
commit
3ee23dea5a
  1. 97
      mh-admin/src/main/java/com/mh/web/controller/report/ReportSysController.java
  2. 263
      mh-common/src/main/java/com/mh/common/core/domain/dto/MaglevReportSysParamDTO.java
  3. 288
      mh-common/src/main/java/com/mh/common/core/domain/entity/ReportSysRunParamHis.java
  4. 81
      mh-common/src/main/java/com/mh/common/utils/file/handle/ExcelFillCellMergeHandler.java
  5. 49
      mh-common/src/main/java/com/mh/common/utils/file/handle/ReportDayAndMonthParamHandler.java
  6. 46
      mh-common/src/main/java/com/mh/common/utils/file/handle/ReportSysParamHandler.java
  7. 25
      mh-common/src/main/java/com/mh/common/utils/file/handle/RowHeightStyleHandler.java
  8. 33
      mh-system/src/main/java/com/mh/system/mapper/report/ReportSysRunParamHisMapper.java
  9. 21
      mh-system/src/main/java/com/mh/system/service/report/IReportSysService.java
  10. 90
      mh-system/src/main/java/com/mh/system/service/report/impl/ReportSysServiceImpl.java

97
mh-admin/src/main/java/com/mh/web/controller/report/ReportSysController.java

@ -0,0 +1,97 @@
package com.mh.web.controller.report;
import com.alibaba.excel.EasyExcel;
import com.mh.common.core.controller.BaseController;
import com.mh.common.core.domain.AjaxResult;
import com.mh.common.core.domain.dto.MaglevReportSysParamDTO;
import com.mh.common.core.domain.entity.ReportSysRunParamHis;
import com.mh.common.core.page.TableDataInfo;
import com.mh.common.utils.StringUtils;
import com.mh.common.utils.file.handle.ExcelFillCellMergeHandler;
import com.mh.common.utils.file.handle.ReportSysParamHandler;
import com.mh.common.utils.file.handle.RowHeightStyleHandler;
import com.mh.system.service.report.IReportSysService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 系统参数报表
* @date 2024-05-30 08:45:57
*/
@RestController
@RequestMapping("/reportSys")
@Slf4j
public class ReportSysController extends BaseController {
private final IReportSysService reportSysService;
private ReportSysController(IReportSysService reportSysService) {
this.reportSysService = reportSysService;
}
@PostMapping("/list")
public TableDataInfo list(@RequestBody ReportSysRunParamHis reportSysRunParamHis)
{
startPage();
List<ReportSysRunParamHis> list = reportSysService.selectList(reportSysRunParamHis);
return getDataTable(list);
}
@PutMapping("/edit")
public AjaxResult edit(@RequestBody ReportSysRunParamHis reportSysRunParamHis)
{
return toAjax(reportSysService.updateSysRunParams(reportSysRunParamHis));
}
@PostMapping("/export")
public void exportExcel(@RequestBody ReportSysRunParamHis reportSysRunParamHis, HttpServletResponse response) {
// 文件名
try {
String fileName = "系统参数运行日志报表.xlsx";
String deviceNum = (String) reportSysRunParamHis.getParams().get("deviceNum");
if (!StringUtils.isBlank(deviceNum)) {
if ("2".equals(deviceNum)) {
fileName = "变频螺杆主机系统参数报表.xlsx";
} else {
fileName = "磁悬浮主机系统参数报表.xlsx";
}
}
// 从数据库获取数据
List<ReportSysRunParamHis> list = reportSysService.selectList(reportSysRunParamHis);
if (list != null) {
// 设置响应格式
response.setContentType("application/vdn.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileName, "UTF-8") + "\"");
response.setCharacterEncoding("UTF-8");
ExcelFillCellMergeHandler mergePrevCol = new ExcelFillCellMergeHandler();
int headSize = 3;
List<MaglevReportSysParamDTO> infoDTOS = list.stream().map(info -> {
MaglevReportSysParamDTO deviceInfoDTO = new MaglevReportSysParamDTO();
BeanUtils.copyProperties(info, deviceInfoDTO);
return deviceInfoDTO;
}).collect(Collectors.toList());
// 内容格式
EasyExcel.write(response.getOutputStream(), MaglevReportSysParamDTO.class)
.registerWriteHandler(new ReportSysParamHandler("磁悬浮水冷冷水机组数据运行记录表"))
.registerWriteHandler(mergePrevCol)
.registerWriteHandler(new RowHeightStyleHandler())
.sheet(fileName.replace(".xlsx", ""))
.doWrite(infoDTOS);
}
} catch (IOException e) {
throw new RuntimeException("下载报表异常");
}
}
}

263
mh-common/src/main/java/com/mh/common/core/domain/dto/MaglevReportSysParamDTO.java

@ -0,0 +1,263 @@
package com.mh.common.core.domain.dto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.BorderStyleEnum;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
//import java.math.String;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 磁悬浮主机系统参数报表
* @date 2024-05-30 11:00:12
*/
@Data
@NoArgsConstructor
@Accessors(chain = true)
@HeadRowHeight(25)
@HeadFontStyle(fontHeightInPoints = 14)
@ContentFontStyle(fontHeightInPoints = 13)
@ContentRowHeight(25)
@ContentStyle(
horizontalAlignment = HorizontalAlignmentEnum.CENTER,
borderBottom = BorderStyleEnum.THIN,
borderLeft = BorderStyleEnum.THIN,
borderRight = BorderStyleEnum.THIN,
borderTop = BorderStyleEnum.THIN
)
@ColumnWidth(10)
public class MaglevReportSysParamDTO {
/**
* 当前时间
*/
@ColumnWidth(17)
@ExcelProperty(value = {"${deviceType}", "时间", "时间"}, index = 0)
private String curTime;
// /**
// * 班次
// */
// @ColumnWidth(10)
// @ExcelProperty(value = {"${deviceType}", "班次", "班次"}, index = 1)
// private String classes;
/**
* 冷冻水进水温度
*/
@ColumnWidth(10)
@ExcelProperty(value = {"${deviceType}", "蒸发器", "冷冻水进水温度℃"}, index = 2)
private BigDecimal tempInChillerWater;
/**
* 冷冻水出水温度
*/
@ExcelProperty(value = {"${deviceType}", "蒸发器", "冷冻水出水温度℃"}, index = 3)
@ColumnWidth(10)
private BigDecimal tempOutChillerWater;
/**
* 设计流量%
*/
@ExcelProperty(value = {"${deviceType}", "蒸发器", "设计流量%"}, index = 4)
@ColumnWidth(10)
private BigDecimal designFlow;
/**
* 蒸发器压力kpa
*/
@ExcelProperty(value = {"${deviceType}", "蒸发器", "蒸发器压力kpa"}, index = 5)
@ColumnWidth(10)
private BigDecimal pressEvapSaturation;
/**
* 蒸发器饱和温度
*/
@ExcelProperty(value = {"${deviceType}", "蒸发器", "蒸发器饱和温度℃"}, index = 6)
@ColumnWidth(10)
private BigDecimal tempEvapSaturation;
/**
* 趋近温度
*/
@ExcelProperty(value = {"${deviceType}", "蒸发器", "趋近温度℃"}, index = 7)
@ColumnWidth(10)
private BigDecimal tempEvapApproaching;
/**
* 冷却水进水温度
*/
@ExcelProperty(value = {"${deviceType}", "冷凝器", "冷却水进水温度℃"}, index = 8)
@ColumnWidth(10)
private BigDecimal tempInCoolingWater;
/**
* 冷却水出水温度
*/
@ExcelProperty(value = {"${deviceType}", "冷凝器", "冷却水出水温度℃"}, index = 9)
@ColumnWidth(10)
private BigDecimal tempOutCoolingWater;
/**
* 冷凝器压力kpa
*/
@ExcelProperty(value = {"${deviceType}", "冷凝器", "冷凝器压力kpa"}, index = 10)
@ColumnWidth(10)
private BigDecimal pressCondenserSaturation;
/**
* 冷凝器饱和温度
*/
@ExcelProperty(value = {"${deviceType}", "冷凝器", "冷凝器饱和温度℃"}, index = 11)
@ColumnWidth(10)
private BigDecimal tempCondenserSaturation;
/**
* 冷凝器趋近温度
*/
@ExcelProperty(value = {"${deviceType}", "冷凝器", "趋近温度℃"}, index = 12)
@ColumnWidth(10)
private BigDecimal tempCondenserApproaching;
/**
* 冷冻水设定值
*/
@ExcelProperty(value = {"${deviceType}", "系统", "冷冻水设定值℃"}, index = 13)
@ColumnWidth(10)
private BigDecimal setChillerWater;
/**
* 冷水机需求%
*/
@ExcelProperty(value = {"${deviceType}", "系统", "冷水机需求%"}, index = 14)
@ColumnWidth(10)
private BigDecimal setLoad;
/**
* 总电流A
*/
@ExcelProperty(value = {"${deviceType}", "系统", "总电流A"}, index = 15)
@ColumnWidth(10)
private BigDecimal currentTotal;
/**
* 总输入功率kw
*/
@ExcelProperty(value = {"${deviceType}", "系统", "总输入功率kw"}, index = 16)
@ColumnWidth(10)
private BigDecimal inputPowerTotal;
/**
* 压缩比
*/
@ExcelProperty(value = {"${deviceType}", "系统", "压缩比"}, index = 17)
@ColumnWidth(10)
private BigDecimal ratioComp;
/**
* 膨胀阀开度%
*/
@ExcelProperty(value = {"${deviceType}", "系统", "膨胀阀开度%"}, index = 18)
@ColumnWidth(10)
private BigDecimal openExv;
/**
* 运行中的压缩机数量
*/
@ExcelProperty(value = {"${deviceType}", "系统", "运行中的压缩机数量"}, index = 19)
@ColumnWidth(10)
private Integer runCompNum;
/**
* 冷冻水泵频率hz
*/
@ExcelProperty(value = {"${deviceType}", "冷冻泵", "冷冻水泵频率hz"}, index = 20)
@ColumnWidth(10)
private BigDecimal frequencyChiller;
/**
* 冷冻水进水压力kpa
*/
@ExcelProperty(value = {"${deviceType}", "冷冻泵", "冷冻水进水压力kpa"}, index = 21)
@ColumnWidth(10)
private BigDecimal pressInChillerWater;
/**
* 冷冻水出水压力kpa
*/
@ExcelProperty(value = {"${deviceType}", "冷冻泵", "冷冻水出水压力kpa"}, index = 22)
@ColumnWidth(10)
private BigDecimal pressOutChillerWater;
/**
* 冷却水泵频率hz
*/
@ExcelProperty(value = {"${deviceType}", "冷却泵", "冷却水泵频率hz"}, index = 23)
@ColumnWidth(10)
private BigDecimal frequencyCooling;
/**
* 冷却水进水压力kpa
*/
@ExcelProperty(value = {"${deviceType}", "冷却泵", "冷却水进水压力kpa"}, index = 24)
@ColumnWidth(10)
private BigDecimal pressInCoolingWater;
/**
* 冷却水出水压力kpa
*/
@ExcelProperty(value = {"${deviceType}", "冷却泵", "冷却水出水压力kpa"}, index = 25)
@ColumnWidth(10)
private BigDecimal pressOutCoolingWater;
/**
* 冷却塔频率hz
*/
@ExcelProperty(value = {"${deviceType}", "冷却塔", "冷却塔频率hz"}, index = 26)
private BigDecimal frequencyCoolingTower;
/**
* 冷却塔运行数量原注释可能有误根据列名调整
*/
@ExcelProperty(value = {"${deviceType}", "冷却塔", "冷却塔运行数量"}, index = 27)
private Integer runCoolingTower;
/**
* 室外温度
*/
@ExcelProperty(value = {"${deviceType}", "室外温度℃", "室外温度℃"}, index = 28)
@ColumnWidth(10)
private BigDecimal tempOutdoor;
/**
* 室外湿度%
*/
@ExcelProperty(value = {"${deviceType}", "室外湿度%", "室外湿度%"}, index = 29)
@ColumnWidth(10)
private BigDecimal humidityOutdoor;
/**
* 恒压补水罐压力
*/
@ExcelProperty(value = {"${deviceType}", "恒压补水罐压力MPa", "恒压补水罐压力MPa"}, index = 30)
@ColumnWidth(10)
private BigDecimal pressConstantWaterTank;
/**
* 巡查记录人
*/
@ExcelProperty(value = {"${deviceType}", "巡查记录人", "巡查记录人"}, index = 31)
@ColumnWidth(20)
private String recorder;
}

288
mh-common/src/main/java/com/mh/common/core/domain/entity/ReportSysRunParamHis.java

@ -0,0 +1,288 @@
package com.mh.common.core.domain.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.mh.common.core.domain.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.Map;
/**
* @author LJF
* @version 1.0
* @project EEMCS
* @description 系统参数设备运行历史记录
* @date 2025-08-12 10:44:36
*/
@Data
@TableName("report_sys_run_param_his")
public class ReportSysRunParamHis extends BaseEntity {
/**
* 自增主键
*/
@Id
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 主机id
*/
private String hostId;
/**
* 日期
*/
private LocalDate curDate;
/**
* 时间格式建议与数据库存储一致 "HH:mm:ss" "yyyy-MM-dd HH:mm:ss"
*/
private String curTime;
// /**
// * 班次
// */
// private String classes;
/**
* 冷冻水进水温度
*/
private BigDecimal tempInChillerWater;
/**
* 冷冻水出水温度
*/
private BigDecimal tempOutChillerWater;
/**
* 设计流量%修正列名 "design flow" 含空格
*/
private BigDecimal designFlow;
/**
* 蒸发器压力kpa--磁悬浮
*/
private BigDecimal pressEvapSaturation;
/**
* 蒸发器饱和温度
*/
private BigDecimal tempEvapSaturation;
/**
* 蒸发器趋近温度
*/
private BigDecimal tempEvapApproaching;
/**
* 冷却水进水温度
*/
private BigDecimal tempInCoolingWater;
/**
* 冷却水出水温度
*/
private BigDecimal tempOutCoolingWater;
/**
* 冷凝器压力kpa--磁悬浮
*/
private BigDecimal pressCondenserSaturation;
/**
* 冷凝器饱和温度
*/
private BigDecimal tempCondenserSaturation;
/**
* 冷凝器趋近温度
*/
private BigDecimal tempCondenserApproaching;
/**
* 冷冻水设定值
*/
private BigDecimal setChillerWater;
/**
* 冷水机需求%
*/
private BigDecimal setLoad;
/**
* 总电流%
*/
private BigDecimal currentTotal;
/**
* 总输入功率kw
*/
private BigDecimal inputPowerTotal;
/**
* 压缩比
*/
private BigDecimal ratioComp;
/**
* 膨胀阀开度%
*/
private BigDecimal openExv;
/**
* 运行中的压缩机数量
*/
private Integer runCompNum;
/**
* 冷冻水泵频率hz
*/
private BigDecimal frequencyChiller;
/**
* 冷冻水出水压力kpa
*/
private BigDecimal pressOutChillerWater;
/**
* 冷冻水进水压力kpa
*/
private BigDecimal pressInChillerWater;
/**
* 冷却水泵频率hz
*/
private BigDecimal frequencyCooling;
/**
* 冷却水出水压力kpa
*/
private BigDecimal pressOutCoolingWater;
/**
* 冷却水进水压力kpa
*/
private BigDecimal pressInCoolingWater;
/**
* 冷却塔水泵频率hz
*/
private BigDecimal frequencyCoolingTower;
/**
* 冷却塔运行数量原注释可能有误根据列名调整
*/
private Integer runCoolingTower;
/**
* 恒压补水罐压力
*/
private BigDecimal pressConstantWaterTank;
/**
* 室外温度
*/
private BigDecimal tempOutdoor;
/**
* 室外湿度%
*/
private BigDecimal humidityOutdoor;
/**
* 巡查记录人
*/
private String recorder;
/**
* 备注
*/
private String remark;
@JsonIgnore
@TableField(exist = false)
private String searchValue;
/**
* 请求参数
*/
@TableField(exist = false)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> params;
/** 创建者 */
@TableField(exist = false)
private String createBy;
/** 创建时间 */
@TableField(exist = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新者 */
@TableField(exist = false)
private String updateBy;
/** 更新时间 */
@TableField(exist = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", id)
.append("hostId", hostId)
.append("curDate", curDate)
.append("curTime", curTime)
.append("tempInChillerWater", tempInChillerWater)
.append("tempOutChillerWater", tempOutChillerWater)
.append("designFlow", designFlow)
.append("pressEvapSaturation", pressEvapSaturation)
.append("tempEvapSaturation", tempEvapSaturation)
.append("tempEvapApproaching", tempEvapApproaching)
.append("tempInCoolingWater", tempInCoolingWater)
.append("tempOutCoolingWater", tempOutCoolingWater)
.append("pressCondenserSaturation", pressCondenserSaturation)
.append("tempCondenserSaturation", tempCondenserSaturation)
.append("tempCondenserApproaching", tempCondenserApproaching)
.append("setChillerWater", setChillerWater)
.append("setLoad", setLoad)
.append("currentTotal", currentTotal)
.append("inputPowerTotal", inputPowerTotal)
.append("ratioComp", ratioComp)
.append("openExv", openExv)
.append("runCompNum", runCompNum)
.append("frequencyChiller", frequencyChiller)
.append("pressOutChillerWater", pressOutChillerWater)
.append("pressInChillerWater", pressInChillerWater)
.append("frequencyCooling", frequencyCooling)
.append("pressOutCoolingWater", pressOutCoolingWater)
.append("pressInCoolingWater", pressInCoolingWater)
.append("frequencyCoolingTower", frequencyCoolingTower)
.append("runCoolingTower", runCoolingTower)
.append("pressConstantWaterTank", pressConstantWaterTank)
.append("recorder", recorder)
.append("remark", remark)
.append("searchValue", searchValue)
.append("params", params)
.append("createBy", createBy)
.append("createTime", createTime)
.append("updateBy", updateBy)
.append("updateTime", updateTime)
.toString();
}
}

81
mh-common/src/main/java/com/mh/common/utils/file/handle/ExcelFillCellMergeHandler.java

@ -0,0 +1,81 @@
package com.mh.common.utils.file.handle;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 列合并
* @date 2024-06-03 10:01:07
*/
public class ExcelFillCellMergeHandler implements CellWriteHandler {
private static final String KEY ="%s-%s";
//所有的合并信息都存在了这个map里面
Map<String, Integer> mergeInfo = new HashMap<>();
public ExcelFillCellMergeHandler() {
}
public ExcelFillCellMergeHandler(Map<String, Integer> mergeInfo) {
this.mergeInfo = mergeInfo;
}
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) {
}
@Override
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean aBoolean) {
}
@Override
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//当前行
int curRowIndex = cell.getRowIndex();
//当前列
int curColIndex = cell.getColumnIndex();
Integer num = mergeInfo.get(String.format(KEY, curRowIndex, curColIndex));
if(null != num){
// 合并最后一行 ,列
mergeWithPrevCol(writeSheetHolder, cell, curRowIndex, curColIndex,num);
}
}
public void mergeWithPrevCol(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex, int num) {
Sheet sheet = writeSheetHolder.getSheet();
CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex, curRowIndex, curColIndex, curColIndex + num);
sheet.addMergedRegion(cellRangeAddress);
}
//num从第几列开始增加多少列
// curRowIndex 在第几行进行行合并
// curColIndex 在第几列进行合并
// num 合并多少格
// 比如我上图中中心需要在第三行 从0列开始合并三列 所以我可以传入 (3,0,2)
public void add (int curRowIndex, int curColIndex , int num){
mergeInfo.put(String.format(KEY, curRowIndex, curColIndex),num);
}
}

49
mh-common/src/main/java/com/mh/common/utils/file/handle/ReportDayAndMonthParamHandler.java

@ -0,0 +1,49 @@
package com.mh.common.utils.file.handle;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.util.PropertyPlaceholderHelper;
import java.util.List;
import java.util.Properties;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 报表handle
* @date 2024-05-31 17:36:38
*/
public class ReportDayAndMonthParamHandler implements CellWriteHandler {
private final String title;
private final String value;
PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}");
public ReportDayAndMonthParamHandler(String value, String title) {
this.title = title;
this.value = value;
}
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) {
if (head != null) {
List<String> headNameList = head.getHeadNameList();
if (CollectionUtils.isNotEmpty(headNameList)) {
Properties properties = new Properties();
properties.setProperty(title, value);
for (int i = 0; i < headNameList.size(); i++) {
headNameList.set(i, placeholderHelper.replacePlaceholders(headNameList.get(i), properties));
}
}
}
}
}

46
mh-common/src/main/java/com/mh/common/utils/file/handle/ReportSysParamHandler.java

@ -0,0 +1,46 @@
package com.mh.common.utils.file.handle;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.util.PropertyPlaceholderHelper;
import java.util.List;
import java.util.Properties;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 报表handle
* @date 2024-05-31 17:36:38
*/
public class ReportSysParamHandler implements CellWriteHandler {
private final String title;
PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}");
public ReportSysParamHandler(String title) {
this.title = title;
}
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) {
if (head != null) {
List<String> headNameList = head.getHeadNameList();
if (CollectionUtils.isNotEmpty(headNameList)) {
Properties properties = new Properties();
properties.setProperty("deviceType", title);
for (int i = 0; i < headNameList.size(); i++) {
headNameList.set(i, placeholderHelper.replacePlaceholders(headNameList.get(i), properties));
}
}
}
}
}

25
mh-common/src/main/java/com/mh/common/utils/file/handle/RowHeightStyleHandler.java

@ -0,0 +1,25 @@
package com.mh.common.utils.file.handle;
import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import org.apache.poi.ss.usermodel.Row;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 处理行高
* @date 2024-08-09 15:03:37
*/
public class RowHeightStyleHandler extends AbstractRowHeightStyleStrategy {
@Override
protected void setHeadColumnHeight(Row row, int i) {
if (i == 2) {
row.setHeightInPoints(70);
}
}
@Override
protected void setContentColumnHeight(Row row, int i) {
}
}

33
mh-system/src/main/java/com/mh/system/mapper/report/ReportSysRunParamHisMapper.java

@ -0,0 +1,33 @@
package com.mh.system.mapper.report;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mh.common.core.domain.entity.ReportSysRunParamHis;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.StatementType;
import java.util.List;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 系统运行参数服务类
* @date 2024-05-29 11:23:32
*/
@Mapper
public interface ReportSysRunParamHisMapper extends BaseMapper<ReportSysRunParamHis> {
@Select("exec pro_sys_run_param #{deviceNum,jdbcType=VARCHAR,mode=IN},#{curTime,jdbcType=VARCHAR,mode=IN} ")
@Options(statementType = StatementType.CALLABLE)
void execProSysRunParamHis(@Param("deviceNum") String deviceNum,
@Param("curTime") String curTime);
@Select("select * from report_sys_run_param_his where device_num = #{deviceNum} " +
" and cur_time >= #{beginDate} and cur_time <= #{endDate} order by cur_time desc ")
List<ReportSysRunParamHis> findPage(@Param("deviceNum") String deviceNum,
@Param("beginDate") String beginDate,
@Param("endDate") String endDate);
}

21
mh-system/src/main/java/com/mh/system/service/report/IReportSysService.java

@ -0,0 +1,21 @@
package com.mh.system.service.report;
import com.mh.common.core.domain.entity.ReportSysRunParamHis;
import java.util.List;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 报表服务类
* @date 2024-05-29 11:20:30
*/
public interface IReportSysService {
void execProSysRunParamHis();
List<ReportSysRunParamHis> selectList(ReportSysRunParamHis reportSysRunParamHis);
int updateSysRunParams(ReportSysRunParamHis reportSysRunParamHis);
}

90
mh-system/src/main/java/com/mh/system/service/report/impl/ReportSysServiceImpl.java

@ -0,0 +1,90 @@
package com.mh.system.service.report.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mh.common.core.domain.entity.ReportSysRunParamHis;
import com.mh.common.utils.StringUtils;
import com.mh.system.mapper.report.ReportSysRunParamHisMapper;
import com.mh.system.service.report.IReportSysService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 系统报表服务类实现
* @date 2024-05-29 11:21:12
*/
@Slf4j
@Service
public class ReportSysServiceImpl implements IReportSysService {
@Resource
ReportSysRunParamHisMapper reportSysRunParamHisMapper;
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public int updateSysRunParams(ReportSysRunParamHis reportSysRunParamHis) {
return reportSysRunParamHisMapper.updateById(reportSysRunParamHis);
}
@Override
public void execProSysRunParamHis() {
try {
log.info("执行计算系统参数存储过程");
// 获取上一个小时的时间
// 获取当前日期和时间
LocalDateTime now = LocalDateTime.now();
// 获取一小时前的日期和时间
LocalDateTime oneHourAgo = now.minusHours(1);
// 格式化日期和时间
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedOneHourAgo = oneHourAgo.format(formatter);
// 固定写死三号主机
// reportSysRunParamHisMapper.execProSysRunParamHis("2", formattedOneHourAgo.substring(0, 13));
reportSysRunParamHisMapper.execProSysRunParamHis("3", formattedOneHourAgo.substring(0, 13));
log.info("执行计算系统参数执行完成");
} catch (Exception e) {
log.error("执行计算系统参数存储过程执行失败", e);
throw new RuntimeException(e);
}
}
@Override
public List<ReportSysRunParamHis> selectList(ReportSysRunParamHis reportSysRunParamHis) {
String deviceNum = reportSysRunParamHis.getHostId();
if (StringUtils.isEmpty(deviceNum)) {
// 默认3号主机
deviceNum = "3";
}
if (reportSysRunParamHis.getParams() == null) {
reportSysRunParamHis.setParams(new java.util.HashMap<>());
}
String startTime = (String) reportSysRunParamHis.getParams().get("startTime");
String endTime = (String) reportSysRunParamHis.getParams().get("endTime");
if (StringUtils.isBlank(startTime)) {
LocalDateTime now = LocalDateTime.now();
startTime = now.format(dateTimeFormatter).substring(0, 10);
endTime = now.format(dateTimeFormatter).substring(0, 10);
}
startTime = startTime + " 00";
endTime = endTime + " 23";
return reportSysRunParamHisMapper.selectList(
new QueryWrapper<ReportSysRunParamHis>()
.between("cur_time", startTime, endTime)
.eq("host_id", deviceNum)
.orderByDesc("cur_time"));
}
}
Loading…
Cancel
Save