From c0428a031f0c3ff24f72651f02d7d1cec97aa69f Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 18 May 2023 17:19:40 +0800 Subject: [PATCH] =?UTF-8?q?#bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../equipment/service/impl/EmInfoServiceImpl.java | 51 +++++++++++++++++----- .../service/impl/AbnormalAlarmServiceImpl.java | 18 +++----- .../impl/HistoryAbnormalAlarmServiceImpl.java | 2 +- .../duty/service/impl/ImsDutyMainServiceImpl.java | 3 ++ .../main/service/impl/HydropowerServiceImpl.java | 4 +- .../main/service/impl/PhotovoltaicServiceImpl.java | 2 +- .../main/service/impl/WaterServiceImpl.java | 2 +- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java index 1328a1d..18bf630 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.api.client.util.Sleeper; import com.google.common.collect.Lists; import com.hnac.hzims.equipment.EquipmentContants; import com.hnac.hzims.equipment.entity.*; @@ -21,6 +22,7 @@ import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; @@ -38,6 +40,7 @@ import org.springframework.util.Assert; import javax.validation.Valid; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * 服务实现类 @@ -45,6 +48,7 @@ import java.util.stream.Collectors; * @author Chill */ @Service +@Slf4j public class EmInfoServiceImpl extends BaseServiceImpl implements IEmInfoService { @Autowired private IEmParamService paramService; @@ -77,6 +81,11 @@ public class EmInfoServiceImpl extends BaseServiceImpl getEmInfoByCode(String emCode) { EmInfoNoScopeMapper mapper = SpringUtil.getBean("emInfoNoScopeMapper"); @@ -417,29 +426,38 @@ public class EmInfoServiceImpl extends BaseServiceImpl list = this.baseMapper.selectEminfoAndEmParamVoList(); + List devices = this.baseMapper.selectEminfoAndEmParamVoList(); // 查询所有设备(ct、pt、installedCapacity)配置参数 List paramList = this.paramService.getParamByParamNameGenerate(); - // 获取设备监测点 // 获取设备监测点位:未配置监测点位不进行统计设备 - List multiAnalyzeCodePOList = list.stream().map(o->{ + List multiAnalyzeCodePOList = devices.stream().map(o->{ MultiAnalyzeCodePO multiAnalyzeCodePO = new MultiAnalyzeCodePO(); multiAnalyzeCodePO.setDeviceCode(o.getEmCode()); multiAnalyzeCodePO.setSignages(HomePageConstant.SIGNAGES); return multiAnalyzeCodePO; }).collect(Collectors.toList()); - R> result = searchClient.getAnalyzeCodeBySignages(multiAnalyzeCodePOList); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return; - } + // 切割 + int limit = countStep(multiAnalyzeCodePOList.size()); + List> lists = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> multiAnalyzeCodePOList.stream().skip((long) a * MAX_SEND).limit(MAX_SEND).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + // 接收数据 + List analys = new ArrayList<>(); + lists.forEach(list->{ + R> result = searchClient.getAnalyzeCodeBySignages(list); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return; + } + analys.addAll(result.getData()); + }); // 设备遍历 - list.forEach(item->{ + devices.forEach(item->{ item.setRideCount(1); item.setInstalledCapacity(0.0); + List signages = analys.stream().filter(o-> item.getEmCode().equals(o.getDeviceCode()) && !StringUtil.isEmpty(o.getSignage()) && !StringUtil.isEmpty(o.getRealId())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(signages)){ + return; + } // list -> map - item.setPoint(result.getData().stream().filter(o-> item.getEmCode().equals(o.getDeviceCode()) && StringUtil.isNotBlank(o.getSignage()) && StringUtil.isNotBlank(o.getRealId())). - collect(Collectors.toMap(AnalyzeCodeBySignagesVO::getSignage,AnalyzeCodeBySignagesVO::getRealId))); - + item.setPoint(signages.stream().collect(Collectors.toMap(AnalyzeCodeBySignagesVO::getSignage,AnalyzeCodeBySignagesVO::getRealId))); // 寻找设备配置参数 List itemParamList = paramList.stream().filter(o->item.getId().equals(o.getInfoId())).collect(Collectors.toList()); if(CollectionUtil.isNotEmpty(itemParamList)){ @@ -456,6 +474,8 @@ public class EmInfoServiceImpl extends BaseServiceImpl Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); + redisTemplate.opsForValue().set(em_info_list_path, JSONObject.toJSONString(devices.stream().filter(o-> Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); + } + + /** + * 计算切分次数 + */ + private static Integer countStep(Integer size) { + return (size + MAX_SEND - 1) / MAX_SEND; } private void validEmInfo(EmInfoAddVo em_info) { diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java index e59097d..f8d4c68 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java @@ -71,14 +71,13 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl> result = soeClient.getByStationsAndTime(query); @@ -88,8 +87,8 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl list = result.getData().getRecords().stream().sorted(Comparator.comparing(SoeData::getTs).reversed()) - .collect(Collectors.toMap(o->o.getStation()+o.getSoeType(),Function.identity(),(o1, o2) -> o1)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List list = new ArrayList<>(result.getData().getRecords().stream().sorted(Comparator.comparing(SoeData::getTs).reversed()) + .collect(Collectors.toMap(o -> o.getStation() + o.getSoeType(), Function.identity(), (o1, o2) -> o1)).values()); log.error("alarm_data_handle_end_result : {}",list); list.forEach(item -> { AbnormalAlarmEntity queryEntity = this.baseMapper.getAbnormalAlarm(item.getStation(),item.getSoeType()); @@ -160,6 +159,7 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); if(ObjectUtil.isEmpty(queryEntity) || !flag){ HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); + entity.setAlarmId(item.getId()); entity.setStationId(item.getStation()); entity.setStationName(stationName); entity.setRealId(item.getRealId()); @@ -172,13 +172,9 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl wrapper = Wrappers.lambdaQuery(); + wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); if(StringUtils.isNotEmpty(param.getCode())){ wrapper.eq(StationEntity::getCode,param.getCode()); } @@ -215,7 +216,6 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl() {{ eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index 07dd56e..b7535a6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -285,7 +285,7 @@ public class HydropowerServiceImpl implements HydropowerService { private List getLoadsByDay(EminfoAndEmParamVo device) { String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - List records = analyseDataService.periodTargetData(start, end, 1, 2, device.getEmCode(), HomePageConstant.PV_LOAD); + List records = analyseDataService.periodTargetData(start, end, 3, 2, device.getEmCode(), HomePageConstant.PV_LOAD); if (CollectionUtil.isEmpty(records)) { return new ArrayList<>(); } @@ -526,7 +526,7 @@ public class HydropowerServiceImpl implements HydropowerService { GenerationPowerVo generate = new GenerationPowerVo(); Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + generate.setGenerate(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); return generate; }).collect(Collectors.toList()); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java index 9042377..173e3dd 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java @@ -487,7 +487,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { return "0"; } String value = map.get(realId); - if (StringUtil.isEmpty(realId)) { + if (StringUtil.isEmpty(value)) { return "0"; } // 获取value diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java index 09b81b3..83c7f71 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java @@ -521,7 +521,7 @@ public class WaterServiceImpl implements IWaterService { return "0"; } String value = map.get(realId); - if(StringUtil.isBlank(realId)){ + if(StringUtil.isBlank(value)){ return "0"; } // 获取value