From 78be71b6990b0917f9baa88e45e2f83e77c56a53 Mon Sep 17 00:00:00 2001 From: qinjie <463333974@qq.com> Date: Fri, 27 Dec 2024 15:24:41 +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 | 3 ++- .../com/isu/gaswellwatch/dao/DeviceDao.java | 3 ++- .../gaswellwatch/dao/SwitchStatusExportDao.java | 2 +- .../BusinessMessageHandlerListener.java | 4 ++++ .../isu/gaswellwatch/service/DeviceService.java | 2 +- .../service/SwitchStatusExportService.java | 2 +- .../service/impl/DeviceServiceImpl.java | 17 ++++++++++++++--- .../service/impl/SummaryServiceImpl.java | 5 ++++- .../impl/SwitchStatusExportServiceImpl.java | 5 ++--- .../java/com/isu/gaswellwatch/vo/DeviceVO.java | 2 ++ .../isu/gaswellwatch/vo/SwitchStatusExport.java | 5 +++++ src/main/resources/mapper/DeviceDao.xml | 15 +++++++++++---- .../resources/mapper/SwitchStatusExportDao.xml | 9 +++++---- 13 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java index d0c9a97..ce5efc9 100644 --- a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java +++ b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java @@ -40,8 +40,9 @@ public class DeviceController { @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) String gasWellName, @RequestParam(required = false) String gasStationName, + @RequestParam(required = false) Integer product, @RequestParam Long deviceTypeId,@RequestParam Long blockId) { - return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId,blockId)); + return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId,blockId,product)); } /** diff --git a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java index e7570d4..7b8b3ce 100644 --- a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java +++ b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java @@ -21,7 +21,8 @@ public interface DeviceDao extends BaseMapper { @Param("gasWellName") String gasWellName, @Param("gasStationName") String gasStationName, @Param("deviceTypeId") Long deviceTypeId, - @Param("blockId") Long blockId); + @Param("blockId") Long blockId, + @Param("product") Integer product); DeviceVO getDeviceById(@Param("id") Long id); diff --git a/src/main/java/com/isu/gaswellwatch/dao/SwitchStatusExportDao.java b/src/main/java/com/isu/gaswellwatch/dao/SwitchStatusExportDao.java index ba4195d..0ecc2de 100644 --- a/src/main/java/com/isu/gaswellwatch/dao/SwitchStatusExportDao.java +++ b/src/main/java/com/isu/gaswellwatch/dao/SwitchStatusExportDao.java @@ -14,6 +14,6 @@ public interface SwitchStatusExportDao extends BaseMapper { void deleteData(); - List getSwitchStatusExport(@Param("startTime")String startTime, @Param("endTime")String endTime); + List getSwitchStatusExport(@Param("startTime")String startTime, @Param("endTime")String endTime,@Param("departmentId") Long departmentId); } diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/listener/BusinessMessageHandlerListener.java b/src/main/java/com/isu/gaswellwatch/modbus/data/listener/BusinessMessageHandlerListener.java index e1010ce..f2cb74f 100755 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/listener/BusinessMessageHandlerListener.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/listener/BusinessMessageHandlerListener.java @@ -91,6 +91,9 @@ 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)); + if(null==newObject.getInteger(wellStatusKey)){ + continue; + } //记录开关井状态及对应的套压油压数据 SwitchStatusExport switchStatusExport = new SwitchStatusExport(); switchStatusExport.setId(snowflakeConfig.snowflakeId()); @@ -98,6 +101,7 @@ public class BusinessMessageHandlerListener implements BatchMessageListener { switchStatusExport.setProductName(device.getProduct().getName()); switchStatusExport.setCasPressure(newObject.getString("casPressure")); switchStatusExport.setOilPressure(newObject.getString("oilPressure")); + switchStatusExport.setBlockId(device.getGasWell().getBlockId()); if (newObject.getInteger(wellStatusKey)!=null){ switchStatusExport.setSwitchStatus(newObject.getInteger(wellStatusKey) == 1 ? "开井" : "关井"); } diff --git a/src/main/java/com/isu/gaswellwatch/service/DeviceService.java b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java index 8cf9bc1..23b3078 100644 --- a/src/main/java/com/isu/gaswellwatch/service/DeviceService.java +++ b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java @@ -16,7 +16,7 @@ import java.util.Map; public interface DeviceService extends IService { - Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId, Long blockId); + Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId, Long blockId, Integer product); void add(DeviceCreateDTO deviceCreateDTO); diff --git a/src/main/java/com/isu/gaswellwatch/service/SwitchStatusExportService.java b/src/main/java/com/isu/gaswellwatch/service/SwitchStatusExportService.java index 40bd50f..066534e 100644 --- a/src/main/java/com/isu/gaswellwatch/service/SwitchStatusExportService.java +++ b/src/main/java/com/isu/gaswellwatch/service/SwitchStatusExportService.java @@ -7,6 +7,6 @@ import java.util.List; public interface SwitchStatusExportService extends IService { - List getSwitchStatusExport(String startTime, String endTime); + List getSwitchStatusExport(String startTime, String endTime, Long departmentId); } 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 565904c..348c39b 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java @@ -1,11 +1,13 @@ package com.isu.gaswellwatch.service.impl; +import cn.dev33.satoken.stp.StpUtil; 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; import com.isu.gaswellwatch.config.SnowflakeConfig; +import com.isu.gaswellwatch.constants.UserConstant; import com.isu.gaswellwatch.dao.DeviceDao; import com.isu.gaswellwatch.dto.DeviceCreateDTO; import com.isu.gaswellwatch.dto.DeviceEditDTO; @@ -59,10 +61,12 @@ public class DeviceServiceImpl extends ServiceImpl implements private CacheService cacheService; @Resource private SwitchStatusExportService switchStatusExportService; + @Resource + private UserService userService; @Override - public Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId, Long blockId) { - Page page = this.deviceDao.page(new Page<>(currentPage, pageSize), gasWellName, gasStationName, deviceTypeId, blockId); + public Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId, Long blockId, Integer product) { + Page page = this.deviceDao.page(new Page<>(currentPage, pageSize), gasWellName, gasStationName, deviceTypeId, blockId,product); List deviceVOList = page.getRecords(); // 从Redis获取设备运行数据 if (CollectionUtil.isNotEmpty(deviceVOList)) { @@ -83,6 +87,9 @@ public class DeviceServiceImpl extends ServiceImpl implements Object prePressure = this.redisTemplate.opsForHash().get(deviceKey, "prePressure"); deviceVO.setPrePressure(prePressure == null ? "" : prePressure.toString()); + Object voltage = this.redisTemplate.opsForHash().get(deviceKey, "batteryVoltage"); + deviceVO.setVoltage(voltage == null ? "" : voltage.toString()); + Object online = this.redisTemplate.opsForHash().get(deviceKey, "online"); deviceVO.setOnline(online == null ? "" : online.toString()); @@ -278,7 +285,11 @@ public class DeviceServiceImpl extends ServiceImpl implements @Override public void exportSwitchStatusData(HttpServletResponse response, String startTime, String endTime) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - List list = switchStatusExportService.getSwitchStatusExport(startTime, endTime); + + UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession().get(UserConstant.TOKEN_SESSION); + UserVO userVO = userService.selectUserInfo(userLoginInfoVO.getUserVO().getUsername()); + + List list = switchStatusExportService.getSwitchStatusExport(startTime, endTime,userVO.getDepartment().getId()); List export = ConverterUtil.convert(list, SwitchStatusExportVO.class); diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java index cef65e0..941ccb5 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java @@ -80,7 +80,10 @@ public class SummaryServiceImpl implements SummaryService { Integer onLineCount = 0; Integer offLineCount = 0; - for(DeviceVO deviceVO : deviceVOList){ + + List allDeviceVOList = deviceService.getDeviceVOByIds(null); + + for(DeviceVO deviceVO : allDeviceVOList){ if("true".equalsIgnoreCase(onlineMap.get(deviceVO.getId().toString()))){ onLineCount++; }else { diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/SwitchStatusExportServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/SwitchStatusExportServiceImpl.java index 987b2c3..b63a33d 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/SwitchStatusExportServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/SwitchStatusExportServiceImpl.java @@ -5,7 +5,6 @@ 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; @@ -19,8 +18,8 @@ public class SwitchStatusExportServiceImpl extends ServiceImpl getSwitchStatusExport(String startTime, String endTime) { - return switchStatusExportDao.getSwitchStatusExport(startTime, endTime); + public List getSwitchStatusExport(String startTime, String endTime, Long departmentId) { + return switchStatusExportDao.getSwitchStatusExport(startTime, endTime,departmentId); } } diff --git a/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java b/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java index 9966567..0ee62ed 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java +++ b/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java @@ -73,5 +73,7 @@ public class DeviceVO extends Model { /** 生产状态 */ private String wellStatus; + /** 电压 */ + private String voltage; } diff --git a/src/main/java/com/isu/gaswellwatch/vo/SwitchStatusExport.java b/src/main/java/com/isu/gaswellwatch/vo/SwitchStatusExport.java index 7987253..a792964 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/SwitchStatusExport.java +++ b/src/main/java/com/isu/gaswellwatch/vo/SwitchStatusExport.java @@ -51,6 +51,11 @@ public class SwitchStatusExport extends Model { */ private String switchStatus; + /** + * 区块ID + */ + private Long blockId; + /** * 创建时间 */ diff --git a/src/main/resources/mapper/DeviceDao.xml b/src/main/resources/mapper/DeviceDao.xml index a585062..03da5bb 100644 --- a/src/main/resources/mapper/DeviceDao.xml +++ b/src/main/resources/mapper/DeviceDao.xml @@ -48,6 +48,9 @@ and u.device_type = #{deviceTypeId} + + and u.product = #{product} + and g.block_id = #{blockId} @@ -102,10 +105,14 @@ select u.id, u.device_type, u.code, u.gas_station, u.product, u.gateway_sn, u.gas_well, u.details, u.create_time, u.update_time from device u - where u.id in - - #{id} - + + + u.id in + + #{id} + + + - select * from switch_status_export + select s.* from switch_status_export s join block_department b on s.block_id = b.block_id + b.department_id = #{departmentId} - and create_time >= #{startTime} + and s.create_time >= #{startTime} - and create_time <= #{endTime} + and s.create_time <= #{endTime} - order by create_time desc + order by s.create_time desc