|
|
|
@ -1,755 +0,0 @@
|
|
|
|
|
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.equipment.entity.PlanGenerationEntity; |
|
|
|
|
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.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.main.constant.HomePageConstant; |
|
|
|
|
import com.hnac.hzims.operational.main.service.AreaService; |
|
|
|
|
import com.hnac.hzims.operational.main.service.IAppHomeService; |
|
|
|
|
import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; |
|
|
|
|
import com.hnac.hzims.operational.main.service.IWeatherService; |
|
|
|
|
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.hzinfo.datasearch.soe.domian.SoeData; |
|
|
|
|
import com.hnac.hzinfo.inspect.task.feign.IInspectTaskReportClient; |
|
|
|
|
import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
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.feign.ISysClient; |
|
|
|
|
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.LocalDateTime; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* APP首页实现类 |
|
|
|
|
* @author ysj |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
public class AppHomeServiceImpl implements IAppHomeService { |
|
|
|
|
|
|
|
|
|
private final AreaService areaService; |
|
|
|
|
|
|
|
|
|
private final IStationService stationService; |
|
|
|
|
|
|
|
|
|
private final IImsDutyMainService dutyMainService; |
|
|
|
|
|
|
|
|
|
private final IOperPhenomenonService phenomenonService; |
|
|
|
|
|
|
|
|
|
private final IOperAccessTaskService accessTaskService; |
|
|
|
|
|
|
|
|
|
private final IMainSystemMonitoringService mainService; |
|
|
|
|
|
|
|
|
|
private final IStationAttributeService attributeService; |
|
|
|
|
|
|
|
|
|
private final IOperMaintenanceTaskService maintenanceTaskService; |
|
|
|
|
|
|
|
|
|
private final IInspectTaskReportClient inspectTaskReportClient; |
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
private final IWeatherService weatherService; |
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
// 线程数量
|
|
|
|
|
private final static int POOL_QUANTITY = 5; |
|
|
|
|
|
|
|
|
|
@Value("${hzims.operation.realIdKey}") |
|
|
|
|
public String real_id_key; |
|
|
|
|
|
|
|
|
|
private final static String LOAD_HYDROPOWER_UNIT_REAL_KEY = "hzims:operation:loadhydropowerunit:real:key"; |
|
|
|
|
|
|
|
|
|
private final static String LOAD_HYDROPOWER_UNIT_TARGET_KEY = "hzims:operation:loadhydropowerunit:target:key"; |
|
|
|
|
|
|
|
|
|
private final static String KEY_INDICATORS_INFO = "hzims:operation:key:indicators:info"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* app首页-站点 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<AppStationVo> appStation(Long deptId) { |
|
|
|
|
// 用户权限机构
|
|
|
|
|
R<List<Dept>> R = sysClient.getDeptByCurrentUser(); |
|
|
|
|
if(!R.isSuccess() && CollectionUtil.isEmpty(R.getData())){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 设备信息
|
|
|
|
|
List<EminfoAndEmParamVo> emList = mainService.getEmInfoList(); |
|
|
|
|
if(CollectionUtil.isEmpty(emList)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 站点列表
|
|
|
|
|
List<StationEntity> list = stationService.getStationList(R.getData(),deptId,Collections.singletonList(HomePageConstant.HYDROPOWER),null,true); |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 站点缓存列表
|
|
|
|
|
KeyIndicatorsVo keyIndicatorsVo = (KeyIndicatorsVo) redisTemplate.opsForValue().get(KEY_INDICATORS_INFO); |
|
|
|
|
// 监测点单位
|
|
|
|
|
Map<String,String> unitMap = this.attributeService.getPointUnit(); |
|
|
|
|
// 站点遍历
|
|
|
|
|
List<AppStationVo> result = new ArrayList<>(); |
|
|
|
|
list.forEach(station -> { |
|
|
|
|
if(null == station.getRefDept()){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
AppStationVo vo = new AppStationVo(); |
|
|
|
|
vo.setDeptId(station.getRefDept()); |
|
|
|
|
vo.setDeptName(station.getName()); |
|
|
|
|
vo.setDay(0L); |
|
|
|
|
// 投运时间计算安全运行天数
|
|
|
|
|
if (ObjectUtil.isNotEmpty(station.getCommissionTime())) { |
|
|
|
|
Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); |
|
|
|
|
vo.setDay(dur.toDays()); |
|
|
|
|
} |
|
|
|
|
// 天气温度
|
|
|
|
|
this.getWeather(station,vo); |
|
|
|
|
// 站点告警列表
|
|
|
|
|
List<SoeData> alertList = this.getStationAlert(station.getId(),keyIndicatorsVo); |
|
|
|
|
if(CollectionUtil.isNotEmpty(alertList)){ |
|
|
|
|
vo.setAlertList(alertList); |
|
|
|
|
} |
|
|
|
|
// 遍历监测点数据
|
|
|
|
|
List<EmShowVo> stationEmList = getEmShowList(emList.stream().filter(o->station.getCreateDept().equals(o.getCreateDept())).collect(Collectors.toList()),unitMap); |
|
|
|
|
if(CollectionUtil.isEmpty(stationEmList)){ |
|
|
|
|
vo.setInstalledCapacity(0.0); |
|
|
|
|
vo.setActivePower(0.0); |
|
|
|
|
vo.setUsrRate(0.0); |
|
|
|
|
result.add(vo); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 设备
|
|
|
|
|
vo.setList(stationEmList); |
|
|
|
|
// 总装机容量
|
|
|
|
|
double installedCapacity = stationEmList.stream().filter(o-> null != o.getInstalledCapacity()).mapToDouble(EmShowVo::getInstalledCapacity).sum(); |
|
|
|
|
vo.setInstalledCapacity(installedCapacity); |
|
|
|
|
// 总有功功率
|
|
|
|
|
double activePower = stationEmList.stream().filter(o->StringUtil.isNotBlank(o.getActivePower())).mapToDouble(o->Float.parseFloat(o.getActivePower())).sum(); |
|
|
|
|
vo.setActivePower(activePower); |
|
|
|
|
// 总有功率单位
|
|
|
|
|
List<String> unit = stationEmList.stream().filter(o->StringUtil.isNotBlank(o.getPowerUnit())).map(EmShowVo::getPowerUnit).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isNotEmpty(unit)){ |
|
|
|
|
vo.setPowerUnit(unit.get(0)); |
|
|
|
|
} else { |
|
|
|
|
vo.setPowerUnit("kW"); |
|
|
|
|
} |
|
|
|
|
if(installedCapacity <= 0){ |
|
|
|
|
vo.setUsrRate(0.0); |
|
|
|
|
}else{ |
|
|
|
|
double usrRate = BigDecimal.valueOf(activePower / installedCapacity * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
|
vo.setUsrRate(usrRate); |
|
|
|
|
} |
|
|
|
|
result.add(vo); |
|
|
|
|
}); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取展示设备列表 |
|
|
|
|
* @param valid |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<EmShowVo> getEmShowList(List<EminfoAndEmParamVo> valid,Map<String,String> unitMap) { |
|
|
|
|
if(CollectionUtil.isEmpty(valid)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// readId,value
|
|
|
|
|
String json = (String) redisTemplate.opsForValue().get(real_id_key); |
|
|
|
|
Map<String, String> map = null; |
|
|
|
|
if (StringUtil.isNotBlank(json)) { |
|
|
|
|
map = JSONObject.parseObject(json, new TypeReference<Map<String, String>>() {}); |
|
|
|
|
} |
|
|
|
|
// 展示设备(有功功率)
|
|
|
|
|
List<EmShowVo> list = getActiveList(map,valid,unitMap); |
|
|
|
|
// 设备监测点集合
|
|
|
|
|
List<String> onOffList = valid.stream().filter(o->MapUtils.isNotEmpty(o.getPoint()) && StringUtil.isNotBlank(o.getPoint().get(HomePageConstant.ACTIVE_POWER))). |
|
|
|
|
map(o->o.getPoint().get(HomePageConstant.JOINT_RELAY)).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(onOffList) || MapUtils.isEmpty(map)){ |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
// 展示设备(开关机状态)
|
|
|
|
|
for(EmShowVo em : list){ |
|
|
|
|
em.setOnOff(false); |
|
|
|
|
if (MapUtils.isEmpty(em.getPoint()) || StringUtil.isEmpty(em.getPoint().get(HomePageConstant.JOINT_RELAY))) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String realId = em.getPoint().get(HomePageConstant.JOINT_RELAY); |
|
|
|
|
String value = map.get(realId); |
|
|
|
|
if(StringUtil.isBlank(value)){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (value.contains("1") || "1.0".equals(value)) { |
|
|
|
|
em.setOnOff(true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return list; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取有功功率展示设备 |
|
|
|
|
* @param valid |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<EmShowVo> getActiveList(Map<String, String> map,List<EminfoAndEmParamVo> valid,Map<String,String> unitMap) { |
|
|
|
|
List<String> realIds = valid.stream().filter(o->MapUtils.isNotEmpty(o.getPoint()) && StringUtil.isNotBlank(o.getPoint().get(HomePageConstant.ACTIVE_POWER))). |
|
|
|
|
map(o->o.getPoint().get(HomePageConstant.ACTIVE_POWER)).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isEmpty(realIds) || MapUtils.isEmpty(map)) { |
|
|
|
|
return getEmShowVos(valid); |
|
|
|
|
} |
|
|
|
|
// 遍历设备
|
|
|
|
|
List<EmShowVo> emShowVoList = new ArrayList<>(); |
|
|
|
|
valid.forEach(em -> { |
|
|
|
|
EmShowVo emShowVo = new EmShowVo(); |
|
|
|
|
emShowVo.setDeptId(em.getCreateDept()); |
|
|
|
|
emShowVo.setCode(em.getEmCode()); |
|
|
|
|
emShowVo.setName(em.getName()); |
|
|
|
|
emShowVo.setPoint(em.getPoint()); |
|
|
|
|
emShowVo.setOnOff(false); |
|
|
|
|
emShowVo.setOrd(em.getOrd()); |
|
|
|
|
emShowVo.setInstalledCapacity(em.getInstalledCapacity()); |
|
|
|
|
// 有功功率
|
|
|
|
|
if (MapUtils.isEmpty(em.getPoint())) { |
|
|
|
|
emShowVo.setActivePower("0"); |
|
|
|
|
emShowVoList.add(emShowVo); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
String realId = em.getPoint().get(HomePageConstant.ACTIVE_POWER); |
|
|
|
|
if(StringUtil.isEmpty(realId)){ |
|
|
|
|
emShowVo.setActivePower("0"); |
|
|
|
|
emShowVoList.add(emShowVo); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// websocket 中取realId的value值
|
|
|
|
|
String value = map.get(realId); |
|
|
|
|
if(StringUtil.isEmpty(value)){ |
|
|
|
|
emShowVo.setActivePower("0"); |
|
|
|
|
emShowVoList.add(emShowVo); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
emShowVo.setActivePower(value); |
|
|
|
|
// 单位设置
|
|
|
|
|
if(MapUtils.isNotEmpty(unitMap)){ |
|
|
|
|
String unit = unitMap.get(em.getId()+HomePageConstant.CONCAT_P); |
|
|
|
|
if(StringUtil.isNotBlank(unit)) { |
|
|
|
|
emShowVo.setPowerUnit(unit); |
|
|
|
|
} else { |
|
|
|
|
emShowVo.setPowerUnit("kW"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
emShowVo.setPowerUnit("kW"); |
|
|
|
|
} |
|
|
|
|
emShowVoList.add(emShowVo); |
|
|
|
|
}); |
|
|
|
|
return emShowVoList.stream().sorted(Comparator.comparing(EmShowVo::getOrd)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 默认设备展示信息 |
|
|
|
|
* @param valid |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<EmShowVo> getEmShowVos(List<EminfoAndEmParamVo> valid) { |
|
|
|
|
return valid.stream().map(o -> { |
|
|
|
|
EmShowVo emShowVo = new EmShowVo(); |
|
|
|
|
emShowVo.setDeptId(o.getCreateDept()); |
|
|
|
|
emShowVo.setCode(o.getEmCode()); |
|
|
|
|
emShowVo.setName(o.getName()); |
|
|
|
|
emShowVo.setInstalledCapacity(o.getInstalledCapacity()); |
|
|
|
|
emShowVo.setActivePower("0"); |
|
|
|
|
emShowVo.setPoint(o.getPoint()); |
|
|
|
|
emShowVo.setOnOff(false); |
|
|
|
|
return emShowVo; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取温度 |
|
|
|
|
* @param station |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private void getWeather(StationEntity station,AppStationVo vo) { |
|
|
|
|
Map<String, HeWeatherWeatherDailyResponse> weekWeather = this.weatherService.getWeekWeather(Collections.singletonList(station.getCode())); |
|
|
|
|
if(MapUtils.isEmpty(weekWeather)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
List<Daily> list = weekWeather.get(station.getCode()).getDaily(); |
|
|
|
|
if (CollectionUtil.isEmpty(list)) { |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
vo.setTempMin(list.get(0).getTempMin()); |
|
|
|
|
vo.setTempMax(list.get(0).getTempMax()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取站点告警列表 |
|
|
|
|
* @param stationId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public List<SoeData> getStationAlert(Long stationId,KeyIndicatorsVo keyIndicatorsVo) { |
|
|
|
|
if(ObjectUtil.isEmpty(keyIndicatorsVo) || null == stationId){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
List<PowerStationTotalVo> powerStationTotalVoList = keyIndicatorsVo.getPowerStationTotalVoList(); |
|
|
|
|
if(CollectionUtil.isEmpty(powerStationTotalVoList)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
List<PowerStationTotalVo> stationAlertList = powerStationTotalVoList.stream().filter(o->stationId.equals(o.getStationId())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(stationAlertList)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return stationAlertList.get(0).getAlertList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* app首页-站点列表数据 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<AppStationAreaVo> appStationList(Long deptId) { |
|
|
|
|
// 获取区域或者站点map结构
|
|
|
|
|
Map<Dept,List<StationEntity>> map = areaService.areaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER),true); |
|
|
|
|
if(MapUtils.isEmpty(map)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 获取站点计划发电量集合
|
|
|
|
|
//List<PlanGenerationEntity> planPowerList = sideHustleService.getStaionPlanPower(map);
|
|
|
|
|
// 获取设备指标数据列表
|
|
|
|
|
List<HydropowerUnitTargetVo> targetList = (List<HydropowerUnitTargetVo>) redisTemplate.opsForValue().get(LOAD_HYDROPOWER_UNIT_TARGET_KEY); |
|
|
|
|
// 获取设备实时数据
|
|
|
|
|
List<HydropowerUnitRealVo> realList = (List<HydropowerUnitRealVo>) redisTemplate.opsForValue().get(LOAD_HYDROPOWER_UNIT_REAL_KEY); |
|
|
|
|
// 响应结果
|
|
|
|
|
List<AppStationAreaVo> result = new ArrayList<>(); |
|
|
|
|
map.forEach((key,value)->{ |
|
|
|
|
AppStationAreaVo vo = new AppStationAreaVo(); |
|
|
|
|
List<AppStationTargetVo> children = new ArrayList<>(); |
|
|
|
|
value.forEach(item->{ |
|
|
|
|
AppStationTargetVo response = new AppStationTargetVo(); |
|
|
|
|
response.setDeptId(item.getRefDept()); |
|
|
|
|
response.setDeptName(item.getName()); |
|
|
|
|
// 站点年计划发电量
|
|
|
|
|
//float planPowerYear = this.getPlanPowerYear(planPowerList,item.getCode());
|
|
|
|
|
response.setPlanPowerYear(0f); |
|
|
|
|
// 站点发电完成率
|
|
|
|
|
double powerRate = this.getPowerRate(targetList,item.getCreateDept(),0f); |
|
|
|
|
response.setPowerRate(powerRate); |
|
|
|
|
// 设备总数
|
|
|
|
|
int deviceSum = this.getDeviceSum(realList,item.getCreateDept(),false); |
|
|
|
|
response.setDeviceSum(deviceSum); |
|
|
|
|
// 设备开机数
|
|
|
|
|
int deviceRunSum = this.getDeviceSum(realList,item.getCreateDept(),true); |
|
|
|
|
response.setDeviceRunSum(deviceRunSum); |
|
|
|
|
// 实时负荷
|
|
|
|
|
float realPowerSum = this.getRealPowerSum(realList,item.getCreateDept()); |
|
|
|
|
response.setRealPowerSum(realPowerSum); |
|
|
|
|
// 负荷单位
|
|
|
|
|
String unit = this.getPowerUnit(realList,item.getCreateDept()); |
|
|
|
|
response.setRealPowerUnit(unit); |
|
|
|
|
children.add(response); |
|
|
|
|
}); |
|
|
|
|
vo.setList(children); |
|
|
|
|
vo.setDeptId(key.getId()); |
|
|
|
|
vo.setDeptName(key.getDeptName()); |
|
|
|
|
result.add(vo); |
|
|
|
|
}); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取站点年计划发电量 |
|
|
|
|
* @param list |
|
|
|
|
* @param code |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private float getPlanPowerYear(List<PlanGenerationEntity> list, String code) { |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return 0f; |
|
|
|
|
} |
|
|
|
|
return (float) list.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()) && HomePageConstant.OFF.equals(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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 负荷单位 |
|
|
|
|
* @param list |
|
|
|
|
* @param createDept |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String getPowerUnit(List<HydropowerUnitRealVo> list, Long createDept) { |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return "kW"; |
|
|
|
|
} |
|
|
|
|
List<String> units = list.stream().filter(o->createDept.equals(o.getDeptId())).map(HydropowerUnitRealVo::getPowerUnit).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(units)){ |
|
|
|
|
return "kW"; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return units.get(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* app首页-当班数据 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<AppAreaDutyVo> getDutyData(Long deptId) { |
|
|
|
|
// 获取当班列表数据
|
|
|
|
|
List<DutyMainInfoVo> list = this.dutyMainService.getDutyDataV2(deptId); |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 响应数据
|
|
|
|
|
return list.stream().map(duty->{ |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
pool.shutdown(); |
|
|
|
|
// 任务完成率
|
|
|
|
|
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; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 班组基础数据设置 |
|
|
|
|
* @param duty |
|
|
|
|
* @param item |
|
|
|
|
*/ |
|
|
|
|
private void settingBase(DutyMainInfoVo duty, AppAreaDutyVo item) { |
|
|
|
|
item.setShift(duty.getClassName()); |
|
|
|
|
item.setTeam(duty.getGroupName()); |
|
|
|
|
// 班组负责人
|
|
|
|
|
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) || ObjectUtil.isEmpty(nextDuty.getId())){ |
|
|
|
|
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 = maintenanceTaskService.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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |