提交代码

This commit is contained in:
qinjie 2024-12-12 14:52:02 +08:00
parent a32a910873
commit 642ed4e302
10 changed files with 197 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.service.DeviceService; import com.isu.gaswellwatch.service.DeviceService;
import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceHistoryVO;
import com.isu.gaswellwatch.vo.DeviceVO; import com.isu.gaswellwatch.vo.DeviceVO;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; 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("日期格式错误");
}
}
} }

View File

@ -43,5 +43,11 @@ public interface DeviceDao extends BaseMapper<Device> {
List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime, String tableName); List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime, String tableName);
List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime, String tableName,String deviceProduct); List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime, String tableName,String deviceProduct);
List<DeviceHistoryVO> getDeviceHistoryData(@Param("startTime")Date startTime,
@Param("endTime")Date endTime,
@Param("deviceId") Long deviceId,
@Param("tableName") String tableName,
@Param("deviceProduct") String deviceProduct);
} }

View File

@ -8,6 +8,7 @@ import com.isu.gaswellwatch.entity.Device;
import com.isu.gaswellwatch.entity.DeviceOptLog; import com.isu.gaswellwatch.entity.DeviceOptLog;
import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceHistoryVO;
import com.isu.gaswellwatch.vo.DeviceVO; import com.isu.gaswellwatch.vo.DeviceVO;
import jakarta.servlet.http.HttpServletResponse;
import java.text.ParseException; import java.text.ParseException;
import java.util.List; import java.util.List;
@ -36,5 +37,7 @@ public interface DeviceService extends IService<Device> {
List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime); List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime);
List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime,String deviceProduct); List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime,String deviceProduct);
void exportHistoryData(HttpServletResponse response, Long deviceId, String startTime, String endTime) throws ParseException;
} }

View File

@ -1,6 +1,7 @@
package com.isu.gaswellwatch.service.impl; package com.isu.gaswellwatch.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.DictionaryService;
import com.isu.gaswellwatch.service.GasWellService; import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.utils.ConverterUtil; import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.DeviceHistoryDataExportVO;
import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceHistoryVO;
import com.isu.gaswellwatch.vo.DeviceVO; import com.isu.gaswellwatch.vo.DeviceVO;
import com.isu.gaswellwatch.vo.UserOperationRecordExportVO;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -223,6 +230,57 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
return deviceDao.getSwitchStatusData(deviceId,startTime,endTime,tableName,deviceProduct); 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<DeviceHistoryVO> list = this.deviceDao.getDeviceHistoryData(start, end,deviceId,tableName,device.getProduct().getCode());
if (CollectionUtil.isNotEmpty(list)) {
Map<String, Dictionary> 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<String, Dictionary> 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<DeviceHistoryDataExportVO> 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<List<String>> 去传入
.doWrite(export);
} catch (Exception e) {
log.error(e.getMessage());
}
}
@Override @Override
public Page<DeviceHistoryVO> getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException { public Page<DeviceHistoryVO> getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException {

View File

@ -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;
}

View File

@ -3,6 +3,8 @@ package com.isu.gaswellwatch.vo.command.etc;
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Command;
import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.Timing;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
@ -37,36 +39,43 @@ public class CasPressureOptimization extends Command implements Timing {
* 套压PSI比例 * 套压PSI比例
* 262 * 262
*/ */
@NotNull(message = "套压PSI比例不能为空")
private BigDecimal casPressureSensorRange; private BigDecimal casPressureSensorRange;
/** /**
* 开井套压 * 开井套压
* 263 * 263
*/ */
@NotNull(message = "开井套压不能为空")
private BigDecimal openCasPressure; private BigDecimal openCasPressure;
/** /**
* 复位套压 * 复位套压
* 264 * 264
*/ */
@NotNull(message = "复位套压不能为空")
private BigDecimal openResetCasPressure; private BigDecimal openResetCasPressure;
/** /**
* 稳定时间 * 稳定时间
* 265-267 * 265-267
*/ */
@NotBlank(message = "稳定时间不能为空")
private String openCasPressureStableTime; private String openCasPressureStableTime;
/** /**
* 关井套压 * 关井套压
* 279 * 279
*/ */
@NotNull(message = "关井套压不能为空")
private BigDecimal closeCasPressure; private BigDecimal closeCasPressure;
/** /**
* 跳闸套压 * 跳闸套压
* 280 * 280
*/ */
@NotNull(message = "跳闸套压不能为空")
private BigDecimal closeTripCasPressure; private BigDecimal closeTripCasPressure;
/** /**
* 稳定时长 * 稳定时长
* 281-283 * 281-283
*/ */
@NotBlank(message = "稳定时长不能为空")
private String closeCasPressureStableTime; private String closeCasPressureStableTime;
public CasPressureOptimization() { public CasPressureOptimization() {

View File

@ -3,6 +3,8 @@ package com.isu.gaswellwatch.vo.command.etc;
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Command;
import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.Timing;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
@ -29,43 +31,51 @@ public class TimingMode extends Command implements Timing {
* 最小关井时长 * 最小关井时长
* 100 -> 3 * 100 -> 3
*/ */
@NotBlank(message = "最小关井时长不能为空")
private String minCloseWellTime; private String minCloseWellTime;
/** /**
* 目标上升时长 * 目标上升时长
* 106 -> 3 * 106 -> 3
*/ */
@NotBlank(message = "目标上升时长不能为空")
private String plungerRiseTime; private String plungerRiseTime;
/** /**
* 最小开井时长 * 最小开井时长
* 121 -> 3 * 121 -> 3
*/ */
@NotBlank(message = "最小开井时长不能为空")
private String minOpenWellTime; private String minOpenWellTime;
/** /**
* 最大开井时长 * 最大开井时长
* 130 -> 3 * 130 -> 3
*/ */
@NotBlank(message = "最大开井时长不能为空")
private String maxOpenWellTime; private String maxOpenWellTime;
/** /**
* 最大关井时长 * 最大关井时长
* 136 -> 3 * 136 -> 3
*/ */
@NotBlank(message = "最大关井时长不能为空")
private String maxCloseWellTime; private String maxCloseWellTime;
/** /**
* 柱塞未到达关井时长 * 柱塞未到达关井时长
* 到达传感器延时时间 * 到达传感器延时时间
* 139 -> 3 * 139 -> 3
*/ */
@NotBlank(message = "柱塞未到达关井时长不能为空")
private String arrivalSensorDelayTime; private String arrivalSensorDelayTime;
/** /**
* 关井时长 * 关井时长
* 142 -> 3 * 142 -> 3
*/ */
@NotBlank(message = "关井时长不能为空")
private String wellShutInTime; private String wellShutInTime;
/** /**
* 开井时长 * 开井时长
* 续流时间 * 续流时间
* 145 -> 3 * 145 -> 3
*/ */
@NotBlank(message = "开井时长不能为空")
private String afterFlowTime; private String afterFlowTime;
public TimingMode() { public TimingMode() {

View File

@ -3,6 +3,8 @@ package com.isu.gaswellwatch.vo.command.etc;
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Command;
import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.Timing;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
@ -32,18 +34,22 @@ public class TubPressureOptimization extends Command implements Timing {
/** /**
* 套压PSI比例 * 套压PSI比例
*/ */
@NotNull(message = "套压PSI比例不能为空")
private BigDecimal tubPressureSensorRange; private BigDecimal tubPressureSensorRange;
/** /**
* 开井油压 * 开井油压
*/ */
@NotNull(message = "开井油压不能为空")
private BigDecimal openTubPressure; private BigDecimal openTubPressure;
/** /**
* 复位油压 * 复位油压
*/ */
@NotNull(message = "复位油压不能为空")
private BigDecimal openResetTubPressure; private BigDecimal openResetTubPressure;
/** /**
* 稳定时间 * 稳定时间
*/ */
@NotNull(message = "稳定时间不能为空")
private String openTubPressureStableTime; private String openTubPressureStableTime;
public TubPressureOptimization() { public TubPressureOptimization() {

View File

@ -45,8 +45,8 @@ public class SamplingInterval extends Command {
@Override @Override
public boolean validate() { public boolean validate() {
return super.validate() return super.validate()
&& this.continuousSamplingIntervalDuration > 0 && this.continuousSamplingIntervalDuration >= 0
&& this.sensorSignalEffectiveLevel.compareTo(BigDecimal.ZERO) > 0; && this.sensorSignalEffectiveLevel.compareTo(BigDecimal.ZERO) >= 0;
} }
@Override @Override

View File

@ -77,10 +77,10 @@
from ${tableName} t from ${tableName} t
<where> <where>
t.device_id = #{deviceId} t.device_id = #{deviceId}
<if test="startTime!=null and startTime!=''"> <if test="startTime!=null">
and t.collection_time &gt;= #{startTime} and t.collection_time &gt;= #{startTime}
</if> </if>
<if test="endTime!=null and endTime!=''"> <if test="endTime!=null">
and t.collection_time &lt;= #{endTime} and t.collection_time &lt;= #{endTime}
</if> </if>
</where> </where>
@ -131,15 +131,34 @@
from ${tableName} t from ${tableName} t
<where> <where>
t.device_id = #{deviceId} t.device_id = #{deviceId}
<if test="startTime!=null and startTime!=''"> <if test="startTime!=null">
and t.collection_time &gt;= #{startTime} and t.collection_time &gt;= #{startTime}
</if> </if>
<if test="endTime!=null and endTime!=''"> <if test="endTime!=null">
and t.collection_time &lt;= #{endTime} and t.collection_time &lt;= #{endTime}
</if> </if>
</where> </where>
order by t.collection_time asc order by t.collection_time asc
</select> </select>
<select id="getDeviceHistoryData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time,t.oil_pressure,t.cas_pressure,t.pre_pressure
<if test="deviceProduct!=null and deviceProduct=='knpc'">,t.run_mode,t.status_end_time,t.temperature,t.humidity,t.well_status,t.plug_status</if>
<if test="deviceProduct!=null and deviceProduct=='etc'">,t.current_status_remaining_time as statusEndTime,t.controller_current_status as runMode,t.solenoid_valve_status as wellStatus</if>
<if test="deviceProduct!=null and deviceProduct=='scss'">,t.ctl_model as runMode,t.remaining_time_action as statusEndTime,t.solar_voltage,t.first_solenoid_status as wellStatus</if>
from ${tableName} t
<where>
t.device_id = #{deviceId}
<if test="startTime!=null">
and t.collection_time &gt;= #{startTime}
</if>
<if test="endTime!=null">
and t.collection_time &lt;= #{endTime}
</if>
</where>
order by t.collection_time desc
</select>
</mapper> </mapper>