高低电压穿越相关接口走算法模块

This commit is contained in:
guofeihu
2024-08-23 11:15:41 +08:00
parent 043b8f9a71
commit 21f4466580
29 changed files with 378 additions and 84 deletions

View File

@@ -3,8 +3,13 @@ package com.njcn.prepare.harmonic.api.event;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.prepare.harmonic.api.event.fallback.SpThroughFeignClientFallbackFactory;
import com.njcn.prepare.harmonic.pojo.param.SpThroughParam;
import com.njcn.prepare.harmonic.pojo.vo.SpThroughVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* 高低电压穿越Feign客户端
@@ -20,4 +25,10 @@ public interface SpThroughFeignClient {
@PostMapping("/record")
HttpResult<Boolean> record();
@PostMapping("/getDataByEventIds")
HttpResult<SpThroughVO> getDataByEventIds(@RequestBody @Validated SpThroughParam spThroughParam);
@PostMapping("/formatEventIds")
HttpResult<List<String>> formatEventIds(@RequestBody @Validated SpThroughParam spThroughParam);
}

View File

@@ -4,10 +4,13 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.prepare.harmonic.api.event.SpThroughFeignClient;
import com.njcn.prepare.harmonic.pojo.param.SpThroughParam;
import com.njcn.prepare.harmonic.pojo.vo.SpThroughVO;
import com.njcn.prepare.harmonic.utils.PrepareEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 高低电压穿越熔断降级
@@ -33,6 +36,18 @@ public class SpThroughFeignClientFallbackFactory implements FallbackFactory<SpTh
log.error("{}异常,降级处理,异常为:{}", "高低电压穿越记录: ", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<SpThroughVO> getDataByEventIds(SpThroughParam spThroughParam) {
log.error("{}异常,降级处理,异常为:{}", "根据事件ID集合及能源站类型获取高低电压穿越次数: ", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<String>> formatEventIds(SpThroughParam spThroughParam) {
log.error("{}异常,降级处理,异常为:{}", "根据原有的事件集合进行过滤: ", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,27 @@
package com.njcn.prepare.harmonic.pojo.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author guofeihu
* @since 2024-08-14
*/
@Data
public class SpThroughParam {
@ApiModelProperty(name = "eventIds",value = "事件ID集合")
private List<String> eventIds;
@ApiModelProperty(name = "lineType",value = "监测点类别(1:风电场、2:光伏电站)")
private String stationType;
public SpThroughParam(List<String> eventIds, String stationType) {
this.eventIds = eventIds;
this.stationType = stationType;
}
public SpThroughParam() {
}
}

View File

@@ -0,0 +1,19 @@
package com.njcn.prepare.harmonic.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author guofeihu
* @since 2024-08-14
*/
@Data
public class SpThroughVO {
@ApiModelProperty("低压次数")
private String lowPressure;
@ApiModelProperty("高压次数")
private String highPressure;
}

View File

@@ -6,7 +6,8 @@ import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.prepare.harmonic.pojo.po.SpThroughPO;
import com.njcn.prepare.harmonic.pojo.param.SpThroughParam;
import com.njcn.prepare.harmonic.pojo.vo.SpThroughVO;
import com.njcn.prepare.harmonic.service.mysql.event.SpThroughService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
@@ -45,11 +46,19 @@ public class SpThroughController extends BaseController {
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.QUERY)
@PostMapping("/getDataByLineIds")
@ApiOperation("根据监测点ID集合获取高低电压穿越信息")
public HttpResult<List<SpThroughPO>> getDataByLineIds(@RequestBody List<String> lineIds) {
String methodDescribe = getMethodDescribe("getDataByLineIds");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, spThroughService.getDataByLineIds(lineIds), methodDescribe);
@PostMapping("/getDataByEventIds")
@ApiOperation("根据事件ID集合及能源站类型获取高低电压穿越次数")
public HttpResult<SpThroughVO> getDataByEventIds(@RequestBody SpThroughParam spThroughParam) {
String methodDescribe = getMethodDescribe("getDataByEventIds");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, spThroughService.getDataByEventIds(spThroughParam), methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.QUERY)
@PostMapping("/formatEventIds")
@ApiOperation("根据原有的事件集合进行过滤")
public HttpResult<List<String>> formatEventIds(@RequestBody SpThroughParam spThroughParam) {
String methodDescribe = getMethodDescribe("formatEventIds");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, spThroughService.formatEventIds(spThroughParam), methodDescribe);
}
}

View File

@@ -1,11 +1,25 @@
package com.njcn.prepare.harmonic.service.mysql.Impl.event;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.device.biz.commApi.CommLineClient;
import com.njcn.device.biz.pojo.dto.LineDTO;
import com.njcn.device.pq.api.NewStationClient;
import com.njcn.device.pq.constant.Param;
import com.njcn.device.pq.pojo.po.NewStation;
import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.prepare.harmonic.mapper.mysql.event.SpThroughMapper;
import com.njcn.prepare.harmonic.pojo.param.SpThroughParam;
import com.njcn.prepare.harmonic.pojo.po.SpThroughPO;
import com.njcn.prepare.harmonic.pojo.vo.SpThroughVO;
import com.njcn.prepare.harmonic.service.mysql.event.SpThroughService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* 高低电压穿越 服务实现类
@@ -13,15 +27,105 @@ import java.util.List;
* @since 2024-08-22
*/
@Service
@RequiredArgsConstructor
public class SpThroughServiceImpl extends MppServiceImpl<SpThroughMapper, SpThroughPO> implements SpThroughService {
private final EventDetailFeignClient eventDetailFeignClient;
private final CommLineClient commLineClient;
private final NewStationClient newStationClient;
@Override
public void record() {
LocalDateTime currentTime = LocalDateTime.now();
//获取最新的暂态事件信息(截至目前为止)
List<RmpEventDetailPO> evenStDetailPOS = eventDetailFeignClient.getNewEventDetailByTime(getLastTime(),currentTime).getData();
for(RmpEventDetailPO rmpEventDetailPO : evenStDetailPOS){
//获取监测点
LineDTO lineDTO = commLineClient.getLineDetail(rmpEventDetailPO.getMeasurementPointId()).getData();
if(lineDTO != null && lineDTO.getNewStationId() != null){
NewStation newStation = newStationClient.selectById(lineDTO.getNewStationId()).getData();
if(newStation != null){
//暂升事件
if(Param.UPPEREVENT.equals(rmpEventDetailPO.getEventType())){
//风电场
if(Param.WINDFARM.equals(newStation.getStationType())){
}
//光伏电站
if(Param.PHOTOVOLTAICPOWER.equals(newStation.getStationType())){
}
}
//暂降事件
if(Param.LOWEREVENT.equals(rmpEventDetailPO.getEventType())){
//风电场
if(Param.WINDFARM.equals(newStation.getStationType())){
}
//光伏电站
if(Param.PHOTOVOLTAICPOWER.equals(newStation.getStationType())){
}
}
}
}
}
}
//拿到最近一次插入高低电压穿越表信息的时间
private LocalDateTime getLastTime(){
LambdaQueryWrapper<SpThroughPO> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.orderByDesc(SpThroughPO::getCreateTime);
Page<SpThroughPO> page = new Page<>(1, 1);
List<SpThroughPO> spThroughPOS = this.baseMapper.selectPage(page,lambdaQueryWrapper).getRecords();
if(!spThroughPOS.isEmpty()){
return spThroughPOS.get(0).getCreateTime();
}
return null;
}
@Override
public List<SpThroughPO> getDataByLineIds(List<String> lineIds) {
return null;
public SpThroughVO getDataByEventIds(SpThroughParam spThroughParam) {
SpThroughVO spThroughVO = new SpThroughVO();
LambdaQueryWrapper<SpThroughPO> upperLambdaQueryWrapper = new LambdaQueryWrapper();
upperLambdaQueryWrapper.in(SpThroughPO::getEventId,spThroughParam.getEventIds())
.eq(SpThroughPO::getIsOrNot,1)
.eq(SpThroughPO::getStationType,spThroughParam.getStationType().equals("1")?Param.WINDFARM:Param.PHOTOVOLTAICPOWER)
.eq(SpThroughPO::getState,1)
.eq(SpThroughPO::getEventType,Param.UPPEREVENT);
Integer upperCount = this.baseMapper.selectCount(upperLambdaQueryWrapper);
spThroughVO.setHighPressure(upperCount == 0?null:upperCount.toString());
LambdaQueryWrapper<SpThroughPO> lowLambdaQueryWrapper = new LambdaQueryWrapper();
lowLambdaQueryWrapper.in(SpThroughPO::getEventId,spThroughParam.getEventIds())
.eq(SpThroughPO::getIsOrNot,1)
.eq(SpThroughPO::getStationType,spThroughParam.getStationType().equals("1")?Param.WINDFARM:Param.PHOTOVOLTAICPOWER)
.eq(SpThroughPO::getState,1)
.eq(SpThroughPO::getEventType,Param.LOWEREVENT);
Integer lowCount = this.baseMapper.selectCount(lowLambdaQueryWrapper);
spThroughVO.setLowPressure(lowCount == 0?null:lowCount.toString());
return spThroughVO;
}
/**
* 说明:
* 此方法是专门提供给event模块-高低压穿越模块中-根据区域获取暂态事件列表使用
* 根据区域获取各个子区域高低电压穿越次数是基于sp_through表中记录来的 那么在根据区域获取暂态事件列表数据也应该基于sp_through表中记录来
* 因为如果不基于sp_through表中记录来 那么根据区域获取暂态事件可能数据非常多且可能一部分的事件数据并没有被定时任务(record方法)所执行
* @param spThroughParam
* @return
*/
@Override
public List<String> formatEventIds(SpThroughParam spThroughParam) {
LambdaQueryWrapper<SpThroughPO> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.in(SpThroughPO::getEventId,spThroughParam.getEventIds())
.eq(SpThroughPO::getIsOrNot,1)
.eq(SpThroughPO::getStationType,spThroughParam.getStationType().equals("1")?Param.WINDFARM:Param.PHOTOVOLTAICPOWER)
.eq(SpThroughPO::getState,1);
List<SpThroughPO> spThroughPOS = this.baseMapper.selectList(lambdaQueryWrapper);
return spThroughPOS.stream().map(SpThroughPO::getEventId).collect(Collectors.toList());
}
}

View File

@@ -1,7 +1,9 @@
package com.njcn.prepare.harmonic.service.mysql.event;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.prepare.harmonic.pojo.param.SpThroughParam;
import com.njcn.prepare.harmonic.pojo.po.SpThroughPO;
import com.njcn.prepare.harmonic.pojo.vo.SpThroughVO;
import java.util.List;
/**
@@ -17,8 +19,13 @@ public interface SpThroughService extends IMppService<SpThroughPO> {
void record();
/**
* 根据监测点ID集合获取高低电压穿越信息
* 根据事件ID集合及能源站类型获取高低电压穿越次数
*/
List<SpThroughPO> getDataByLineIds(List<String> lineIds);
SpThroughVO getDataByEventIds(SpThroughParam spThroughParam);
/**
* 根据原有的事件集合进行过滤
*/
List<String> formatEventIds(SpThroughParam spThroughParam);
}