From 642ed4e3020e71d8fa1693a952cfb894e033b1ba Mon Sep 17 00:00:00 2001 From: qinjie <463333974@qq.com> Date: Thu, 12 Dec 2024 14:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DeviceController.java | 17 +++++ .../com/isu/gaswellwatch/dao/DeviceDao.java | 6 ++ .../gaswellwatch/service/DeviceService.java | 3 + .../service/impl/DeviceServiceImpl.java | 58 +++++++++++++++++ .../vo/DeviceHistoryDataExportVO.java | 63 +++++++++++++++++++ .../command/etc/CasPressureOptimization.java | 9 +++ .../vo/command/etc/TimingMode.java | 10 +++ .../command/etc/TubPressureOptimization.java | 6 ++ .../vo/command/scss/SamplingInterval.java | 4 +- src/main/resources/mapper/DeviceDao.xml | 27 ++++++-- 10 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/isu/gaswellwatch/vo/DeviceHistoryDataExportVO.java diff --git a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java index 355c901..d947644 100644 --- a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java +++ b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java @@ -11,6 +11,7 @@ import com.isu.gaswellwatch.exception.BusinessException; import com.isu.gaswellwatch.service.DeviceService; import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceVO; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -125,6 +126,22 @@ public class DeviceController { } } + /** + * 设备历史数据导出 + */ + @GetMapping("/exportHistoryData") + @OperationLog(description = "设备历史数据导出",type = LogType.EXPORT) + public void exportHistoryData(HttpServletResponse response, + @RequestParam Long deviceId, + @RequestParam String startTime, + @RequestParam String endTime) { + try{ + deviceService.exportHistoryData(response,deviceId, startTime, endTime); + } catch (ParseException e) { + throw new BusinessException("日期格式错误"); + } + } + } diff --git a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java index c586d4e..e7570d4 100644 --- a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java +++ b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java @@ -43,5 +43,11 @@ public interface DeviceDao extends BaseMapper { List getPressureChartData(Long deviceId, String startTime, String endTime, String tableName); List getSwitchStatusData(Long deviceId, String startTime, String endTime, String tableName,String deviceProduct); + + List getDeviceHistoryData(@Param("startTime")Date startTime, + @Param("endTime")Date endTime, + @Param("deviceId") Long deviceId, + @Param("tableName") String tableName, + @Param("deviceProduct") String deviceProduct); } diff --git a/src/main/java/com/isu/gaswellwatch/service/DeviceService.java b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java index c5305b0..416c962 100644 --- a/src/main/java/com/isu/gaswellwatch/service/DeviceService.java +++ b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java @@ -8,6 +8,7 @@ import com.isu.gaswellwatch.entity.Device; import com.isu.gaswellwatch.entity.DeviceOptLog; import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceVO; +import jakarta.servlet.http.HttpServletResponse; import java.text.ParseException; import java.util.List; @@ -36,5 +37,7 @@ public interface DeviceService extends IService { List getPressureChartData(Long deviceId, String startTime, String endTime); List getSwitchStatusData(Long deviceId, String startTime, String endTime,String deviceProduct); + + void exportHistoryData(HttpServletResponse response, Long deviceId, String startTime, String endTime) throws ParseException; } diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java index ca229ff..b4cc41d 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java @@ -1,6 +1,7 @@ package com.isu.gaswellwatch.service.impl; import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -22,15 +23,21 @@ import com.isu.gaswellwatch.service.DeviceService; import com.isu.gaswellwatch.service.DictionaryService; import com.isu.gaswellwatch.service.GasWellService; import com.isu.gaswellwatch.utils.ConverterUtil; +import com.isu.gaswellwatch.vo.DeviceHistoryDataExportVO; import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceVO; +import com.isu.gaswellwatch.vo.UserOperationRecordExportVO; import jakarta.annotation.Resource; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -223,6 +230,57 @@ public class DeviceServiceImpl extends ServiceImpl implements return deviceDao.getSwitchStatusData(deviceId,startTime,endTime,tableName,deviceProduct); } + @Override + public void exportHistoryData(HttpServletResponse response, Long deviceId, String startTime, String endTime) throws ParseException { + String tableName = Redis2DBPersistenceService.DEFAULT_DATA_TABLE + deviceId; + Date start = null; + Date end = null; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + if (!StringUtils.isEmpty(startTime)) { + start = simpleDateFormat.parse(startTime); + } + if (!StringUtils.isEmpty(endTime)) { + end = simpleDateFormat.parse(endTime); + } + //判断设备品牌 + DeviceVO device = this.getDevice(deviceId); + List list = this.deviceDao.getDeviceHistoryData(start, end,deviceId,tableName,device.getProduct().getCode()); + + if (CollectionUtil.isNotEmpty(list)) { + Map runModeMap = this.dictionaryService.getValueMapByType("runMode"); + if(PersistenceHandler.ETC_MODBUS_TYPE.equalsIgnoreCase(device.getProduct().getCode())){ + runModeMap = this.dictionaryService.getValueMapByType("controlMode"); + }else if(PersistenceHandler.SCSS_MODBUS_TYPE.equalsIgnoreCase(device.getProduct().getCode())){ + runModeMap = this.dictionaryService.getValueMapByType("ctlMode"); + } + Map plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus"); + + for (DeviceHistoryVO deviceVO : list) { + deviceVO.setRunMode(StringUtils.isEmpty(deviceVO.getRunMode()) ? "" : runModeMap.get(deviceVO.getRunMode()).getName()); + deviceVO.setPlugStatus(StringUtils.isEmpty(deviceVO.getPlugStatus()) ? "" : plugStatusMap.get(deviceVO.getPlugStatus()).getName()); + } + } + + List export = ConverterUtil.convert(list, DeviceHistoryDataExportVO.class); + + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = null; + try { + ServletOutputStream outputStream = response.getOutputStream(); + fileName = URLEncoder.encode(device.getGasWell().getName()+"|"+simpleDateFormat.format(new Date()), StandardCharsets.UTF_8).replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + EasyExcel.write(outputStream) + // 这里放入动态头 + .head(DeviceHistoryDataExportVO.class).sheet("data") + // 当然这里数据也可以用 List> 去传入 + .doWrite(export); + } catch (Exception e) { + log.error(e.getMessage()); + } + + } + @Override public Page getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException { diff --git a/src/main/java/com/isu/gaswellwatch/vo/DeviceHistoryDataExportVO.java b/src/main/java/com/isu/gaswellwatch/vo/DeviceHistoryDataExportVO.java new file mode 100644 index 0000000..5a44f07 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/DeviceHistoryDataExportVO.java @@ -0,0 +1,63 @@ +package com.isu.gaswellwatch.vo; +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DeviceHistoryDataExportVO { + + + /** 采集时间 */ + @ExcelProperty(value = "采集时间") + private String collectionTime; + + /** 油压 */ + @ExcelProperty(value = "油压") + private String oilPressure; + + /** 套压 */ + @ExcelProperty(value = "套压") + private String casPressure; + + /** 输压 */ + @ExcelProperty(value = "输压") + private String prePressure; + + /** 运行模式 */ + @ExcelProperty(value = "运行模式") + private String runMode; + + /** 柱塞状态 */ + @ExcelProperty(value = "柱塞状态") + private String plugStatus; + + /** 气井状态 */ + @ExcelProperty(value = "气井状态") + private String wellStatus; + + /** 倒计时 */ + @ExcelProperty(value = "倒计时") + private String statusEndTime; + + /** 温度 */ + @ExcelProperty(value = "温度") + private String temperature; + + /** 湿度 */ + @ExcelProperty(value = "湿度") + private String humidity; + + /** 太阳能电压 */ + @ExcelProperty(value = "太阳能电压") + private String solarVoltage; + + + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/CasPressureOptimization.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/CasPressureOptimization.java index 3b2b6b4..6257925 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/etc/CasPressureOptimization.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/CasPressureOptimization.java @@ -3,6 +3,8 @@ package com.isu.gaswellwatch.vo.command.etc; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; import lombok.experimental.SuperBuilder; @@ -37,36 +39,43 @@ public class CasPressureOptimization extends Command implements Timing { * 套压PSI比例 * 262 */ + @NotNull(message = "套压PSI比例不能为空") private BigDecimal casPressureSensorRange; /** * 开井套压 * 263 */ + @NotNull(message = "开井套压不能为空") private BigDecimal openCasPressure; /** * 复位套压 * 264 */ + @NotNull(message = "复位套压不能为空") private BigDecimal openResetCasPressure; /** * 稳定时间 * 265-267 */ + @NotBlank(message = "稳定时间不能为空") private String openCasPressureStableTime; /** * 关井套压 * 279 */ + @NotNull(message = "关井套压不能为空") private BigDecimal closeCasPressure; /** * 跳闸套压 * 280 */ + @NotNull(message = "跳闸套压不能为空") private BigDecimal closeTripCasPressure; /** * 稳定时长 * 281-283 */ + @NotBlank(message = "稳定时长不能为空") private String closeCasPressureStableTime; public CasPressureOptimization() { diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/TimingMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TimingMode.java index 53181b6..200c3ed 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/etc/TimingMode.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TimingMode.java @@ -3,6 +3,8 @@ package com.isu.gaswellwatch.vo.command.etc; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; import lombok.experimental.SuperBuilder; @@ -29,43 +31,51 @@ public class TimingMode extends Command implements Timing { * 最小关井时长 * 100 -> 3 */ + @NotBlank(message = "最小关井时长不能为空") private String minCloseWellTime; /** * 目标上升时长 * 106 -> 3 */ + @NotBlank(message = "目标上升时长不能为空") private String plungerRiseTime; /** * 最小开井时长 * 121 -> 3 */ + @NotBlank(message = "最小开井时长不能为空") private String minOpenWellTime; /** * 最大开井时长 * 130 -> 3 */ + @NotBlank(message = "最大开井时长不能为空") private String maxOpenWellTime; /** * 最大关井时长 * 136 -> 3 */ + @NotBlank(message = "最大关井时长不能为空") private String maxCloseWellTime; /** * 柱塞未到达关井时长 * 到达传感器延时时间 * 139 -> 3 */ + @NotBlank(message = "柱塞未到达关井时长不能为空") private String arrivalSensorDelayTime; /** * 关井时长 * 142 -> 3 */ + @NotBlank(message = "关井时长不能为空") private String wellShutInTime; /** * 开井时长 * 续流时间 * 145 -> 3 */ + @NotBlank(message = "开井时长不能为空") private String afterFlowTime; public TimingMode() { diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/TubPressureOptimization.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TubPressureOptimization.java index 5b80199..a0879d2 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/etc/TubPressureOptimization.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TubPressureOptimization.java @@ -3,6 +3,8 @@ package com.isu.gaswellwatch.vo.command.etc; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; import lombok.experimental.SuperBuilder; @@ -32,18 +34,22 @@ public class TubPressureOptimization extends Command implements Timing { /** * 套压PSI比例 */ + @NotNull(message = "套压PSI比例不能为空") private BigDecimal tubPressureSensorRange; /** * 开井油压 */ + @NotNull(message = "开井油压不能为空") private BigDecimal openTubPressure; /** * 复位油压 */ + @NotNull(message = "复位油压不能为空") private BigDecimal openResetTubPressure; /** * 稳定时间 */ + @NotNull(message = "稳定时间不能为空") private String openTubPressureStableTime; public TubPressureOptimization() { diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/SamplingInterval.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/SamplingInterval.java index ae51bbe..e031856 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/scss/SamplingInterval.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/SamplingInterval.java @@ -45,8 +45,8 @@ public class SamplingInterval extends Command { @Override public boolean validate() { return super.validate() - && this.continuousSamplingIntervalDuration > 0 - && this.sensorSignalEffectiveLevel.compareTo(BigDecimal.ZERO) > 0; + && this.continuousSamplingIntervalDuration >= 0 + && this.sensorSignalEffectiveLevel.compareTo(BigDecimal.ZERO) >= 0; } @Override diff --git a/src/main/resources/mapper/DeviceDao.xml b/src/main/resources/mapper/DeviceDao.xml index 41922f1..a585062 100644 --- a/src/main/resources/mapper/DeviceDao.xml +++ b/src/main/resources/mapper/DeviceDao.xml @@ -77,10 +77,10 @@ from ${tableName} t t.device_id = #{deviceId} - + and t.collection_time >= #{startTime} - + and t.collection_time <= #{endTime} @@ -131,15 +131,34 @@ from ${tableName} t t.device_id = #{deviceId} - + and t.collection_time >= #{startTime} - + and t.collection_time <= #{endTime} order by t.collection_time asc + + +