|
|
|
@ -2,7 +2,9 @@ package com.hnac.hzims.operational.main.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
|
|
import com.hnac.hzims.EquipmentConstants; |
|
|
|
|
import com.hnac.hzims.equipment.entity.PlanGenerationEntity; |
|
|
|
|
import com.hnac.hzims.equipment.feign.IPlanGenertionClient; |
|
|
|
@ -10,17 +12,33 @@ import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
|
|
|
|
|
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.access.constants.AccessConstants; |
|
|
|
|
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; |
|
|
|
|
import com.hnac.hzims.operational.access.service.IOperAccessTaskService; |
|
|
|
|
import com.hnac.hzims.operational.defect.constants.TreatMethodConstant; |
|
|
|
|
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; |
|
|
|
|
import com.hnac.hzims.operational.defect.service.IOperPhenomenonService; |
|
|
|
|
import com.hnac.hzims.operational.duty.service.IImsDutyMainService; |
|
|
|
|
import com.hnac.hzims.operational.duty.vo.DutyMainInfoVo; |
|
|
|
|
import com.hnac.hzims.operational.fill.service.GenerateService; |
|
|
|
|
import com.hnac.hzims.operational.fill.service.PowerService; |
|
|
|
|
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.maintenance.constants.MaintenanceConstant; |
|
|
|
|
import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; |
|
|
|
|
import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; |
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
|
import com.hnac.hzims.operational.station.service.IStationAttributeService; |
|
|
|
|
import com.hnac.hzims.operational.station.service.IStationService; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.feign.ITicketInfoClient; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.soe.ISoeClient; |
|
|
|
|
import com.hnac.hzinfo.datasearch.soe.domian.SoeData; |
|
|
|
|
import com.hnac.hzinfo.inspect.task.feign.IInspectTaskReportClient; |
|
|
|
|
import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
@ -29,16 +47,21 @@ import org.springblade.core.tool.utils.DateUtil;
|
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
|
import org.springblade.system.user.cache.UserCache; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.time.Duration; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -49,6 +72,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
public class HydropowerServiceImpl implements HydropowerService { |
|
|
|
|
|
|
|
|
|
private final AreaService areaService; |
|
|
|
|
|
|
|
|
|
private final IWeatherService weatherService; |
|
|
|
|
|
|
|
|
|
private final IStationService stationService; |
|
|
|
@ -57,18 +82,30 @@ public class HydropowerServiceImpl implements HydropowerService {
|
|
|
|
|
|
|
|
|
|
private final PowerService photovoltaicService; |
|
|
|
|
|
|
|
|
|
private final AreaService areaService; |
|
|
|
|
private final IImsDutyMainService dutyMainService; |
|
|
|
|
|
|
|
|
|
private final IAnalyseDataService analyseDataService; |
|
|
|
|
|
|
|
|
|
private final IOperPhenomenonService phenomenonService; |
|
|
|
|
|
|
|
|
|
private final IOperAccessTaskService accessTaskService; |
|
|
|
|
|
|
|
|
|
private final IStationAttributeService attributeService; |
|
|
|
|
|
|
|
|
|
private final IMainSystemMonitoringService maintenanceTaskService; |
|
|
|
|
|
|
|
|
|
private final IMainTaskStatisticService mainTaskStatisticService; |
|
|
|
|
|
|
|
|
|
private final IOperMaintenanceTaskService operMaintenanceTaskService; |
|
|
|
|
|
|
|
|
|
private final ISoeClient soeClient; |
|
|
|
|
|
|
|
|
|
private final ITicketInfoClient ticketInfoClient; |
|
|
|
|
|
|
|
|
|
private final IPlanGenertionClient planGenertionClient; |
|
|
|
|
|
|
|
|
|
private final IInspectTaskReportClient inspectTaskReportClient; |
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
@Value("${hzims.operation.realIdKey}") |
|
|
|
@ -79,6 +116,8 @@ public class HydropowerServiceImpl implements HydropowerService {
|
|
|
|
|
private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; |
|
|
|
|
private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; |
|
|
|
|
|
|
|
|
|
private final static int POOL_QUANTITY = 4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 加载水电站机组实时数据 |
|
|
|
@ -1181,4 +1220,594 @@ public class HydropowerServiceImpl implements HydropowerService {
|
|
|
|
|
return powerYearVo; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*=====================================================app=====================================================*/ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* app集团数据 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<HydropowerAreaVo> group(Long deptId) { |
|
|
|
|
Map<Dept,List<StationEntity>> areas = areaService.areaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); |
|
|
|
|
if(MapUtils.isEmpty(areas)) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 实时监测点数据
|
|
|
|
|
List<HydropowerUnitRealVo> reals = (List<HydropowerUnitRealVo>) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); |
|
|
|
|
// 获取站点机组指标数据
|
|
|
|
|
List<HydropowerUnitTargetVo> targets = (List<HydropowerUnitTargetVo>) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); |
|
|
|
|
// 获取站点编码集合
|
|
|
|
|
List<String> stations = areas.values().stream().map(values -> values.get(0).getCode()).collect(Collectors.toList()); |
|
|
|
|
// 获取站点实时天气
|
|
|
|
|
Map<String, HeWeatherWeatherNowResponse> nowWeather = this.weatherService.getNowWeather(stations); |
|
|
|
|
// 获取站点7日天气
|
|
|
|
|
Map<String, HeWeatherWeatherDailyResponse> weekWeather = this.weatherService.getWeekWeather(stations); |
|
|
|
|
List<String> codes = new ArrayList<>(); |
|
|
|
|
areas.forEach((key,value)-> codes.addAll(value.stream().map(StationEntity::getCode).collect(Collectors.toList()))); |
|
|
|
|
// 计划发电量
|
|
|
|
|
List<PlanGenerationEntity> plans = planGenertionClient.getPlanGenerationByParam(codes,null,String.valueOf(Calendar.getInstance().get(Calendar.YEAR))); |
|
|
|
|
return areas.entrySet().stream().map(entry->{ |
|
|
|
|
HydropowerAreaVo area = new HydropowerAreaVo(); |
|
|
|
|
area.setDeptId(entry.getKey().getId()); |
|
|
|
|
area.setDeptName(entry.getKey().getDeptName()); |
|
|
|
|
// 天气
|
|
|
|
|
this.appAreaWeather(area,nowWeather,weekWeather,entry.getValue().get(0).getCode()); |
|
|
|
|
// 计划发电量
|
|
|
|
|
double plan = this.appAreaPlan(entry.getValue(),plans); |
|
|
|
|
area.setPlan(plan); |
|
|
|
|
// 实际发电量
|
|
|
|
|
area.setReality(this.appAreaReality(entry.getValue(),targets)); |
|
|
|
|
// 发电完成率
|
|
|
|
|
if(Math.abs(plan) > 0){ |
|
|
|
|
area.setRate(BigDecimal.valueOf(area.getReality() / plan *100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
|
}else{ |
|
|
|
|
area.setRate(0.0); |
|
|
|
|
} |
|
|
|
|
// 当月任务执行情况
|
|
|
|
|
this.complteTask(area); |
|
|
|
|
// 站点指标数据
|
|
|
|
|
area.setStationTargets(this.stationTarget(entry.getValue(),reals,targets,plans)); |
|
|
|
|
return area; |
|
|
|
|
}).sorted(Comparator.comparing(HydropowerAreaVo::getReality)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 区域实时天气 |
|
|
|
|
* @param area |
|
|
|
|
* @param nowWeather |
|
|
|
|
* @param code |
|
|
|
|
*/ |
|
|
|
|
private void appAreaWeather(HydropowerAreaVo area, Map<String, HeWeatherWeatherNowResponse> nowWeather,Map<String, HeWeatherWeatherDailyResponse> weekWeather, String code) { |
|
|
|
|
// 实时天气
|
|
|
|
|
if(MapUtils.isNotEmpty(nowWeather) && nowWeather.containsKey(code)){ |
|
|
|
|
HeWeatherWeatherNowResponse nowData = nowWeather.get(code); |
|
|
|
|
if(ObjectUtil.isNotEmpty(nowData.getNow())){ |
|
|
|
|
area.setNow(nowData.getNow()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 站点七日内天气
|
|
|
|
|
if(MapUtils.isNotEmpty(weekWeather) && weekWeather.containsKey(code)){ |
|
|
|
|
HeWeatherWeatherDailyResponse weekData = weekWeather.get(code); |
|
|
|
|
List<Daily> dailyList = weekData.getDaily(); |
|
|
|
|
if (CollectionUtil.isNotEmpty(dailyList)) { |
|
|
|
|
area.setWeather(dailyList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计划发电量 |
|
|
|
|
* @param stations |
|
|
|
|
* @param plans |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Double appAreaPlan(List<StationEntity> stations, List<PlanGenerationEntity> plans) { |
|
|
|
|
if(CollectionUtil.isEmpty(stations) || CollectionUtil.isEmpty(plans)){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return plans.stream().filter(plan->stations.stream().map(StationEntity::getCode).collect(Collectors.toList()).contains(plan.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 实际发电量 |
|
|
|
|
* @param stations |
|
|
|
|
* @param targets |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Double appAreaReality(List<StationEntity> stations, List<HydropowerUnitTargetVo> targets) { |
|
|
|
|
if(CollectionUtil.isEmpty(stations) || CollectionUtil.isEmpty(targets)){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return targets.stream().filter(target->stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(target.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当月任务执行情况 |
|
|
|
|
* @param area |
|
|
|
|
*/ |
|
|
|
|
private void complteTask(HydropowerAreaVo area) { |
|
|
|
|
String start = DateUtil.format(new Date(),"yyyy-mm") + "-01 00:00:00"; |
|
|
|
|
area.setStart(start); |
|
|
|
|
String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); |
|
|
|
|
area.setEnd(end); |
|
|
|
|
// 线程
|
|
|
|
|
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("app-area-taget-pool-%d").build(); |
|
|
|
|
ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(POOL_QUANTITY, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); |
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); |
|
|
|
|
// 日常维护
|
|
|
|
|
exe.execute(()->{ |
|
|
|
|
MaintainVo maintainVo = mainTaskStatisticService.getMaintain(start,end,Collections.singletonList(area.getDeptId())); |
|
|
|
|
area.setMaintain(maintainVo.getMaintain()); |
|
|
|
|
area.setMaintainFinish(maintainVo.getMaintainFinish()); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 消缺
|
|
|
|
|
exe.execute(()->{ |
|
|
|
|
ShortagesVo shortagesVo = mainTaskStatisticService.getShortage(start,end,Collections.singletonList(area.getDeptId())); |
|
|
|
|
area.setDefect(shortagesVo.getShortagesSum()); |
|
|
|
|
area.setDefectFinish(shortagesVo.getShortages()); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 检修
|
|
|
|
|
exe.execute(()->{ |
|
|
|
|
OverhaulVo overhaulVo = mainTaskStatisticService.getOverhaul(start,end,Collections.singletonList(area.getDeptId())); |
|
|
|
|
area.setOverhaul(overhaulVo.getOverhaul()); |
|
|
|
|
area.setOverhaulFinish(overhaulVo.getOverhaulFinish()); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 操作票&工作票
|
|
|
|
|
exe.execute(()->{ |
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
|
map.put("startDate",start); |
|
|
|
|
map.put("endDate",end); |
|
|
|
|
map.put("deptList",Collections.singletonList(area.getDeptId())); |
|
|
|
|
R<TicketMonthVO> result = ticketInfoClient.getOperateWorkStatistic(map); |
|
|
|
|
if (result.isSuccess() && ObjectUtil.isNotEmpty(result.getData())) { |
|
|
|
|
// 操作票
|
|
|
|
|
TicketMonthVO tiket = result.getData(); |
|
|
|
|
area.setOperate(tiket.getOperate()); |
|
|
|
|
area.setOperateFinish(tiket.getOperateQualify()); |
|
|
|
|
// 工作票
|
|
|
|
|
area.setWork(tiket.getWork()); |
|
|
|
|
area.setWorkFinish(tiket.getWorkQualify()); |
|
|
|
|
} |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 等待所有线程执行完成
|
|
|
|
|
try { |
|
|
|
|
countDownLatch.await(); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
|
} |
|
|
|
|
exe.shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 站点指标数据 |
|
|
|
|
* @param stations |
|
|
|
|
* @param reals |
|
|
|
|
* @param targets |
|
|
|
|
* @param plans |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<AppStationTargetVo> stationTarget(List<StationEntity> stations,List<HydropowerUnitRealVo> reals,List<HydropowerUnitTargetVo> targets,List<PlanGenerationEntity> plans) { |
|
|
|
|
if(CollectionUtil.isEmpty(stations)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
return stations.stream().map(station->{ |
|
|
|
|
AppStationTargetVo target = new AppStationTargetVo(); |
|
|
|
|
target.setDeptId(station.getRefDept()); |
|
|
|
|
target.setDeptName(station.getName()); |
|
|
|
|
// 站点年计划发电量
|
|
|
|
|
target.setPlanPowerYear(this.plan(plans,station.getCode())); |
|
|
|
|
// 站点发电完成率
|
|
|
|
|
double powerRate = this.getPowerRate(targets,station.getRefDept(),target.getPlanPowerYear()); |
|
|
|
|
target.setPowerRate(powerRate); |
|
|
|
|
// 设备总数
|
|
|
|
|
int deviceSum = this.getDeviceSum(reals,station.getRefDept(),false); |
|
|
|
|
target.setDeviceSum(deviceSum); |
|
|
|
|
// 设备开机数
|
|
|
|
|
int deviceRunSum = this.getDeviceSum(reals,station.getRefDept(),true); |
|
|
|
|
target.setDeviceRunSum(deviceRunSum); |
|
|
|
|
// 实时负荷
|
|
|
|
|
float realPowerSum = this.getRealPowerSum(reals,station.getRefDept()); |
|
|
|
|
target.setRealPowerSum(realPowerSum); |
|
|
|
|
// 负荷单位
|
|
|
|
|
String unit = this.getPowerUnit(reals,station.getRefDept()); |
|
|
|
|
target.setRealPowerUnit(unit); |
|
|
|
|
return target; |
|
|
|
|
}).sorted(Comparator.comparing(AppStationTargetVo::getRealPowerSum).reversed()).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 站点计划发电量 |
|
|
|
|
* @param plans |
|
|
|
|
* @param code |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Float plan(List<PlanGenerationEntity> plans, String code) { |
|
|
|
|
if(CollectionUtil.isEmpty(plans)){ |
|
|
|
|
return 0f; |
|
|
|
|
} |
|
|
|
|
return (float) plans.stream().filter(o->code.equals(o.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 站点发电完成率 |
|
|
|
|
* @param list |
|
|
|
|
* @param createDept |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private double getPowerRate(List<HydropowerUnitTargetVo> list, Long createDept ,float planPowerYear) { |
|
|
|
|
if(CollectionUtil.isEmpty(list) || ObjectUtil.isEmpty(createDept)){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
if(Math.abs(planPowerYear) <= 0){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
double power = list.stream().filter(o->createDept.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); |
|
|
|
|
if(Math.abs(power) <= 0){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return BigDecimal.valueOf((float) power / planPowerYear * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设备总数 |
|
|
|
|
* @param list |
|
|
|
|
* @param createDept |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private int getDeviceSum(List<HydropowerUnitRealVo> list, Long createDept,boolean isRun) { |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
if(isRun){ |
|
|
|
|
return (int) list.stream().filter(o -> createDept.equals(o.getDeptId()) && o.getState()).count(); |
|
|
|
|
} |
|
|
|
|
return (int) list.stream().filter(o -> createDept.equals(o.getDeptId())).count(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 实时负荷 |
|
|
|
|
* @param list |
|
|
|
|
* @param createDept |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private float getRealPowerSum(List<HydropowerUnitRealVo> list, Long createDept) { |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return (float) list.stream().filter(o->createDept.equals(o.getDeptId())).mapToDouble(o->Double.valueOf(o.getActivePower())).sum(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* app区域数据 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<AppHydropowerStationVo> area(Long deptId) { |
|
|
|
|
// 查询水电站站点
|
|
|
|
|
List<StationEntity> stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), HomePageConstant.HYDROPOWER_SERVETYPE); |
|
|
|
|
if (CollectionUtil.isEmpty(stations)) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 实时监测点数据
|
|
|
|
|
List<HydropowerUnitRealVo> reals = (List<HydropowerUnitRealVo>) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); |
|
|
|
|
return stations.stream().map(station -> { |
|
|
|
|
AppHydropowerStationVo hydropower = new AppHydropowerStationVo(); |
|
|
|
|
hydropower.setDeptId(station.getRefDept()); |
|
|
|
|
hydropower.setDeptName(station.getName()); |
|
|
|
|
// 装机容量
|
|
|
|
|
hydropower.setCapacity(reals.stream().filter(real-> real.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitRealVo::getInstalledCapacity).sum()); |
|
|
|
|
// 负荷
|
|
|
|
|
hydropower.setLoad(reals.stream().filter(real-> real.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitRealVo::getActivePower).sum()); |
|
|
|
|
// 出力
|
|
|
|
|
if(Math.abs(hydropower.getCapacity()) > 0){ |
|
|
|
|
hydropower.setOutput(BigDecimal.valueOf(hydropower.getLoad() / hydropower.getCapacity() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
|
|
|
|
}else{ |
|
|
|
|
hydropower.setOutput(0.0); |
|
|
|
|
} |
|
|
|
|
// 运行天数
|
|
|
|
|
hydropower.setRunDay(this.getRunDay(station)); |
|
|
|
|
// 告警
|
|
|
|
|
Result<List<SoeData>> result = soeClient.getByLastLimitTime(null, station.getCode(), 1); |
|
|
|
|
if(result.isSuccess() || CollectionUtil.isNotEmpty(result.getData())){ |
|
|
|
|
hydropower.setAlertList(result.getData()); |
|
|
|
|
} |
|
|
|
|
// 站点设备
|
|
|
|
|
List<HydropowerUnitRealVo> devices = reals.stream().filter(real-> real.getDeptId().equals(station.getRefDept())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isNotEmpty(devices)){ |
|
|
|
|
// 设备
|
|
|
|
|
hydropower.setDevices(devices.stream().map(real->{ |
|
|
|
|
AppHydropowerDeviceVo device = new AppHydropowerDeviceVo(); |
|
|
|
|
device.setDeviceCode(real.getDeviceCode()); |
|
|
|
|
device.setDeviceName(real.getDeviceName()); |
|
|
|
|
device.setState(real.getState()); |
|
|
|
|
device.setLoadUnit(Optional.ofNullable(real.getPowerUnit()).orElse("kw")); |
|
|
|
|
device.setCapacity(real.getInstalledCapacity()); |
|
|
|
|
device.setLoad(real.getActivePower()); |
|
|
|
|
return device; |
|
|
|
|
}).collect(Collectors.toList())); |
|
|
|
|
hydropower.setLoadUnit(hydropower.getDevices().get(0).getLoadUnit()); |
|
|
|
|
} |
|
|
|
|
return hydropower; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* app区域值班数据 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public AppAreaDutyVo areaDuty(Long deptId) { |
|
|
|
|
// 获取当班列表数据
|
|
|
|
|
List<DutyMainInfoVo> dutys = this.dutyMainService.getDutyDataV2(deptId); |
|
|
|
|
if(CollectionUtil.isEmpty(dutys)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
DutyMainInfoVo duty = dutys.get(0); |
|
|
|
|
// 响应数据
|
|
|
|
|
AppAreaDutyVo item = new AppAreaDutyVo(); |
|
|
|
|
// 班组基础数据设置
|
|
|
|
|
this.settingBase(duty,item); |
|
|
|
|
// 开始时间、结束时间
|
|
|
|
|
LocalDateTime localDateTime = LocalDateTime.ofInstant(duty.getDutyDate().toInstant(), ZoneId.systemDefault()); |
|
|
|
|
LocalDateTime startDate = localDateTime.withHour(duty.getStartTime().getHours()).withMinute(duty.getStartTime().getMinutes()).withSecond(00); |
|
|
|
|
//LocalDateTime endDate = localDateTime.withHour(duty.getEndTime().getHours()).withMinute(duty.getEndTime().getMinutes()).withSecond(00);
|
|
|
|
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); |
|
|
|
|
String start = dtf.format(startDate); |
|
|
|
|
String end = dtf.format(LocalDateTime.now()); |
|
|
|
|
List<Long> deptList = Collections.singletonList(duty.getCreateDept()); |
|
|
|
|
// 使用多线程处理数据
|
|
|
|
|
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("duty_data-pool-%d").build(); |
|
|
|
|
ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); |
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); |
|
|
|
|
// 下一班组
|
|
|
|
|
pool.execute(()-> { |
|
|
|
|
this.getNextDuty(item,duty.getId()); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 缺陷
|
|
|
|
|
pool.execute(()-> { |
|
|
|
|
this.getDutyDefect(item,startDate,null); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 巡检
|
|
|
|
|
pool.execute(()-> { |
|
|
|
|
this.getInspectionTask(item,start,end,deptList); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 维护
|
|
|
|
|
pool.execute(()-> { |
|
|
|
|
this.getMaintenanceTask(item,start,end,deptList); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 检修
|
|
|
|
|
pool.execute(()-> { |
|
|
|
|
this.getOverhaulTask(item,start,end,deptList); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 等待所有线程执行完成
|
|
|
|
|
try { |
|
|
|
|
countDownLatch.await(); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
|
} |
|
|
|
|
// 任务完成率
|
|
|
|
|
int taskSum = item.getDefectSum() + item.getInspectionTaskCount() + item.getMaintenanceTaskCount() + item.getOverhaulTaskCount(); |
|
|
|
|
int finishSum = item.getSolvedCount() + item.getInspectionTaskFinishCount() + item.getMaintenanceTaskFinishCount() + item.getOverhaulTaskFinishCount(); |
|
|
|
|
if(Math.abs(taskSum) <= 0){ |
|
|
|
|
item.setTaskRate(0.0); |
|
|
|
|
}else{ |
|
|
|
|
double taskRate = BigDecimal.valueOf((double)finishSum / (double)taskSum * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
|
item.setTaskRate(taskRate); |
|
|
|
|
} |
|
|
|
|
return item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 班组基础数据设置 |
|
|
|
|
* @param duty |
|
|
|
|
* @param item |
|
|
|
|
*/ |
|
|
|
|
private void settingBase(DutyMainInfoVo duty, AppAreaDutyVo item) { |
|
|
|
|
item.setShift(duty.getClassName()); |
|
|
|
|
item.setTeam(Optional.ofNullable(duty.getGroupName()).orElse("灵活排班")); |
|
|
|
|
// 班组负责人
|
|
|
|
|
String managerName = this.getManagerName(duty.getManagerId()); |
|
|
|
|
item.setTeamLeader(managerName); |
|
|
|
|
// 班组成员
|
|
|
|
|
String classMember = this.getClassMemberName(duty.getDutyPersonIds(),duty.getManagerId()); |
|
|
|
|
item.setClassMember(classMember); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取下一班组数据 |
|
|
|
|
* @param item |
|
|
|
|
* @param id |
|
|
|
|
*/ |
|
|
|
|
private void getNextDuty(AppAreaDutyVo item, Long id) { |
|
|
|
|
DutyMainInfoVo nextDuty = this.dutyMainService.getNextDutyDataV2(id); |
|
|
|
|
if(ObjectUtil.isEmpty(nextDuty)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
item.setNextShift(nextDuty.getClassName()); |
|
|
|
|
item.setNextTeam(nextDuty.getGroupName()); |
|
|
|
|
// 下一班组负责人
|
|
|
|
|
String managerName = this.getManagerName(nextDuty.getManagerId()); |
|
|
|
|
item.setNextTeamLeader(managerName); |
|
|
|
|
// 下一班组成员
|
|
|
|
|
String classMember = this.getClassMemberName(nextDuty.getDutyPersonIds(),nextDuty.getManagerId()); |
|
|
|
|
item.setNextClassMember(classMember); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取巡检任务数量 |
|
|
|
|
* @param item |
|
|
|
|
* @param startDate |
|
|
|
|
* @param endDate |
|
|
|
|
*/ |
|
|
|
|
private void getInspectionTask(AppAreaDutyVo item, String startDate, String endDate, List<Long> deptList) { |
|
|
|
|
item.setInspectionTaskCount(0); |
|
|
|
|
item.setInspectionTaskFinishCount(0); |
|
|
|
|
item.setNotInspectionTaskCount(0); |
|
|
|
|
// 查询当班巡检任务
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
|
params.put("startDate",startDate); |
|
|
|
|
params.put("endDate",endDate); |
|
|
|
|
params.put("deptList",deptList); |
|
|
|
|
R<DutyInspectTaskVO> response = inspectTaskReportClient.getDutyInspectTask(params); |
|
|
|
|
if(!response.isSuccess() || ObjectUtil.isEmpty(response.getData())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 赋值
|
|
|
|
|
item.setInspectionTaskCount(response.getData().getInspectTaskSum()); |
|
|
|
|
item.setInspectionTaskFinishCount(response.getData().getInspectTaskFinish()); |
|
|
|
|
item.setNotInspectionTaskCount(response.getData().getNotExecuteTaskCount()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当班日常维护数据 |
|
|
|
|
* @param item |
|
|
|
|
* @param start |
|
|
|
|
* @param end |
|
|
|
|
* @param deptList |
|
|
|
|
*/ |
|
|
|
|
private void getMaintenanceTask(AppAreaDutyVo item, String start, String end, List<Long> deptList) { |
|
|
|
|
item.setMaintenanceTaskCount(0); |
|
|
|
|
item.setMaintenanceTaskFinishCount(0); |
|
|
|
|
item.setNotMaintenanceTaskCount(0); |
|
|
|
|
// 查询当班日常维护任务
|
|
|
|
|
List<OperMaintenanceTaskEntity> list = operMaintenanceTaskService.getMaintenanceTask(start, end, deptList); |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 总数
|
|
|
|
|
item.setMaintenanceTaskCount(list.size()); |
|
|
|
|
// 完成数
|
|
|
|
|
int maintenanceTaskFinishCount = (int) list.stream().filter(o-> MaintenanceConstant.TASK_STATUS_5 == o.getStatus()).count(); |
|
|
|
|
item.setMaintenanceTaskFinishCount(maintenanceTaskFinishCount); |
|
|
|
|
// 未完成数
|
|
|
|
|
int notMaintenanceTaskCount = list.size() - maintenanceTaskFinishCount; |
|
|
|
|
item.setNotMaintenanceTaskCount(notMaintenanceTaskCount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取检修任务数量 |
|
|
|
|
* @param item |
|
|
|
|
* @param start |
|
|
|
|
* @param end |
|
|
|
|
* @param deptList |
|
|
|
|
*/ |
|
|
|
|
private void getOverhaulTask(AppAreaDutyVo item, String start, String end, List<Long> deptList) { |
|
|
|
|
item.setOverhaulTaskCount(0); |
|
|
|
|
item.setNotOverhaulTaskCount(0); |
|
|
|
|
item.setOverhaulTaskFinishCount(0); |
|
|
|
|
// 查询当班检修任务
|
|
|
|
|
List<OperAccessTaskEntity> list = accessTaskService.getAccessTask(start, end, deptList); |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 总数
|
|
|
|
|
item.setOverhaulTaskCount(list.size()); |
|
|
|
|
// 完成数
|
|
|
|
|
int overhaulTaskFinishCount = (int) list.stream().filter(o-> AccessConstants.ACCESS_TASK_STATUS_4 == o.getStatus()).count(); |
|
|
|
|
item.setOverhaulTaskFinishCount(overhaulTaskFinishCount); |
|
|
|
|
// 未开始数
|
|
|
|
|
int notOverhaulTaskCount = (int) list.stream().filter(o-> AccessConstants.ACCESS_TASK_STATUS_0 == o.getStatus()).count(); |
|
|
|
|
item.setNotOverhaulTaskCount(notOverhaulTaskCount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当班缺陷数据 |
|
|
|
|
* @param item |
|
|
|
|
* @param startTime |
|
|
|
|
* @param endTime |
|
|
|
|
*/ |
|
|
|
|
private void getDutyDefect(AppAreaDutyVo item, LocalDateTime startTime, LocalDateTime endTime) { |
|
|
|
|
LambdaQueryWrapper<OperPhenomenonEntity> wrapper = Wrappers.lambdaQuery(); |
|
|
|
|
wrapper.ge(OperPhenomenonEntity::getCreateTime,startTime); |
|
|
|
|
//wrapper.le(OperPhenomenonEntity::getCreateTime,endTime);
|
|
|
|
|
wrapper.eq(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.IS_DEFECT); |
|
|
|
|
wrapper.eq(OperPhenomenonEntity::getDiscriminateStatus,TreatMethodConstant.AUTO_SCREENED); |
|
|
|
|
// 查询现象
|
|
|
|
|
List<OperPhenomenonEntity> list = phenomenonService.list(wrapper); |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
item.setUnsolvedCount(0); |
|
|
|
|
item.setSolvedCount(0); |
|
|
|
|
item.setDefectSum(0); |
|
|
|
|
item.setSeriousCount(0); |
|
|
|
|
item.setDefectRate(0.0); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 缺陷总数
|
|
|
|
|
int defectSum = list.size(); |
|
|
|
|
item.setDefectSum(defectSum); |
|
|
|
|
// 缺陷已解决数量
|
|
|
|
|
int solvedCount = (int) list.stream().filter(o->TreatMethodConstant.CONCLUSION_COMPLETED.equals(o.getConclusionStatus())).count(); |
|
|
|
|
item.setSolvedCount(solvedCount); |
|
|
|
|
// 缺陷未解决数量
|
|
|
|
|
int unsolvedCount = list.size() - solvedCount; |
|
|
|
|
item.setUnsolvedCount(unsolvedCount); |
|
|
|
|
// 缺陷严重数量
|
|
|
|
|
int seriousCount = (int) list.stream().filter(o-> TreatMethodConstant.CLASS_I_DEFECT.toString().equals(o.getDefectLevel())).count(); |
|
|
|
|
item.setSeriousCount(seriousCount); |
|
|
|
|
// 消缺率
|
|
|
|
|
double defectRate = BigDecimal.valueOf((double) solvedCount / (double)list.size() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
|
|
|
|
item.setDefectRate(defectRate); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取班组负责人 |
|
|
|
|
* @param managerId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String getManagerName(String managerId) { |
|
|
|
|
if(StringUtil.isBlank(managerId)){ |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
User user = UserCache.getUser(Long.valueOf(managerId)); |
|
|
|
|
if (ObjectUtil.isEmpty(user)) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
return user.getName(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取班组成员 |
|
|
|
|
* @param personIds |
|
|
|
|
* @param managerId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String getClassMemberName(String personIds,String managerId) { |
|
|
|
|
if(StringUtil.isBlank(personIds)){ |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
|
// 遍历成员
|
|
|
|
|
for (String item : personIds.split("\\^")) { |
|
|
|
|
if (item.equals(managerId)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
User user = UserCache.getUser(Long.valueOf(item)); |
|
|
|
|
if (ObjectUtil.isEmpty(user)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
builder.append(user.getName()).append(","); |
|
|
|
|
} |
|
|
|
|
if(builder.length() <= 0){ |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
return builder.substring(0,builder.toString().length() - 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|