diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java index eab3ee0..9ece78b 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java @@ -8,11 +8,13 @@ import java.util.List; */ public interface AbnormalAlarmConstant { + List INTERRUPT_LIST = Arrays.asList("13","14"); + List TYPE_LIST = Arrays.asList("3","2","5","10","13","14"); List LONG_TYPE_LIST = Arrays.asList(3L,2L,5L,10L,13L,14L); - List SEND_MESSSAGE_TYPE_LIST = Arrays.asList("2","13","14"); + List SEND_MESSSAGE_TYPE_LIST = Arrays.asList("3","13","14"); String LEVEL_TYPE_LIST = "3,2,5,10,13,14"; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/DeviceVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/DeviceVo.java index 929fa20..24834f6 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/DeviceVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/DeviceVo.java @@ -19,6 +19,9 @@ public class DeviceVo { @ApiModelProperty(value = "设备状态") private Boolean state; + @ApiModelProperty(value = "容量") + private Double capacity; + @ApiModelProperty(value = "有功功率") private Double active; @@ -31,8 +34,8 @@ public class DeviceVo { @ApiModelProperty(value = "下泄流量") private Double discharge; - @ApiModelProperty(value = "发电流量") - private Double generate; + @ApiModelProperty(value = "发电效率") + private Double generateRate; @ApiModelProperty(value = "建议有功调整") private Double adjust; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/StationVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/StationVo.java index da88113..0fd6dfd 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/StationVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/StationVo.java @@ -27,9 +27,15 @@ public class StationVo { @ApiModelProperty(value = "下泄流量") private Double dischargeFlow; + @ApiModelProperty(value = "平均效率") + private Double generateRate; + @ApiModelProperty(value = "设备集合") private List devices; - @ApiModelProperty(value = "设备集合") + @ApiModelProperty(value = "水位曲线集合") private List waters; + + @ApiModelProperty(value = "下泄流量集合") + List discharges; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/WaterVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/WaterVo.java index f112b59..5e348a4 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/WaterVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/WaterVo.java @@ -15,4 +15,7 @@ public class WaterVo { @ApiModelProperty(value = "水位") private Double water; + + @ApiModelProperty(value = "下泄流量") + private Double discharge; } \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/entity/UserDeptEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/entity/UserDeptEntity.java new file mode 100644 index 0000000..ba35e1f --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/entity/UserDeptEntity.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.operational.main.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springblade.core.tenant.mp.TenantEntity; + +import java.io.Serializable; + +/** + * @author ysj + */ +@EqualsAndHashCode(callSuper = true) +@Data +@TableName("hzims_user_dept") +public class UserDeptEntity extends TenantEntity implements Serializable { + + @ApiModelProperty("主键ID") + private Long id; + + @ApiModelProperty("用户ID") + private Long userId; + + @ApiModelProperty("机构Id") + private Long deptId; + + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerUnitVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerUnitVo.java index d3cd159..d02f355 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerUnitVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerUnitVo.java @@ -17,7 +17,7 @@ public class HydropowerUnitVo { @ApiModelProperty(value = "水电站机组名称") private String deivceName; - @ApiModelProperty(value = "排序") + @ApiModelProperty(value = "水电站机组名称") private Integer ord; @ApiModelProperty(value = "水电站机组实时数据") diff --git a/hzims-service/operational/pom.xml b/hzims-service/operational/pom.xml index 3000a95..a2e3f33 100644 --- a/hzims-service/operational/pom.xml +++ b/hzims-service/operational/pom.xml @@ -139,6 +139,7 @@ org.springblade blade-user-api + 5.0.1.RELEASE diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java index 9e80292..da37623 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java @@ -1,7 +1,8 @@ package com.hnac.hzims.operational.alert.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.message.MessageConstants; -import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.dto.BusinessMessageDTO; import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; @@ -24,6 +25,7 @@ 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.entity.User; import org.springblade.system.user.feign.IUserClient; @@ -31,8 +33,6 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; import java.util.stream.Collectors; /** @@ -57,61 +57,77 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl stations = stationService.list(); if(CollectionUtil.isEmpty(stations)){ return; } + // 查询告警数据: 间隔3分钟 SoeQueryConditionByStation query = new SoeQueryConditionByStation(); query.setTypes(AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST); query.setStationIds(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); Calendar calendar = Calendar.getInstance(); query.setEndTime(LocalDateTime.parse(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); - calendar.add(Calendar.MINUTE,-2); + calendar.add(Calendar.MINUTE,-3); query.setBeginTime(LocalDateTime.parse(DateUtil.format(calendar.getTime() , DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); query.setNeedPage(false); - log.error("alarm_data_handle_param : {}",query); + query.setPage(1); + query.setLimit(100000); Result> result = soeClient.getByStationsAndTime(query); // 未查询到告警信息 - if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData().getRecords())){ + if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())) { return; } - log.error("alarm_data_handle_begin_result : {}",result.getData().getRecords()); // 遍历告警信息 - List list = new ArrayList<>(result.getData().getRecords().stream().sorted(Comparator.comparing(SoeData::getTs).reversed()) - .collect(Collectors.toMap(o -> o.getStation() + o.getSoeType(), Function.identity(), (o1, o2) -> o1)).values()); - log.error("alarm_data_handle_end_result : {}",list); - list.forEach(item -> { - AbnormalAlarmEntity queryEntity = this.baseMapper.getAbnormalAlarm(item.getStation(),item.getSoeType()); - boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); - String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); - if(ObjectUtil.isEmpty(queryEntity)){ - AbnormalAlarmEntity entity = new AbnormalAlarmEntity(); - entity.setStationId(item.getStation()); - entity.setStationName(stationName); - entity.setRealId(item.getRealId()); - entity.setSoeExplain(item.getSoeExplain()); - entity.setType(item.getSoeType()); - entity.setStartTime(item.getTs()); - entity.setEndTime(null); - entity.setStatus(0); - if(flag){ - entity.setStartTime(null); - entity.setEndTime(item.getTs()); - entity.setStatus(1); - } - // 保存告警信息 - this.save(entity); + result.getData().getRecords().forEach(item -> { + if(!AbnormalAlarmConstant.INTERRUPT_LIST.contains(item.getSoeType())){ return; } + this.interrupt(stations,item); + }); + + // 历史数据处理 + this.saveHistoryAlarm(stations,result.getData().getRecords()); + } + + /** + * 中断、异常数据处理 + * @param stations + * @param item + */ + private void interrupt(List stations,SoeData item) { + // 查询中断数据 + AbnormalAlarmEntity queryEntity = this.baseMapper.getAbnormalAlarm(item.getStation(),item.getSoeType()); + // 是否为中断恢复 + boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); + // 站点名称 + String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); + // 不存在记录进行保存 + if(ObjectUtil.isEmpty(queryEntity)){ + AbnormalAlarmEntity entity = new AbnormalAlarmEntity(); + entity.setStationId(item.getStation()); + entity.setStationName(stationName); + entity.setRealId(item.getRealId()); + entity.setSoeExplain(item.getSoeExplain()); + entity.setType(item.getSoeType()); + entity.setStartTime(item.getTs()); + entity.setEndTime(null); + entity.setStatus(0); + if(flag){ + entity.setStartTime(null); + entity.setEndTime(item.getTs()); + entity.setStatus(1); + } + // 保存告警信息 + this.save(entity); + // 存在记录进行修改 + }else{ queryEntity.setSoeExplain(item.getSoeExplain()); - queryEntity.setStationName(stationName); - queryEntity.setType(item.getSoeType()); queryEntity.setStartTime(queryEntity.getStartTime()); queryEntity.setUpdateTime(new Date()); queryEntity.setEndTime(null); @@ -121,60 +137,46 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl this.saveHistoryAlarm(result.getData().getRecords(),stations)); - } - - /** - * 查询实时告警数据 - * @return - */ - @Override - public List getAbnormalAlarmList() { - List alarmList = this.baseMapper.getAbnormalAlarmList(); - if(CollectionUtil.isEmpty(alarmList)){ - return new ArrayList<>(); } - return alarmList; } /** - * 保存告警历史信息 + * 历史数据处理 + * + * @param stations * @param list - * @return */ - private String saveHistoryAlarm(List list,List stations) { - list.forEach(item -> { - Date ts = DateUtil.parse(DateUtil.format(item.getTs(),DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMAT); - // 历史数据异常查询 - HistoryAbnormalAlarmEntity queryEntity = this.historyAbnormalAlarmService.getAbnormalAlarm(item.getStation(),item.getSoeType()); - // 数据中断恢复 - boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); - String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); - if(ObjectUtil.isEmpty(queryEntity) || !flag){ - HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); - entity.setAlarmId(item.getId()); - entity.setStationId(item.getStation()); - entity.setStationName(stationName); - entity.setRealId(item.getRealId()); - entity.setSoeExplain(item.getSoeExplain()); - entity.setType(item.getSoeType()); - entity.setStartTime(ts); - entity.setStatus(0); - this.historyAbnormalAlarmService.save(entity); - // 消息推送 - this.sendAlarmMessage(Collections.singletonList(entity),stations); + private void saveHistoryAlarm(List stations, List list) { + List historys = historyAbnormalAlarmService.list(Wrappers.lambdaQuery() + .in(HistoryAbnormalAlarmEntity::getAlarmId,list.stream().map(SoeData::getId).collect(Collectors.toList())) + ); + Set explainSet = new HashSet<>(); + list.forEach(item->{ + if(CollectionUtil.isNotEmpty(historys) && historys.stream().map(HistoryAbnormalAlarmEntity::getAlarmId).collect(Collectors.toList()).contains(item.getId())){ return; } - queryEntity.setSoeExplain(item.getSoeExplain()); - queryEntity.setUpdateTime(new Date()); - queryEntity.setEndTime(ts); - queryEntity.setStatus(1); - this.historyAbnormalAlarmService.updateById(queryEntity); + if(explainSet.contains(item.getSoeExplain())){ + return; + } + HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); + String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); + entity.setAlarmId(item.getId()); + entity.setStationId(item.getStation()); + entity.setStationName(stationName); + entity.setRealId(item.getRealId()); + entity.setSoeExplain(item.getSoeExplain()); + entity.setType(item.getSoeType()); + entity.setStartTime(item.getTs()); + if(AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType())){ + entity.setStatus(1); + }else{ + entity.setStatus(1); + } + this.historyAbnormalAlarmService.save(entity); + // 相同告警只允许添加一次,发送一次消息 + explainSet.add(item.getSoeExplain()); + this.sendAlarmMessage(Collections.singletonList(entity),stations); }); - return "success"; } /** @@ -199,34 +201,62 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl> result = userClient.userListByDeptId(depts.get(0)); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + List users = this.parentAuthUser(depts.get(0)); + if(CollectionUtil.isEmpty(users)){ + log.error("alarmmessagestation {} user is null",entity.getStationId()); return; } - MessagePushRecordDto message = new MessagePushRecordDto(); + BusinessMessageDTO message = new BusinessMessageDTO(); + message.setDeptId(depts.get(0)); message.setBusinessClassify("warning"); + message.setUserIds(users.stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); message.setTaskId(entity.getId()); message.setTenantId("200000"); message.setContent(entity.getSoeExplain()); - message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); - message.setPushType(MessageConstants.IMMEDIATELY); - message.setDeptId(depts.get(0)); - message.setCreateDept(depts.get(0)); R deptName = sysClient.getDeptName(depts.get(0)); if (deptName.isSuccess()) { message.setDeptName(deptName.getData()); } User admin = userClient.userByAccount("200000", "admin").getData(); message.setCreateUser(admin.getId()); - result.getData().forEach(user->{ - message.setPusher(String.valueOf(user.getId())); - message.setPusherName(user.getName()); - message.setAccount(String.valueOf(user.getId())); - messageClient.sendMessage(message); - }); + messageClient.sendAppAndWsMsgByUsers(message); }); } + + /** + * 获取本级机构或者上级机构用户 + * @param deptId + * @return + */ + private List parentAuthUser(Long deptId) { + List users = new ArrayList<>(); + R> selfs = userClient.userListByDeptId(deptId); + if(selfs.isSuccess() && CollectionUtil.isNotEmpty(selfs.getData())){ + users.addAll(selfs.getData()); + } + R dept = sysClient.getDept(deptId); + if(dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())){ + R> parents = userClient.userByDeptId("200000",deptId); + if(parents.isSuccess() && CollectionUtil.isNotEmpty(parents.getData())){ + users.addAll(parents.getData()); + } + } + return users; + } + + /** + * 查询实时告警数据 + * @return + */ + @Override + public List getAbnormalAlarmList() { + List alarmList = this.baseMapper.getAbnormalAlarmList(); + if(CollectionUtil.isEmpty(alarmList)){ + return new ArrayList<>(); + } + return alarmList; + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyEmergencyServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyEmergencyServiceImpl.java index 4badcdc..7e836e0 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyEmergencyServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyEmergencyServiceImpl.java @@ -80,12 +80,13 @@ public class ImsDutyEmergencyServiceImpl extends BaseServiceImpl { R user = userClient.userInfoById(sig.getRegistrant()); - if (!user.isSuccess()&&ObjectUtils.isNotEmpty(user)){ - + if (user.isSuccess()&&ObjectUtils.isNotEmpty(user.getData())){ + sig.setRegistrantName(user.getData().getName()); } - sig.setRegistrantName(user.getData().getName()); R userR = userClient.userInfoById(sig.getChargePerson()); - sig.setChargePersonName(userR.getData().getName()); + if (userR.isSuccess()&&ObjectUtils.isNotEmpty(userR.getData())){ + sig.setChargePersonName(userR.getData().getName()); + } ImsDutyClassEntity classEntity = imsDutyClassService.getById(sig.getDutyClass()); sig.setDutyClassName(classEntity.getClassName()); return sig; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/impl/EcologyFlowStationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/impl/EcologyFlowStationServiceImpl.java index 8f03b4e..c5d6ccb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/impl/EcologyFlowStationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/impl/EcologyFlowStationServiceImpl.java @@ -204,19 +204,43 @@ public class EcologyFlowStationServiceImpl extends BaseServiceImpl() {{ eq(HzimsAnalyzeModelStationEntity::getStationId, item.getCode()); }}); // 水位曲线 if(ObjectUtil.isNotEmpty(model)){ - station.setWaters(this.water(model.getInstanceCode())); + List waters = this.water(model.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); + List discharges = this.water(model.getInstanceCode(),HomePageConstant.DISCHARGE_FLOW); + station.setWaters(waters.stream().peek(water->{ + water.setDischarge(0.0); + List filter = discharges.stream().filter(discharge->water.getTime().equals(discharge.getTime())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(filter)){ + water.setDischarge(filter.get(0).getWater()); + } + }).collect(Collectors.toList())); + station.setDischarges(discharges); } return station; }).collect(Collectors.toList()); } /** + * 站点平均发电效率 + */ + private void generateRate(StationVo station) { + double capacitySum = station.getDevices().stream().mapToDouble(DeviceVo::getCapacity).sum(); + double activeSum = station.getDevices().stream().mapToDouble(DeviceVo::getActive).sum(); + if(Math.abs(capacitySum) <=0 || Math.abs(activeSum) <= 0){ + station.setGenerateRate(0.0); + }else{ + station.setGenerateRate(BigDecimal.valueOf(activeSum / capacitySum * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + } + + /** * 获取站点设备信息 * @param station * @return @@ -233,6 +257,7 @@ public class EcologyFlowStationServiceImpl extends BaseServiceImpl water(String code) { + private List water(String code,String signages) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH,-7); calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); @@ -283,8 +312,7 @@ public class EcologyFlowStationServiceImpl extends BaseServiceImpl records = analyseDataService.periodTargetData(start,end,3,3,code,HomePageConstant.FRONT_WATER_LEVEL); - Random random = new Random(); + List records = analyseDataService.periodTargetData(start,end,3,3,code,signages); if(CollectionUtil.isEmpty(records)){ return new ArrayList<>(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/mapper/UserDeptMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/mapper/UserDeptMapper.java new file mode 100644 index 0000000..e662bb4 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/mapper/UserDeptMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.operational.main.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.operational.main.entity.UserDeptEntity; + +/** + * @author ysj + */ +public interface UserDeptMapper extends BaseMapper { + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/mapper/UserDeptMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/mapper/UserDeptMapper.xml new file mode 100644 index 0000000..8bfd4a9 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/mapper/UserDeptMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/ISideHustleService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/ISideHustleService.java index c729404..084660e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/ISideHustleService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/ISideHustleService.java @@ -29,6 +29,4 @@ public interface ISideHustleService { List getMapMarker(Long deptId,List types); List getStaionPlanPower(Map> map); - - Map> getAreaOrStaion(Long deptId, List types); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/UserDeptService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/UserDeptService.java new file mode 100644 index 0000000..7c28df7 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/UserDeptService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.operational.main.service; + +import com.hnac.hzims.operational.main.entity.UserDeptEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface UserDeptService extends BaseService { + +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaServiceImpl.java index 2bdc625..7f41981 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaServiceImpl.java @@ -1,10 +1,14 @@ package com.hnac.hzims.operational.main.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.main.entity.UserDeptEntity; import com.hnac.hzims.operational.main.service.AreaService; import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.service.UserDeptService; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import lombok.RequiredArgsConstructor; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -25,7 +29,10 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class AreaServiceImpl implements AreaService { + private final UserDeptService userDeptService; + private final IStationService stationService; + private final ISysClient sysClient; /** @@ -97,7 +104,19 @@ public class AreaServiceImpl implements AreaService { if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { return null; } - if(ObjectUtil.isNotEmpty(deptId)){ + List configs = userDeptService.list(new LambdaQueryWrapper(){{ + eq(UserDeptEntity::getUserId, AuthUtil.getUserId()); + }}); + if(CollectionUtil.isNotEmpty(configs)){ + List stations =stationService.list(new LambdaQueryWrapper(){{ + eq(StationEntity::getType,HomePageConstant.HYDROPOWER); + eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); + }}); + if(CollectionUtil.isEmpty(stations)){ + return new HashMap<>(); + } + return stations.stream().collect(Collectors.toMap(m->R.getData().stream().filter(dept->m.getRefDept().equals(dept.getId())).collect(Collectors.toList()).get(0), Collections::singletonList)); + }else if(ObjectUtil.isNotEmpty(deptId)){ List list = R.getData().stream().filter(o->deptId.equals(o.getId())).collect(Collectors.toList()); if(CollectionUtil.isEmpty(list)){ return null; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index 4ed2033..94c67a3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -23,6 +23,7 @@ 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.entity.UserDeptEntity; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; @@ -42,6 +43,7 @@ import com.hnac.hzinfo.sdk.core.response.Result; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; @@ -82,6 +84,8 @@ public class HydropowerServiceImpl implements HydropowerService { private final GenerateService generateService; + private final UserDeptService userDeptService; + private final PowerService photovoltaicService; private final IImsDutyMainService dutyMainService; @@ -1000,7 +1004,7 @@ public class HydropowerServiceImpl implements HydropowerService { @Override public HydropowerScoreVo KPIs(Long deptId) { // 查询水电站站点 - List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), HomePageConstant.HYDROPOWER_SERVETYPE); + List stations = this.getStations(deptId); if (CollectionUtil.isEmpty(stations)) { return new HydropowerScoreVo(); } @@ -1161,6 +1165,24 @@ public class HydropowerServiceImpl implements HydropowerService { /** + * 获取站点 + * @param deptId + * @return + */ + private List getStations(Long deptId) { + List configs = userDeptService.list(new LambdaQueryWrapper(){{ + eq(UserDeptEntity::getUserId, AuthUtil.getUserId()); + }}); + if(CollectionUtil.isNotEmpty(configs)){ + return stationService.list(new LambdaQueryWrapper(){{ + eq(StationEntity::getType,HomePageConstant.HYDROPOWER); + eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); + }}); + } + return stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), HomePageConstant.HYDROPOWER_SERVETYPE); + } + + /** * 区域天气 * @param scale * @param nowWeather @@ -1510,7 +1532,7 @@ public class HydropowerServiceImpl implements HydropowerService { @Override public List area(Long deptId) { // 查询水电站站点 - List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), HomePageConstant.HYDROPOWER_SERVETYPE); + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.HYDROPOWER), null); if (CollectionUtil.isEmpty(stations)) { return new ArrayList<>(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java index adc1d46..d4adeea 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.main.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.entity.EmInfoEntity; @@ -24,6 +25,7 @@ import com.hnac.hzims.operational.duty.vo.DutyInfoVo; import com.hnac.hzims.operational.duty.vo.DutyTaskVo; import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.entity.UserDeptEntity; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; @@ -43,6 +45,7 @@ import com.xxl.job.core.log.XxlJobLogger; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; import org.springblade.system.entity.Dept; @@ -66,6 +69,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; +import static org.springblade.system.user.UserConstants.UserDataScopeTypeEnum.dept; + /** * @author ysj */ @@ -81,6 +86,8 @@ public class SideHustleServiceImpl implements ISideHustleService { @NotNull private final IStationService stationService; @NotNull + private final UserDeptService userDeptService; + @NotNull private final IPlanGenertionClient planGenertionClient; @NotNull private final IOperPhenomenonService operPhenomenonService; @@ -838,7 +845,7 @@ public class SideHustleServiceImpl implements ISideHustleService { @Override public List areaPowerScale(Long deptId) { // 获取区域或者站点map结构 - Map> map = this.getAreaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); + Map> map = areaService.areaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); if(MapUtils.isEmpty(map)){ return null; } @@ -872,7 +879,7 @@ public class SideHustleServiceImpl implements ISideHustleService { @Override public List areaScale(Long deptId) { // 获取区域或者站点map结构 - Map> map = this.getAreaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); + Map> map = areaService.areaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); if(MapUtils.isEmpty(map)){ return null; } @@ -941,7 +948,7 @@ public class SideHustleServiceImpl implements ISideHustleService { types = Collections.singletonList(HomePageConstant.HYDROPOWER); } // 获取集团/区域map结构数据 - Map> deptMap = this.getAreaOrStaion(deptId,types); + Map> deptMap = areaService.areaOrStaion(deptId,types); if (MapUtils.isEmpty(deptMap)) { return null; } @@ -1193,7 +1200,7 @@ public class SideHustleServiceImpl implements ISideHustleService { List runtList = deviceClassifyMap.get(HomePageConstant.RUN); // 获取部门 - Map> deptMap = this.getAreaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); + Map> deptMap = areaService.areaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER)); if (MapUtils.isEmpty(deptMap)) { return null; } @@ -1282,45 +1289,6 @@ public class SideHustleServiceImpl implements ISideHustleService { } - /** - * 获取区域或者站点map结构 - * @param deptId - * @return - */ - @Override - public Map> getAreaOrStaion(Long deptId,List types) { - //根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { - return null; - } - if(ObjectUtil.isNotEmpty(deptId)){ - List list = R.getData().stream().filter(o->deptId.equals(o.getId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(list)){ - return null; - } - Dept dept = list.get(0); - // 机构为站点 key-站点机构 value-站点 - if(HomePageConstant.AREA.equals(dept.getDeptCategory())){ - List stationList = stationService.getStationList(R.getData(),dept.getId(),types,HomePageConstant.HYDROPOWER_SERVETYPE); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - Map> map = new HashMap<>(); - stationList.forEach(item->{ - List stationDeptList = R.getData().stream().filter(o->o.getId().equals(item.getRefDept())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(stationDeptList)){ - return; - } - // 站点机构 - Dept station = stationDeptList.get(0); - map.put(station,Collections.singletonList(item)); - }); - return map; - } - } - return areaService.getAuthArea(R.getData(),deptId,types,HomePageConstant.HYDROPOWER_SERVETYPE); - } /** * 设备信息设置 @@ -1544,7 +1512,6 @@ public class SideHustleServiceImpl implements ISideHustleService { */ @Override public PowerFinishVo powerFinishMonth(Long deptId) { - // 获取用户权限机构 R> R = sysClient.getDeptByCurrentUser(); if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { return null; @@ -1555,8 +1522,32 @@ public class SideHustleServiceImpl implements ISideHustleService { return null; } Dept area = list.get(0); + // 获取用户权限机构 + List stations = this.getPowerStation(R.getData(),area,deptId); + if(CollectionUtil.isEmpty(stations)){ + return null; + } + List dayList = this.getCurrentDayList(); + // 获取区域月发电数据 + return this.getPowerMonth(area,dayList,stations); + } + + /** + * 智能生产-水电站获取 + * @param deptId + */ + private List getPowerStation(List depts,Dept area,Long deptId) { + List configs = userDeptService.list(new LambdaQueryWrapper(){{ + eq(UserDeptEntity::getUserId, AuthUtil.getUserId()); + }}); + if(CollectionUtil.isNotEmpty(configs)){ + return stationService.list(new LambdaQueryWrapper(){{ + eq(StationEntity::getType,HomePageConstant.HYDROPOWER); + eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); + }}); + } // 获取区域下站点级机构集合 - List stationDeprList = homePageService.getChildDept(R.getData(), area.getId(), new ArrayList<>()); + List stationDeprList = homePageService.getChildDept(depts, area.getId(), new ArrayList<>()); if (CollectionUtil.isEmpty(stationDeprList)) { return null; } @@ -1565,9 +1556,7 @@ public class SideHustleServiceImpl implements ISideHustleService { if(CollectionUtil.isEmpty(stationList)){ return null; } - List dayList = this.getCurrentDayList(); - // 获取区域月发电数据 - return this.getPowerMonth(area,dayList,stationList); + return stationList; } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/UserDeptServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/UserDeptServiceImpl.java new file mode 100644 index 0000000..4d1b7df --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/UserDeptServiceImpl.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.operational.main.service.impl; + + +import com.hnac.hzims.operational.main.entity.UserDeptEntity; +import com.hnac.hzims.operational.main.mapper.UserDeptMapper; +import com.hnac.hzims.operational.main.service.UserDeptService; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author Lch + */ +@Service +@Slf4j +public class UserDeptServiceImpl extends BaseServiceImpl implements UserDeptService { + +}