From 74525df6f5ac99ba34dde1eb8e0d4931e0b4de77 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 13 Apr 2023 16:40:41 +0800 Subject: [PATCH 1/7] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99=E5=8F=91?= =?UTF-8?q?=E5=A1=AB=E6=8A=A5=E7=94=B5=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/operational/fill/entity/UseEntity.java | 5 + .../operational/fill/service/GenerateService.java | 9 + .../fill/service/impl/GenerateServiceImpl.java | 54 +++ .../main/controller/WebHomeController.java | 9 +- .../main/service/HydropowerService.java | 2 +- .../main/service/impl/HydropowerServiceImpl.java | 406 ++++++++++++--------- .../main/service/impl/SideHustleServiceImpl.java | 72 +--- .../main/service/impl/WaterServiceImpl.java | 182 ++++----- 8 files changed, 395 insertions(+), 344 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java index f097c8d..75b7786 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java @@ -5,12 +5,17 @@ import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; import java.io.Serializable; import java.math.BigDecimal; +/** + * @author usj + */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("hzims_fill_use") @ApiModel(value="UseEntity", description="保存用电量填报数据对象") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java index 8e7bcfe..29bb8aa 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java @@ -6,12 +6,15 @@ import com.hnac.hzims.operational.fill.entity.RainfallEntity; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.vo.RainfallVo; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import java.util.List; +import java.util.Map; /** * @author ysj @@ -26,6 +29,12 @@ public interface GenerateService extends BaseService { // 新增/修改发电量填报数据 boolean saveUpdate(GenerateEntity entity); + // 查询填报用电量 + Float generate(String date,String station); + + // 查询30天填报用电量 + List generate30Day(String day, String station); + // 获取站点填报发电量 List generateThreeYear(String start, String end, String station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index 6ff4613..2b1f037 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -5,12 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.fill.entity.UseEntity; import com.hnac.hzims.operational.fill.mapper.GenerateMapper; import com.hnac.hzims.operational.fill.service.GenerateService; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.wrapper.GenerateWrapper; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -25,6 +28,7 @@ import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; @@ -88,6 +92,56 @@ public class GenerateServiceImpl extends BaseServiceImpl powers = this.list(Wrappers.lambdaQuery() + .likeRight(GenerateEntity::getFillDate,date) + .eq(GenerateEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0f; + } + return (float) powers.stream().mapToDouble(GenerateEntity::getGenerate).sum(); + } + + /** + * 查询30天填报用电量 + * @param day : 结束日期 yyyy-MM-dd + * @param station 站点编码 + * @return + */ + @Override + public List generate30Day(String day, String station) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = this.list(Wrappers.lambdaQuery() + .between(GenerateEntity::getFillDate,start,end) + .eq(GenerateEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record->{ + GenerationPowerVo generate = new GenerationPowerVo(); + generate.setDate(record.getFillDate()); + if(Math.abs(record.getGenerate()) <= 0){ + generate.setGenerate(0f); + }else{ + generate.setGenerate(Float.parseFloat(record.getGenerate().toString())); + } + return generate; + }).collect(Collectors.toList()); + } + + /** * * @param start 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd * @param end 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java index c7a5096..1f53f74 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java @@ -17,6 +17,9 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; +/** + * @author ysj + */ @RestController @RequestMapping("/webHome") @Api(value = "app首页", tags = "app-首页") @@ -24,12 +27,13 @@ import java.util.List; public class WebHomeController extends BladeController { private final HydropowerService service; + @ApiLog @ApiOperation("水电站站点统计") @GetMapping("/webStation") @ApiOperationSupport(order = 1) public R hydropowerStation(@ApiParam(value = "站点机构ID") Long deptId) { - HydropowerStationVo response = service.webStation(deptId); + HydropowerStationVo response = service.station(deptId); return R.data(response); } @ApiLog @@ -41,7 +45,6 @@ public class WebHomeController extends BladeController { return R.data(list); } @ApiLog - @ApiOperation("水电站站点列表") @GetMapping("/webStationList") @ApiOperationSupport(order = 2) @@ -49,4 +52,4 @@ public class WebHomeController extends BladeController { return R.data(service.webStationList(deptId)); } -} +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java index b7a0576..6ccae65 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java @@ -14,7 +14,7 @@ public interface HydropowerService { void loadHydropowerTarget(String param); - HydropowerStationVo webStation(Long deptId); + HydropowerStationVo station(Long deptId); List hydropowerDevice(Long deptId); 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 8393825..38f74be 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 @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.main.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.feign.IPlanGenertionClient; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; @@ -9,9 +10,10 @@ import com.hnac.hzims.equipment.vo.PlanPowerYearVo; import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; +import com.hnac.hzims.operational.fill.service.GenerateService; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationAttributeService; import com.hnac.hzims.operational.station.service.IStationService; @@ -44,23 +46,25 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class HydropowerServiceImpl implements HydropowerService { - private final IAnalyseDataService analyseDataService; - - private final IHomePageService homePageService; + private final IWaterService waterService; - private final IMainSystemMonitoringService maintenanceTaskService; + private final IWeatherService weatherService; private final IStationService stationService; - private final IStationAttributeService attributeService; + private final GenerateService generateService; - private final IWaterService waterService; + private final IHomePageService homePageService; - private final IPlanGenertionClient planGenertionClient; + private final IAnalyseDataService analyseDataService; + + private final IStationAttributeService attributeService; + + private final IMainSystemMonitoringService maintenanceTaskService; private final ISoeClient soeClient; - private final IWeatherService weatherService; + private final IPlanGenertionClient planGenertionClient; private final RedisTemplate redisTemplate; @@ -79,63 +83,54 @@ public class HydropowerServiceImpl implements HydropowerService { */ @Override public void loadHydropowerReal(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ + // 水电站站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 水电站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(devices)){ return; } // 实时数据 Map map = this.getRealMap(); // 单位 Map unitMap = this.attributeService.getPointUnit(); - List list = new ArrayList<>(); - valid.forEach(device->{ - HydropowerUnitRealVo realVo = new HydropowerUnitRealVo(); - realVo.setDeptId(device.getCreateDept()); - realVo.setDeviceCode(device.getEmCode()); - realVo.setDeptName(device.getName()); - realVo.setDeviceName(device.getName()); + // 实时数据 + List reals = devices.stream().map(device->{ + HydropowerUnitRealVo real = new HydropowerUnitRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeptName(device.getName()); + real.setDeviceName(device.getName()); // 开关机状态 - String state = this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY); - realVo.setState(state); + real.setState(this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY)); // 有功功率 - String activePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER); - realVo.setActivePower(activePower); + real.setActivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER)); // 无功功率 - String reactivePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER); - realVo.setReactivePower(reactivePower); + real.setReactivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER)); // 功率因数 - String powerFactor = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR); - realVo.setPowerFactor(powerFactor); + real.setPowerFactor(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR)); // 机组频率 - String frequency = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY); - realVo.setFrequency(frequency); + real.setFrequency(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY)); // 导叶开度 - String guideOpen = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN); - realVo.setGuideOpen(guideOpen); + real.setGuideOpen(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN)); // 定子电压 - String statorVoltage = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE); - realVo.setStatorVoltage(statorVoltage); + real.setStatorVoltage(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE)); // 定子电流 - String statorCurrent = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT); - realVo.setStatorCurrent(statorCurrent); + real.setStatorCurrent(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT)); // 单位设置 - this.setttingUnit(device,unitMap,realVo); - list.add(realVo); - }); - redisTemplate.opsForValue().set(load_hydropower_unit_real_key,list); - } - - /** - * 获取实时数据 - * @return - */ - private Map getRealMap() { - String json = (String) redisTemplate.opsForValue().get(real_id_key); - if(StringUtil.isBlank(json)){ - return null; + this.setttingUnit(device,unitMap,real); + return real; + }).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(reals)){ + return; } - return JSONObject.parseObject(json, new TypeReference>() {}); + redisTemplate.opsForValue().set(load_hydropower_unit_real_key,reals); } /** @@ -144,59 +139,98 @@ public class HydropowerServiceImpl implements HydropowerService { */ @Override public void loadHydropowerTarget(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ + // 水电站站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 补充填补发电指标 + List targets = this.generteFill(stations); + // 水电站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isNotEmpty(devices)){ + targets.addAll(devices.stream().map(device->{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeviceName(device.getName()); + target.setDeptName(device.getName()); + // 当年发电量 + target.setPowerYear(this.getGenerationPower(device,0)); + // 当月发电量 + target.setPowerMon(this.getGenerationPower(device,1)); + // 当日发电量 + target.setPowerDay(this.getGenerationPower(device,2)); + // 当天有功功率 + target.setActivePowerVoList(waterService.getActivePowerVoList(device)); + // 30天发电量 + target.setGenerationPowerVoList(this.getGenerationPowerList(device)); + return target; + }).collect(Collectors.toList())); + } + // 站点指标数据为空 + if(CollectionUtil.isEmpty(targets)){ return; } - List list = new ArrayList<>(); - valid.forEach(device->{ - HydropowerUnitTargetVo targetVo = new HydropowerUnitTargetVo(); - targetVo.setDeptId(device.getCreateDept()); - targetVo.setDeviceCode(device.getEmCode()); - targetVo.setDeviceName(device.getName()); - targetVo.setDeptName(device.getName()); + redisTemplate.opsForValue().set(load_hydropower_unit_target_key,targets); + } + + /** + * 获取填报用电量 + * @param stations + * @return + */ + private List generteFill(List stations) { + Calendar calendar = Calendar.getInstance(); + String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + return stations.stream().map(station ->{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); // 当年发电量 - float powerYear = this.getGenerationPower(device,0); - targetVo.setPowerYear(powerYear); + target.setPowerYear(generateService.generate(year,station.getCode())); // 当月发电量 - float powerMon = this.getGenerationPower(device,1); - targetVo.setPowerMon(powerMon); + target.setPowerMon(generateService.generate(mon,station.getCode())); // 当日发电量 - float powerDay = this.getGenerationPower(device,2); - // 当天有功功率 - List activePowerVoList = waterService.getActivePowerVoList(device); - targetVo.setActivePowerVoList(activePowerVoList); + target.setPowerDay(generateService.generate(day,station.getCode())); // 30天发电量 - List generationPowerVoList = this.getGenerationPowerList(device); - targetVo.setGenerationPowerVoList(generationPowerVoList); - targetVo.setPowerDay(powerDay); - list.add(targetVo); - }); - redisTemplate.opsForValue().set(load_hydropower_unit_target_key,list); + target.setGenerationPowerVoList(generateService.generate30Day(day,station.getCode())); + return target; + }).collect(Collectors.toList()); } + /** - * 获取有效设备 + * 泵站设备 + * @param stations * @return */ - private List getValidDeviceList() { - // 水利站点(All) - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), null); - if(CollectionUtil.isEmpty(stationList)){ - return null; + private List pumpDevices(List stations){ + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); } - // 获取所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - if(CollectionUtil.isEmpty(deviceList)){ - return null; + List devices = maintenanceTaskService.getEmInfoList(); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); } - // 有效泵租设备 - List deptIdList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptIdList)){ + return devices.stream().filter(device->stations.contains(device.getCreateDept())).collect(Collectors.toList()); + } + + /** + * 获取实时数据 + * @return + */ + private Map getRealMap() { + String json = (String) redisTemplate.opsForValue().get(real_id_key); + if(StringUtil.isBlank(json)){ return null; } - return deviceList.stream().filter(o->deptIdList.contains(o.getCreateDept())).collect(Collectors.toList()); + return JSONObject.parseObject(json, new TypeReference>() {}); } @@ -334,7 +368,7 @@ public class HydropowerServiceImpl implements HydropowerService { * @return */ @Override - public HydropowerStationVo webStation(Long deptId) { + public HydropowerStationVo station(Long deptId) { if(ObjectUtil.isEmpty(deptId)){ return null; } @@ -343,86 +377,76 @@ public class HydropowerServiceImpl implements HydropowerService { if(ObjectUtil.isEmpty(station)){ return null; } - List list = this.getHydropowerStationList(Collections.singletonList(station)); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return list.get(0); + // 实时监测点数据 + List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); + // 获取站点机组指标数据 + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + // 所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + // 实时天气 + Map weather = this.getWeather(Collections.singletonList(station.getCode())); + // 七天天气 + Map weekWeather = this.getWeekWeather(Collections.singletonList(station.getCode())); + HydropowerStationVo response = new HydropowerStationVo(); + response.setDeptId(station.getRefDept()); + response.setDeptName(station.getName()); + response.setStationCode(station.getCode()); + // 站点状态 + List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); + response.setStationStatus(!CollectionUtil.isNotEmpty(soeDataList)); + // 站点实时天气 + response.setTemp(this.getTemp(weather,station.getCode())); + // 站点七天天气 + response.setWeather(this.getDailyList(weekWeather,station.getCode())); + // 限制水位 + response.setLimitWaterLevel(station.getLimitWaterLevel()); + // 运行天数 + response.setRunDay(this.getRunDay(station)); + // 装机容量 + response.setInstalledCapacity(this.getInstalledCapacity(deviceList,station.getRefDept())); + // 总有功功率(总发电负荷) + response.setPowerSum(this.getPowerSum(realList,station.getRefDept())); + // 总有功单位 + response.setPowerUnit(this.getPowerUnit(realList,station.getRefDept())); + // 月计划发电量 + response.setPlanPowerMon(this.getPlanPowerrMon(station.getCode())); + // 年计划发电量 + response.setPlanPowerYear(this.getPlanPowerYear(station.getCode())); + // 月发电量、年发电量、年发电完成率 + this.handleStationInfo(station.getRefDept(),response); + // 水位、水位曲线 + this.handleWaterLeve(station.getCode(),response); + // 年发电量完成百分比 + response.setPowerYearMap(this.handlePowerFinish(station)); + // 设备信息 + response.setDeviceList(this.getDevices(station,realList,targetList)); + return response; } + /** - * 获取首页站点信息 - * @param list + * 水电站-机组列表 + * @param deptId * @return */ - private List getHydropowerStationList(List list) { - if(CollectionUtil.isEmpty(list)){ + @Override + public List hydropowerDevice(Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return null; + } + // 查询站点 + StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); + if(ObjectUtil.isEmpty(station)){ return null; } // 实时监测点数据 List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); // 获取站点机组指标数据 List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - // 所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - // 实时天气 - Map weather = this.getWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); - // 七天天气 - Map weekWeather = this.getWeekWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); - List result = new ArrayList<>(); - list.forEach(station ->{ - HydropowerStationVo response = new HydropowerStationVo(); - response.setDeptId(station.getRefDept()); - response.setDeptName(station.getName()); - response.setStationCode(station.getCode()); - // 站点状态 - List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); - if (CollectionUtil.isNotEmpty(soeDataList)) { - response.setStationStatus(false); - } else { - response.setStationStatus(true); - } - // 站点实时天气 - String temp = this.getTemp(weather,station.getCode()); - response.setTemp(temp); - // 站点七天天气 - List dailys = this.getDailyList(weekWeather,station.getCode()); - response.setWeather(dailys); - // 限制水位 - response.setLimitWaterLevel(station.getLimitWaterLevel()); - // 运行天数 - int runDay = this.getRunDay(station); - response.setRunDay(runDay); - // 装机容量 - double installedCapacity = this.getInstalledCapacity(deviceList,station.getRefDept()); - response.setInstalledCapacity(installedCapacity); - // 总有功功率(总发电负荷) - double powerSum = this.getPowerSum(realList,station.getRefDept()); - response.setPowerSum(powerSum); - // 总有功单位 - String unit = this.getPowerUnit(realList,station.getRefDept()); - response.setPowerUnit(unit); - // 月计划发电量 - float planPowerMon = this.getPlanPowerrMon(station.getCode()); - response.setPlanPowerMon(planPowerMon); - // 年计划发电量 - float planPowerYear = this.getPlanPowerYear(station.getCode()); - response.setPlanPowerYear(planPowerYear); - // 月发电量、年发电量、年发电完成率 - this.handleStationInfo(station.getRefDept(),response); - // 水位、水位曲线 - this.handleWaterLeve(station.getCode(),response); - // 年发电量完成百分比 - List powerYearList = this.handlePowerFinish(station); - response.setPowerYearMap(powerYearList); - // 设备信息 - List devices = this.getDevices(station,realList,targetList); - response.setDeviceList(devices); - result.add(response); - }); - return result; + return this.getDevices(station,realList,targetList); } + /** * 获取站点设备信息 * @param station @@ -705,39 +729,63 @@ public class HydropowerServiceImpl implements HydropowerService { }).collect(Collectors.toList()); } + /** - * 水电站-机组列表 + * 水电站站点列表 * @param deptId * @return */ @Override - public List hydropowerDevice(Long deptId) { - if(ObjectUtil.isEmpty(deptId)){ - return null; - } - // 查询站点 - StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); - if(ObjectUtil.isEmpty(station)){ + public List webStationList(Long deptId) { + List stations = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE,Collections.singletonList(HomePageConstant.HYDROPOWER),null); + if(CollectionUtil.isEmpty(stations)){ return null; } // 实时监测点数据 List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); // 获取站点机组指标数据 List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - return this.getDevices(station,realList,targetList); - } - - /** - * 水电站站点列表 - * @param deptId - * @return - */ - @Override - public List webStationList(Long deptId) { - List list = stationService.getStationType(null,Collections.singletonList(HomePageConstant.HYDROPOWER),null); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return this.getHydropowerStationList(list); + // 所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + // 实时天气 + Map weather = this.getWeather(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); + // 七天天气 + Map weekWeather = this.getWeekWeather(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); + return stations.stream().map(station->{ + HydropowerStationVo hydropower = new HydropowerStationVo(); + hydropower.setDeptId(station.getRefDept()); + hydropower.setDeptName(station.getName()); + hydropower.setStationCode(station.getCode()); + // 站点状态 + List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); + hydropower.setStationStatus(!CollectionUtil.isNotEmpty(soeDataList)); + // 站点实时天气 + hydropower.setTemp(this.getTemp(weather,station.getCode())); + // 站点七天天气 + hydropower.setWeather(this.getDailyList(weekWeather,station.getCode())); + // 限制水位 + hydropower.setLimitWaterLevel(station.getLimitWaterLevel()); + // 运行天数 + hydropower.setRunDay(this.getRunDay(station)); + // 装机容量 + hydropower.setInstalledCapacity(this.getInstalledCapacity(deviceList,station.getRefDept())); + // 总有功功率(总发电负荷) + hydropower.setPowerSum(this.getPowerSum(realList,station.getRefDept())); + // 总有功单位 + hydropower.setPowerUnit(this.getPowerUnit(realList,station.getRefDept())); + // 月计划发电量 + hydropower.setPlanPowerMon(this.getPlanPowerrMon(station.getCode())); + // 年计划发电量 + hydropower.setPlanPowerYear(this.getPlanPowerYear(station.getCode())); + // 月发电量、年发电量、年发电完成率 + this.handleStationInfo(station.getRefDept(),hydropower); + // 水位、水位曲线 + this.handleWaterLeve(station.getCode(),hydropower); + // 年发电量完成百分比 + hydropower.setPowerYearMap(this.handlePowerFinish(station)); + // 设备信息 + hydropower.setDeviceList(this.getDevices(station,realList,targetList)); + return hydropower; + }).collect(Collectors.toList()); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java index decfe3d..1da8b9b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java @@ -23,9 +23,9 @@ import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.duty.vo.DutyInfoVo; import com.hnac.hzims.operational.duty.vo.DutyTaskVo; import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; @@ -66,6 +66,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; +/** + * @author ysj + */ @Service @RequiredArgsConstructor @Slf4j @@ -308,13 +311,6 @@ public class SideHustleServiceImpl implements ISideHustleService { }}); List faultList = operPhenomenonEntityList.stream().map(OperPhenomenonEntity::getEmCode).distinct().collect(Collectors.toList()); deviceClassifyMap.put(HomePageConstant.FAULT,faultList); - // 保养 - /*List operMaintenanceTaskEntityList = operMaintenanceTaskService.list(new QueryWrapper() {{ - in("EM_CODE", deviceCodeList); - ne("STATUS", MaintenanceConstant.TASK_STATUS_5); - }}); - List maintainList = operMaintenanceTaskEntityList.stream().map(OperMaintenanceTaskEntity::getEmCode).collect(Collectors.toList()); - deviceClassifyMap.put(HomePageConstant.MAINTAIN,maintainList);*/ // 检修 List operAccessTaskEntityList = operAccessTaskService.list(new QueryWrapper() {{ in("EM_CODE", deviceCodeList); @@ -506,11 +502,11 @@ public class SideHustleServiceImpl implements ISideHustleService { areaDutyVo.setGeneratingCapacity(generatingCapacity); } - /** + /*** * 根据当班时间查询发电量 * @param devices - * @param startDate - * @param endDate + * @param start + * @param end * @return */ private float generateByDuty(List devices, Date start, Date end) { @@ -520,7 +516,7 @@ public class SideHustleServiceImpl implements ISideHustleService { } for(EminfoAndEmParamVo device : devices ){ generate += analyseDataService.periodTargetFloat(DateUtil.format(start,DateUtil.PATTERN_DATETIME),DateUtil.format(end,DateUtil.PATTERN_DATETIME),3,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - }; + } return generate; } @@ -585,7 +581,7 @@ public class SideHustleServiceImpl implements ISideHustleService { dateCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE)); dateCal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND)); return dateCal.getTime(); - }; + } /** * 获取结束时间 @@ -608,7 +604,7 @@ public class SideHustleServiceImpl implements ISideHustleService { dateCal.set(Calendar.MINUTE, endCal.get(Calendar.MINUTE)); dateCal.set(Calendar.SECOND, endCal.get(Calendar.SECOND)); return dateCal.getTime(); - }; + } /** * 当班运行数据 @@ -840,7 +836,7 @@ public class SideHustleServiceImpl implements ISideHustleService { return null; } Map> powerMap = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - List monList = homePageService.getMonthList(0,12,false);; + List monList = homePageService.getMonthList(0,12,false); // 获取总发电量 float sumPower = this.getSumPower(map.values(),powerMap,monList); List list = new ArrayList<>(); @@ -854,7 +850,7 @@ public class SideHustleServiceImpl implements ISideHustleService { } areaPowerScaleVo.setPower(power); // 发电量占比 - double scale = this.getPowerScale(power,sumPower);; + double scale = this.getPowerScale(power,sumPower); areaPowerScaleVo.setScale(scale); list.add(areaPowerScaleVo); }); @@ -874,7 +870,7 @@ public class SideHustleServiceImpl implements ISideHustleService { return null; } // 获取站点编码集合 - List codes = map.entrySet().stream().map(o-> o.getValue().get(0).getCode()).collect(Collectors.toList()); + List codes = map.values().stream().map(stationEntities -> stationEntities.get(0).getCode()).collect(Collectors.toList()); // 获取站点实时天气 Map nowWeather = this.weatherService.getNowWeather( codes); // 获取站点7日天气 @@ -974,7 +970,7 @@ public class SideHustleServiceImpl implements ISideHustleService { * @return */ private List getStationData() { - Map map = new HashMap<>(); + Map map; Object json = redisTemplate.opsForValue().get(station_data_key); if (ObjectUtil.isNotEmpty(json)) { map = JSONObject.parseObject(json.toString(), new TypeReference>() { @@ -1166,9 +1162,7 @@ public class SideHustleServiceImpl implements ISideHustleService { } List codeList = new ArrayList<>(); // 添加所有站点Code - map.values().forEach(item->{ - codeList.addAll(item.stream().map(StationEntity::getCode).collect(Collectors.toList())); - }); + map.values().forEach(item-> codeList.addAll(item.stream().map(StationEntity::getCode).collect(Collectors.toList()))); if(CollectionUtil.isEmpty(codeList)){ return null; } @@ -1214,7 +1208,6 @@ public class SideHustleServiceImpl implements ISideHustleService { return; } // 存放设备信息集合 - List deviceVoList = new ArrayList<>(); List equipmentCodeList = R.getData().stream().map(EmInfoEntity::getNumber).collect(Collectors.toList()); // 总数 @@ -1224,7 +1217,7 @@ public class SideHustleServiceImpl implements ISideHustleService { // 故障 List fault = this.handlerDeviceStatus(faultList,equipmentCodeList,"故障"); equipmentCountVo.setFaultCount((long) fault.size()); - deviceVoList.addAll(fault); + List deviceVoList = new ArrayList<>(fault); // 检修 List overhaul = this.handlerDeviceStatus(overhaultList,equipmentCodeList,"检修"); equipmentCountVo.setOverhaulCount((long) overhaul.size()); @@ -1266,7 +1259,7 @@ public class SideHustleServiceImpl implements ISideHustleService { if(CollectionUtil.isEmpty(statusList) || CollectionUtil.isEmpty(equipmentCodeList)){ return new ArrayList<>(); } - List statusDevice = statusList.stream().filter(o->equipmentCodeList.contains(o)).distinct().collect(Collectors.toList()); + List statusDevice = statusList.stream().filter(equipmentCodeList::contains).distinct().collect(Collectors.toList()); if(CollectionUtil.isEmpty(statusDevice)){ return new ArrayList<>(); } @@ -1340,37 +1333,6 @@ public class SideHustleServiceImpl implements ISideHustleService { } /** - * 递归查询子站点 - * - * @param departList - * @param parentPart - * @param list - * @return - */ - private List getAreaStation(List departList, Dept parentPart, List list) { - departList.forEach(dept -> { - if (dept.getParentId().equals(parentPart.getId())) { - // FIXME 是否只需要添加站点 - if (dept.getDeptCategory().equals(4)) { - list.add(dept); - } - getAreaStation(departList, dept, list); - } - }); - if(CollectionUtil.isEmpty(list)){ - return null; - } - List deptList = list.stream().map(Dept::getId).collect(Collectors.toList()); - List stationList = this.getStation(Collections.singletonList(HomePageConstant.HYDROPOWER), deptList); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - List refDeptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - return list.stream().filter(o->refDeptList.contains(o.getId())).collect(Collectors.toList()); - } - - - /** * 区域机构下是否存在水电站 * @param deptAuthList * @param area 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 a27d3fa..76f664a 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 @@ -100,41 +100,42 @@ public class WaterServiceImpl implements IWaterService { */ @Override public void loadWaterPumpReal(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ + // 水利站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,HomePageConstant.waterList) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 泵站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(devices)){ return; } // 实时数据 Map map = this.getRealMap(); - List list = new ArrayList<>(); - valid.forEach(device->{ - WaterPumpRealVo waterPumpRealVo = new WaterPumpRealVo(); - waterPumpRealVo.setDeptId(device.getCreateDept()); - waterPumpRealVo.setDeviceCode(device.getEmCode()); - waterPumpRealVo.setDeptName(device.getName()); + List list = devices.stream().map(device->{ + WaterPumpRealVo real = new WaterPumpRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeptName(device.getName()); // 装机容量 - waterPumpRealVo.setInstalledCapacity(device.getInstalledCapacity()); + real.setInstalledCapacity(device.getInstalledCapacity()); // 开机状态 - int state = this.getPumpState(device,map); - waterPumpRealVo.setState(state); + real.setState(this.getPumpState(device,map)); // 功率因数 - double powerFactor = this.getPowerFactor(device,map); - waterPumpRealVo.setPowerFactor(powerFactor); + real.setPowerFactor(this.getPowerFactor(device,map)); // 有功功率 - float activePower = this.getActivePower(device,map); - waterPumpRealVo.setActivePower(activePower); + real.setActivePower(this.getActivePower(device,map)); // 无功功率 - float reactivePower = this.getReactivePower(device,map); - waterPumpRealVo.setReactivePower(reactivePower); + real.setReactivePower(this.getReactivePower(device,map)); // 电压 - double voltage = this.getVoltage(device,map); - waterPumpRealVo.setVoltage(voltage); + real.setVoltage(this.getVoltage(device,map)); // 电流 - double current = this.getCurrent(device,map); - waterPumpRealVo.setCurrent(current); - list.add(waterPumpRealVo); - }); + real.setCurrent(this.getCurrent(device,map)); + return real; + }).collect(Collectors.toList()); redisTemplate.opsForValue().set(loadwaterpump_real_key,list); } @@ -144,50 +145,47 @@ public class WaterServiceImpl implements IWaterService { */ @Override public void loadWaterPumpTarget(String param) { - List valid = this.getValidDeviceList(); - List list = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(valid)){ - valid.forEach(device->{ - WaterPumpTargetVo waterPumpTargetVo = new WaterPumpTargetVo(); - waterPumpTargetVo.setDeptId(device.getCreateDept()); - waterPumpTargetVo.setDeviceCode(device.getEmCode()); - waterPumpTargetVo.setDeptName(device.getName()); + // 水利站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,HomePageConstant.waterList) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 泵站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + // 补充站点填报发电量 + List list = this.useFill(stations); + // 站点设备数据统计 + if(CollectionUtil.isNotEmpty(devices)){ + list.addAll(devices.stream().map(device->{ + WaterPumpTargetVo target = new WaterPumpTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeptName(device.getName()); // 当年用电量 - float usrPowerYear = this.getUsrPowerYear(device); - waterPumpTargetVo.setUsrPowerYear(usrPowerYear); + target.setUsrPowerYear(this.getUsrPowerYear(device)); // 当月用电量 - float usrPowerMon = this.getUsrPowerMon(device); - waterPumpTargetVo.setUsrPowerMon(usrPowerMon); + target.setUsrPowerMon(this.getUsrPowerMon(device)); // 当日用电量 - float usrPowerDay = this.getUsrPowerDay(device); - waterPumpTargetVo.setUsrPowerDay(usrPowerDay); + target.setUsrPowerDay(this.getUsrPowerDay(device)); + // 当日机组有功功率 + target.setActivePowerVoList(this.getActivePowerVoList(device)); + // 近30天用电量 + target.setUsrPowerVoList(this.getUsrPowerVoList(device)); + // 近3年用电量 + target.setUsrYearMap(this.getUsrYearMap(device)); // 月运行次数、时长 WaterRunVo runMon = this.getRunData(device,1); - waterPumpTargetVo.setRunCountMon(runMon.getCount()); - waterPumpTargetVo.setRunDurationMon(runMon.getHour()); + target.setRunCountMon(runMon.getCount()); + target.setRunDurationMon(runMon.getHour()); // 年运行次数、时长 WaterRunVo runYear = this.getRunData(device,0); - waterPumpTargetVo.setRunCountYear(runYear.getCount()); - waterPumpTargetVo.setRunDurationYear(runYear.getHour()); - // 当日机组有功功率 - List activePowerVoList = this.getActivePowerVoList(device); - waterPumpTargetVo.setActivePowerVoList(activePowerVoList); - // 近30天用电量 - List usrPowerVoList = this.getUsrPowerVoList(device); - waterPumpTargetVo.setUsrPowerVoList(usrPowerVoList); - // 近3年用电量 - Map usrYearMap = this.getUsrYearMap(device); - waterPumpTargetVo.setUsrYearMap(usrYearMap); - list.add(waterPumpTargetVo); - }); - } - // 补充站点填报发电量 - List stations = stationService.list(Wrappers.lambdaQuery() - .in(StationEntity::getType, HomePageConstant.waterList) - .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) - ); - if(CollectionUtil.isNotEmpty(stations)){ - list.addAll(this.useFill(stations)); + target.setRunCountYear(runYear.getCount()); + target.setRunDurationYear(runYear.getHour()); + return target; + }).collect(Collectors.toList())); } redisTemplate.opsForValue().set(loadwaterpump_target_key,list); } @@ -234,22 +232,19 @@ public class WaterServiceImpl implements IWaterService { } /** - * 获取监测点位是否配置 - * @param instanceCode + * 泵站设备 + * @param stations * @return */ - private boolean getSetting(String instanceCode) { - // 获取设备监测点位:未配置监测点位不进行统计设备 - List list = new ArrayList<>(); - MultiAnalyzeCodePO po = new MultiAnalyzeCodePO(); - po.setDeviceCode(instanceCode); - po.setSignages(Collections.singletonList(HomePageConstant.FRONT_WATER_LEVEL)); - list.add(po); - R> result = analyseDataSearchClient.getAnalyzeCodeBySignages(list); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return true; + private List pumpDevices(List stations){ + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); } - return false; + List devices = maintenanceTaskService.getEmInfoList(); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + return devices.stream().filter(device->stations.contains(device.getCreateDept())).collect(Collectors.toList()); } /** @@ -264,7 +259,7 @@ public class WaterServiceImpl implements IWaterService { List signages = Collections.singletonList(signage); realData.setSignages(signages); // 调用fegin接口查询实时数据 - R> R = null; + R> R; try { R = analyseDataSearchClient.getRealDataByAnalyzeCode(realData); } catch (Exception e) { @@ -333,29 +328,6 @@ public class WaterServiceImpl implements IWaterService { } /** - * 获取有效设备 - * @return - */ - private List getValidDeviceList() { - // 水利站点(All) - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, HomePageConstant.waterList, null); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - // 获取所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - if(CollectionUtil.isEmpty(deviceList)){ - return null; - } - // 有效泵租设备 - List deptIdList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptIdList)){ - return null; - } - return deviceList.stream().filter(o->deptIdList.contains(o.getCreateDept())).collect(Collectors.toList()); - } - - /** * 获取有效站点模型 * @return */ @@ -793,7 +765,7 @@ public class WaterServiceImpl implements IWaterService { PowerMonthVo generate = new PowerMonthVo(); Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); generate.setStrMonth(DateUtil.format(time, DateUtil.PATTERN_DATE)); - generate.setPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); return generate; }).collect(Collectors.toMap(PowerMonthVo::getStrMonth,PowerMonthVo::getPower)); } @@ -809,8 +781,6 @@ public class WaterServiceImpl implements IWaterService { String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); String year = String.valueOf(calendar.get(Calendar.YEAR)); - //calendar.add(Calendar.DAY_OF_MONTH,-1); - //String yesterday = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); return stations.stream().map(station ->{ WaterPumpTargetVo target = new WaterPumpTargetVo(); target.setDeptId(station.getRefDept()); @@ -929,7 +899,7 @@ public class WaterServiceImpl implements IWaterService { return null; } // 获取站点编码集合 - List codes = map.entrySet().stream().map(o-> o.getValue().get(0).getCode()).collect(Collectors.toList()); + List codes = map.values().stream().map(stationEntities -> stationEntities.get(0).getCode()).collect(Collectors.toList()); // 获取实时天气 Map nowWeather = this.weatherService.getNowWeather(codes); // 获取七天天气 @@ -1018,7 +988,7 @@ public class WaterServiceImpl implements IWaterService { * @return */ private List getStationList(Map> map) { - return map.values().stream().collect(Collectors.toList()).get(0); + return new ArrayList<>(map.values()).get(0); } /** @@ -1102,7 +1072,7 @@ public class WaterServiceImpl implements IWaterService { if(CollectionUtil.isEmpty(stationList)){ return null; } - List codeList = stationList.stream().filter(o->StringUtil.isNotBlank(o.getCode())).map(StationEntity::getCode).collect(Collectors.toList()); + List codeList = stationList.stream().map(StationEntity::getCode).filter(StringUtil::isNotBlank).collect(Collectors.toList()); if(CollectionUtil.isEmpty(codeList)){ return null; } @@ -1331,12 +1301,12 @@ public class WaterServiceImpl implements IWaterService { response.setUsePowerMon((float) kwhMon); // 月运行时长 Optional waterPumpTargetVoOptional = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationMon)); - double monRunTime = waterPumpTargetVoOptional.isPresent() ? waterPumpTargetVoOptional.map(WaterPumpTargetVo::getRunDurationMon).orElse(0.0) : 0.0; + double monRunTime = waterPumpTargetVoOptional.map(WaterPumpTargetVo::getRunDurationMon).orElse(0.0); //double monRunTime = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationMon)).get().getRunDurationMon(); response.setRunDurationMon(monRunTime); // 年运行时长 Optional optionalWaterPumpTargetVo = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationYear)); - double yearRunTime = optionalWaterPumpTargetVo.isPresent() ? optionalWaterPumpTargetVo.map(WaterPumpTargetVo::getRunDurationYear).orElse(0.0) : 0.0; + double yearRunTime = optionalWaterPumpTargetVo.map(WaterPumpTargetVo::getRunDurationYear).orElse(0.0); //double yearRunTime = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationYear)).get().getRunDurationYear(); response.setRunDurationYear(yearRunTime); // 水位曲线/年用电量 From 87a7c96f5446d5443341cf05deafd521c48dfff3 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 13 Apr 2023 16:41:58 +0800 Subject: [PATCH 2/7] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=9C=88=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/main/vo/AreaMonthReportVo.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java index 0d7d77b..3d3894e 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java @@ -1,5 +1,7 @@ package com.hnac.hzims.operational.main.vo; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -10,65 +12,85 @@ import lombok.Data; public class AreaMonthReportVo { @ApiModelProperty(value = "区域Id") + @JsonSerialize(nullsUsing = NullSerializer.class) private Long areaId; @ApiModelProperty(value = "区域名称") private String areaName; @ApiModelProperty(value = "计划发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Float planPower; @ApiModelProperty(value = "实际发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Float actualPower; @ApiModelProperty(value = "发电完成率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double powerFinishRate; @ApiModelProperty(value = "同比") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double comparePowerRate; @ApiModelProperty(value = "发电计划预测") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double predictPlanPower; @ApiModelProperty(value = "操作票") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer operate; @ApiModelProperty(value = "操作票合格率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double operaQualifyRate; @ApiModelProperty(value = "工作票") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer work; @ApiModelProperty(value = "工作票合格率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double workQualifyRate; @ApiModelProperty(value = "日常维护") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer routineMaintenance; @ApiModelProperty(value = "巡检任务") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer inspect; @ApiModelProperty(value = "缺陷数") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer defect; @ApiModelProperty(value = "消缺率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double defectRate; @ApiModelProperty(value = "检修任务数量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer maintenanceTasks; @ApiModelProperty(value = "安全生产会议次数") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer safetyMeeting; @ApiModelProperty(value = "月度自查报告") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer selfReport; @ApiModelProperty(value = "设备试验") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer deviceTry; @ApiModelProperty(value = "技能培训") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer skillTrainy; @ApiModelProperty(value = "安全大检查") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer securityCheck; } From 849cb6553d5e285281bfeb6cf54031ad8bb63829 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 13 Apr 2023 16:45:17 +0800 Subject: [PATCH 3/7] =?UTF-8?q?#=20=E8=AE=BE=E5=A4=87=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=97=B6=E5=90=8D=E7=A7=B0=E5=94=AF=E4=B8=80=E6=80=A7=E6=A0=A1?= =?UTF-8?q?=E9=AA=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 94de0e7..df84d16 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 @@ -472,7 +472,7 @@ public class EmInfoServiceImpl extends BaseServiceImpl existName = this.list( - Wrappers.lambdaQuery().eq(EmInfoEntity::getName, em_info.getInfo().getName()) + Wrappers.lambdaQuery().eq(EmInfoEntity::getName, em_info.getInfo().getName()).eq(EmInfoEntity::getDepartment, em_info.getInfo().getDepartment()) ); Assert.isTrue(CollectionUtil.isEmpty(existName),()-> { throw new ServiceException("设备名称已存在"); From b8e7c2d6418c2af40fc965359c45e802c85699be Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 13 Apr 2023 16:48:56 +0800 Subject: [PATCH 4/7] =?UTF-8?q?#=E9=9B=86=E4=B8=AD=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/ws/WebSocketClientConfig.java | 93 ------------ .../config/ws/WebsocketConfigClient.java | 124 ---------------- .../service/impl/RealMonitorServiceImpl.java | 165 +++++++++------------ 3 files changed, 66 insertions(+), 316 deletions(-) delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebSocketClientConfig.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketConfigClient.java diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebSocketClientConfig.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebSocketClientConfig.java deleted file mode 100644 index d887ad0..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebSocketClientConfig.java +++ /dev/null @@ -1,93 +0,0 @@ -/* -package com.hnac.hzims.operational.config.ws; - -import cn.hutool.core.collection.CollectionUtil; -import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.operational.config.service.StFocusPropertiesService; -import com.hnac.hzims.operational.config.vo.StationRealVo; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@Slf4j -@EnableScheduling -@Component -public class WebSocketClientConfig { - - @Value("${hzims.config.ws-url}") - String wsUrl; - - List clientList; - - @Autowired - private StFocusPropertiesService stFocusPropertiesService; - - - private static final Integer MAX_SEND = 40; - - */ -/** - * 定时30秒推送一次消息 - *//* - - @Scheduled(cron = "0/30 * * * * ?") - private void keepAlive() throws InterruptedException, URISyntaxException { - */ -/*try { - List message = stFocusPropertiesService.getStationRealIds(); - if (CollectionUtil.isEmpty(message)) { - return; - } - int limit = countStep(message.size()); - List> list = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> message.stream().skip(a * MAX_SEND).limit(MAX_SEND).parallel().collect(Collectors.toList())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(list)) { - return; - } - if (CollectionUtil.isEmpty(clientList)) { - clientList = new ArrayList<>(); - for (int i = 0; i < limit; i++) { - WebsocketConfigClient client = new WebsocketConfigClient(new URI(wsUrl)); - if (client.connectBlocking()) { - String json = JSONObject.toJSONString(list.get(i)); - client.send(json); - clientList.add(client); - } - } - return; - } - if(CollectionUtil.isNotEmpty(clientList.stream().filter(o->!o.isOpen()).collect(Collectors.toList()))){ - clientList.clear(); - return; - } - for (int i = 0; i < limit; i++) { - String json = JSONObject.toJSONString(list.get(i)); - WebsocketConfigClient client = clientList.get(i); - client.send(json); - } - }catch (Exception e){ - log.error("[WebsocketConfigClient] 错误={}",e.toString()); - }*//* - - } - - - */ -/** - * 计算切分次数 - *//* - - private static Integer countStep(Integer size) { - return (size + MAX_SEND - 1) / MAX_SEND; - } -} -*/ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketConfigClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketConfigClient.java deleted file mode 100644 index 0860782..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketConfigClient.java +++ /dev/null @@ -1,124 +0,0 @@ -/* -package com.hnac.hzims.operational.config.ws; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.hnac.hzims.operational.config.service.StAlamRecordService; -import com.hnac.hzims.operational.station.service.IRealMonitorService; -import jodd.util.StringUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.handshake.ServerHandshake; -import org.springblade.core.tool.utils.SpringUtil; -import org.springframework.beans.factory.annotation.Value; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.net.URI; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Map; -import java.util.concurrent.CompletableFuture; - - -@Slf4j -public class WebsocketConfigClient extends WebSocketClient { - - @Value("${hzims.config.ws-url}") - String wsUrl; - - StAlamRecordService stAlamRecordService; - - private static final String MSG_SUCCESS_STATUS = "200"; - - - public WebsocketConfigClient(URI serverUri) { - super(serverUri); - stAlamRecordService = SpringUtil.getBean(StAlamRecordService.class); - if (serverUri.toString().contains("wss://") && serverUri.toString().contains("/data")) { - trustAllHosts(this); - } - } - - @Override - public void onOpen(ServerHandshake handshakedata) { - System.out.println("onOpen"); - } - - @Override - public void onMessage(String message) { - try { - manageHandleMsg(message); - } catch (Exception e) { - log.error("websocketConfigClient error{}",message,e); - } - log.error("onMessage"); - } - - @Override - public void onClose(int code, String reason, boolean remote) { - log.error("-----------------------------------------------,123,onClose"); - } - - @Override - public void onError(Exception ex) { - log.error("------------------onError"); - } - - - private void manageHandleMsg(String message) { - if(StringUtil.isBlank(message)) { - return; - } - // 将信息转换成json - JSONObject msg = JSONObject.parseObject(message); - String status = msg.getString("status"); - String result = msg.getString("result"); - if(StringUtil.isBlank(result)){ - return; - } - if(StringUtil.isBlank(status) || !MSG_SUCCESS_STATUS.equals(status)){ - return; - } - // 将结果响应结果转换成嵌套Map格式 - Map> resultMap = JSONObject.parseObject(result, new TypeReference>>(){}); - if(MapUtils.isEmpty(resultMap)) { - return; - } - // 存储redis - stAlamRecordService.receiveDataStorage(resultMap); - } - - - - void trustAllHosts(WebsocketConfigClient appClient) { - log.info("[websocket] wss 连接 ----- "); - try { - // wss需添加 - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, new TrustManager[]{new X509TrustManager() { - @Override - public void checkClientTrusted(X509Certificate[] chain, - String authType) { - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) { - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - }}, new SecureRandom()); - SSLSocketFactory factory = sslContext.getSocketFactory(); - appClient.setSocket(factory.createSocket()); - } catch (Exception e) { - log.error("[websocket] trustAllHosts 错误 - " + e.toString()); - } - } - -} -*/ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index 5181197..4fe1b37 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -50,8 +50,6 @@ import org.springframework.web.socket.TextMessage; import javax.validation.constraints.NotNull; import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.*; import java.util.stream.Collectors; @@ -163,45 +161,43 @@ public class RealMonitorServiceImpl implements IRealMonitorService { } // 数据切割 int limit = countStep(stationRealVos.size()); - List> list = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stationRealVos.stream().skip(a * MAX_SEND).limit(MAX_SEND).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + List> list = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stationRealVos.stream().skip((long) a * MAX_SEND).limit(MAX_SEND).parallel().collect(Collectors.toList())).collect(Collectors.toList()); ExecutorService pool = Executors.newFixedThreadPool(limit); // Map valueMap = new ConcurrentHashMap<>(); // > Map> keyMap = new ConcurrentHashMap<>(); CountDownLatch countDownLatch = new CountDownLatch(limit); - pool.execute(()->{ - list.forEach(stations -> { - stations.forEach(stationReal -> { - String[] realIdArr = stationReal.getRealId(); - List realIds = Stream.of(realIdArr).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(realIds)){ - return; - } - List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); - if(CollectionUtil.isEmpty(objects)){ - return; - } - for(int i = 0; i < objects.size() ;i++){ - if(ObjectUtil.isEmpty(objects.get(i))){ - log.error(realIds.get(i) + "is null"); - continue; - } - Map attribute = (Map) JSONObject.parse(objects.get(i)); - attribute.put("realId",attribute.get("k")); - attribute.put("value",attribute.get("v")); - attribute.put("time",attribute.get("t")); - attribute.remove("v"); - attribute.remove("k"); - attribute.remove("t"); - this.getCheckMap(attribute,switchOnOff); - valueMap.put(realIdArr[i],attribute.get("value")); - keyMap.put(realIdArr[i],attribute); + pool.execute(()-> list.forEach(stations -> { + stations.forEach(stationReal -> { + String[] realIdArr = stationReal.getRealId(); + List realIds = Stream.of(realIdArr).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(realIds)){ + return; + } + List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); + if(CollectionUtil.isEmpty(objects)){ + return; + } + for(int i = 0; i < objects.size() ;i++){ + if(ObjectUtil.isEmpty(objects.get(i))){ + log.error(realIds.get(i) + "is null"); + continue; } - }); - countDownLatch.countDown(); + Map attribute = (Map) JSONObject.parse(objects.get(i)); + attribute.put("realId",attribute.get("k")); + attribute.put("value",attribute.get("v")); + attribute.put("time",attribute.get("t")); + attribute.remove("v"); + attribute.remove("k"); + attribute.remove("t"); + this.getCheckMap(attribute,switchOnOff); + valueMap.put(realIdArr[i],attribute.get("value")); + keyMap.put(realIdArr[i],attribute); + } }); - }); + countDownLatch.countDown(); + })); // 等待所有线程执行完成 try { countDownLatch.await(); @@ -224,24 +220,19 @@ public class RealMonitorServiceImpl implements IRealMonitorService { * @return */ private void getCheckMap(Map value,List switchOnOff){ - try{ - // 不处理开机状态监测点 - if(switchOnOff.contains(value.get("realId"))){ - return; - } - String time = value.get("time"); - if(StringUtil.isEmpty(time)){ - return; - } - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); - Date date = simpleDateFormat.parse(time); - // 实时数据超出10分钟未刷新,值置为 0 显示 - if(System.currentTimeMillis() - date.getTime() > 10 * 60 * 1000L){ - value.put("value","0"); - } - }catch (ParseException e){ + // 不处理开机状态监测点 + if(switchOnOff.contains(value.get("realId"))){ return; } + String time = value.get("time"); + if(StringUtil.isEmpty(time)){ + return; + } + Date date = DateUtil.parse(time,DateUtil.PATTERN_DATETIME); + // 实时数据超出10分钟未刷新,值置为 0 显示 + if(System.currentTimeMillis() - date.getTime() > 10 * 60 * 1000L){ + value.put("value","0"); + } } /** @@ -285,45 +276,23 @@ public class RealMonitorServiceImpl implements IRealMonitorService { // key->机构编号 value -> 设备集合 Map> deviceMap = devices.stream().collect(Collectors.groupingBy(EminfoAndEmParamVo::getCreateDept)); Map data = new HashMap<>(); - deviceMap.entrySet().forEach(entry -> { - JointRelayVo value = new JointRelayVo(); - List relays = entry.getValue().stream().filter(o-> MapUtils.isNotEmpty(o.getPoint()) && !StringUtil.isEmpty(o.getPoint().get(HomePageConstant.JOINT_RELAY))).map(relay-> map.get(relay.getPoint().get(HomePageConstant.JOINT_RELAY))).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(relays)){ - value.setUnitSum(0); - value.setShutdownCount(0); - value.setStartingUpCount(0); - }else{ - value.setUnitSum(relays.size()); - Optional> off = Optional.ofNullable(relays.stream().filter(relay -> "0".equals(relay)).collect(Collectors.toList())); - value.setShutdownCount(off.map(o->o.size()).orElse(0)); - Optional> on = Optional.ofNullable(relays.stream().filter(relay -> "1".equals(relay)).collect(Collectors.toList())); - value.setStartingUpCount(on.map(o->o.size()).orElse(0)); + deviceMap.forEach((key, value) -> { + JointRelayVo jointRelay = new JointRelayVo(); + List relays = value.stream().filter(o -> MapUtils.isNotEmpty(o.getPoint()) && !StringUtil.isEmpty(o.getPoint().get(HomePageConstant.JOINT_RELAY))).map(relay -> map.get(relay.getPoint().get(HomePageConstant.JOINT_RELAY))).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(relays)) { + jointRelay.setUnitSum(0); + jointRelay.setShutdownCount(0); + jointRelay.setStartingUpCount(0); + } else { + jointRelay.setUnitSum(relays.size()); + Optional> off = Optional.ofNullable(relays.stream().filter("0"::equals).collect(Collectors.toList())); + jointRelay.setShutdownCount(off.map(List::size).orElse(0)); + Optional> on = Optional.ofNullable(relays.stream().filter("1"::equals).collect(Collectors.toList())); + jointRelay.setStartingUpCount(on.map(List::size).orElse(0)); } - data.put(entry.getKey(),value); + data.put(key, jointRelay); }); redisTemplate.opsForValue().set(joint_relay_key, data); - - /*List jointRelayInfo = alertService.getJointRelayInfo(); - - //根据站点统计开关机 - Map> jointRelayMap = jointRelayInfo.stream().collect(Collectors.groupingBy(AnalyzeCodeBySignagesVO::getStation)); - jointRelayMap.forEach((key, value) -> { - List readIdList = value.stream().map(AnalyzeCodeBySignagesVO::getRealId).collect(Collectors.toList()); - vo = new JointRelayVo(); - readIdList.forEach(iter -> { - String jointRelay = map.get(iter); - if ("0".equals(jointRelay)) {//关机 - vo.setShutdownCount(vo.getShutdownCount() + 1); - vo.setShutdownRealId(iter + "," + vo.getShutdownRealId()); - vo.setUnitSum(vo.getUnitSum() + 1); - } else if ("1".equals(jointRelay)) {//开机 - vo.setStartingUpCount(vo.getStartingUpCount() + 1); - vo.setStartingUpRealId(iter + "," + vo.getStartingUpRealId()); - vo.setUnitSum(vo.getUnitSum() + 1); - } - }); - stationJointRelayMap.put(key, vo); - });*/ } /** @@ -393,7 +362,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { */ @Override public void centralizedMonitoring(String param) { - Long beginTime = System.currentTimeMillis(); + long beginTime = System.currentTimeMillis(); Thread thread = Thread.currentThread(); Object json = redisTemplate.opsForValue().get(real_id_key_gather_path); if (ObjectUtil.isEmpty(json)) { @@ -440,19 +409,17 @@ public class RealMonitorServiceImpl implements IRealMonitorService { // 根据站点分组 Map> stationAttbtMap = list.stream().collect(Collectors.groupingBy(StationAttributeEntity::getStationId)); // 获取站点列表 - List stationEntityList = stationService.getStationByInCode(stationAttbtMap.keySet().stream().collect(Collectors.toList())); + List stationEntityList = stationService.getStationByInCode(new ArrayList<>(stationAttbtMap.keySet())); log.info(thread.getName() + "步骤8站点列表 耗时 : {}",System.currentTimeMillis() - beginTime); beginTime = System.currentTimeMillis(); // 隐藏设备列表 List hideList = stationAttrConfigService.getHideList(); // 分割,每个map限制10个长度 - List>> handleList = this.mapChunk(stationAttbtMap,MAX_SEND); + List>> handleList = this.mapChunk(stationAttbtMap); log.info(thread.getName() + "步骤9监测点数据切割 耗时 : {}",System.currentTimeMillis() - beginTime); beginTime = System.currentTimeMillis(); // 创建线程池 ExecutorService pool = Executors.newFixedThreadPool(handleList.size()); - //ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("centralized_monitor-pool-%d").build(); - //ExecutorService pool = new ThreadPoolExecutor(5, handleList.size(), 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); CountDownLatch countDownLatch = new CountDownLatch(handleList.size()); log.info(thread.getName() +"步骤10创建线程 耗时 : {}",System.currentTimeMillis() - beginTime); beginTime = System.currentTimeMillis(); @@ -521,14 +488,14 @@ public class RealMonitorServiceImpl implements IRealMonitorService { /** * map分割 - * @param chunkMap - * @param chunkNum - * @return + * * @param * @param + * @param chunkMap + * @return */ - private List> mapChunk(Map chunkMap, int chunkNum) { - if (chunkMap == null || chunkNum <= 0) { + private List> mapChunk(Map chunkMap) { + if (chunkMap == null || RealMonitorServiceImpl.MAX_SEND <= 0) { List> list = new ArrayList<>(); list.add(chunkMap); return list; @@ -541,7 +508,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { while (iterator.hasNext()) { k next = iterator.next(); tem.put(next, chunkMap.get(next)); - if (i == chunkNum) { + if (i == RealMonitorServiceImpl.MAX_SEND) { total.add(tem); tem = new HashMap<>(); i = 0; @@ -677,9 +644,9 @@ public class RealMonitorServiceImpl implements IRealMonitorService { // 正常状态 attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); int quality = Optional.ofNullable(attest.getQuality()).orElse(-1); - String time = Optional.ofNullable(attest.getTime()).orElse(null); + String time = Optional.ofNullable(attest.getTime()).orElse(""); // 延时状态 :质量为空 && 时间为空 - if (-1 == quality && StringUtil.isBlank(time)) { + if (-1 == quality && StringUtil.isEmpty(time)) { attest.setStatus(ConfigStatus.ConfigStatusEnum.GRAY.getStatus()); } int type = item.getAttributeType(); @@ -842,7 +809,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { */ @Override public TextMessage getSendMessage(MessageParamVo message) { - Long beginTime = System.currentTimeMillis(); + long beginTime = System.currentTimeMillis(); Thread thread = Thread.currentThread(); // 权限机构过滤 if(ObjectUtil.isEmpty(message) || CollectionUtil.isEmpty(message.getDeptIds())){ From 3974893d8359070e65db34a6d4ade047f27b203b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Thu, 13 Apr 2023 16:54:41 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=89=80=E5=B1=9E?= =?UTF-8?q?=E6=9C=BA=E6=9E=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../defect/entity/OperDefectEntity.java | 2 + .../inspect/areamonthly/vo/TaskListQuery.java | 2 + .../hzims/safeproduct/entity/CheckMonthEntity.java | 3 +- .../areamonthly/vo/MaintenanceTaskWithAreaVo.java | 7 ++ .../ticket/areamonthly/vo/StandardTicketVo.java | 20 ++++++ .../areamonthly/vo/StandardTicketWithAreaVo.java | 6 ++ .../ticket/areamonthly/vo/StandardWorkVo.java | 10 +++ .../service/impl/StatisticsServiceImpl.java | 6 ++ .../middle/systemlog/vo/SysLogStatisticsVo.java | 2 +- hzims-service/operational/pom.xml | 13 ++++ .../hzims/operational/OperationApplication.java | 1 - .../access/dto/OperAccessStatisticsDTO.java | 7 +- .../hzims/operational/config/Swagger2Config.java | 60 ++++++++++++++++ .../web/AreaMonthlyDetailsController.java | 79 ++++++++++++++-------- .../station/service/impl/StationServiceImpl.java | 2 + 15 files changed, 186 insertions(+), 34 deletions(-) create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/Swagger2Config.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java index 7a5cbe2..c4b174c 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java @@ -104,11 +104,13 @@ public class OperDefectEntity extends TenantEntity { /** * 区域Id */ + @ApiModelProperty(value = "区域Id") @TableField(exist = false) private String areaId; /** * 年月 */ + @ApiModelProperty(value = "年月") @TableField(exist = false) private YearMonth yearMonth; } diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/areamonthly/vo/TaskListQuery.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/areamonthly/vo/TaskListQuery.java index 12321b7..a8e08e5 100644 --- a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/areamonthly/vo/TaskListQuery.java +++ b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/areamonthly/vo/TaskListQuery.java @@ -126,11 +126,13 @@ public class TaskListQuery implements Serializable { /** * 月份 */ + @ApiModelProperty("月份") private YearMonth yearmonth; /** * 区域Id */ + @ApiModelProperty("区域Id") private String areaId; diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java index c91da19..de8ae87 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java @@ -47,6 +47,7 @@ public class CheckMonthEntity extends TenantEntity implements Serializable { * 年月 */ @TableField(exist = false) + @ApiModelProperty("月份") private YearMonth yearMonth; @@ -55,6 +56,4 @@ public class CheckMonthEntity extends TenantEntity implements Serializable { private String itemName; - - } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/MaintenanceTaskWithAreaVo.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/MaintenanceTaskWithAreaVo.java index e3c7288..6118c75 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/MaintenanceTaskWithAreaVo.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/MaintenanceTaskWithAreaVo.java @@ -1,5 +1,6 @@ package com.hnac.hzims.ticket.areamonthly.vo; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.time.YearMonth; @@ -17,33 +18,39 @@ public class MaintenanceTaskWithAreaVo { /** * 区域编号 */ + @ApiModelProperty("区域编号") private String areaId; /** * 月份 */ + @ApiModelProperty("月份") private java.time.YearMonth YearMonth; /** * 项目名称 */ + @ApiModelProperty("项目名称") private String title; /** * 维护内容 */ + @ApiModelProperty("维护内容") private String content; /** * 执行状态 */ + @ApiModelProperty("执行状态") private Integer status; /** * 任务类型 */ + @ApiModelProperty("执行状态") private String taskType; } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketVo.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketVo.java index 8a2abe6..9e8e9b0 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketVo.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketVo.java @@ -1,5 +1,6 @@ package com.hnac.hzims.ticket.areamonthly.vo; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -18,6 +19,7 @@ import java.util.Date; */ @EqualsAndHashCode @Data +@ApiModel("操作票对象") public class StandardTicketVo implements Serializable { private static final long serialVersionUID = -8870464581684939369L; @@ -26,91 +28,109 @@ public class StandardTicketVo implements Serializable { /** * 编号 */ + @ApiModelProperty("编号") private Long id; /** * 开票种类 */ + @ApiModelProperty("开票种类") private String ticketType; /** * 单位 */ + @ApiModelProperty("单位") private String company; /** * 编号 */ + @ApiModelProperty("编号") private String code; /** * 开票来源 */ + @ApiModelProperty("开票来源") private String taskType; /** * 开票来源名称 */ + @ApiModelProperty("开票来源名称") private String taskTypeName; /** * 开票任务来源 */ + @ApiModelProperty("开票任务来源") private String taskName; /** * 发令人 */ + @ApiModelProperty("发令人") private Long issueOrderPerson; /** * 发令人名称 */ + @ApiModelProperty("发令人名称") private String issueOrderPersonName; /** * 受令人 */ + @ApiModelProperty("受令人") private Long accessOrderPerson; /** * 受令人名称 */ + @ApiModelProperty("受令人名称") private String accessOrderPersonName; /** * 监护人 */ + @ApiModelProperty("监护人") private Long guardian; /** * 监护人名称 */ + @ApiModelProperty("监护人名称") private String guardianName; /** * 值班负责人 */ + @ApiModelProperty("值班负责人") private Long principal; /** * 值班负责人 */ + @ApiModelProperty("值班负责人名称") private String principalName; /** * 开票时间 */ + @ApiModelProperty("开票时间") private Date createTime; /** * 状态 */ + @ApiModelProperty("状态") private Integer status; /** * 是否评价 */ + @ApiModelProperty("是否评价") private Integer isEvaluate; } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketWithAreaVo.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketWithAreaVo.java index 3ebd967..3f9e5ca 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketWithAreaVo.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardTicketWithAreaVo.java @@ -21,34 +21,40 @@ public class StandardTicketWithAreaVo { /** * 区域编号 */ + @ApiModelProperty("区域编号") private String areaId; /** * 月份 */ + @ApiModelProperty("月份") private YearMonth YearMonth; /** * 开票种类 */ + @ApiModelProperty("开票种类") private String ticketType; /** * 编号 */ + @ApiModelProperty("编号") private String code; /** * 开票来源 */ + @ApiModelProperty("开票来源") private String taskType; /** * 状态 */ + @ApiModelProperty("状态") private Integer status; diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardWorkVo.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardWorkVo.java index 14cff7c..545edb5 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardWorkVo.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/areamonthly/vo/StandardWorkVo.java @@ -1,5 +1,6 @@ package com.hnac.hzims.ticket.areamonthly.vo; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -22,45 +23,54 @@ public class StandardWorkVo implements Serializable { /** * 编号 */ + @ApiModelProperty("编号") private Long id; /** * 开票种类 */ + @ApiModelProperty("开票种类") private String type; /** * 单位 */ + @ApiModelProperty("单位") private String company; /** * 编号 */ + @ApiModelProperty("编号") private String code; /** * 开票来源 */ + @ApiModelProperty("开票来源") private String taskType; /** * 开票任务来源 */ + @ApiModelProperty("开票任务来源") private String taskName; /** * 开票时间 */ + @ApiModelProperty("开票时间") private Date createTime; /** * 状态 */ + @ApiModelProperty("状态") private Integer status; /** * 是否评价 */ + @ApiModelProperty("是否评价") private Integer isEvaluate; } diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/systemlog/service/impl/StatisticsServiceImpl.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/systemlog/service/impl/StatisticsServiceImpl.java index a551ab5..78c135e 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/systemlog/service/impl/StatisticsServiceImpl.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/systemlog/service/impl/StatisticsServiceImpl.java @@ -54,10 +54,16 @@ public class StatisticsServiceImpl extends ServiceImpl UTF-8 1.0.3 + 1.9.6 @@ -214,6 +215,18 @@ com.hnac.hzinfo.data hzinfo-data-sdk + + + + + + com.github.xiaoymin + swagger-bootstrap-ui + ${swagger-bootstrap-ui.version} + + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java index 42143c2..3dc2e04 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java @@ -48,7 +48,6 @@ public class OperationApplication extends SpringBootServletInitializer { } - public static void main(String[] args) { BladeApplication.run(OperationalConstants.APP_NAME, OperationApplication.class, args); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java index 0091f31..0d1dd0c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java @@ -27,14 +27,15 @@ public class OperAccessStatisticsDTO extends OperAccessStatisticsEntity { private List deptIds; /** - * 年月 + * 月份 */ - private YearMonth yearMonth; - + @ApiModelProperty("月份") + private YearMonth yearmonth; /** * 区域Id */ + @ApiModelProperty("区域Id") private String areaId; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/Swagger2Config.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/Swagger2Config.java new file mode 100644 index 0000000..18d9559 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/Swagger2Config.java @@ -0,0 +1,60 @@ +package com.hnac.hzims.operational.config; + +import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; +import com.google.common.base.Predicates; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/13 13:40 + */ +@Configuration +@EnableSwagger2 +public class Swagger2Config implements WebMvcConfigurer { + + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/**") + .addResourceLocations("classpath:/static/"); + registry.addResourceHandler("doc.html") + .addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + + + @Bean + public Docket webApiConfig(){ + return new Docket(DocumentationType.SWAGGER_2) + .groupName("operationApplication") + .apiInfo(webApiInfo()) + .select() + //只显示api路径下的页面 + .paths(Predicates.and(PathSelectors.regex("/areaMonthlyDetails/.*"))) + .build(); + + } + + private ApiInfo webApiInfo() { + return new ApiInfoBuilder() + .title("网站-API文档") + .description("本文档描述了网站微服务接口定义") + .version("1.0") + .contact(new Contact("WL", "http://localhost:8501/", "55317332@qq.com")) + .build(); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java index 99a9de9..2857f91 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java @@ -28,7 +28,9 @@ import com.hnac.hzims.ticket.areamonthly.vo.*; import com.hnac.hzinfo.inspect.areamonthly.vo.TaskListQuery; import com.hnac.hzinfo.inspect.areamonthly.vo.TaskVo; import com.hnac.hzinfo.inspect.task.entity.TaskEntity; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseEntity; @@ -49,6 +51,7 @@ import java.util.List; * @Serial 1.0 * @Date 2023/4/10 11:21 */ +@Api(tags = "水电生成报告详情数据") @Slf4j @RequiredArgsConstructor @RestController @@ -66,12 +69,16 @@ public class AreaMonthlyDetailsController { private final IOperAccessStatisticsService accessStatisticsService; /** - * 操作票 根据月份,区域 获取操作详情数据 + * 操作票 根据月份,区域 获取操作详情数据 * * @return */ + @ApiOperation("操作票 根据月份,区域 获取操作详情数据") @GetMapping("/areaMonthlyWithOperation/{page}/{size}") - public R areaMonthlyWithOperation(@PathVariable("page") Long page, @PathVariable("size") Long size, StandardTicketWithAreaVo areaMonthly) { + public R areaMonthlyWithOperation( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + StandardTicketWithAreaVo areaMonthly) { BladePage standardTicketInfoVoIPage = areaMonthlyDetailsService.areaMonthlyWithOperation(page, size, areaMonthly); return R.data(standardTicketInfoVoIPage); } @@ -82,6 +89,7 @@ public class AreaMonthlyDetailsController { * * @return */ + @ApiOperation("操作票 根据月份,区域 获取操作详情数据") @GetMapping("/areaMonthlyWithOperation/detail/{id}") public R areaMonthlyWithOperationDetail(@PathVariable("id") Long id) { StandardTicketInfoVO standardTicketInfoVoIPage = areaMonthlyDetailsService.areaMonthlyWithOperationDetail(id); @@ -92,6 +100,7 @@ public class AreaMonthlyDetailsController { /** * 查询工作票评论 */ + @ApiOperation("查询工作票评论") @GetMapping("/areaMonthlyWithOperation/workTicketCommentList") public R> workTicketCommentList(TicketInfoEvaluateEntity req) { List ticketInfoEvaluateVOS = areaMonthlyDetailsService.workTicketCommentList(req); @@ -102,6 +111,7 @@ public class AreaMonthlyDetailsController { /** * 保存评论信息 */ + @ApiOperation("保存评论信息") @PostMapping("/saveComment") public R saveComment(@RequestBody TicketInfoEvaluateDto req) { return R.data(areaMonthlyDetailsService.saveComment(req)); @@ -110,8 +120,12 @@ public class AreaMonthlyDetailsController { /** * 根据月份和区域查询工作票列表详情 */ + @ApiOperation("根据月份和区域查询工作票列表详情") @GetMapping("/workTicketListByMonthAndArea/{page}/{size}") - R> workTicketListByMonthAndArea(@PathVariable Long page, @PathVariable Long size, @SpringQueryMap StandardTicketWithAreaVo areaMonthlyVo) { + R> workTicketListByMonthAndArea( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + @SpringQueryMap StandardTicketWithAreaVo areaMonthlyVo) { BladePage standardWorkVoIPage = areaMonthlyDetailsService.workTicketListByMonthAndArea(page, size, areaMonthlyVo); return R.data(standardWorkVoIPage); } @@ -121,9 +135,12 @@ public class AreaMonthlyDetailsController { * 根据区域和月份分页查询日志维护列表 */ @ApiOperationSupport(order = 100) - @ApiOperation(value = "日志维护列表分页查询") + @ApiOperation(value = "根据区域和月份分页查询日志维护列表") @GetMapping("/queryLogMaintenancePageList/{page}/{size}") - public R> queryLogMaintenancePageList(@PathVariable Long page, @PathVariable Long size, MaintenanceTaskWithAreaVo maintenanceTaskVo) { + public R> queryLogMaintenancePageList( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + MaintenanceTaskWithAreaVo maintenanceTaskVo) { Page pageParam = new Page<>(page, size); IPage taskList = taskService.queryLogMaintenancePageList(pageParam, maintenanceTaskVo); return R.data(taskList); @@ -135,7 +152,7 @@ public class AreaMonthlyDetailsController { */ @GetMapping("/queryLogMaintenancePageList/detail/{id}") @ApiOperationSupport(order = 40) - @ApiOperation(value = "详情") + @ApiOperation(value = "根据区域和月份分页查询日志维护 根据id获取详情") public R detail(@PathVariable Long id) { return taskService.detail(id); } @@ -145,7 +162,7 @@ public class AreaMonthlyDetailsController { * 根据区域和月份分页查询巡检任务 */ @ApiOperationSupport(order = 50) - @ApiOperation(value = "分页查询") + @ApiOperation(value = "根据区域和月份分页查询巡检任务") @GetMapping("/queryCheckTaskPageList") public R> queryCheckTaskPageList(TaskListQuery task, Query query) { BladePage taskVoIPage = areaMonthlyDetailsService.queryCheckTaskPageList(task, query); @@ -156,9 +173,9 @@ public class AreaMonthlyDetailsController { /** * 根据id查询巡检任务 */ + @ApiOperation(value = "根据id查询巡检任务") @GetMapping("/queryCheckTaskById/{id}") @ApiOperationSupport(order = 60) - @ApiOperation(value = "详情") public R queryCheckTaskById(@PathVariable Long id) { TaskEntity task = areaMonthlyDetailsService.queryCheckTaskById(id); return R.data(task); @@ -169,11 +186,11 @@ public class AreaMonthlyDetailsController { * 根据区域和月份分页查询缺陷库 */ @ApiOperationSupport(order = 70) - @ApiOperation(value = "分页查询") + @ApiOperation(value = "根据区域和月份分页查询缺陷库") @GetMapping("/queryDefectPageList/{page}/{size}") public R> queryDefectPageList( - @PathVariable Long page, - @PathVariable Long size, + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, OperDefectEntity defect) { Page operDefectEntityPage = new Page<>(page, size); IPage pages = defectService.selectPage(operDefectEntityPage, defect); @@ -187,7 +204,7 @@ public class AreaMonthlyDetailsController { */ @GetMapping("queryDefectPageDetail/detail") @ApiOperationSupport(order = 1) - @ApiOperation(value = "详情", notes = "传入defect") + @ApiOperation(value = "根据区域和月份分页查询缺陷库 详情", notes = "传入defect") public R queryDefectPageDetail(OperDefectEntity defect) { return defectService.detail(defect); } @@ -200,7 +217,8 @@ public class AreaMonthlyDetailsController { @ApiOperation(value = "根据区域和月份分页查询检修任务") @GetMapping("/queryReconditionPageList/{page}/{size}") public R> queryReconditionPageList( - @PathVariable Long page, @PathVariable Long size, + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, OperAccessStatisticsDTO result) { Page dbPage = new Page<>(page, size); R> r = accessStatisticsService.list(result, dbPage); @@ -226,8 +244,10 @@ public class AreaMonthlyDetailsController { @GetMapping("/queryProduceNumByAreaCode/{page}/{size}") @ApiOperationSupport(order = 90) @ApiOperation(value = "根据区域编号查询安全生产会议次数") - public R> queryProduceNumByAreaCode(@PathVariable Long page, @PathVariable Long size, - CheckMonthEntity req) { + public R> queryProduceNumByAreaCode( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + CheckMonthEntity req) { req.setItemName("现场每月1次安全生产会议"); BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryProduceByAreaCode(page, size, req); @@ -240,7 +260,10 @@ public class AreaMonthlyDetailsController { @GetMapping("/querySkillByAreaCode/{page}/{size}") @ApiOperationSupport(order = 100) @ApiOperation(value = "根据区域编号查询技能培训") - public R> querySkillByAreaCode(@PathVariable Long page, @PathVariable Long size, CheckMonthEntity req) { + public R> querySkillByAreaCode( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + CheckMonthEntity req) { req.setItemName("每月开展1次技能培训"); BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryProduceByAreaCode(page, size, req); @@ -254,21 +277,23 @@ public class AreaMonthlyDetailsController { @GetMapping("/queryProduceByAreaCode/{page}/{size}") @ApiOperationSupport(order = 100) @ApiOperation(value = "根据区域编号查询技能培训") - public R> queryProduceByAreaCode(@PathVariable Long page, @PathVariable Long size, CheckMonthEntity req) { + public R> queryProduceByAreaCode( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + CheckMonthEntity req) { BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryProduceByAreaCode(page, size, req); return R.data(checkMonthVoBladePage); } - /** * 根据区域编号查询 月度自查 技能培训 安全生产会议次数 */ @GetMapping("/queryProduceByAreaCodeDetail/detail/{id}") @ApiOperationSupport(order = 40) - @ApiOperation(value = "详情", notes = "传入id") - public R queryProduceByAreaCodeDetail(@PathVariable Long id){ + @ApiOperation(value = "根据区域编号查询 月度自查 技能培训 安全生产会议次数", notes = "传入id") + public R queryProduceByAreaCodeDetail(@PathVariable Long id) { CheckMonthVo checkMonthVo = areaMonthlyDetailsService.queryProduceByAreaCodeDetail(id); return R.data(checkMonthVo); } @@ -280,9 +305,10 @@ public class AreaMonthlyDetailsController { @GetMapping("/querySecurityAreaCode/{page}/{size}") @ApiOperationSupport(order = 100) @ApiOperation(value = "根据区域编号查询安全检查") - public R> querySecurityAreaCode(@PathVariable Long page, - @PathVariable Long size, - CheckCompanyEntity req) { + public R> querySecurityAreaCode( + @ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page, + @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable("size") Long size, + CheckCompanyEntity req) { BladePage checkMonthVoBladePage = areaMonthlyDetailsService.querySecurityAreaCode(page, size, req); return R.data(checkMonthVoBladePage); @@ -301,7 +327,6 @@ public class AreaMonthlyDetailsController { } - /** * 根据区域编号查询设备试验 */ @@ -309,11 +334,11 @@ public class AreaMonthlyDetailsController { @ApiOperationSupport(order = 100) @ApiOperation(value = "根据区域编号查询设备试验") public R> queryEquipmentAreaCode( - @PathVariable Long page, - @PathVariable Long size, + @ApiParam(name = "page",value = "当前页",required = true) @PathVariable("page") Long page, + @ApiParam(name = "size",value = "每页记录数",required = true) @PathVariable("size") Long size, SafeEquipmentTrialDTO safeEquipmentTrialDTO) { BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryEquipmentAreaCode(page - ,size,safeEquipmentTrialDTO); + , size, safeEquipmentTrialDTO); return R.data(checkMonthVoBladePage); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index 3d425d6..e7d9e38 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -141,6 +141,8 @@ public class StationServiceImpl extends BaseServiceImpl Date: Thu, 13 Apr 2023 16:58:42 +0800 Subject: [PATCH 6/7] =?UTF-8?q?#=E9=9B=86=E4=B8=AD=E7=9B=91=E6=8E=A7websoc?= =?UTF-8?q?ket=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/config/config/WebSocketConfig.java | 6 ++++-- .../operational/config/ws/MessageHandler.java | 24 +++++++--------------- .../hzims/operational/config/ws/MyInterceptor.java | 16 ++++++--------- .../operational/config/ws/SessionManager.java | 3 +++ .../hzims/operational/config/ws/SocketPool.java | 5 ++++- .../hzims/operational/config/ws/WebsocketRun.java | 13 ------------ 6 files changed, 24 insertions(+), 43 deletions(-) delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketRun.java diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java index 0fca3b6..2da4d77 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java @@ -13,13 +13,15 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer; import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; import org.springframework.web.socket.server.standard.ServerEndpointExporter; +/** + * @author ysj + */ @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer{ @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(myHandler(), "/comprehensiveD/{uid}") - .setAllowedOrigins("*"); + registry.addHandler(myHandler(), "/comprehensiveD/{uid}").setAllowedOrigins("*"); } @Bean diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MessageHandler.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MessageHandler.java index ff4bab4..7160f5a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MessageHandler.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MessageHandler.java @@ -3,7 +3,6 @@ package com.hnac.hzims.operational.config.ws; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.operational.config.vo.MessageParamVo; import com.hnac.hzims.operational.station.service.IRealMonitorService; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; @@ -14,25 +13,20 @@ import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; import java.io.IOException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +/** + * @author ysj + */ @Slf4j public class MessageHandler extends TextWebSocketHandler { - private ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); - - private Long defaultRealDataRefreshTime = 20000L; + private final Long defaultRealDataRefreshTime = 20000L; @Autowired private IRealMonitorService monitorService; - private WebSocketSession session; - @Override public void afterConnectionEstablished(WebSocketSession session) { - this.session = session; String[] split = session.getUri().toString().split("/"); String uid = split[split.length - 1]; SessionManager.add(uid, session); @@ -45,20 +39,16 @@ public class MessageHandler extends TextWebSocketHandler { @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { SessionManager.removeAndClose(session.getId()); - if (SocketPool.pool.containsKey(session.getId())) { - SocketPool.pool.remove(session.getId()); - } + SocketPool.pool.remove(session.getId()); log.info("sessionId: " + session.getId()); log.info("uri: " + session.getUri()); log.info("session closed successful!"); } @Override - public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { + public void handleTransportError(WebSocketSession session, Throwable exception) { SessionManager.removeAndClose(session.getId()); - if (SocketPool.pool.containsKey(session.getId())) { - SocketPool.pool.remove(session.getId()); - } + SocketPool.pool.remove(session.getId()); } @Override diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MyInterceptor.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MyInterceptor.java index d2f755d..5f4c58d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MyInterceptor.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/MyInterceptor.java @@ -8,37 +8,34 @@ import org.springframework.stereotype.Component; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.server.HandshakeInterceptor; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +/** + * @author ysj + */ @Component public class MyInterceptor implements HandshakeInterceptor { /** * 握手前 - * * @param request * @param response * @param wsHandler * @param attributes * @return - * @throws Exception */ @Override - public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map attributes) throws Exception { - System.out.println("握手开始"); + public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map attributes) { // 获得请求参数 - - HashMap paramMap = (HashMap) HttpUtil.decodeParamMap(request.getURI().getQuery(), Charset.forName("utf-8")); + HashMap paramMap = (HashMap) HttpUtil.decodeParamMap(request.getURI().getQuery(), StandardCharsets.UTF_8); String uid = paramMap.get("token"); if (StrUtil.isNotBlank(uid)) { // 放入属性域 attributes.put("token", uid); - System.out.println("用户 token " + uid + " 握手成功!"); return true; } - System.out.println("用户登录已失效"); return false; } @@ -52,7 +49,6 @@ public class MyInterceptor implements HandshakeInterceptor { */ @Override public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) { - System.out.println("握手完成"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java index d2e5eed..fbd6176 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java @@ -7,6 +7,9 @@ import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; +/** + * @author ysj + */ @Slf4j public class SessionManager { /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java index f0d2668..a48c9ae 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java @@ -3,8 +3,11 @@ package com.hnac.hzims.operational.config.ws; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +/** + * @author ysj + */ public class SocketPool { - public static Map pool = new ConcurrentHashMap(); + public static Map pool = new ConcurrentHashMap<>(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketRun.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketRun.java deleted file mode 100644 index 15b3a80..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/WebsocketRun.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.operational.config.ws; - - - -public class WebsocketRun extends Thread{ - - - - @Override - public void run() { - super.run(); - } -} From 54f6ea559c528811366c1a9952389c96255c23fe Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 13 Apr 2023 19:48:27 +0800 Subject: [PATCH 7/7] =?UTF-8?q?#=E5=91=8A=E8=AD=A6websocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/constants/AbnormalAlarmConstant.java | 8 ++ .../alert/entity/HistoryAbnormalAlarmEntity.java | 6 ++ .../hzims/operational/alert/vo/AlarmDataVo.java | 2 + .../hzims/operational/alert/vo/AlarmMergeVo.java | 36 +++++++ .../alert/service/AlarmMergeService.java | 15 +++ .../alert/service/LevelAlarmService.java | 10 ++ .../alert/service/impl/AlertDefectServiceImpl.java | 1 + .../alert/service/impl/AlertMerageServiceImpl.java | 106 +++++++++++++++++++++ .../impl/HistoryAbnormalAlarmServiceImpl.java | 1 + .../alert/service/impl/LevelAlarmServiceImpl.java | 18 ++++ .../operational/config/config/WebSocketConfig.java | 21 ++-- .../hzims/operational/config/ws/AlarmHandler.java | 79 +++++++++++++++ .../operational/config/ws/AlarmSessionManager.java | 58 +++++++++++ .../operational/config/ws/SessionManager.java | 3 - .../hzims/operational/config/ws/SocketPool.java | 2 + 15 files changed, 353 insertions(+), 13 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmMergeVo.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java index 1bdcfb6..8a194ab 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java @@ -13,6 +13,13 @@ public interface AbnormalAlarmConstant { /**通讯恢复*/ String ABNORMAL_STATUS = "1"; + /**事故**/ + String FAULT = "2"; + + String WEBSOCKET_FAULT = "0"; + + List ALARM_WARN_TYPES = Arrays.asList("0","1","2"); + String[] TYPE_NAMES = {"默认", "系统", "告警", "故障", "用户操作", "遥测越限", "遥信变位", "注册信息", "信息提示", "设备巡检", "遥控操作", "遥测越限恢复","未定义","通讯中断","数据异常"}; /**处理、延后、误报*/ @@ -22,4 +29,5 @@ public interface AbnormalAlarmConstant { * 2-告警,3-故障,5-遥测越限,13-通讯异常,14-数据异常 */ List SOE_TYPE_LIST = Arrays.asList(2,3,5,13,14); + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/HistoryAbnormalAlarmEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/HistoryAbnormalAlarmEntity.java index 9768788..8dc40fd 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/HistoryAbnormalAlarmEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/HistoryAbnormalAlarmEntity.java @@ -9,6 +9,9 @@ import org.springblade.core.mp.base.BaseEntity; import java.util.Date; +/** + * @author ysj + */ @Data @TableName("hzims_history_abnormal_alarm") @EqualsAndHashCode(callSuper = false) @@ -24,6 +27,9 @@ public class HistoryAbnormalAlarmEntity extends BaseEntity { @ApiModelProperty("站点名称") private String stationName; + @ApiModelProperty("告警编码") + private Long alarmId; + @ApiModelProperty("检查点") private String realId; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmDataVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmDataVo.java index 99f5235..ecc5e1c 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmDataVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmDataVo.java @@ -3,12 +3,14 @@ package com.hnac.hzims.operational.alert.vo; import com.hnac.hzinfo.datasearch.soe.domian.SoeData; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; /** * @author ysj * @date 2023/03/23 14:06:27 * @version 4.0.0 */ +@EqualsAndHashCode(callSuper = true) @Data public class AlarmDataVo extends SoeData { diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmMergeVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmMergeVo.java new file mode 100644 index 0000000..1cc360a --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmMergeVo.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.operational.alert.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author ysj + * @date 2023/03/17 10:02:33 + * @version 4.0.0 + */ +@Data +public class AlarmMergeVo{ + + @ApiModelProperty("站点编号") + private String stationCode; + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("检测点位") + private String realId; + + @ApiModelProperty("告警编号") + private String alarmCode; + + @ApiModelProperty("告警类型: 0 - 事故 、 1 - 一级告警、 2 - 二级告警") + private String type; + + @ApiModelProperty("告警内容: 0 - 事故 、 1 - 一级告警、 2 - 二级告警") + private String content; + + @ApiModelProperty("告警时间") + private Date date; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java new file mode 100644 index 0000000..4cb0260 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.operational.alert.service; + +import com.hnac.hzims.operational.config.vo.MessageParamVo; +import org.springframework.web.socket.TextMessage; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface AlarmMergeService { + + // 获取发送消息 + TextMessage getSendMessage(MessageParamVo param); +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java new file mode 100644 index 0000000..0c6c0be --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java @@ -0,0 +1,10 @@ +package com.hnac.hzims.operational.alert.service; + +/** + * 告警处理接口 + * @author ysj + */ +public interface LevelAlarmService { + + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java index f665a67..bff16bb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; /** * 告警缺陷处理实现类 + * @author ysj */ @Slf4j @Service diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java new file mode 100644 index 0000000..5398e76 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java @@ -0,0 +1,106 @@ +package com.hnac.hzims.operational.alert.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; +import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; +import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; +import com.hnac.hzims.operational.alert.service.AlarmHandleService; +import com.hnac.hzims.operational.alert.service.AlarmMergeService; +import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; +import com.hnac.hzims.operational.alert.service.LevelAlarmService; +import com.hnac.hzims.operational.alert.vo.AlarmMergeVo; +import com.hnac.hzims.operational.config.vo.MessageParamVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.service.IStationService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springframework.stereotype.Service; +import org.springframework.web.socket.TextMessage; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 告警合并处理实现类 + * @author ysj + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AlertMerageServiceImpl implements AlarmMergeService { + + private final IStationService stationService; + + private final LevelAlarmService levelAlarmService; + + private final AlarmHandleService alarmHandleService; + + private final HistoryAbnormalAlarmService faultAlarmService; + + /** + * 根据用户获取hz3000事故告警、平台一级告警、二级告警 + * @param param + * @return + */ + @Override + public TextMessage getSendMessage(MessageParamVo param) { + // 查询用户 + if(ObjectUtil.isEmpty(param)){ + return null; + } + List depts = param.getDeptIds(); + if(CollectionUtil.isEmpty(depts)){ + return null; + } + // 查询站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .in(StationEntity::getRefDept,depts) + .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) + ); + if(CollectionUtil.isEmpty(stations)){ + return null; + } + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 23:59:59"; + + // hz3000事故告警 + List faults = faultAlarmService.list(Wrappers.lambdaQuery() + .in(HistoryAbnormalAlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())) + .eq(HistoryAbnormalAlarmEntity::getType, AbnormalAlarmConstant.FAULT) + .between(HistoryAbnormalAlarmEntity::getStartTime,start,end) + ); + // 处理告警记录 + List handles = alarmHandleService.list(Wrappers.lambdaQuery() + .in(AlarmHandleEntity::getStationCode,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())) + .in(AlarmHandleEntity::getAlarmType, AbnormalAlarmConstant.ALARM_WARN_TYPES) + .between(AlarmHandleEntity::getCreateTime,start,end) + ); + List alarms = new ArrayList<>(); + if(CollectionUtil.isNotEmpty(faults)){ + alarms.addAll(faults.stream().filter(o -> CollectionUtil.isEmpty(handles) + || handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()).contains(o.getAlarmId())). + map(fault->{ + AlarmMergeVo alarm = new AlarmMergeVo(); + alarm.setStationCode(fault.getStationId()); + alarm.setStationName(fault.getStationName()); + alarm.setContent(fault.getSoeExplain()); + alarm.setDate(fault.getStartTime()); + alarm.setRealId(fault.getRealId()); + alarm.setType(AbnormalAlarmConstant.WEBSOCKET_FAULT); + return alarm; + }).collect(Collectors.toList())); + } + // hz3000事故告警 + // faultAlarmService.list(); + + return new TextMessage(JSONObject.toJSONString(alarms.stream().sorted(Comparator.comparing(AlarmMergeVo::getDate)).collect(Collectors.toList()))); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 8d1cb2a..87a7fc8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -49,6 +49,7 @@ import java.util.stream.Collectors; /** * 历史告警实现类 + * @author ysj */ @Slf4j @Service diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java new file mode 100644 index 0000000..1883ff4 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.operational.alert.service.impl; + +import com.hnac.hzims.operational.alert.service.LevelAlarmService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * 等级告警实现类 + * @author ysj + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class LevelAlarmServiceImpl implements LevelAlarmService { + + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java index 2da4d77..eab3f8d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java @@ -1,10 +1,8 @@ package com.hnac.hzims.operational.config.config; +import com.hnac.hzims.operational.config.ws.AlarmHandler; import com.hnac.hzims.operational.config.ws.MessageHandler; -import com.hnac.hzims.operational.vRView.service.IHzImsRealDataService; -import com.hnac.hzims.operational.vRView.ws.HzWebSocketServer; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.socket.WebSocketHandler; @@ -21,21 +19,24 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter; public class WebSocketConfig implements WebSocketConfigurer{ @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(myHandler(), "/comprehensiveD/{uid}").setAllowedOrigins("*"); + // 集中监控处理器 + registry.addHandler(monitorHandler(), "/comprehensiveD/{uid}").setAllowedOrigins("*"); + // 告警处理器 + registry.addHandler(alarmHandler(), "/alarmHandler/{uid}").setAllowedOrigins("*"); } @Bean - public WebSocketHandler myHandler() { + public WebSocketHandler monitorHandler() { return new MessageHandler(); } @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); + public WebSocketHandler alarmHandler() { + return new AlarmHandler(); } - @Autowired - public void hzImsRealDataService(IHzImsRealDataService realDataService) { - HzWebSocketServer.hzImsRealDataService = realDataService; + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java new file mode 100644 index 0000000..39d317d --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java @@ -0,0 +1,79 @@ +package com.hnac.hzims.operational.config.ws; + +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.operational.alert.service.AlarmHandleService; +import com.hnac.hzims.operational.alert.service.AlarmMergeService; +import com.hnac.hzims.operational.config.vo.MessageParamVo; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +import java.io.IOException; + +/** + * @author ysj + */ +@Slf4j +public class AlarmHandler extends TextWebSocketHandler { + + private final Long defaultRealDataRefreshTime = 20000L; + + @Autowired + private AlarmMergeService alarmMergeService; + + + //WebSocket连接建立成功之后调用 + @Override + public void afterConnectionEstablished(WebSocketSession session) { + String[] split = session.getUri().toString().split("/"); + String uid = split[split.length - 1]; + // session 参数设置用户进行标识 + session.getAttributes().put("userId", uid); + AlarmSessionManager.add(uid, session); + SocketPool.alarm_pool.put(session.getId(), this); + } + + // 连接关闭时调用 + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { + // 移除会话 + AlarmSessionManager.removeAndClose(session.getId()); + // map移除用户 + SocketPool.alarm_pool.remove(session.getId()); + } + + // 消息传输错误触发 + @Override + public void handleTransportError(WebSocketSession session, Throwable exception) { + // 移除会话 + SessionManager.removeAndClose(session.getId()); + // map移除用户 + SocketPool.pool.remove(session.getId()); + } + + + // 接收消息触发 + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) throws IOException { + // 获取会话用户编号 + String userId = (String) session.getAttributes().get("userId"); + String message = textMessage.getPayload(); + if(StringUtil.isBlank(message)){ + return; + } + MessageParamVo depts = JSONObject.parseObject(message, MessageParamVo.class); + if(ObjectUtil.isEmpty(depts)){ + return; + } + TextMessage sendMessage = alarmMergeService.getSendMessage(depts); + if(ObjectUtil.isEmpty(sendMessage)){ + return; + } + session.sendMessage(sendMessage); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java new file mode 100644 index 0000000..33fbd36 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java @@ -0,0 +1,58 @@ +package com.hnac.hzims.operational.config.ws; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.socket.WebSocketSession; + +import java.io.IOException; +import java.util.concurrent.ConcurrentHashMap; + + +/** + * @author Lch + */ +@Slf4j +public class AlarmSessionManager { + + public static ConcurrentHashMap SESSION_POOL = new ConcurrentHashMap<>(); + + /** + * 添加会话 + * @param uid 用户 + * @param session 会话对象 + */ + public static void add(String uid, WebSocketSession session) { + if (SESSION_POOL.containsKey(uid)) { + AlarmSessionManager.removeAndClose(uid); + } + SESSION_POOL.put(uid, session); + log.info("添加 WebSocketSession 会话成功,uid=" + uid); + } + + + /** + * 获取会话 + * @param uid 用户 + * @return + */ + public static WebSocketSession get(String uid) { + return SESSION_POOL.get(uid); + } + + /** + * 移除会话并关闭会话 + * @param uid 用户 + */ + public static void removeAndClose(String uid) { + WebSocketSession session = SESSION_POOL.get(uid); + if (session != null) { + try { + //关闭连接 + session.close(); + } catch (IOException ex) { + throw new RuntimeException("关闭ws会话失败!", ex); + } + } + + SESSION_POOL.remove(uid); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java index fbd6176..d2e5eed 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SessionManager.java @@ -7,9 +7,6 @@ import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; -/** - * @author ysj - */ @Slf4j public class SessionManager { /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java index a48c9ae..a38b27c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java @@ -10,4 +10,6 @@ public class SocketPool { public static Map pool = new ConcurrentHashMap<>(); + public static Map alarm_pool = new ConcurrentHashMap<>(); + }