高级算法 部分

This commit is contained in:
njcn_dhj
2022-08-26 14:24:42 +08:00
parent fda3b2c172
commit 8dda0820d5
22 changed files with 862 additions and 92 deletions

View File

@@ -97,5 +97,14 @@ public class OperationContrController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getComunicateStatics")
@ApiOperation("获取中断异常统计")
@ApiImplicitParam(name = "conditionBusinessParam", value = "实体", required = true)
public HttpResult<DeviceAbnormalVO> getComunicateStatics(@RequestBody @Validated DeviceInfoParam.ConditionBusinessParam conditionBusinessParam) {
String methodDescribe = getMethodDescribe("getComunicateStatics");
DeviceAbnormalVO result = lineService.getComunicateStatics(conditionBusinessParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -141,5 +141,11 @@ public interface LineService {
*/
List<Line> getBaseLineList(List<String> lineIndex);
/**
* 获取终端异常数据
* @param deviceInfoParam 参数
* @return 结果
*/
DeviceAbnormalVO getComunicateStatics(DeviceInfoParam.ConditionBusinessParam deviceInfoParam);
}

View File

@@ -23,6 +23,8 @@ import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.po.*;
import com.njcn.device.pojo.vo.*;
import com.njcn.device.service.LineService;
import com.njcn.device.utils.PublicDateUtil;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.api.AreaFeignClient;
@@ -42,7 +44,6 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -73,8 +74,6 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
private final SubstationMapper substationMapper;
private final CommunicateMapper communicateMapper;
private final GeneralDeviceService generalDeviceService;
private final LineMapper lineMapper;
@@ -158,7 +157,7 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
@Override
public CommunicateVO getComFlagInfoData(String id, String searchBeginTime, String searchEndTime) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<Communicate> communicateList = getCommunicate(id,searchBeginTime,searchEndTime);
List<Communicate> communicateList = getCommunicate(id, searchBeginTime, searchEndTime);
CommunicateVO communicateVOList = new CommunicateVO();
List<String> updateTime = new ArrayList<>();
List<Integer> comType = new ArrayList<>();
@@ -260,24 +259,23 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList()));
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
//根据部门id去获取省份信息
Area area = areaFeignClient.areaDeptPro(generalDeviceDTO.getIndex()).getData();
LineDistributionVO lineDistributionVO = new LineDistributionVO();
lineDistributionVO.setName(generalDeviceDTO.getName());
lineDistributionVO.setValue(generalDeviceDTO.getLineIndexes().size());
lineDistributionVOList.add(lineDistributionVO);
}
List<LineDistributionVO> result =new ArrayList<LineDistributionVO>();
List<LineDistributionVO> result = new ArrayList<LineDistributionVO>();
Map<String, Integer> map = new HashMap<String, Integer>();
for(LineDistributionVO lineDistributionVO:lineDistributionVOList){
for (LineDistributionVO lineDistributionVO : lineDistributionVOList) {
if (map.containsKey(lineDistributionVO.getName())) {
map.put(lineDistributionVO.getName(), map.get(lineDistributionVO.getName())+lineDistributionVO.getValue());
map.put(lineDistributionVO.getName(), map.get(lineDistributionVO.getName()) + lineDistributionVO.getValue());
} else {
map.put(lineDistributionVO.getName(), lineDistributionVO.getValue());
}
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
result.add(new LineDistributionVO(entry.getKey(),entry.getValue()));
result.add(new LineDistributionVO(entry.getKey(), entry.getValue()));
}
return result;
}
@@ -383,9 +381,9 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
//根据监测点id获取终端id
String devIndex = lineMapper.getDevIndex(lineId);
//获取在线率
List<LineStaticsValueVO> onlineRateValue = getDevOnline(devIndex,startTime,endTime);
List<LineStaticsValueVO> onlineRateValue = getDevOnline(devIndex, startTime, endTime);
//获取数据完整性
List<LineStaticsValueVO> integrityValue = getInegrity(lineId,startTime,endTime);
List<LineStaticsValueVO> integrityValue = getInegrity(lineId, startTime, endTime);
//获取流量占比
List<LineStaticsValueVO> flowMealValue = new ArrayList<>();
//组装
@@ -415,8 +413,8 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
for (LineFlowMealDetailVO lineFlowMealDetailVO : monitorList) {
for (LineInfluxDbInegrityVO lineInfluxDbInegrity : lineInfluxDbInegrityVO) {
if (lineFlowMealDetailVO.getId().equals(lineInfluxDbInegrity.getLineId())) {
BigDecimal flow =new BigDecimal(lineInfluxDbInegrity.getIntegrity().floatValue());
lineFlowMealDetailVO.setIntegrity(flow.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
BigDecimal flow = new BigDecimal(lineInfluxDbInegrity.getIntegrity().floatValue());
lineFlowMealDetailVO.setIntegrity(flow.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
}
}
}
@@ -426,18 +424,18 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
List<LineFlowMealDetailVO> deviceList = lineMapper.getFlowLineRunStatistics(busBarList.stream().map(LineFlowMealDetailVO::getPid).distinct().collect(Collectors.toList()), DateUtil.endOfDay(DateUtil.parse(steadyParam.getSearchBeginTime())), DateUtil.beginOfDay(DateUtil.parse(steadyParam.getSearchEndTime())));
for (LineFlowMealDetailVO lineFlowMealDetailVO : deviceList) {
System.out.println(lineFlowMealDetailVO.getId());
Float staticsValue = getStatisValueFlow(lineFlowMealDetailVO.getId(),steadyParam);
BigDecimal b = new BigDecimal(staticsValue);
float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
Float staticsValue = getStatisValueFlow(lineFlowMealDetailVO.getId(), steadyParam);
BigDecimal b = new BigDecimal(staticsValue);
float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
lineFlowMealDetailVO.setStatisValue(f1);
BigDecimal flow =new BigDecimal(f1/lineFlowMealDetailVO.getFlowMeal()*100);
BigDecimal flow = new BigDecimal(f1 / lineFlowMealDetailVO.getFlowMeal() * 100);
//获取流量占比
lineFlowMealDetailVO.setFlowProportion(flow.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
lineFlowMealDetailVO.setFlowProportion(flow.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
for (LineInfluxDbOnlineVO lineInfluxDbOnline : lineInfluxDbOnlineVO) {
if (lineFlowMealDetailVO.getId().equals(lineInfluxDbOnline.getDevIndex())) {
BigDecimal flowValue =new BigDecimal(lineInfluxDbOnline.getOnlineRate().floatValue());
lineFlowMealDetailVO.setOnlineRate(flowValue.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
BigDecimal flowValue = new BigDecimal(lineInfluxDbOnline.getOnlineRate().floatValue());
lineFlowMealDetailVO.setOnlineRate(flowValue.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
}
}
}
@@ -589,7 +587,7 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
if (!CollectionUtils.isEmpty(list)) {
List<List<Object>> listData = list.get(0).getValues();
for (int i = 0; i < listData.size(); i++) {
LineStaticsValueVO lineStaticsValueVO =new LineStaticsValueVO();
LineStaticsValueVO lineStaticsValueVO = new LineStaticsValueVO();
List<Object> objectList = listData.get(i);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
lineStaticsValueVO.setTime(formatter.parse(objectList.get(0).toString()).toString());
@@ -614,7 +612,7 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
if (!CollectionUtils.isEmpty(list)) {
List<List<Object>> listData = list.get(0).getValues();
for (int i = 0; i < listData.size(); i++) {
LineStaticsValueVO lineStaticsValueVO =new LineStaticsValueVO();
LineStaticsValueVO lineStaticsValueVO = new LineStaticsValueVO();
List<Object> objectList = listData.get(i);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
lineStaticsValueVO.setTime(formatter.parse(objectList.get(0).toString()).toString());
@@ -626,7 +624,7 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
}
@SneakyThrows
public Float getStatisValueFlow(String lineIndex,DeviceInfoParam.BusinessParam steadyParam) {
public Float getStatisValueFlow(String lineIndex, DeviceInfoParam.BusinessParam steadyParam) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(steadyParam.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(steadyParam.getSearchEndTime()))).append("' and ");
@@ -639,19 +637,19 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
if (!CollectionUtils.isEmpty(list)) {
List<List<Object>> listData = list.get(0).getValues();
List<Object> objectList = listData.get(0);
staticsValue = ((Double)objectList.get(1)).floatValue();
}else {
staticsValue = ((Double) objectList.get(1)).floatValue();
} else {
staticsValue = 0f;
}
return staticsValue;
}
public List<Communicate> getCommunicate(String lineIndex, String startTime,String endTime) {
public List<Communicate> getCommunicate(String lineIndex, String startTime, String endTime) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("line_id = '").append(lineIndex).append("' group by line_id ").append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select * from "+InfluxDBPublicParam.PQS_COMMUNICATE+" where " + stringBuilder.toString();
String sql = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where " + stringBuilder.toString();
//获取暂降事件
QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
@@ -661,15 +659,226 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
@Override
public List<AreaLineInfoVO> getBaseLineAreaInfo(List<String> lineIndex,String searchValue,Integer comFlag) {
return this.baseMapper.getBaseLineAreaInfo(lineIndex,searchValue,comFlag);
public List<AreaLineInfoVO> getBaseLineAreaInfo(List<String> lineIndex, String searchValue, Integer comFlag) {
return this.baseMapper.getBaseLineAreaInfo(lineIndex, searchValue, comFlag);
}
@Override
public List<Line> getBaseLineList(List<String> lineIndex) {
LambdaQueryWrapper<Line> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Line::getState, DataStateEnum.ENABLE.getCode()).in(Line::getId,lineIndex);
lambdaQueryWrapper.eq(Line::getState, DataStateEnum.ENABLE.getCode()).in(Line::getId, lineIndex);
return this.list(lambdaQueryWrapper);
}
@SneakyThrows
@Override
public DeviceAbnormalVO getComunicateStatics(DeviceInfoParam.ConditionBusinessParam conditionBusinessParam) {
DeviceAbnormalVO deviceAbnormalVO = new DeviceAbnormalVO();
//获取所有监测点
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(conditionBusinessParam, null, Stream.of(1).collect(Collectors.toList()));
List<String> lineIndexs = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (conditionBusinessParam.getTimeFlag() == 0) {
List<String> intervalTime = this.getIntervalTime(conditionBusinessParam.getSearchBeginTime(), conditionBusinessParam.getSearchEndTime());
List<AbnomalCommuncateVO> abnomalCommuncateVOS = new ArrayList<>();
deviceAbnormalVO.setIsPid(true);
for (String interTime : intervalTime) {
System.out.println(lineIndexs);
AbnomalCommuncateVO inter = new AbnomalCommuncateVO();
String startTime, endTime;
inter.setMonth(interTime.substring(5));
inter.setYear(interTime.substring(0, 4));
startTime = PublicDateUtil.getFisrtDayOfMonth(Integer.parseInt(interTime.substring(0,4)),Integer.parseInt (interTime.substring(5)));
endTime = PublicDateUtil.getLastDayOfMonth(Integer.parseInt(interTime.substring(0,4)),Integer.parseInt(interTime.substring(5)));
List<Communicate> communicateList = getCommunicateAbnorm(lineIndexs,startTime,endTime);
inter.setDay("/");
if (communicateList.size()==0){
inter.setAbnormalTimes("3.14159");
}else {
inter.setAbnormalTimes(String.valueOf(communicateList.size()));
}
abnomalCommuncateVOS.add(inter);
}
deviceAbnormalVO.setData(abnomalCommuncateVOS);
} else {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt = simpleDateFormat.parse(conditionBusinessParam.getSearchBeginTime());
Date dtDate = simpleDateFormat.parse(conditionBusinessParam.getSearchEndTime());
Integer year = Integer.valueOf(String.format("%tY", dt));
Integer mon = Integer.valueOf(String.format("%tm", dt));
Integer day = Integer.valueOf(String.format("%td", dtDate));
List<String> intervalTime = this.getIntervalDateTime(year, mon,day);
List<AbnomalCommuncateVO> abnomalCommuncateVOS = new ArrayList<>();
deviceAbnormalVO.setIsPid(false);
for (String interTime : intervalTime) {
AbnomalCommuncateVO inter = new AbnomalCommuncateVO();
String startTime, endTime;
inter.setMonth(interTime.substring(5,7));
inter.setYear(interTime.substring(0, 4));
inter.setDay(interTime.substring(8));
startTime = sdf.format(DateUtil.beginOfDay(DateUtil.parse(interTime)));
endTime = sdf.format(DateUtil.endOfDay(DateUtil.parse(interTime)));
List<Communicate> communicateList = getCommunicateAbnorm(lineIndexs,startTime,endTime);
if (communicateList.size()==0){
inter.setAbnormalTimes("3.14159");
}else {
inter.setAbnormalTimes(String.valueOf(communicateList.size()));
}
abnomalCommuncateVOS.add(inter);
}
deviceAbnormalVO.setData(abnomalCommuncateVOS);
}
return deviceAbnormalVO;
}
/**
* 根据用户选择的时间区间返回月份日期
*/
@SneakyThrows
private List<String> getIntervalTime(String startTime, String endTime) {
List<String> times = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date start = sdf.parse(startTime);
Date end = sdf.parse(endTime);
// 同月
if (start.getTime() == end.getTime()) {
String time = startTime.substring(0, 7);
times.add(time);
} else if (start.getYear() == end.getYear()) {
// 同年
int startM = start.getMonth() + 1;
int endM = end.getMonth() + 1;
int temp = endM - startM;
for (int i = 0; i <= temp; i++) {
String time = start.getYear() + 1900 + "";
int month = startM + i;
if (month < 10) {
time = time + "-0" + month;
} else {
time = time + "-" + month;
}
times.add(time);
}
} else {
// 不同年!!!!这里忽略了年份之间跨年的情况
int startY = start.getYear() + 1900;
int startM = start.getMonth() + 1;
int endY = end.getYear() + 1900;
int endM = end.getMonth() + 1;
int tempS = 12 - startM;
// 连续的年份
if (endY - startY == 1) {
// 第一年的时间获取
for (int i = 0; i <= tempS; i++) {
int month = startM + i;
String time = startY + "-";
if (month < 10) {
time = time + "0" + month;
} else {
time = time + month;
}
times.add(time);
}
// 第二年的时间获取
for (int i = 1; i <= endM; i++) {
String time = endY + "-";
if (i < 10) {
time = time + "0" + i;
} else {
time = time + i;
}
times.add(time);
}
} else {
// 不连续的年份
// 第一年的时间获取
for (int i = 0; i <= tempS; i++) {
int month = startM + i;
String time = startY + "-";
if (month < 10) {
time = time + "0" + month;
} else {
time = time + month;
}
times.add(time);
}
int tempY = endY - startY;
// 中间年份的时间
for (int i = 1; i < tempY; i++) {
for (int j = 1; j <= 12; j++) {
String time = startY + i + "-";
if (j < 10) {
time = time + "0" + j;
} else {
time = time + j;
}
times.add(time);
}
}
// 最后一年的时间获取
for (int i = 1; i <= endM; i++) {
String time = endY + "-";
if (i < 10) {
time = time + "0" + i;
} else {
time = time + i;
}
times.add(time);
}
}
}
return times;
}
@SneakyThrows
private List<String> getIntervalDateTime(Integer startTime, Integer endTime,Integer dd) {
List<String> list = new ArrayList<>();
Calendar calendar = Calendar.getInstance(Locale.CHINA);
calendar.set(startTime, endTime - 1, 1);
int year = calendar.get(Calendar.YEAR);//年份
int month = calendar.get(Calendar.MONTH) + 1;//月份
for (int i = 1; i <= dd; i++) {
String date = null;
if (month < 10 && i < 10) {
date = year + "-0" + month + "-0" + i;
}
if (month < 10 && i >= 10) {
date = year + "-0" + month + "-" + i;
}
if (month >= 10 && i < 10) {
date = year + "-" + month + "-0" + i;
}
if (month >= 10 && i >= 10) {
date = year + "-" + month + "-" + i;
}
list.add(date);
}
return list;
}
public List<Communicate> getCommunicateAbnorm(List<String> lineIndex, String startTime, String endTime) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("(");
for (int i = 0; i < lineIndex.size(); i++) {
if (lineIndex.size() - i != 1) {
stringBuilder.append("line_id = '").append(lineIndex.get(i)).append("' or ");
} else {
stringBuilder.append("line_id = '").append(lineIndex.get(i)).append("')");
}
}
stringBuilder.append("and type = 0").append(" group by line_id ").append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where " + stringBuilder.toString();
QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<Communicate> communicateList = influxDBResultMapper.toPOJO(result, Communicate.class);
return communicateList;
}
}