diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/census/vo/PhotovoTargetVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/census/vo/PhotovoTargetVo.java new file mode 100644 index 0000000..ff81022 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/census/vo/PhotovoTargetVo.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.operational.census.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + * @date 2023/04/19 15:01:17 + * @version 4.0.0 + */ +@Data +public class PhotovoTargetVo { + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generate; + + @ApiModelProperty("功率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double load; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/TargetController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/TargetController.java index 7374e95..24767af 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/TargetController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/TargetController.java @@ -122,7 +122,6 @@ public class TargetController { return R.data(service.hydropowerTarget(stationName,deptId,target)); } - @ApiLog @ApiOperation("水利集团、区域指标关联") @GetMapping("/water-target") @@ -132,14 +131,13 @@ public class TargetController { } @ApiLog - @ApiOperation("集团设备统计") - @GetMapping("/device-group") - @ApiOperationSupport(order = 11) - public R deviceGroup(@RequestParam(value = "areaName",required = false) String areaName) { - return R.data(service.deviceGroup(areaName)); + @ApiOperation("光伏集团、区域指标关联") + @GetMapping("/photovoltaic-target") + @ApiOperationSupport(order = 10) + public R photovoltaicTarget(@RequestParam(value = "stationName",required = false) String stationName, @RequestParam(value = "deptId",required = false) Long deptId,@RequestParam(value = "target") Integer target) { + return R.data(service.photovoltaicTarget(stationName,deptId,target)); } - @ApiLog @ApiOperation("集团操作票/工作票") @GetMapping("/ticket-group") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/TargetService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/TargetService.java index 425adec..626b59e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/TargetService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/TargetService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO; import com.hnac.hzims.operational.access.vo.OperAccessTaskVO; import com.hnac.hzims.operational.census.vo.*; +import com.hnac.hzims.operational.main.vo.PhotovoltaicTargetVo; import com.hnac.hzims.operational.maintenance.dto.OperMaintenanceTaskDTO; import com.hnac.hzims.operational.maintenance.vo.OperMaintenanceTaskVO; import org.springblade.core.mp.support.Query; @@ -54,9 +55,13 @@ public interface TargetService { // 水利指标关联数据 List waterTarget(String stationName, Long deptId,Integer target); + // 光伏指标关联数据 + List photovoltaicTarget(String stationName, Long deptId, Integer target); + // 集团设备 List deviceGroup(String areaName); // 集团工作牌/操作票 List ticketGroup(String areaName,Long type); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/TargetServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/TargetServiceImpl.java index 1b5ef69..345df01 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/TargetServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/TargetServiceImpl.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.census.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; 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.feign.IPlanGenertionClient; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; @@ -11,15 +12,15 @@ import com.hnac.hzims.operational.access.service.IOperAccessTaskService; import com.hnac.hzims.operational.access.vo.OperAccessTaskVO; import com.hnac.hzims.operational.census.constants.CensusConstant; import com.hnac.hzims.operational.census.service.TargetService; -import com.hnac.hzims.operational.census.vo.*; import com.hnac.hzims.operational.census.vo.WaterTargetVo; +import com.hnac.hzims.operational.census.vo.*; import com.hnac.hzims.operational.defect.service.IOperPhenomenonService; import com.hnac.hzims.operational.fill.entity.*; import com.hnac.hzims.operational.fill.service.*; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.AreaService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.maintenance.dto.OperMaintenanceTaskDTO; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; import com.hnac.hzims.operational.maintenance.vo.OperMaintenanceTaskVO; @@ -45,14 +46,11 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.math.BigDecimal; -import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; import java.util.stream.Collectors; /** @@ -64,41 +62,35 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class TargetServiceImpl implements TargetService { - private final IStationService stationService; - - private final IMainSystemMonitoringService maintenanceService; - - private final PowerService powerService; - private final AreaService areaService; - private final IOperMaintenanceTaskService maintenanceTaskService; - - private final IOperPhenomenonService phenomenonService; - private final OverService overService; - private final OverDetailsService overDetailsService; + private final PowerService powerService; private final SolveService solveService; private final OtherService otherService; + private final IStationService stationService; + + private final OverDetailsService overDetailsService; + private final IOperAccessTaskService accessTaskService; - private final IPlanGenertionClient planClient; + private final IOperPhenomenonService phenomenonService; - private final ITicketInfoAllClient ticketInfoAllClient; + private final IMainSystemMonitoringService maintenanceService; - private final ISysClient sysClient; + private final IOperMaintenanceTaskService maintenanceTaskService; - private final RedisTemplate redisTemplate; + private final ISysClient sysClient; - private final SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); + private final IPlanGenertionClient planClient; - private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; + private final ITicketInfoAllClient ticketInfoAllClient; - private final static String KEY_INDICATORS_INFO = "hzims:operation:key:indicators:info"; + private final RedisTemplate redisTemplate; @Value("${hzims.operation.region.deviceClassifyKey}") private String device_classify_key; @@ -109,9 +101,17 @@ public class TargetServiceImpl implements TargetService { @Value("${hzims.operation.region.areaDutyInfoKey}") private String areaDutyInfoKey; - private final static String loadwaterpump_target_key = "hzims:operation:loadwaterpump:target:key"; + private final static String load_waterpump_real_key = "hzims:operation:loadwaterpump:real:key"; + + private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key"; + + private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; - private final static String loadwaterpump_real_key = "hzims:operation:loadwaterpump:real:key"; + private final static String load_waterpump_target_key = "hzims:operation:loadwaterpump:target:key"; + + private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; + + private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; /** * 获取站点装机容量 @@ -121,7 +121,7 @@ public class TargetServiceImpl implements TargetService { public List installedCapacity(String stationName,Integer type) { // 站点 LambdaQueryWrapper wappers = Wrappers.lambdaQuery(); - wappers.eq(StationEntity::getType, HomePageConstant.HYDROPOWER); + wappers.eq(StationEntity::getType, type); wappers.eq(StationEntity::getServeType,2); if(!StringUtils.isEmpty(stationName)){ wappers.like(StationEntity::getName,stationName); @@ -130,46 +130,25 @@ public class TargetServiceImpl implements TargetService { if(CollectionUtils.isEmpty(stations)){ return new ArrayList<>(); } - if(HomePageConstant.HYDROPOWER.equals(type)){ - // 设备 - List devices = maintenanceService.getEmInfoList(); - return stations.stream().map(station->{ - InstalledCapacityVo item = new InstalledCapacityVo(); - item.setStationName(station.getName()); - List stationDevices = devices.stream().filter(device->device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(stationDevices)){ - item.setInstalledCapacity(0.0); - item.setDetail("站点暂无设备!"); - return item; - } - // 装机容量 - double sum = stationDevices.stream().mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); - item.setInstalledCapacity(sum); - // 装机容量详情 - List details = stationDevices.stream().map(device-> "[" + device.getName() + " " +device.getInstalledCapacity() +"kw]").collect(Collectors.toList()); - item.setDetail(String.join("|",details)); - return item; - }).collect(Collectors.toList()); - } - // 查询填报数据 - String mon = DateUtil.format(new Date(),"yyyy"); - List powers = powerService.list(Wrappers.lambdaQuery() - .in(PowerEntity::getCreateDept,stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())) - .ge(PowerEntity::getMon, mon + "-01") - ); - return stations.stream().map(station -> { + // 设备 + List devices = maintenanceService.getEmInfoList(); + return stations.stream().map(station->{ InstalledCapacityVo item = new InstalledCapacityVo(); item.setStationName(station.getName()); - // 装机容量 - List stationPowers = powers.stream().filter(o->o.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(stationPowers)){ + List stationDevices = devices.stream().filter(device->device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(stationDevices)){ item.setInstalledCapacity(0.0); - }else{ - item.setInstalledCapacity(stationPowers.stream().sorted(Comparator.comparing(PowerEntity::getMon).reversed()).collect(Collectors.toList()).get(0).getInstalledCapacity()); + item.setDetail("站点暂无设备!"); + return item; } - item.setDetail("站点为填报数据,暂无设备装机容量信息!"); + // 装机容量 + double sum = stationDevices.stream().mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); + item.setInstalledCapacity(sum); + // 装机容量详情 + List details = stationDevices.stream().map(device-> "[" + device.getName() + " " +device.getInstalledCapacity() +"kw]").collect(Collectors.toList()); + item.setDetail(String.join("|",details)); return item; - }).collect(Collectors.toList()); + }).filter(capacity->Math.abs(capacity.getInstalledCapacity()) > 0).collect(Collectors.toList()); } /** @@ -180,7 +159,7 @@ public class TargetServiceImpl implements TargetService { public List electricGeneration(String stationName,Integer type) { // 站点 LambdaQueryWrapper wappers = Wrappers.lambdaQuery(); - wappers.eq(StationEntity::getType, HomePageConstant.HYDROPOWER); + wappers.eq(StationEntity::getType, type); wappers.eq(StationEntity::getServeType,2); if(!StringUtils.isEmpty(stationName)){ wappers.like(StationEntity::getName,stationName); @@ -206,13 +185,36 @@ public class TargetServiceImpl implements TargetService { return item; } // 年发电量 - double sum = targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); + double sum = targets.stream().filter(target->target.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); + item.setElectricGeneration(sum); + // 发电量详情 + List details = targets.stream().filter(target->target.getDeptId().equals(station.getRefDept())).map(target-> "[" + Optional.ofNullable(target.getDeviceCode()).orElse("填报电量") + " " + target.getPowerYear() +"kWh]").collect(Collectors.toList()); + item.setDetail(String.join("|",details)); + return item; + }).filter(generate->Math.abs(generate.getElectricGeneration()) > 0).collect(Collectors.toList()); + }else if(HomePageConstant.PHOTOVOLTAIC.equals(type)){ + List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + if(CollectionUtil.isEmpty(targets)){ + return new ArrayList<>(); + } + return stations.stream().map(station->{ + ElectricGenerationVo item = new ElectricGenerationVo(); + item.setStationName(station.getName()); + List stationTargets = targets.stream().filter(device->device.getDeptId().equals(station.getRefDept())).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(stationTargets)){ + item.setElectricGeneration(0.0); + item.setDetail("站点暂无发电"); + return item; + } + // 年发电量 + double sum = targets.stream().filter(target->target.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum(); item.setElectricGeneration(sum); // 发电量详情 - List details = targets.stream().map(target-> "[" + target.getDeviceCode() + " " + target.getPowerYear() +"kw]").collect(Collectors.toList()); + List details = targets.stream().filter(target->target.getDeptId().equals(station.getRefDept())).map(target-> "[" + Optional.ofNullable(target.getDeviceCode()).orElse("填报电量") + " " + target.getGenerationYear() +"kWh]").collect(Collectors.toList()); item.setDetail(String.join("|",details)); return item; - }).collect(Collectors.toList()); + }).filter(generate->Math.abs(generate.getElectricGeneration()) > 0).collect(Collectors.toList()); + } // 查询填报数据 String mon = DateUtil.format(new Date(),"yyyy"); @@ -243,7 +245,7 @@ public class TargetServiceImpl implements TargetService { public List completeGeneration(String stationName,Integer type) { // 站点 LambdaQueryWrapper wappers = Wrappers.lambdaQuery(); - wappers.eq(StationEntity::getType, HomePageConstant.HYDROPOWER); + wappers.eq(StationEntity::getType, type); wappers.eq(StationEntity::getServeType,2); if(!StringUtils.isEmpty(stationName)){ wappers.like(StationEntity::getName,stationName); @@ -263,29 +265,77 @@ public class TargetServiceImpl implements TargetService { return stations.stream().map(station->{ CompleteGenerationVo item = new CompleteGenerationVo(); item.setStationName(station.getName()); - List stationTargets = targets.stream().filter(device->device.getDeptId().equals(station.getRefDept())).collect(Collectors.toList()); + List stationTargets = targets.stream().filter(target->target.getDeptId().equals(station.getRefDept())).collect(Collectors.toList()); // 实际发电量 if(CollectionUtils.isEmpty(stationTargets)){ item.setRealityGeneration(0.0); }else { - double sum = targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); + double sum = stationTargets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); item.setRealityGeneration(sum); } - // 计划发电量 - List planGenerations = plans.stream().filter(plan->plan.getStationId().equals(station.getCode())).map(PlanGenerationEntity::getPlanGeneration).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(planGenerations)){ - item.setPlanGeneration(0.0); + if(CollectionUtil.isNotEmpty(plans)){ + // 计划发电量 + double planGenerate = plans.stream().filter(plan -> plan.getStationId().equals(station.getCode())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + if(Math.abs(planGenerate) <= 0){ + item.setPlanGeneration(0.0); + }else{ + item.setPlanGeneration(planGenerate); + } + // 完成率 + if(Math.abs(item.getPlanGeneration()) <= 0){ + item.setCompleteRate(0.0); + }else{ + item.setCompleteRate(BigDecimal.valueOf(item.getRealityGeneration() / item.getPlanGeneration() * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); + } }else{ - item.setPlanGeneration(BigDecimal.valueOf(planGenerations.get(0)).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - // 完成率 - if(Math.abs(item.getPlanGeneration()) <= 0){ + item.setPlanGeneration(0.0); item.setCompleteRate(0.0); + } + return item; + }).filter(complete->Math.abs(complete.getPlanGeneration()) > 0 || Math.abs(complete.getRealityGeneration()) > 0).collect(Collectors.toList()); + }else if(HomePageConstant.PHOTOVOLTAIC.equals(type)){ + // 计划发电量 + String mon = DateUtil.format(new Date(),"yyyy"); + List plans = powerService.list(Wrappers.lambdaQuery() + .in(PowerEntity::getCreateDept,stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())) + .ge(PowerEntity::getMon, mon + "-01") + ); + // 设备指标数据 + List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + if(CollectionUtils.isEmpty(targets)){ + return new ArrayList<>(); + } + return stations.stream().map(station->{ + CompleteGenerationVo item = new CompleteGenerationVo(); + item.setStationName(station.getName()); + List stationTargets = targets.stream().filter(target->target.getDeptId().equals(station.getRefDept())).collect(Collectors.toList()); + // 实际发电量 + if(CollectionUtils.isEmpty(stationTargets)){ + item.setRealityGeneration(0.0); + }else { + double sum = stationTargets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum(); + item.setRealityGeneration(sum); + } + if(CollectionUtil.isNotEmpty(plans)){ + // 计划发电量 + double planGenerate = plans.stream().filter(plan -> plan.getCreateDept().equals(station.getRefDept())).mapToDouble(PowerEntity::getPlannedPowerMon).sum(); + if(Math.abs(planGenerate) <= 0){ + item.setPlanGeneration(0.0); + }else{ + item.setPlanGeneration(planGenerate); + } + // 完成率 + if(Math.abs(item.getPlanGeneration()) <= 0){ + item.setCompleteRate(0.0); + }else{ + item.setCompleteRate(BigDecimal.valueOf(item.getRealityGeneration() / item.getPlanGeneration() * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); + } }else{ - item.setCompleteRate(BigDecimal.valueOf(item.getRealityGeneration() / item.getPlanGeneration() * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); + item.setPlanGeneration(0.0); + item.setCompleteRate(0.0); } return item; - }).collect(Collectors.toList()); + }).filter(complete->Math.abs(complete.getPlanGeneration()) > 0 || Math.abs(complete.getRealityGeneration()) > 0).collect(Collectors.toList()); } String mon = DateUtil.format(new Date(),"yyyy"); List powers = powerService.list(Wrappers.lambdaQuery() @@ -327,24 +377,20 @@ public class TargetServiceImpl implements TargetService { }else{ types = Collections.singletonList(type); } - // 获取水电站区域机构 - Map> areas = areaService.getAuthArea(null,null,types,HomePageConstant.HYDROPOWER_SERVETYPE); - if(MapUtils.isEmpty(areas)){ - return new ArrayList<>(); - } - List depts = areas.keySet().stream().filter(dept -> StringUtils.isEmpty(areaName) || dept.getDeptName().contains(areaName)).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(depts)){ + List areas = this.areas(types); + if(CollectionUtils.isEmpty(areas)){ return new ArrayList<>(); } // 开始时间 LocalDate firstDay = LocalDate.now().withDayOfYear(1); LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - ExecutorService pool = Executors.newFixedThreadPool(depts.size()); + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(areas.size(), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); //监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(depts.size()); + CountDownLatch countDownLatch = new CountDownLatch(areas.size()); List completeTickets = new ArrayList<>(); - pool.execute(()-> { - for (Dept dept: depts) { + exe.execute(()-> { + for (Dept dept: areas) { // 双票 DoublePassRateVO doublePass = ticketInfoAllClient.getDoublePassRate(Collections.singletonList(dept.getId()), firstDateTime, LocalDateTime.now()); CompleteTicketVo completeTicketVo = new CompleteTicketVo(); @@ -370,8 +416,33 @@ public class TargetServiceImpl implements TargetService { e.printStackTrace(); Thread.currentThread().interrupt(); } - pool.shutdown(); - return completeTickets; + exe.shutdown(); + return completeTickets.stream().filter(complete->Math.abs(Integer.parseInt(complete.getTicketCount())) > 0 || Math.abs(Integer.parseInt(complete.getCompleteCount())) > 0).collect(Collectors.toList()); + } + + /** + * 获取区域机构 + * @param types + * @return + */ + private List areas(List types) { + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,types) + ); + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); + } + R> result = sysClient.getDeptByCurrentUser(); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + // 站点父级区域 + List parents = result.getData().stream().filter(dept->stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).distinct().collect(Collectors.toList()); + if(CollectionUtil.isEmpty(parents)){ + return new ArrayList<>(); + } + return result.getData().stream().filter(dept->parents.contains(dept.getId()) && HomePageConstant.AREA.equals(dept.getDeptCategory())).collect(Collectors.toList()); } /** @@ -399,7 +470,13 @@ public class TargetServiceImpl implements TargetService { // 双票合格率 item.setTicketCount("*"); item.setCompleteCount("*"); - item.setCompleteRate(powers.stream().mapToDouble(o->Double.valueOf(o.getDoubleQualifyRate())).average().toString()); + List stationPower = powers.stream().filter(power->power.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(stationPower)){ + item.setCompleteRate("0.0"); + }else{ + double rate = stationPower.stream().mapToDouble(o->Double.parseDouble(o.getDoubleQualifyRate())).sum(); + item.setCompleteRate(String.valueOf(BigDecimal.valueOf(rate/ stationPower.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())); + } return item; }).collect(Collectors.toList()); } @@ -427,11 +504,13 @@ public class TargetServiceImpl implements TargetService { } String startTime = this.getFristDayByYear(); String endTime = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); - ExecutorService pool = Executors.newFixedThreadPool(depts.size()); + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(depts.size(), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + //监控线程执行完后返回结果 CountDownLatch countDownLatch = new CountDownLatch(depts.size()); List completeDefects = new ArrayList<>(); - pool.execute(()-> { + exe.execute(()-> { for (Dept dept: depts) { // 缺陷 DutyDefectVO defectVO = phenomenonService.getDutyDefect(startTime, endTime, Collections.singletonList(dept.getId())); @@ -454,7 +533,7 @@ public class TargetServiceImpl implements TargetService { e.printStackTrace(); Thread.currentThread().interrupt(); } - pool.shutdown(); + exe.shutdown(); return completeDefects; } @@ -660,9 +739,9 @@ public class TargetServiceImpl implements TargetService { return new ArrayList<>(); } // 获取设备集合 - List deviceClassifys = devices.stream().sorted(Comparator.comparing(EminfoAndEmParamVo::getCreateDept)).map(device -> { + List deviceClassifys = devices.stream().filter(device->detpIds.contains(device.getCreateDept())).sorted(Comparator.comparing(EminfoAndEmParamVo::getCreateDept)).map(device -> { DeviceClassifyVo deviceClassify = new DeviceClassifyVo(); - deviceClassify.setStationName(stations.stream().filter(o-> o.getRefDept().equals(o.getCreateDept())).collect(Collectors.toList()).get(0).getName()); + deviceClassify.setStationName(stations.stream().filter(o-> o.getRefDept().equals(device.getCreateDept())).collect(Collectors.toList()).get(0).getName()); deviceClassify.setDeviceName(device.getName()); if(faultList.contains(device.getEmCode())){ deviceClassify.setDeviceStatus(4); @@ -693,13 +772,12 @@ public class TargetServiceImpl implements TargetService { // 站点 LambdaQueryWrapper wappers = Wrappers.lambdaQuery(); wappers.eq(StationEntity::getType, HomePageConstant.HYDROPOWER); - wappers.eq(StationEntity::getServeType,2); - if(!StringUtils.isEmpty(stationName)){ + wappers.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); + if(!StringUtil.isEmpty(stationName)){ wappers.like(StationEntity::getName,stationName); } - if(!ObjectUtil.isEmpty(deptId)){ - List deptIds = sysClient.getDeptByCurrentUser().getData().stream().filter(dept -> dept.getParentId().equals(deptId)).map(Dept::getId).collect(Collectors.toList()); - wappers.in(StationEntity::getRefDept,deptIds); + if(ObjectUtil.isNotEmpty(deptId)){ + wappers.in(StationEntity::getRefDept,sysClient.getDeptByCurrentUser().getData().stream().filter(dept -> dept.getParentId().equals(deptId)).map(Dept::getId).collect(Collectors.toList())); } List stations = stationService.list(wappers); if(CollectionUtils.isEmpty(stations)){ @@ -707,48 +785,44 @@ public class TargetServiceImpl implements TargetService { } // 功率 if(HomePageConstant.POWER.equals(target)){ - Map activePowerMap = (Map) redisTemplate.opsForValue().get(activePowerKey); + // 实时数据 + List reals = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); return stations.stream().map(station->{ - HydropowerTargetVo hydropowerTarget = new HydropowerTargetVo(); - hydropowerTarget.setStationName(station.getName()); - if(MapUtils.isEmpty(activePowerMap)){ - hydropowerTarget.setPower(0.0); - return hydropowerTarget; + HydropowerTargetVo hydropower = new HydropowerTargetVo(); + hydropower.setStationName(station.getName()); + if(CollectionUtil.isEmpty(reals)){ + hydropower.setPower(0.0); + }else{ + hydropower.setPower(reals.stream().filter(real->real.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitRealVo::getActivePower).sum()); } - Double power = activePowerMap.get(station.getCode()); - hydropowerTarget.setPower(Optional.ofNullable(power).orElse(0.0)); - return hydropowerTarget; - }).sorted(Comparator.comparing(HydropowerTargetVo::getPower)).collect(Collectors.toList()); + return hydropower; + })/*.filter(hydropower -> Math.abs(hydropower.getPower()) > 0)*/.sorted(Comparator.comparing(HydropowerTargetVo::getPower)).collect(Collectors.toList()); } + // 指标数据 + List targets = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); // 发电量 - KeyIndicatorsVo keyIndicatorsVo = (KeyIndicatorsVo) redisTemplate.opsForValue().get(KEY_INDICATORS_INFO); - // 水电站 - List powers = keyIndicatorsVo.getPowerStationTotalVoList(); return stations.stream().map(station->{ HydropowerTargetVo hydropowerTarget = new HydropowerTargetVo(); hydropowerTarget.setStationName(station.getName()); - if(CollectionUtils.isEmpty(powers)){ - hydropowerTarget.setElectric(0.0); - return hydropowerTarget; - } - List stationTargets = powers.stream().filter(o-> o.getStationId().equals(station.getId())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(stationTargets)){ + if(CollectionUtils.isEmpty(targets)){ hydropowerTarget.setElectric(0.0); - return hydropowerTarget; - } - switch (target){ - case 3: - hydropowerTarget.setElectric(new BigDecimal(stationTargets.get(0).getCurrentYearPowerGeneration()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - break; - case 2: - hydropowerTarget.setElectric(stationTargets.get(0).getPowerGeneration()); - break; - case 1: - hydropowerTarget.setElectric(new BigDecimal(stationTargets.get(0).getCurrentDayPowerGeneration()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - break; + }else{ + switch (target){ + case 3: + hydropowerTarget.setElectric(targets.stream().filter(t -> t.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum()); + break; + case 2: + hydropowerTarget.setElectric(targets.stream().filter(t -> t.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum()); + break; + case 1: + hydropowerTarget.setElectric(targets.stream().filter(t -> t.getDeptId().equals(station.getRefDept())).mapToDouble(HydropowerUnitTargetVo::getPowerDay).sum()); + break; + default: + hydropowerTarget.setElectric(0.0); + } } return hydropowerTarget; - }).sorted(Comparator.comparing(HydropowerTargetVo::getElectric)).collect(Collectors.toList()); + })/*.filter(hydropower -> Math.abs(hydropower.getElectric()) > 0)*/.sorted(Comparator.comparing(HydropowerTargetVo::getElectric)).collect(Collectors.toList()); } /** @@ -776,7 +850,7 @@ public class TargetServiceImpl implements TargetService { } // 负荷 if(HomePageConstant.LOADING.equals(target)){ - List pumps = (List) redisTemplate.opsForValue().get(loadwaterpump_real_key); + List pumps = (List) redisTemplate.opsForValue().get(load_waterpump_real_key); return stations.stream().map(station->{ WaterTargetVo water = new WaterTargetVo(); water.setStationName(station.getName()); @@ -787,10 +861,10 @@ public class TargetServiceImpl implements TargetService { Double use = pumps.stream().filter(o->o.getDeptId().equals(station.getRefDept())).mapToDouble(WaterPumpRealVo::getActivePower).sum(); water.setLoad(Optional.ofNullable(use).orElse(0.0)); return water; - }).sorted(Comparator.comparing(WaterTargetVo::getLoad)).collect(Collectors.toList()); + })/*.filter(water -> Math.abs(water.getLoad()) > 0)*/.sorted(Comparator.comparing(WaterTargetVo::getLoad)).collect(Collectors.toList()); } // 用电量 - List targets = (List) redisTemplate.opsForValue().get(loadwaterpump_target_key); + List targets = (List) redisTemplate.opsForValue().get(load_waterpump_target_key); return stations.stream().map(station->{ WaterTargetVo water = new WaterTargetVo(); water.setStationName(station.getName()); @@ -808,9 +882,69 @@ public class TargetServiceImpl implements TargetService { case 1: water.setUse(targets.stream().filter(o->o.getDeptId().equals(station.getRefDept())).mapToDouble(WaterPumpTargetVo::getUsrPowerDay).sum()); break; + default: + water.setUse(0.0); } return water; - }).sorted(Comparator.comparing(WaterTargetVo::getUse)).collect(Collectors.toList()); + })/*.filter(water -> Math.abs(water.getUse()) > 0)*/.sorted(Comparator.comparing(WaterTargetVo::getUse)).collect(Collectors.toList()); + } + + @Override + public List photovoltaicTarget(String stationName, Long deptId, Integer target) { + // 站点 + LambdaQueryWrapper wappers = Wrappers.lambdaQuery(); + wappers.in(StationEntity::getType, HomePageConstant.waterList); + wappers.eq(StationEntity::getServeType,2); + if(!StringUtils.isEmpty(stationName)){ + wappers.like(StationEntity::getName,stationName); + } + if(!ObjectUtil.isEmpty(deptId)){ + List deptIds = sysClient.getDeptByCurrentUser().getData().stream().filter(dept -> dept.getParentId().equals(deptId)).map(Dept::getId).collect(Collectors.toList()); + wappers.in(StationEntity::getRefDept,deptIds); + } + List stations = stationService.list(wappers); + if(CollectionUtils.isEmpty(stations)){ + return new ArrayList<>(); + } + // 负荷 + if(HomePageConstant.LOADING.equals(target)){ + // 实时数据 + List reals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + return stations.stream().map(station->{ + PhotovoTargetVo photovo = new PhotovoTargetVo(); + photovo.setStationName(station.getName()); + if(CollectionUtil.isEmpty(reals)){ + photovo.setLoad(0.0); + }else{ + photovo.setLoad(reals.stream().filter(o->o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicRealVo::getLoad).sum()); + } + return photovo; + })/*.filter(photovoltaic -> Math.abs(photovoltaic.getLoad()) > 0)*/.sorted(Comparator.comparing(PhotovoTargetVo::getLoad)).collect(Collectors.toList()); + } + // 发电量 + List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + return stations.stream().map(station->{ + PhotovoTargetVo photovo = new PhotovoTargetVo(); + photovo.setStationName(station.getName()); + if(CollectionUtil.isEmpty(targets)){ + photovo.setGenerate(0.0); + }else{ + switch (target){ + case 3: + photovo.setGenerate(targets.stream().filter(o->o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); + break; + case 2: + photovo.setGenerate(targets.stream().filter(o->o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicTargetVo::getGenerationMon).sum()); + break; + case 1: + photovo.setGenerate(targets.stream().filter(o->o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); + break; + default: + photovo.setGenerate(0.0); + } + } + return photovo; + })/*.filter(photovo -> Math.abs(photovo.getGenerate()) > 0)*/.sorted(Comparator.comparing(PhotovoTargetVo::getGenerate)).collect(Collectors.toList()); } /** @@ -912,6 +1046,6 @@ public class TargetServiceImpl implements TargetService { calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - return sdf.format(calendar.getTime()); + return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/SideHustleController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/SideHustleController.java index 45bc420..4a31ce5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/SideHustleController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/SideHustleController.java @@ -72,6 +72,7 @@ public class SideHustleController extends BladeController { List powerFinishVoList = regionService.areaPowerMonth(deptId); return R.data(powerFinishVoList); } + @ApiLog @ApiOperation("获取地图标记") @GetMapping("/getMapMarker") @@ -81,9 +82,10 @@ public class SideHustleController extends BladeController { public R> getMapMarker(@ApiParam(value = "区域机构ID") Long deptId,@RequestParam(value ="types") List types) { return R.data(regionService.getMapMarker(deptId,types)); } + @ApiLog @ApiOperation("区域当月发电量完成情况") - // @GetMapping("/powerFinishMonth") + @GetMapping("/powerFinishMonth") @ApiOperationSupport(order = 7) public R powerFinishMonth(@ApiParam(value = "区域id",required = true) @RequestParam("deptId") Long deptId) { PowerFinishVo response = regionService.powerFinishMonth(deptId); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java index 0aca6ba..3daa316 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java @@ -297,7 +297,7 @@ public class HomeServiceImpl implements HomeService { target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); } // 双票合格率 - target.setTaget_four(BigDecimal.valueOf(pass / list.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + target.setTaget_four(BigDecimal.valueOf(pass / list.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); } return target; } @@ -335,7 +335,7 @@ public class HomeServiceImpl implements HomeService { List areas = result.getData().stream().filter(dept -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).collect(Collectors.toList()); if(CollectionUtil.isNotEmpty(areas)){ ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); - ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(4, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(STORAGE_POOL_QUANTITY, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); // 监控线程执行完后返回结果 CountDownLatch countDownLatch = new CountDownLatch(STORAGE_POOL_QUANTITY); // 日常维护 @@ -385,7 +385,7 @@ public class HomeServiceImpl implements HomeService { target.setTypeName(DictCache.getValue("stationType", HomePageConstant.DISTRIBUTION_NETWORK)); // 线程池 ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("network-taget-pool-%d").build(); - ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(3, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(NETWORK_POOL_QUANTITY, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); // 监控线程执行完后返回结果 CountDownLatch countDownLatch = new CountDownLatch(NETWORK_POOL_QUANTITY); // 当月 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java index d6dffbf..0b96f20 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java @@ -3,6 +3,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.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; @@ -44,9 +45,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; import java.util.stream.Collectors; @@ -1107,8 +1106,8 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { LocalDate firstDay = LocalDate.now().withDayOfMonth(1); LocalDateTime startTime = LocalDateTime.of(firstDay, LocalTime.MIN); LocalDateTime endTime = LocalDateTime.now(); - //通过线程池异步获取月报各模块内容 主要分为五块内容 - ExecutorService exe = Executors.newFixedThreadPool(POOL_QUANTITY); + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(POOL_QUANTITY, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); //监控线程执行完后返回结果 CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); // 日常维护 @@ -1302,7 +1301,21 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { * @return */ private List periodLoadDay(List stations) { - // redis实时数据 + // FIXME 当天功率测试数据 + Calendar start = Calendar.getInstance(); + start.add(Calendar.HOUR_OF_DAY,-start.get(Calendar.HOUR_OF_DAY)); + List list = new ArrayList<>(); + Random random = new Random(); + while (start.getTime().compareTo(new Date()) <= 0){ + PhotovoltaicLoadGenerateVo load = new PhotovoltaicLoadGenerateVo(); + load.setPeriod(DateUtil.format(start.getTime(),"yyyy-mm-dd HH")); + load.setValue(random.nextFloat() * 500); + list.add(load); + start.add(Calendar.HOUR_OF_DAY,1); + } + return list; + /* + // redis实时数据 List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); if(CollectionUtil.isEmpty(photovoltaics)){ return new ArrayList<>(); @@ -1312,14 +1325,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { if(CollectionUtil.isEmpty(devices)){ return new ArrayList<>(); } - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); - // 开始日期 - Calendar calendar = Calendar.getInstance(); - String end = sdf.format(calendar.getTime()); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - String start = sdf.format(calendar.getTime()); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); List list = new ArrayList<>(); for(PhotovoltaicTargetVo device : devices){ list.addAll(analyseDataService.periodTargetData(start,end,1,2,device.getDeviceCode(),HomePageConstant.PV_LOAD)); @@ -1333,7 +1339,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { target.setPeriod(String.valueOf(time.getHour())); target.setValue((float) entry.getValue().stream().mapToDouble(o-> Double.parseDouble(String.valueOf(o.getVal()))).sum()); return target; - }).collect(Collectors.toList()); + }).collect(Collectors.toList());*/ } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/DeptController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/DeptController.java index 4b0b279..c595de2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/DeptController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/DeptController.java @@ -3,8 +3,10 @@ package com.hnac.hzims.operational.report.controller; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.OperatorType; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.report.service.IDeptService; import io.swagger.annotations.ApiOperation; +import io.swagger.models.auth.In; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.boot.ctrl.BladeController; @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.Collections; import java.util.List; @Slf4j @@ -45,4 +48,14 @@ public class DeptController extends BladeController { public R> alarmDeptByCurrentUser(){ return R.data(deptService.alarmDeptByCurrentUser()); } + + @ApiLog + @ApiOperation(value = "区域机构",notes = "下拉框区域") + @GetMapping("/select_area") + public R> selectArea(@RequestParam(value = "serveType") Integer serveType, @RequestParam(value = "type") Integer type){ + if(HomePageConstant.WATER_CONSERVANCY.equals(type)){ + return R.data(deptService.selectArea(serveType,HomePageConstant.waterList)); + } + return R.data(deptService.selectArea(serveType,Collections.singletonList(type))); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IDeptService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IDeptService.java index 52c51d7..afcaedc 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IDeptService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IDeptService.java @@ -1,5 +1,6 @@ package com.hnac.hzims.operational.report.service; +import io.swagger.models.auth.In; import org.springblade.system.entity.Dept; import org.springblade.system.vo.DeptVO; @@ -29,4 +30,6 @@ public interface IDeptService { List getCurrentUserDept(String name,String type); List alarmDeptByCurrentUser(); + + List selectArea(Integer servrType,List types); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/DeptServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/DeptServiceImpl.java index d71b0bf..e08e9e6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/DeptServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/DeptServiceImpl.java @@ -147,4 +147,31 @@ public class DeptServiceImpl implements IDeptService { } return stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); } + + /** + * + * 获取区域机构 + * @param types + * @return + */ + @Override + public List selectArea(Integer servrType,List types) { + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,servrType) + .in(StationEntity::getType,types) + ); + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); + } + R> result = sysClient.getDeptByCurrentUser(); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + // 站点父级区域 + List parents = result.getData().stream().filter(dept->stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).distinct().collect(Collectors.toList()); + if(CollectionUtil.isEmpty(parents)){ + return new ArrayList<>(); + } + return result.getData().stream().filter(dept->parents.contains(dept.getId()) && HomePageConstant.AREA.equals(dept.getDeptCategory())).collect(Collectors.toList()); + } } 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 b6d843a..8986d08 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 @@ -486,7 +486,7 @@ public class StationServiceImpl extends BaseServiceImpl min = authList.stream().min(Comparator.comparing(Dept::getDeptCategory)); - dept = min.isPresent() ? min.get() : null; + dept = min.orElse(null); if (ObjectUtil.isEmpty(dept)) { return null; }