2024-11-25 01:04:53 +08:00
|
|
|
|
package com.isu.gaswellwatch.service.impl;
|
|
|
|
|
|
2024-12-27 15:24:41 +08:00
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
2024-12-12 14:52:02 +08:00
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.isu.gaswellwatch.config.SnowflakeConfig;
|
2024-12-27 15:24:41 +08:00
|
|
|
|
import com.isu.gaswellwatch.constants.UserConstant;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import com.isu.gaswellwatch.dao.DeviceDao;
|
|
|
|
|
import com.isu.gaswellwatch.dto.DeviceCreateDTO;
|
|
|
|
|
import com.isu.gaswellwatch.dto.DeviceEditDTO;
|
2024-11-28 23:35:05 +08:00
|
|
|
|
import com.isu.gaswellwatch.entity.Device;
|
|
|
|
|
import com.isu.gaswellwatch.entity.DeviceOptLog;
|
|
|
|
|
import com.isu.gaswellwatch.entity.Dictionary;
|
|
|
|
|
import com.isu.gaswellwatch.entity.GasWell;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import com.isu.gaswellwatch.exception.BusinessException;
|
2024-12-09 16:05:45 +08:00
|
|
|
|
import com.isu.gaswellwatch.modbus.data.CacheService;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
import com.isu.gaswellwatch.modbus.data.PersistenceHandler;
|
2024-11-26 18:46:34 +08:00
|
|
|
|
import com.isu.gaswellwatch.modbus.data.Redis2DBPersistenceService;
|
2024-12-17 14:32:18 +08:00
|
|
|
|
import com.isu.gaswellwatch.service.*;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import com.isu.gaswellwatch.utils.ConverterUtil;
|
2024-12-17 14:32:18 +08:00
|
|
|
|
import com.isu.gaswellwatch.vo.*;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import jakarta.annotation.Resource;
|
2024-12-12 14:52:02 +08:00
|
|
|
|
import jakarta.servlet.ServletOutputStream;
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2024-11-28 01:30:00 +08:00
|
|
|
|
import org.springframework.data.redis.RedisConnectionFailureException;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
2024-12-12 14:52:02 +08:00
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
import java.util.List;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
import java.util.Map;
|
2025-02-21 13:53:37 +08:00
|
|
|
|
import java.util.Objects;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
|
2024-11-25 01:04:53 +08:00
|
|
|
|
|
|
|
|
|
@Service("deviceService")
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements DeviceService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SnowflakeConfig snowflakeConfig;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DeviceDao deviceDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private GasWellService gasWellService;
|
2024-11-26 03:12:53 +08:00
|
|
|
|
@Resource(name = "stringRedisTemplate")
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
@Resource
|
|
|
|
|
private DictionaryService dictionaryService;
|
2024-11-26 18:46:34 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private DeviceOptLogService deviceOptLogService;
|
2024-11-28 01:30:00 +08:00
|
|
|
|
@Resource
|
2024-12-09 16:05:45 +08:00
|
|
|
|
private CacheService cacheService;
|
2024-12-17 14:32:18 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private SwitchStatusExportService switchStatusExportService;
|
2024-12-27 15:24:41 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private UserService userService;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
|
|
|
|
|
@Override
|
2024-12-27 15:24:41 +08:00
|
|
|
|
public Page<DeviceVO> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId, Long blockId, Integer product) {
|
2025-02-21 13:53:37 +08:00
|
|
|
|
Page<DeviceVO> page = this.deviceDao.page(new Page<>(currentPage, pageSize), gasWellName, gasStationName, deviceTypeId, blockId, product);
|
2024-11-26 03:12:53 +08:00
|
|
|
|
List<DeviceVO> deviceVOList = page.getRecords();
|
|
|
|
|
// 从Redis获取设备运行数据
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (CollectionUtil.isNotEmpty(deviceVOList)) {
|
|
|
|
|
Map<String, Dictionary> runModeMap = this.dictionaryService.getValueMapByType("runMode");
|
|
|
|
|
Map<String, Dictionary> plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus");
|
2024-12-11 12:47:42 +08:00
|
|
|
|
Map<String, Dictionary> controlModeMap = this.dictionaryService.getValueMapByType("controlMode");
|
|
|
|
|
Map<String, Dictionary> ctlModeMap = this.dictionaryService.getValueMapByType("ctlMode");
|
2024-11-26 03:12:53 +08:00
|
|
|
|
|
2024-11-28 01:30:00 +08:00
|
|
|
|
try {
|
|
|
|
|
for (DeviceVO deviceVO : deviceVOList) {
|
|
|
|
|
String deviceKey = PersistenceHandler.DEVICE_DATA_CACHE + deviceVO.getId();
|
2024-11-28 23:35:05 +08:00
|
|
|
|
Object casPressure = this.redisTemplate.opsForHash().get(deviceKey, "casPressure");
|
2024-11-28 01:30:00 +08:00
|
|
|
|
deviceVO.setCasPressure(casPressure == null ? "" : casPressure.toString());
|
|
|
|
|
|
2024-11-28 23:35:05 +08:00
|
|
|
|
Object oilPressure = this.redisTemplate.opsForHash().get(deviceKey, "oilPressure");
|
2024-11-28 01:30:00 +08:00
|
|
|
|
deviceVO.setOilPressure(oilPressure == null ? "" : oilPressure.toString());
|
|
|
|
|
|
2024-11-28 23:35:05 +08:00
|
|
|
|
Object prePressure = this.redisTemplate.opsForHash().get(deviceKey, "prePressure");
|
2024-11-28 01:30:00 +08:00
|
|
|
|
deviceVO.setPrePressure(prePressure == null ? "" : prePressure.toString());
|
|
|
|
|
|
2024-12-27 15:24:41 +08:00
|
|
|
|
Object voltage = this.redisTemplate.opsForHash().get(deviceKey, "batteryVoltage");
|
|
|
|
|
deviceVO.setVoltage(voltage == null ? "" : voltage.toString());
|
|
|
|
|
|
2024-11-28 23:35:05 +08:00
|
|
|
|
Object online = this.redisTemplate.opsForHash().get(deviceKey, "online");
|
2024-11-28 01:30:00 +08:00
|
|
|
|
deviceVO.setOnline(online == null ? "" : online.toString());
|
|
|
|
|
|
2025-02-21 13:53:37 +08:00
|
|
|
|
if (PersistenceHandler.ETC_MODBUS_TYPE.equalsIgnoreCase(deviceVO.getProduct().getCode())) {
|
2024-12-11 13:56:14 +08:00
|
|
|
|
Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "solenoidValveStatus");
|
|
|
|
|
deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString());
|
|
|
|
|
|
|
|
|
|
Object runMode = this.redisTemplate.opsForHash().get(deviceKey, "controllerCurrentStatus");
|
|
|
|
|
if (runMode == null) {
|
|
|
|
|
deviceVO.setRunMode("");
|
|
|
|
|
} else {
|
|
|
|
|
Dictionary runMode1 = controlModeMap.get(runMode.toString());
|
|
|
|
|
deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName());
|
|
|
|
|
}
|
2025-02-21 13:53:37 +08:00
|
|
|
|
} else if (PersistenceHandler.SCSS_MODBUS_TYPE.equalsIgnoreCase(deviceVO.getProduct().getCode())) {
|
2024-12-11 13:56:14 +08:00
|
|
|
|
Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "firstSolenoidStatus");
|
|
|
|
|
deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString());
|
|
|
|
|
|
|
|
|
|
Object runMode = this.redisTemplate.opsForHash().get(deviceKey, "ctlModel");
|
|
|
|
|
if (runMode == null) {
|
|
|
|
|
deviceVO.setRunMode("");
|
|
|
|
|
} else {
|
|
|
|
|
Dictionary runMode1 = ctlModeMap.get(runMode.toString());
|
|
|
|
|
deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName());
|
|
|
|
|
}
|
2025-02-21 13:53:37 +08:00
|
|
|
|
} else {
|
2024-12-11 13:56:14 +08:00
|
|
|
|
Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "wellStatus");
|
|
|
|
|
deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString());
|
|
|
|
|
|
|
|
|
|
Object runMode = this.redisTemplate.opsForHash().get(deviceKey, "runMode");
|
|
|
|
|
if (runMode == null) {
|
|
|
|
|
deviceVO.setRunMode("");
|
|
|
|
|
} else {
|
|
|
|
|
Dictionary runMode1 = runModeMap.get(runMode.toString());
|
|
|
|
|
deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName());
|
2024-12-11 12:47:42 +08:00
|
|
|
|
}
|
2024-11-28 01:30:00 +08:00
|
|
|
|
}
|
2024-12-11 13:56:14 +08:00
|
|
|
|
|
|
|
|
|
|
2024-11-28 23:35:05 +08:00
|
|
|
|
Object plugStatus = this.redisTemplate.opsForHash().get(deviceKey, "plugStatus");
|
|
|
|
|
if (plugStatus == null) {
|
2024-11-28 01:30:00 +08:00
|
|
|
|
deviceVO.setPlugStatus("");
|
2024-11-28 23:35:05 +08:00
|
|
|
|
} else {
|
2024-11-28 01:30:00 +08:00
|
|
|
|
Dictionary plugStatus1 = plugStatusMap.get(plugStatus.toString());
|
2024-11-28 23:35:05 +08:00
|
|
|
|
deviceVO.setPlugStatus(plugStatus1 == null ? "" : plugStatus1.getName());
|
2024-11-28 01:30:00 +08:00
|
|
|
|
}
|
2024-11-26 22:51:15 +08:00
|
|
|
|
|
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
} catch (RedisConnectionFailureException e) {
|
|
|
|
|
this.log.error("redis连接失败,请检查redis连接");
|
2024-11-26 03:12:53 +08:00
|
|
|
|
}
|
2024-11-28 01:30:00 +08:00
|
|
|
|
|
2024-11-26 03:12:53 +08:00
|
|
|
|
}
|
2024-11-25 15:48:00 +08:00
|
|
|
|
return ConverterUtil.convertPage(page, DeviceVO.class);
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-28 23:35:05 +08:00
|
|
|
|
public void add(DeviceCreateDTO deviceCreateDTO) throws NumberFormatException {
|
2024-11-25 01:04:53 +08:00
|
|
|
|
//查重
|
2024-11-28 23:35:05 +08:00
|
|
|
|
List<Device> list = this.list(new LambdaQueryWrapper<Device>().eq(Device::getId, deviceCreateDTO.getCode()));
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) {
|
2024-11-25 01:04:53 +08:00
|
|
|
|
throw new BusinessException("已有相同设备编码,请重新输入");
|
|
|
|
|
}
|
2024-11-25 16:29:26 +08:00
|
|
|
|
|
2024-11-28 23:35:05 +08:00
|
|
|
|
GasWell gasWell = this.gasWellService.getOne(new LambdaQueryWrapper<GasWell>().eq(GasWell::getId, deviceCreateDTO.getGasWell()));
|
|
|
|
|
if (gasWell == null) {
|
2024-11-25 16:29:26 +08:00
|
|
|
|
throw new BusinessException("该气井不存在");
|
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (gasWell.getDeviceId() != null) {
|
2024-11-25 16:29:26 +08:00
|
|
|
|
throw new BusinessException("该气井已存在绑定设备,无法添加新设备");
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 01:04:53 +08:00
|
|
|
|
Device device = ConverterUtil.convert(deviceCreateDTO, Device.class);
|
|
|
|
|
//code必须为整形,用于在缓存中查询设备的上报数据
|
|
|
|
|
device.setId(Long.valueOf(deviceCreateDTO.getCode()));
|
2024-11-28 23:35:05 +08:00
|
|
|
|
this.save(device);
|
2024-11-25 01:04:53 +08:00
|
|
|
|
|
|
|
|
|
//在气井中绑定设备
|
2024-11-28 23:35:05 +08:00
|
|
|
|
this.gasWellService.bindDevice(deviceCreateDTO.getGasWell(), device.getId());
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-28 23:35:05 +08:00
|
|
|
|
public void edit(DeviceEditDTO deviceEditDTO) {
|
|
|
|
|
this.updateById(ConverterUtil.convert(deviceEditDTO, Device.class));
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-28 23:35:05 +08:00
|
|
|
|
public void delete(Long id) {
|
|
|
|
|
Long gasWellId = this.getDevice(id).getGasWell().getId();
|
2024-11-25 01:04:53 +08:00
|
|
|
|
//删除设备
|
2024-11-28 23:35:05 +08:00
|
|
|
|
this.removeById(id);
|
2024-11-28 01:30:00 +08:00
|
|
|
|
//解绑气井
|
2024-11-28 23:35:05 +08:00
|
|
|
|
this.gasWellService.unbindDevice(gasWellId);
|
2024-12-09 16:05:45 +08:00
|
|
|
|
|
|
|
|
|
//删除t_data_设备历史数据表 删除缓存和MQ
|
2025-02-21 13:53:37 +08:00
|
|
|
|
this.cacheService.cleanDeviceCache(id);
|
2024-12-09 16:05:45 +08:00
|
|
|
|
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-25 15:48:00 +08:00
|
|
|
|
public DeviceVO getDevice(Long id) {
|
2024-11-28 23:35:05 +08:00
|
|
|
|
return this.deviceDao.getDeviceById(id);
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-28 23:35:05 +08:00
|
|
|
|
public Map<String, String> getDeviceControlData(Long deviceId) {
|
|
|
|
|
return this.redisTemplate.opsForHash().entries(PersistenceHandler.DEVICE_DATA_CACHE + deviceId);
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-26 18:46:34 +08:00
|
|
|
|
public Page<DeviceOptLog> getDeviceLogData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException {
|
|
|
|
|
Date start = null;
|
|
|
|
|
Date end = null;
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (!StringUtils.isEmpty(startTime)) {
|
2024-11-26 18:46:34 +08:00
|
|
|
|
start = simpleDateFormat.parse(startTime);
|
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (!StringUtils.isEmpty(endTime)) {
|
2024-11-26 18:46:34 +08:00
|
|
|
|
end = simpleDateFormat.parse(endTime);
|
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
return this.deviceOptLogService.page(new Page<>(currentPage, pageSize), start, end, deviceId);
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-11-28 01:30:00 +08:00
|
|
|
|
public List<DeviceVO> getDeviceVOByIds(List<Long> deviceIdList) {
|
2024-11-28 23:35:05 +08:00
|
|
|
|
return this.deviceDao.getDeviceVOByIds(deviceIdList);
|
2024-11-26 03:12:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 21:17:08 +08:00
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime) {
|
|
|
|
|
String tableName = Redis2DBPersistenceService.DEFAULT_DATA_TABLE + deviceId;
|
2025-02-21 13:53:37 +08:00
|
|
|
|
return this.deviceDao.getPressureChartData(deviceId, startTime, endTime, tableName);
|
2024-12-10 21:17:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-02-21 13:53:37 +08:00
|
|
|
|
public List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime, String deviceProduct) {
|
2024-12-10 21:17:08 +08:00
|
|
|
|
String tableName = Redis2DBPersistenceService.DEFAULT_DATA_TABLE + deviceId;
|
2025-02-21 13:53:37 +08:00
|
|
|
|
return this.deviceDao.getSwitchStatusData(deviceId, startTime, endTime, tableName, deviceProduct);
|
2024-12-10 21:17:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 14:52:02 +08:00
|
|
|
|
@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);
|
2025-02-21 13:53:37 +08:00
|
|
|
|
List<DeviceHistoryVO> list = this.deviceDao.getDeviceHistoryData(start, end, deviceId, tableName, device.getProduct().getCode());
|
2024-12-12 14:52:02 +08:00
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) {
|
|
|
|
|
Map<String, Dictionary> runModeMap = this.dictionaryService.getValueMapByType("runMode");
|
2025-02-21 13:53:37 +08:00
|
|
|
|
if (PersistenceHandler.ETC_MODBUS_TYPE.equalsIgnoreCase(device.getProduct().getCode())) {
|
2024-12-12 14:52:02 +08:00
|
|
|
|
runModeMap = this.dictionaryService.getValueMapByType("controlMode");
|
2025-02-21 13:53:37 +08:00
|
|
|
|
} else if (PersistenceHandler.SCSS_MODBUS_TYPE.equalsIgnoreCase(device.getProduct().getCode())) {
|
2024-12-12 14:52:02 +08:00
|
|
|
|
runModeMap = this.dictionaryService.getValueMapByType("ctlMode");
|
|
|
|
|
}
|
|
|
|
|
Map<String, Dictionary> plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus");
|
|
|
|
|
|
|
|
|
|
for (DeviceHistoryVO deviceVO : list) {
|
2025-02-21 13:53:37 +08:00
|
|
|
|
if (Objects.equals(deviceVO.getType(), PersistenceHandler.WEPS_PLUG_MODBUS_TYPE)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-12-12 14:52:02 +08:00
|
|
|
|
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();
|
2025-02-21 13:53:37 +08:00
|
|
|
|
fileName = URLEncoder.encode(device.getGasWell().getName() + "|" + simpleDateFormat.format(new Date()), StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
|
|
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
2024-12-12 14:52:02 +08:00
|
|
|
|
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) {
|
2025-02-21 13:53:37 +08:00
|
|
|
|
this.log.error(e.getMessage());
|
2024-12-12 14:52:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 14:32:18 +08:00
|
|
|
|
@Override
|
|
|
|
|
public void exportSwitchStatusData(HttpServletResponse response, String startTime, String endTime) {
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
2024-12-27 15:24:41 +08:00
|
|
|
|
|
|
|
|
|
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession().get(UserConstant.TOKEN_SESSION);
|
2025-02-21 13:53:37 +08:00
|
|
|
|
UserVO userVO = this.userService.selectUserInfo(userLoginInfoVO.getUserVO().getUsername());
|
2024-12-27 15:24:41 +08:00
|
|
|
|
|
2025-02-21 13:53:37 +08:00
|
|
|
|
List<SwitchStatusExport> list = this.switchStatusExportService.getSwitchStatusExport(startTime, endTime, userVO.getDepartment().getId());
|
2024-12-17 14:32:18 +08:00
|
|
|
|
|
|
|
|
|
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();
|
2025-02-21 13:53:37 +08:00
|
|
|
|
fileName = URLEncoder.encode("全井数据-" + simpleDateFormat.format(new Date()), StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
|
|
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
2024-12-17 14:32:18 +08:00
|
|
|
|
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) {
|
2025-02-21 13:53:37 +08:00
|
|
|
|
this.log.error(e.getMessage());
|
2024-12-17 14:32:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-28 01:30:00 +08:00
|
|
|
|
|
2024-11-26 03:12:53 +08:00
|
|
|
|
@Override
|
|
|
|
|
public Page<DeviceHistoryVO> getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException {
|
|
|
|
|
Date start = null;
|
|
|
|
|
Date end = null;
|
2024-11-26 18:46:34 +08:00
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (!StringUtils.isEmpty(startTime)) {
|
2024-11-26 03:12:53 +08:00
|
|
|
|
start = simpleDateFormat.parse(startTime);
|
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (!StringUtils.isEmpty(endTime)) {
|
2024-11-26 03:12:53 +08:00
|
|
|
|
end = simpleDateFormat.parse(endTime);
|
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
String tableName = Redis2DBPersistenceService.DEFAULT_DATA_TABLE + deviceId;
|
2024-12-08 21:18:38 +08:00
|
|
|
|
|
|
|
|
|
//判断设备品牌
|
|
|
|
|
DeviceVO device = this.getDevice(deviceId);
|
|
|
|
|
|
2025-02-21 13:53:37 +08:00
|
|
|
|
Page<DeviceHistoryVO> page = this.deviceDao.historyPage(new Page<>(currentPage, pageSize), start, end, deviceId, tableName, device.getProduct().getCode());
|
2024-11-26 03:12:53 +08:00
|
|
|
|
List<DeviceHistoryVO> deviceHistoryVO = page.getRecords();
|
2024-11-28 23:35:05 +08:00
|
|
|
|
if (CollectionUtil.isNotEmpty(deviceHistoryVO)) {
|
|
|
|
|
Map<String, Dictionary> runModeMap = this.dictionaryService.getValueMapByType("runMode");
|
2025-02-21 13:53:37 +08:00
|
|
|
|
if (PersistenceHandler.ETC_MODBUS_TYPE.equalsIgnoreCase(device.getProduct().getCode())) {
|
2024-12-09 21:01:54 +08:00
|
|
|
|
runModeMap = this.dictionaryService.getValueMapByType("controlMode");
|
2025-02-21 13:53:37 +08:00
|
|
|
|
} else if (PersistenceHandler.SCSS_MODBUS_TYPE.equalsIgnoreCase(device.getProduct().getCode())) {
|
2024-12-11 12:47:42 +08:00
|
|
|
|
runModeMap = this.dictionaryService.getValueMapByType("ctlMode");
|
2024-12-09 21:01:54 +08:00
|
|
|
|
}
|
2024-11-28 23:35:05 +08:00
|
|
|
|
Map<String, Dictionary> plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus");
|
2024-11-26 03:12:53 +08:00
|
|
|
|
|
|
|
|
|
for (DeviceHistoryVO deviceVO : deviceHistoryVO) {
|
2024-11-28 23:35:05 +08:00
|
|
|
|
deviceVO.setRunMode(StringUtils.isEmpty(deviceVO.getRunMode()) ? "" : runModeMap.get(deviceVO.getRunMode()).getName());
|
|
|
|
|
deviceVO.setPlugStatus(StringUtils.isEmpty(deviceVO.getPlugStatus()) ? "" : plugStatusMap.get(deviceVO.getPlugStatus()).getName());
|
2024-11-26 03:12:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return page;
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 18:46:34 +08:00
|
|
|
|
|
2024-11-25 01:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
|