1.暂降预览页面接口

This commit is contained in:
2025-11-25 09:11:58 +08:00
parent f7477ea8ff
commit 9ae17b14f5
12 changed files with 669 additions and 0 deletions

View File

@@ -22,4 +22,10 @@ public interface CsCommTerminalFeignClient {
@GetMapping("lineUnitDetail") @GetMapping("lineUnitDetail")
HttpResult<PqsDeviceUnit> lineUnitDetail(@RequestParam("lineId") String lineId); HttpResult<PqsDeviceUnit> lineUnitDetail(@RequestParam("lineId") String lineId);
@PostMapping("getDevIdsByUser")
HttpResult<List<String>> getDevIdsByUser(@RequestBody String userId);
@PostMapping("getLineIdsByUser")
HttpResult<List<String>> getLineIdsByUser(@RequestBody String userId);
} }

View File

@@ -9,6 +9,8 @@ import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
/** /**
* @author xy * @author xy
*/ */
@@ -31,6 +33,18 @@ public class CsCommTerminalFeignClientFallbackFactory implements FallbackFactory
log.error("{}异常,降级处理,异常为:{}","查询分组",cause.toString()); log.error("{}异常,降级处理,异常为:{}","查询分组",cause.toString());
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }
@Override
public HttpResult<List<String>> getDevIdsByUser(String userId) {
log.error("{}异常,降级处理,异常为:{}","查询分组",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<String>> getLineIdsByUser(String userId) {
log.error("{}异常,降级处理,异常为:{}","查询分组",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
}; };
} }
} }

View File

@@ -1,12 +1,18 @@
package com.njcn.csdevice.controller.ledger; package com.njcn.csdevice.controller.ledger;
import cn.hutool.core.collection.CollUtil;
import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.mapper.PqsDeviceUnitMapper; import com.njcn.csdevice.mapper.PqsDeviceUnitMapper;
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.service.CsDeviceUserPOService;
import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit; import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@@ -17,7 +23,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
/** /**
@@ -34,7 +44,57 @@ public class CsCommTerminalController extends BaseController {
private final PqsDeviceUnitMapper pqsDeviceUnitMapper; private final PqsDeviceUnitMapper pqsDeviceUnitMapper;
private final CsDeviceUserPOService csDeviceUserPOService;
private final CsLinePOService csLinePOService;
/**
* 根据用户获取设备信息
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getDevIdsByUser")
@ApiOperation("根据监测点id获取数据单位")
@ApiImplicitParam(name = "lineId", value = "实体", required = true)
public HttpResult<List<String>> getDevIdsByUser(@RequestBody String userId) {
String methodDescribe = getMethodDescribe("getDevIdsByUser");
List<String> result;
List<CsDeviceUserPO> poList = csDeviceUserPOService.lambdaQuery().select(CsDeviceUserPO::getDeviceId)
.and(w->w.eq(CsDeviceUserPO::getPrimaryUserId,userId).or().eq(CsDeviceUserPO::getSubUserId,userId))
.eq(CsDeviceUserPO::getStatus, DataStateEnum.ENABLE.getCode()).list();
if(CollUtil.isNotEmpty(poList)){
result = poList.stream().map(CsDeviceUserPO::getDeviceId).distinct().collect(Collectors.toList());
}else {
result = Collections.emptyList();
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
/**
* 根据用户获取设备信息
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getLineIdsByUser")
@ApiOperation("根据监测点id获取数据单位")
@ApiImplicitParam(name = "lineId", value = "实体", required = true)
public HttpResult<List<String>> getLineIdsByUser(@RequestBody String userId) {
String methodDescribe = getMethodDescribe("getLineIdsByUser");
List<CsDeviceUserPO> devList = csDeviceUserPOService.lambdaQuery().select(CsDeviceUserPO::getDeviceId)
.and(w->w.eq(CsDeviceUserPO::getPrimaryUserId,userId).or().eq(CsDeviceUserPO::getSubUserId,userId))
.eq(CsDeviceUserPO::getStatus, DataStateEnum.ENABLE.getCode()).list();
if(CollUtil.isNotEmpty(devList)){
List<String> devIds = devList.stream().map(CsDeviceUserPO::getDeviceId).distinct().collect(Collectors.toList());
List<CsLinePO> poList = csLinePOService.lambdaQuery().select(CsLinePO::getLineId).in(CsLinePO::getDeviceId,devIds)
.eq(CsLinePO::getStatus,DataStateEnum.ENABLE.getCode()).list();
if(CollUtil.isEmpty(poList)){
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, Collections.emptyList(), methodDescribe);
}else {
List<String> result = poList.stream().map(CsLinePO::getLineId).distinct().collect(Collectors.toList());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, Collections.emptyList(), methodDescribe);
}
}
/** /**
* 通过监测点获取监测点数据单位 * 通过监测点获取监测点数据单位

View File

@@ -0,0 +1,26 @@
package com.njcn.csharmonic.enums;
import lombok.Getter;
@Getter
public enum CsEventEnum {
EVENT_TYPE(0,"暂态事件"),
HARMONIC_TYPE(1,"稳态事件"),
DEVICE_TYPE(2,"设备事件"),
ALARM_TYPE(3,"告警事件")
;
private final Integer code;
private final String name;
CsEventEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
}

View File

@@ -0,0 +1,30 @@
package com.njcn.csharmonic.enums;
import lombok.Getter;
@Getter
public enum CsTransientEnum {
EVT_SYS_DIPSTR("Evt_Sys_DipStr","电压暂降"),
EVT_SYS_INTRSTRr("Evt_Sys_IntrStr","电压中断"),
EVT_SYS_SWLSTR("Evt_Sys_SwlStr","电压暂升"),
TRANSIENT("Transient","录波"),
UN_KNOW("Un_Know","未知")
;
private final String code;
private final String name;
CsTransientEnum(String code, String name) {
this.code = code;
this.name = name;
}
}

View File

@@ -0,0 +1,29 @@
package com.njcn.csharmonic.pojo.param;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @Author: cdf
* @CreateTime: 2025-11-21
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class EventStatisticParam extends BaseParam {
/**
* 监测点id
*/
@ApiModelProperty("监测点id")
private String lineId;
/**
* 安装位置
*/
@ApiModelProperty("字典表:安装位置(负载侧,电网侧, 输出侧)")
private String position;
}

View File

@@ -0,0 +1,26 @@
package com.njcn.csharmonic.pojo.vo.event;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: cdf
* @CreateTime: 2025-11-24
* @Description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EventCoordsVO {
@ApiModelProperty(name = "x",value = "x轴")
private Integer x;
@ApiModelProperty(name = "y",value = "y轴")
private Integer y;
@ApiModelProperty(name = "z",value = "z轴")
private Integer z;
}

View File

@@ -0,0 +1,36 @@
package com.njcn.csharmonic.pojo.vo.event;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;
import org.apache.ibatis.javassist.runtime.Inner;
import java.util.List;
/**
* @Author: cdf
* @CreateTime: 2025-11-20
* @Description:
*/
@Data
public class EventStatisticVO {
private String id;
@ApiModelProperty(value = "名称")
private String name;
@ApiModelProperty(value = "暂降")
private Integer eventDown = 0;
@ApiModelProperty(value = "中断")
private Integer eventOff = 0;
@ApiModelProperty(value = "暂升")
private Integer eventUp = 0;
@ApiModelProperty(value = "总数")
private Integer allNum = 0;
}

View File

@@ -0,0 +1,24 @@
package com.njcn.csharmonic.pojo.vo.event;
import lombok.Data;
import java.math.BigDecimal;
/**
* @Author: cdf
* @CreateTime: 2025-11-21
* @Description:
*/
@Data
public class F47Curve {
private String id;
private String tag;
private BigDecimal persistTime;
private BigDecimal amplitude;
}

View File

@@ -0,0 +1,94 @@
package com.njcn.csharmonic.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
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.csharmonic.pojo.param.EventStatisticParam;
import com.njcn.csharmonic.pojo.vo.event.EventCoordsVO;
import com.njcn.csharmonic.pojo.vo.event.EventStatisticVO;
import com.njcn.csharmonic.pojo.vo.event.F47Curve;
import com.njcn.csharmonic.service.event.EventOverviewService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Author: cdf
* @CreateTime: 2025-11-20
* @Description: 暂降概览
*/
@Slf4j
@RestController
@RequestMapping("/csevent")
@Api(tags = "暂降概览")
@RequiredArgsConstructor
public class EventOverviewController extends BaseController {
private final EventOverviewService eventOverviewService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("暂降类型分类统计Echart")
@PostMapping("netEventEcharts")
public HttpResult<EventStatisticVO> netEventEcharts(@RequestBody EventStatisticParam baseParam){
String methodDescribe = getMethodDescribe("netEventEcharts");
EventStatisticVO eventStatisticVO = eventOverviewService.netEventEcharts(baseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eventStatisticVO, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("暂降类型分类统计表格")
@PostMapping("netEventTable")
public HttpResult<List<EventStatisticVO>> netEventTable(@RequestBody EventStatisticParam baseParam){
String methodDescribe = getMethodDescribe("netEventTable");
List<EventStatisticVO> list = eventOverviewService.netEventTable(baseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("F47曲线")
@PostMapping("f47Curve")
public HttpResult<List<F47Curve>> getF47Curve(@RequestBody EventStatisticParam baseParam){
String methodDescribe = getMethodDescribe("getF47Curve");
List<F47Curve> list = eventOverviewService.getF47Curve(baseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("日历暂降事件详情")
@PostMapping("getEventDate")
public HttpResult<List<EventStatisticVO>> getEventDate(@RequestBody EventStatisticParam baseParam){
String methodDescribe = getMethodDescribe("getEventDate");
List<EventStatisticVO> list = eventOverviewService.getEventDate(baseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getEventCoords")
@ApiOperation("获取电压暂态表及密度坐标图")
public HttpResult<List<EventCoordsVO>> getEventCoords(@RequestBody EventStatisticParam baseParam){
String methodDescribe = getMethodDescribe("getEventCoords");
List<EventCoordsVO> list = eventOverviewService.getEventCoords(baseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe);
}
}

View File

@@ -0,0 +1,31 @@
package com.njcn.csharmonic.service.event;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csharmonic.pojo.param.EventStatisticParam;
import com.njcn.csharmonic.pojo.vo.event.EventCoordsVO;
import com.njcn.csharmonic.pojo.vo.event.EventStatisticVO;
import com.njcn.csharmonic.pojo.vo.event.F47Curve;
import com.njcn.web.pojo.param.BaseParam;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @Author: cdf
* @CreateTime: 2025-11-20
* @Description: 暂降相关
*/
public interface EventOverviewService {
EventStatisticVO netEventEcharts(EventStatisticParam baseParam);
List<EventStatisticVO> netEventTable(EventStatisticParam baseParam);
List<F47Curve> getF47Curve(EventStatisticParam baseParam);
List<EventStatisticVO> getEventDate(EventStatisticParam baseParam);
List<EventCoordsVO> getEventCoords(EventStatisticParam baseParam);
}

View File

@@ -0,0 +1,293 @@
package com.njcn.csharmonic.service.impl.event;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.*;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableMap;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csharmonic.enums.CsEventEnum;
import com.njcn.csharmonic.enums.CsTransientEnum;
import com.njcn.csharmonic.pojo.param.EventStatisticParam;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.vo.event.EventCoordsVO;
import com.njcn.csharmonic.pojo.vo.event.EventStatisticVO;
import com.njcn.csharmonic.pojo.vo.event.F47Curve;
import com.njcn.csharmonic.service.CsEventPOService;
import com.njcn.csharmonic.service.event.EventOverviewService;
import com.njcn.parser.component.WaveFileComponent;
import com.njcn.parser.pojo.dto.WaveDataDTO;
import com.njcn.parser.utils.WaveUtil;
import com.njcn.web.pojo.param.BaseParam;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @Author: cdf
* @CreateTime: 2025-11-20
* @Description:
*/
@Service
@RequiredArgsConstructor
public class EventOverviewServiceImpl implements EventOverviewService {
private static final List<String> EVENT_TAGS = Arrays.asList(
CsTransientEnum.EVT_SYS_DIPSTR.getCode(),
CsTransientEnum.EVT_SYS_INTRSTRr.getCode(),
CsTransientEnum.EVT_SYS_SWLSTR.getCode()
);
private final CsEventPOService csEventPOService;
private final CsLineFeignClient csLineFeignClient;
@Override
public EventStatisticVO netEventEcharts(EventStatisticParam baseParam) {
DateTime start = DateUtil.beginOfDay(DateUtil.parse(baseParam.getSearchBeginTime()));
DateTime end = DateUtil.endOfDay(DateUtil.parse(baseParam.getSearchEndTime()));
List<CsEventPO> csEventPOList = csEventPOService.lambdaQuery()
.between(CsEventPO::getStartTime, start, end)
.eq(CsEventPO::getType, CsEventEnum.EVENT_TYPE.getCode())
.in(CsEventPO::getTag, EVENT_TAGS)
//TODO
.list();
EventStatisticVO result = new EventStatisticVO();
if (CollUtil.isEmpty(csEventPOList)) {
return result;
}
Map<String, Long> eventCountByTag = csEventPOList.stream().collect(Collectors.groupingBy(CsEventPO::getTag, Collectors.counting()));
result.setEventDown(eventCountByTag.getOrDefault(CsTransientEnum.EVT_SYS_DIPSTR.getCode(), 0L).intValue());
result.setEventOff(eventCountByTag.getOrDefault(CsTransientEnum.EVT_SYS_INTRSTRr.getCode(), 0L).intValue());
result.setEventUp(eventCountByTag.getOrDefault(CsTransientEnum.EVT_SYS_SWLSTR.getCode(), 0L).intValue());
result.setAllNum(csEventPOList.size());
return result;
}
@Override
public List<EventStatisticVO> netEventTable(EventStatisticParam baseParam) {
DateTime start = DateUtil.beginOfDay(DateUtil.parse(baseParam.getSearchBeginTime()));
DateTime end = DateUtil.endOfDay(DateUtil.parse(baseParam.getSearchEndTime()));
List<String> lineIds = StrUtil.isBlank(baseParam.getSearchValue())
? csLineFeignClient.getAllLine().getData()
: Collections.singletonList(baseParam.getSearchValue());
List<CsLinePO> csLinePOList = csLineFeignClient.queryLineById(lineIds).getData();
if (CollUtil.isEmpty(csLinePOList)) {
return Collections.emptyList();
}
List<String> validLineIds = csLinePOList.stream()
.map(CsLinePO::getLineId)
.distinct()
.collect(Collectors.toList());
List<CsEventPO> csEventPOList = csEventPOService.lambdaQuery()
.between(CsEventPO::getStartTime, start, end)
.eq(CsEventPO::getType, CsEventEnum.EVENT_TYPE.getCode())
.in(CsEventPO::getTag, EVENT_TAGS)
.in(CsEventPO::getLineId, validLineIds)
.list();
if (CollUtil.isEmpty(csEventPOList)) {
return csLinePOList.stream()
.map(line -> {
EventStatisticVO vo = new EventStatisticVO();
vo.setName(line.getName());
return vo;
})
.collect(Collectors.toList());
}
// 按线路ID和事件类型分组统计
Map<String, Map<String, Long>> eventCountByLineAndTag = csEventPOList.stream()
.collect(Collectors.groupingBy(
CsEventPO::getLineId,
Collectors.groupingBy(
CsEventPO::getTag,
Collectors.counting()
)
));
return csLinePOList.stream()
.map(line -> {
EventStatisticVO vo = new EventStatisticVO();
vo.setName(line.getName());
Map<String, Long> lineEvents = eventCountByLineAndTag.getOrDefault(line.getLineId(), Collections.emptyMap());
vo.setEventDown(lineEvents.getOrDefault(CsTransientEnum.EVT_SYS_DIPSTR.getCode(), 0L).intValue());
vo.setEventOff(lineEvents.getOrDefault(CsTransientEnum.EVT_SYS_INTRSTRr.getCode(), 0L).intValue());
vo.setEventUp(lineEvents.getOrDefault(CsTransientEnum.EVT_SYS_SWLSTR.getCode(), 0L).intValue());
return vo;
}).sorted(Comparator.comparing(EventStatisticVO::getEventDown, Comparator.reverseOrder())
.thenComparing(EventStatisticVO::getEventOff, Comparator.reverseOrder()).thenComparing(EventStatisticVO::getEventUp, Comparator.reverseOrder()))
.collect(Collectors.toList());
}
@Override
public List<F47Curve> getF47Curve(EventStatisticParam baseParam) {
DateTime start = DateUtil.beginOfDay(DateUtil.parse(baseParam.getSearchBeginTime()));
DateTime end = DateUtil.endOfDay(DateUtil.parse(baseParam.getSearchEndTime()));
List<CsEventPO> csEventPOList = csEventPOService.lambdaQuery().select(CsEventPO::getId,CsEventPO::getTag,CsEventPO::getPersistTime,CsEventPO::getAmplitude)
.between(CsEventPO::getStartTime, start, end)
.eq(CsEventPO::getType, CsEventEnum.EVENT_TYPE.getCode())
.in(CsEventPO::getTag, EVENT_TAGS)
//TODO
.list();
List<F47Curve> f47CurveList = csEventPOList.stream().map(item->{
F47Curve f47Curve = new F47Curve();
f47Curve.setId(item.getId());
f47Curve.setTag(item.getTag());
f47Curve.setPersistTime(BigDecimal.valueOf(item.getPersistTime()));
f47Curve.setAmplitude(BigDecimal.valueOf(item.getAmplitude()));
return f47Curve;
}).collect(Collectors.toList());
return f47CurveList;
}
@Override
public List<EventStatisticVO> getEventDate(EventStatisticParam baseParam) {
if(StrUtil.isBlank(baseParam.getSearchBeginTime())){
throw new BusinessException(CommonResponseEnum.FAIL,"月份不可为空");
}
DateTime dateTime = DateUtil.parse(baseParam.getSearchBeginTime(), DatePattern.NORM_MONTH_PATTERN);
DateTime start = DateUtil.beginOfMonth(dateTime);
DateTime end = DateUtil.endOfMonth(dateTime);
List<DateTime> rangList = DateUtil.rangeToList(start,end, DateField.DAY_OF_MONTH);
List<CsEventPO> csEventPOList = csEventPOService.lambdaQuery().select(CsEventPO::getId,CsEventPO::getTag,CsEventPO::getStartTime,CsEventPO::getPersistTime,CsEventPO::getAmplitude)
.between(CsEventPO::getStartTime, start, end)
.eq(CsEventPO::getType, CsEventEnum.EVENT_TYPE.getCode())
.in(CsEventPO::getTag, EVENT_TAGS)
//TODO
.list();
if(CollUtil.isEmpty(csEventPOList)){
return rangList.stream().map(item->{
EventStatisticVO eventStatisticVO = new EventStatisticVO();
eventStatisticVO.setName(DateUtil.format(item,DatePattern.NORM_DATE_PATTERN));
return eventStatisticVO;
}).collect(Collectors.toList());
}
Map<String, Map<String, Long>> map = csEventPOList.stream().collect(Collectors.groupingBy(item-> DateUtil.format(item.getStartTime(),DatePattern.NORM_DATE_PATTERN),Collectors.groupingBy(
CsEventPO::getTag,
Collectors.counting()
)));
return rangList.stream().map(item->{
EventStatisticVO eventStatisticVO = new EventStatisticVO();
String day = DateUtil.format(item,DatePattern.NORM_DATE_PATTERN);
eventStatisticVO.setName(day);
Map<String,Long> itemMap = map.getOrDefault(day,Collections.emptyMap());
eventStatisticVO.setEventDown(itemMap.getOrDefault(CsTransientEnum.EVT_SYS_DIPSTR.getCode(), 0L).intValue());
eventStatisticVO.setEventOff(itemMap.getOrDefault(CsTransientEnum.EVT_SYS_INTRSTRr.getCode(), 0L).intValue());
eventStatisticVO.setEventUp(itemMap.getOrDefault(CsTransientEnum.EVT_SYS_SWLSTR.getCode(), 0L).intValue());
return eventStatisticVO;
}).collect(Collectors.toList());
}
@Override
public List<EventCoordsVO> getEventCoords(EventStatisticParam baseParam) {
// 初始化结果列表10行 x 9列根据原始代码的循环推断
List<EventCoordsVO> result = new ArrayList<>(90);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9; j++) {
result.add(new EventCoordsVO(i, j, 0));
}
}
//查询监测点未处理暂态事件
DateTime start = DateUtil.beginOfDay(DateUtil.parse(baseParam.getSearchBeginTime()));
DateTime end = DateUtil.endOfDay(DateUtil.parse(baseParam.getSearchEndTime()));
List<CsEventPO> events = csEventPOService.lambdaQuery().select(CsEventPO::getId,CsEventPO::getTag,CsEventPO::getStartTime,CsEventPO::getPersistTime,CsEventPO::getAmplitude)
.between(CsEventPO::getStartTime, start, end)
.eq(CsEventPO::getType, CsEventEnum.EVENT_TYPE.getCode())
.in(CsEventPO::getTag, EVENT_TAGS)
//TODO
.list();
// 定义振幅和持续时间的分类规则
// 振幅分类规则
Map<Double, Integer> amplitudeRanges = ImmutableMap.<Double, Integer>builder()
.put(0.0, 0)
.put(0.1, 1)
.put(0.2, 2)
.put(0.3, 3)
.put(0.4, 4)
.put(0.5, 5)
.put(0.6, 6)
.put(0.7, 7)
.put(0.8, 8)
.put(0.9, 9)
// 默认分类
.put(Double.MAX_VALUE, 10)
.build();
// 持续时间分类规则
Map<Double, Integer> persistTimeRanges = ImmutableMap.<Double, Integer>builder()
.put(0.0, 0)
.put(0.020, 1)
.put(0.040, 2)
.put(0.060, 3)
.put(0.080, 4)
.put(0.120, 5)
.put(0.200, 6)
.put(0.400, 7)
.put(0.600, 8)
.put(1.200, 9)
.build();
// 分类事件
for (CsEventPO event : events) {
double amplitude = event.getAmplitude();
double persistTimeSec = event.getPersistTime() / 1000.0;
// 确定振幅分类
int amplitudeGroup = getRangeGroup(amplitudeRanges, amplitude);
// 确定持续时间分类(振幅分类作为行,持续时间分类作为列)
int persistTimeGroup = getRangeGroup(persistTimeRanges, persistTimeSec);
// 计算索引:行 = 振幅分组,列 = 持续时间分组
int row = amplitudeGroup;
int col = persistTimeGroup;
// 10行 x 9列的网格
int index = row * 9 + col;
// 安全更新结果
if (index >= 0 && index < result.size()) {
EventCoordsVO coordsVO = result.get(index);
coordsVO.setZ(coordsVO.getZ() + 1);
}
}
return result;
}
/**
* 根据范围映射表获取分组
*/
private int getRangeGroup(Map<Double, Integer> ranges, double value) {
for (Map.Entry<Double, Integer> entry : ranges.entrySet()) {
if (value <= entry.getKey()) {
return entry.getValue();
}
}
return ranges.size() - 1; // 默认返回最大分组
}
}