提交代码
This commit is contained in:
parent
8480b40ee8
commit
ff200e7bdc
|
@ -142,6 +142,17 @@ public class DeviceController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备开关状态数据导出
|
||||
*/
|
||||
@GetMapping("/exportSwitchStatusData")
|
||||
@OperationLog(description = "设备开关状态数据导出",type = LogType.EXPORT)
|
||||
public void exportSwitchStatusData(HttpServletResponse response,
|
||||
@RequestParam String startTime,
|
||||
@RequestParam String endTime) {
|
||||
deviceService.exportSwitchStatusData(response, startTime, endTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.isu.gaswellwatch.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.isu.gaswellwatch.vo.SwitchStatusExport;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface SwitchStatusExportDao extends BaseMapper<SwitchStatusExport> {
|
||||
|
||||
void deleteData();
|
||||
|
||||
List<SwitchStatusExport> getSwitchStatusExport(@Param("startTime")String startTime, @Param("endTime")String endTime);
|
||||
}
|
||||
|
|
@ -9,7 +9,9 @@ import com.isu.gaswellwatch.modbus.data.PersistenceHandler;
|
|||
import com.isu.gaswellwatch.service.DeviceOptLogService;
|
||||
import com.isu.gaswellwatch.service.DeviceService;
|
||||
import com.isu.gaswellwatch.service.RemindService;
|
||||
import com.isu.gaswellwatch.service.SwitchStatusExportService;
|
||||
import com.isu.gaswellwatch.vo.DeviceVO;
|
||||
import com.isu.gaswellwatch.vo.SwitchStatusExport;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -37,6 +39,8 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
|||
private RemindService remindService;
|
||||
@Resource
|
||||
private SnowflakeConfig snowflakeConfig;
|
||||
@Resource
|
||||
private SwitchStatusExportService switchStatusExportService;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +55,8 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
|||
List<RemindSetting> settingList = this.remindService.getAllRemindSetting();
|
||||
List<RemindRecord> recordList = new ArrayList<>();
|
||||
|
||||
List<SwitchStatusExport> switchStatusExportList = new ArrayList<>();
|
||||
|
||||
//将settingList转换为map,key为deviceId,value为List<RemindSetting>
|
||||
Map<Long, List<RemindSetting>> deviceRemindSettingMap = new HashMap<>();
|
||||
for (RemindSetting setting : settingList) {
|
||||
|
@ -84,6 +90,18 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
|||
//比对新旧数据,看开关状态是否一致
|
||||
if (oldObject.getString(wellStatusKey) != null && (!oldObject.getString(wellStatusKey).equals(newObject.getString(wellStatusKey)))) {
|
||||
deviceWellStatusMap.put(Long.valueOf(deviceId), newObject.getInteger(wellStatusKey));
|
||||
|
||||
//记录开关井状态及对应的套压油压数据
|
||||
SwitchStatusExport switchStatusExport = new SwitchStatusExport();
|
||||
switchStatusExport.setId(snowflakeConfig.snowflakeId());
|
||||
switchStatusExport.setGasWellName(device.getGasWell().getName());
|
||||
switchStatusExport.setProductName(device.getProduct().getName());
|
||||
switchStatusExport.setCasPressure(newObject.getString("casPressure"));
|
||||
switchStatusExport.setOilPressure(newObject.getString("oilPressure"));
|
||||
if (newObject.getInteger(wellStatusKey)!=null){
|
||||
switchStatusExport.setSwitchStatus(newObject.getInteger(wellStatusKey) == 1 ? "开井" : "关井");
|
||||
}
|
||||
switchStatusExportList.add(switchStatusExport);
|
||||
}
|
||||
|
||||
//根据ID找到对应的提醒字段配置
|
||||
|
@ -117,6 +135,11 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
|||
}
|
||||
|
||||
}
|
||||
//保存开关状态数据
|
||||
if (!switchStatusExportList.isEmpty()) {
|
||||
this.switchStatusExportService.saveBatch(switchStatusExportList);
|
||||
}
|
||||
|
||||
|
||||
//若不一致则记录设备操作日志
|
||||
if (!deviceWellStatusMap.isEmpty()) {
|
||||
|
|
|
@ -39,5 +39,7 @@ public interface DeviceService extends IService<Device> {
|
|||
List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime,String deviceProduct);
|
||||
|
||||
void exportHistoryData(HttpServletResponse response, Long deviceId, String startTime, String endTime) throws ParseException;
|
||||
|
||||
void exportSwitchStatusData(HttpServletResponse response, String startTime, String endTime);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.isu.gaswellwatch.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.isu.gaswellwatch.vo.SwitchStatusExport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SwitchStatusExportService extends IService<SwitchStatusExport> {
|
||||
|
||||
List<SwitchStatusExport> getSwitchStatusExport(String startTime, String endTime);
|
||||
}
|
||||
|
|
@ -17,16 +17,9 @@ import com.isu.gaswellwatch.exception.BusinessException;
|
|||
import com.isu.gaswellwatch.modbus.data.CacheService;
|
||||
import com.isu.gaswellwatch.modbus.data.PersistenceHandler;
|
||||
import com.isu.gaswellwatch.modbus.data.Redis2DBPersistenceService;
|
||||
import com.isu.gaswellwatch.modbus.data.listener.DynamicRabbitListener;
|
||||
import com.isu.gaswellwatch.service.DeviceOptLogService;
|
||||
import com.isu.gaswellwatch.service.DeviceService;
|
||||
import com.isu.gaswellwatch.service.DictionaryService;
|
||||
import com.isu.gaswellwatch.service.GasWellService;
|
||||
import com.isu.gaswellwatch.service.*;
|
||||
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 com.isu.gaswellwatch.vo.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
@ -63,9 +56,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
|
|||
@Resource
|
||||
private DeviceOptLogService deviceOptLogService;
|
||||
@Resource
|
||||
private DynamicRabbitListener dynamicRabbitListener;
|
||||
@Resource
|
||||
private CacheService cacheService;
|
||||
@Resource
|
||||
private SwitchStatusExportService switchStatusExportService;
|
||||
|
||||
@Override
|
||||
public Page<DeviceVO> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId, Long blockId) {
|
||||
|
@ -282,6 +275,31 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportSwitchStatusData(HttpServletResponse response, String startTime, String endTime) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
List<SwitchStatusExport> list = switchStatusExportService.getSwitchStatusExport(startTime, endTime);
|
||||
|
||||
List<SwitchStatusExportVO> export = ConverterUtil.convert(list, SwitchStatusExportVO.class);
|
||||
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
String fileName = null;
|
||||
try {
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
fileName = URLEncoder.encode("全井数据-"+simpleDateFormat.format(new Date()), StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
||||
response.setHeader("Access-Control-Expose-Headers","Content-Disposition");
|
||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
EasyExcel.write(outputStream)
|
||||
// 这里放入动态头
|
||||
.head(SwitchStatusExportVO.class).sheet("data")
|
||||
// 当然这里数据也可以用 List<List<String>> 去传入
|
||||
.doWrite(export);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Page<DeviceHistoryVO> getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.isu.gaswellwatch.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.isu.gaswellwatch.dao.SwitchStatusExportDao;
|
||||
import com.isu.gaswellwatch.service.SwitchStatusExportService;
|
||||
import com.isu.gaswellwatch.vo.SwitchStatusExport;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service("switchStatusExportService")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class SwitchStatusExportServiceImpl extends ServiceImpl<SwitchStatusExportDao, SwitchStatusExport> implements SwitchStatusExportService {
|
||||
|
||||
@Resource
|
||||
private SwitchStatusExportDao switchStatusExportDao;
|
||||
|
||||
@Override
|
||||
public List<SwitchStatusExport> getSwitchStatusExport(String startTime, String endTime) {
|
||||
return switchStatusExportDao.getSwitchStatusExport(startTime, endTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.isu.gaswellwatch.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author scwsl
|
||||
* @date 2024-11-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
@ToString(callSuper = true)
|
||||
public class SwitchStatusExport extends Model<SwitchStatusExport> {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 气井名称
|
||||
*/
|
||||
private String gasWellName;
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String productName;
|
||||
|
||||
/**
|
||||
* 油压
|
||||
*/
|
||||
private String oilPressure;
|
||||
|
||||
/**
|
||||
* 套压
|
||||
*/
|
||||
private String casPressure;
|
||||
/**
|
||||
* 开关状态
|
||||
*/
|
||||
private String switchStatus;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.isu.gaswellwatch.vo;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SwitchStatusExportVO {
|
||||
|
||||
|
||||
/**
|
||||
* 气井名称
|
||||
*/
|
||||
@ExcelProperty(value = "井号")
|
||||
private String gasWellName;
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@ExcelProperty(value = "设备品牌")
|
||||
private String productName;
|
||||
|
||||
/**
|
||||
* 油压
|
||||
*/
|
||||
@ExcelProperty(value = "油压")
|
||||
private String oilPressure;
|
||||
|
||||
/**
|
||||
* 套压
|
||||
*/
|
||||
@ExcelProperty(value = "套压")
|
||||
private String casPressure;
|
||||
/**
|
||||
* 开关状态
|
||||
*/
|
||||
@ExcelProperty(value = "开关状态")
|
||||
private String switchStatus;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ExcelProperty(value = "状态变更时间")
|
||||
private String createTime;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?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.isu.gaswellwatch.dao.SwitchStatusExportDao">
|
||||
|
||||
|
||||
<delete id="deleteData">
|
||||
delete from switch_status_export
|
||||
<where>
|
||||
create_time <= DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||
</where>
|
||||
</delete>
|
||||
<select id="getSwitchStatusExport" resultType="com.isu.gaswellwatch.vo.SwitchStatusExport">
|
||||
select * from switch_status_export
|
||||
<where>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
</where> order by create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue