From e9507fe2d697b09566d0c0a6e6da82648dc21208 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Mon, 17 Jun 2024 09:34:36 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=8F=91=E7=94=B5=E9=87=8F=E6=95=B4=E6=94=B9&?= =?UTF-8?q?web/app=E5=91=8A=E8=AD=A6=E6=8E=A8=E9=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E7=AB=99=E7=82=B9=E5=8C=BA=E5=9F=9F=E7=BA=A7=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/service/impl/MessageServiceImpl.java | 2 +- .../hzims/scheduled/mapper/alarm/HandleMapper.java | 16 +++ .../mapper/equipment/ThirtyGenerateMapper.java | 2 + .../mapper/equipment/ThreeGenerateMapper.java | 4 + .../scheduled/service/alarm/HandleService.java | 22 ++++ .../service/alarm/impl/AlarmQueryServiceImpl.java | 20 ++- .../service/alarm/impl/HandleServiceImpl.java | 39 ++++++ .../service/equipment/ThirtyGenerateService.java | 1 + .../service/equipment/ThreeGenerateService.java | 4 + .../equipment/impl/ThirtyGenerateServiceImpl.java | 18 +++ .../equipment/impl/ThreeGenerateServiceImpl.java | 28 ++++ .../home/impl/ObtainGenerationServiceImpl.java | 141 +++++++++++++++++++++ .../operation/monitor/impl/MonitorServiceImpl.java | 4 + .../main/resources/mapper/alarm/HandleMapper.xml | 17 +++ .../mapper/equipment/ThirtyGenerateMapper.xml | 4 + .../mapper/equipment/ThreeGenerateMapper.xml | 14 ++ 16 files changed, 330 insertions(+), 6 deletions(-) create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java index 0156355..dab65e3 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java @@ -75,7 +75,7 @@ public class MessageServiceImpl implements MessageService { } Long dept = stationByCode.getData().getRefDept(); // 获取站点用户 - R> result = userClient.userListByDeptId(dept); + R> result = userClient.userByDeptIdLevel(dept,1); if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { log.error("WEB/APP消息发送失败:用户获取失败 : {}",entity); return; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java new file mode 100644 index 0000000..4e6a789 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.scheduled.mapper.alarm; + +import com.hnac.hzims.alarm.config.entity.AlarmHandleEntity; +import org.apache.ibatis.annotations.Param; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface HandleMapper extends UserDataScopeBaseMapper { + List handles(@Param("start") String start,@Param("end") String end); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThirtyGenerateMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThirtyGenerateMapper.java index d64e3f6..880f243 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThirtyGenerateMapper.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThirtyGenerateMapper.java @@ -3,10 +3,12 @@ package com.hnac.hzims.scheduled.mapper.equipment; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity; +import org.apache.ibatis.annotations.Param; /** * @author ysj */ public interface ThirtyGenerateMapper extends BaseMapper { + void deleteDayGenerate(@Param("day") String day); } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThreeGenerateMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThreeGenerateMapper.java index 218f7ad..e251ea5 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThreeGenerateMapper.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThreeGenerateMapper.java @@ -3,10 +3,14 @@ package com.hnac.hzims.scheduled.mapper.equipment; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; +import org.apache.ibatis.annotations.Param; /** * @author ysj */ public interface ThreeGenerateMapper extends BaseMapper { + void deletemMonthGenerate(@Param("month") String month,@Param("before") String before); + + void deleteFillGenerate(@Param("before") String before); } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java new file mode 100644 index 0000000..65b2524 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.scheduled.service.alarm; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.alarm.config.entity.AlarmHandleEntity; +import com.hnac.hzims.alarm.config.entity.AlarmHandleFlowEntity; +import com.hnac.hzims.alarm.config.vo.AlarmHandleVo; +import com.hnac.hzims.alarm.show.vo.HandleQueryVo; +import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.support.Query; +import org.springblade.system.user.entity.User; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface HandleService extends BaseService { + + List handles(); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java index 41790e9..1b050d8 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.scheduled.service.alarm.impl; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.entity.AlarmEntity; @@ -10,6 +11,7 @@ import com.hnac.hzims.operational.main.vo.HydropowerUnitRealVo; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.scheduled.mapper.alarm.AlarmQueryMapper; import com.hnac.hzims.scheduled.service.alarm.AlarmQueryService; +import com.hnac.hzims.scheduled.service.alarm.HandleService; import com.hnac.hzims.scheduled.service.operation.station.StationService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,6 +35,8 @@ import java.util.stream.Collectors; @DS("alarm") public class AlarmQueryServiceImpl extends BaseServiceImpl implements AlarmQueryService { + private HandleService handleService; + @Override public void clear(String param) { @@ -46,11 +50,17 @@ public class AlarmQueryServiceImpl extends BaseServiceImpl bells(List codes) { - List alarms = this.list(Wrappers.lambdaQuery() - .in(AlarmEntity::getStationId,codes) - .eq(AlarmEntity::getIsSmallBell,0) - .like(AlarmEntity::getAlarmTime, DateUtil.format(new Date(),DateUtil.PATTERN_DATE)) - ); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.in("STATION_ID",codes); + wrapper.eq("IS_SMALL_BELL",0); + wrapper.like("ALARM_TIME",DateUtil.format(new Date(),DateUtil.PATTERN_DATE)); + // 处理告警过滤 :当天处理告警 + List handles = handleService.handles(); + if(!CollectionUtil.isEmpty(handles)){ + wrapper.notIn("ALARM_ID",handles); + } + + List alarms = this.list(wrapper); if(CollectionUtil.isEmpty(alarms)){ return new ArrayList<>(); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java new file mode 100644 index 0000000..7e17a2e --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java @@ -0,0 +1,39 @@ +package com.hnac.hzims.scheduled.service.alarm.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.hnac.hzims.alarm.config.entity.AlarmHandleEntity; +import com.hnac.hzims.scheduled.mapper.alarm.HandleMapper; +import com.hnac.hzims.scheduled.service.alarm.HandleService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @author ysj + * @version 4.0.0 + * @date 2023/03/09 09:29:34 + */ +@Slf4j +@Service +@RequiredArgsConstructor +@DS("alarm") +public class HandleServiceImpl extends BaseServiceImpl implements HandleService { + + + /** + * 查询处理告警记录 + * + * @return + */ + @Override + public List handles() { + String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + return this.baseMapper.handles(start, end); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThirtyGenerateService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThirtyGenerateService.java index 54227a1..5fd6dd7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThirtyGenerateService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThirtyGenerateService.java @@ -8,4 +8,5 @@ import org.springblade.core.mp.base.BaseService; */ public interface ThirtyGenerateService extends BaseService { + void deleteDayGenerate(String month); } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThreeGenerateService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThreeGenerateService.java index 82d15ce..123baa7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThreeGenerateService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThreeGenerateService.java @@ -1,6 +1,7 @@ package com.hnac.hzims.scheduled.service.equipment; import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; +import org.apache.ibatis.annotations.Param; import org.springblade.core.mp.base.BaseService; /** @@ -8,4 +9,7 @@ import org.springblade.core.mp.base.BaseService; */ public interface ThreeGenerateService extends BaseService { + void deletemMonthGenerate(@Param("month") String month); + + void deleteFillGenerate(); } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThirtyGenerateServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThirtyGenerateServiceImpl.java index 3854493..e3943cf 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThirtyGenerateServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThirtyGenerateServiceImpl.java @@ -7,8 +7,12 @@ import com.hnac.hzims.scheduled.service.equipment.ThirtyGenerateService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.DateUtil; import org.springframework.stereotype.Service; +import java.util.Calendar; +import java.util.Date; + /** * @author ysj */ @@ -19,4 +23,18 @@ import org.springframework.stereotype.Service; public class ThirtyGenerateServiceImpl extends BaseServiceImpl implements ThirtyGenerateService { + /** + * 清除超出30日发电量 + * @param month + */ + @Override + public void deleteDayGenerate(String month) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-30); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND)); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + this.baseMapper.deleteDayGenerate(start); + } } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java index b823bc0..1dba482 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.scheduled.service.equipment.impl; import com.baomidou.dynamic.datasource.annotation.DS; +import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import com.hnac.hzims.scheduled.mapper.equipment.ThreeGenerateMapper; import com.hnac.hzims.scheduled.service.equipment.ThreeGenerateService; @@ -9,6 +10,8 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; import org.springframework.stereotype.Service; +import java.util.Calendar; + /** * @author ysj */ @@ -19,4 +22,29 @@ import org.springframework.stereotype.Service; public class ThreeGenerateServiceImpl extends BaseServiceImpl implements ThreeGenerateService { + /** + * 删除近3年当月发电量 + * @param month + */ + @Override + public void deletemMonthGenerate(String month) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(month, DateUtil.PATTERN_DATE)); + calendar.add(Calendar.YEAR,-2); + Integer year = calendar.get(Calendar.YEAR); + this.baseMapper.deletemMonthGenerate(month,year + "-01-01"); + } + + /** + * 清除填报发电量 + */ + @Override + public void deleteFillGenerate() { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-29); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND)); + this.baseMapper.deleteFillGenerate(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME)); + } } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java index 3dcd216..72089f4 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java @@ -99,6 +99,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { */ @Override public void thisDayPowerGeneration(String param) { + String month = DateUtil.format(new Date(),"yyyy-MM") ; // 步骤1.水电、光伏站点 List stations = stationService.list(Wrappers.lambdaQuery().in(StationEntity::getType, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC))); @@ -106,9 +107,149 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() {}); // 步骤3.站点-设备当日发电量 + this.refreshDayGeneration(stations,devices,month + "-01"); + // 步骤4.近3年的当月发电量 + this.thirtyMonthGenerate(stations,month); } + + /** + * 刷新今日发电量 + * @param stations + * @param devices + */ + private void refreshDayGeneration(List stations, List devices,String month) { + String end = month + " 23:59:59"; + String start = month + " 00:00:00"; + // 查询当日已保存发电量 + List generations = thirtyGenerateService.list(Wrappers.lambdaQuery().eq(ThirtyGenerationEntity::getStrDay,start)); + + // 将站点切割 + int limit = countStep(stations.size()); + List> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + CountDownLatch countDownLatch = new CountDownLatch(limits.size()); + List saves = new CopyOnWriteArrayList<>(); + for(List item : limits){ + try{ + pool.submit(()->{ + item.forEach(station->{ + // 站点设备集合 + List eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + // 遍历查询发电量 + eminfos.forEach(device->{ + List records = dataService.periodTargetData(start,end,5,3,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; + } + // 是否包含今日累计发电量数据 + Optional optional = generations.stream().filter(o->o.getStationId().equals(station.getCode()) && o.getDeviceCode().equals(device.getEmCode())).findFirst(); + if(optional.isPresent()){ + if(StringUtil.isEmpty(records.get(0).getVal())){ + optional.get().setGenerate(BigDecimal.ZERO); + }else{ + optional.get().setGenerate(BigDecimal.valueOf(Double.parseDouble(records.get(0).getVal()) * device.getRideCount())); + } + saves.add(optional.get()); + }else{ + ThirtyGenerationEntity generate = new ThirtyGenerationEntity(); + generate.setStationId(station.getCode()); + generate.setStationName(station.getName()); + generate.setDeviceCode(device.getEmCode()); + generate.setDeviceName(device.getName()); + generate.setTenantId(station.getTenantId()); + generate.setCreateDept(station.getRefDept()); + generate.setCreateUser(station.getCreateUser()); + generate.setUpdateUser(station.getUpdateUser()); + Date time = DateUtil.parse(records.get(0).getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrDay(DateUtil.format(time,DateUtil.PATTERN_DATETIME)); + generate.setDay(time.getDate()); + if(StringUtil.isEmpty(records.get(0).getVal())){ + generate.setGenerate(BigDecimal.ZERO); + }else{ + generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(records.get(0).getVal()) * device.getRideCount())); + } + saves.add(generate); + } + }); + }); + countDownLatch.countDown(); + log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); + }); + }catch (Exception e){ + log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); + } + } + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + thirtyGenerateService.saveOrUpdateBatch(saves); + } + + /** + * 更新近3年的当月发电量 + */ + private void thirtyMonthGenerate(List stations,String month) { + // 步骤1.查询设备当月累计发电量 + List generations = thirtyGenerateService.list(Wrappers.lambdaQuery().like(ThirtyGenerationEntity::getStrDay,month)); + + // 步骤2.删除近3年当月发电量 + threeGenerateService.deletemMonthGenerate(month + "-01"); + + // 步骤3.将当月累计发电量新增表 + this.saveThreeMonthGenerate(generations,month); + + // 步骤4.清除填报发电量 + threeGenerateService.deleteFillGenerate(); + + // 步骤5.清除超出30日发电量 + thirtyGenerateService.deleteDayGenerate(month); + + // 步骤6.重新补充填报发电量 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + stations.forEach(station->{ + this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end)); + }); + } + + /** + * 保存近3年当月发电量 + * @param generations + */ + private void saveThreeMonthGenerate(List generations,String month) { + if(CollectionUtil.isEmpty(generations)){ + return; + } + threeGenerateService.saveBatch(generations.stream().collect(Collectors.groupingBy(ThirtyGenerationEntity::getDeviceCode)).entrySet().stream().map(entry->{ + ThreeGenerationEntity generate = new ThreeGenerationEntity(); + generate.setStationId(entry.getValue().get(0).getStationId()); + generate.setStationName(entry.getValue().get(0).getStationName()); + generate.setDeviceCode(entry.getValue().get(0).getDeviceCode()); + generate.setDeviceName(entry.getValue().get(0).getDeviceName()); + generate.setTenantId(entry.getValue().get(0).getTenantId()); + generate.setCreateDept(entry.getValue().get(0).getCreateDept()); + generate.setCreateUser(entry.getValue().get(0).getCreateUser()); + generate.setUpdateUser(entry.getValue().get(0).getUpdateUser()); + String strMonth = month + "-01"; + generate.setStrMonth(strMonth); + generate.setMonth(DateUtil.parse(strMonth,DateUtil.PATTERN_DATE).getMonth() + 1); + generate.setGenerate(BigDecimal.valueOf(entry.getValue().stream().mapToDouble(o->o.getGenerate().doubleValue()).sum()).setScale(2, RoundingMode.HALF_UP)); + return generate; + }).collect(Collectors.toList())); + } + + /** * 查询发电量 * @param stations diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java index 0547edb..279ef93 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -365,6 +365,10 @@ public class MonitorServiceImpl implements MonitorService { device.setState(-1); return; } + if(Double.parseDouble(powers.get(0).getValue()) <= 0){ + device.setState(-1); + return; + } device.setState(1); } }); diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml new file mode 100644 index 0000000..ab99010 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml @@ -0,0 +1,17 @@ + + + + + + + diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThirtyGenerateMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThirtyGenerateMapper.xml index a0937a4..13693bf 100644 --- a/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThirtyGenerateMapper.xml +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThirtyGenerateMapper.xml @@ -2,4 +2,8 @@ + + DELETE FROM HZIMS_EM_THIRTY_GENERATE + WHERE STR_DAY < #{day} + \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThreeGenerateMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThreeGenerateMapper.xml index 972da58..f0465c4 100644 --- a/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThreeGenerateMapper.xml +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThreeGenerateMapper.xml @@ -2,4 +2,18 @@ + + DELETE FROM HZIMS_EM_THREE_GENERATE + WHERE STR_MONTH = #{month} + + OR STR_MONTH < #{before} + + + + DELETE FROM HZIMS_EM_THREE_GENERATE + WHERE DEVICE_CODE IS NULL + + OR STR_MONTH < #{before} + + \ No newline at end of file