|
|
@ -1,13 +1,28 @@ |
|
|
|
package com.hnac.hzims.business.interruption.service.impl; |
|
|
|
package com.hnac.hzims.business.interruption.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.hnac.hzims.business.interruption.entity.InterruptionEntity; |
|
|
|
import com.hnac.hzims.business.interruption.entity.InterruptionEntity; |
|
|
|
import com.hnac.hzims.business.interruption.mapper.InterruptionMapper; |
|
|
|
import com.hnac.hzims.business.interruption.mapper.InterruptionMapper; |
|
|
|
import com.hnac.hzims.business.interruption.service.InterruptionService; |
|
|
|
import com.hnac.hzims.business.interruption.service.InterruptionService; |
|
|
|
|
|
|
|
import com.hnac.hzims.business.interruption.vo.InterruptionDetailVo; |
|
|
|
|
|
|
|
import com.hnac.hzims.business.interruption.vo.InterruptionParamVo; |
|
|
|
|
|
|
|
import com.hnac.hzims.business.interruption.vo.InterruptionStationVo; |
|
|
|
|
|
|
|
import com.hnac.hzims.business.interruption.vo.InterruptionVo; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author ysj |
|
|
|
* @author ysj |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -16,4 +31,178 @@ import org.springframework.stereotype.Service; |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class InterruptionServiceImpl extends BaseServiceImpl<InterruptionMapper, InterruptionEntity> implements InterruptionService { |
|
|
|
public class InterruptionServiceImpl extends BaseServiceImpl<InterruptionMapper, InterruptionEntity> implements InterruptionService { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
|
|
|
|
* 数据中断站点查询 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public List<InterruptionStationVo> interruptionStations() { |
|
|
|
|
|
|
|
return this.baseMapper.interruptionStations(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 数据中断统计 |
|
|
|
|
|
|
|
* @param page |
|
|
|
|
|
|
|
* @param param |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public IPage<InterruptionVo> pageCondition(IPage<InterruptionVo> page, InterruptionParamVo param) { |
|
|
|
|
|
|
|
QueryWrapper<InterruptionEntity> queryWrapper = new QueryWrapper(); |
|
|
|
|
|
|
|
queryWrapper.lambda().in(InterruptionEntity::getType,param.getType()); |
|
|
|
|
|
|
|
queryWrapper.lambda().ge(InterruptionEntity::getCreateTime,param.getStartTime()); |
|
|
|
|
|
|
|
queryWrapper.lambda().le(InterruptionEntity::getCreateTime,param.getEndTime()); |
|
|
|
|
|
|
|
queryWrapper.lambda().orderByAsc(InterruptionEntity::getAlarmTime); |
|
|
|
|
|
|
|
if(!StringUtil.isEmpty(param.getStationId())){ |
|
|
|
|
|
|
|
queryWrapper.lambda().eq(InterruptionEntity::getStationId,param.getStationId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<InterruptionEntity> interruptions = this.list(queryWrapper); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(interruptions)){ |
|
|
|
|
|
|
|
return page; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 根据站点分组
|
|
|
|
|
|
|
|
Map<String,List<InterruptionEntity>> map = interruptions.stream().collect(Collectors.groupingBy(InterruptionEntity::getStationId)); |
|
|
|
|
|
|
|
List<InterruptionVo> list = map.entrySet().stream().map(entry -> { |
|
|
|
|
|
|
|
InterruptionVo interruption = new InterruptionVo(); |
|
|
|
|
|
|
|
interruption.setStationId(entry.getKey()); |
|
|
|
|
|
|
|
interruption.setStationName(entry.getValue().get(0).getStationName()); |
|
|
|
|
|
|
|
interruption.setCount((int) entry.getValue().stream().filter(o-> o.getStatus().equals(0)).count()); |
|
|
|
|
|
|
|
long time = innterruptionTime(entry.getValue().stream().sorted(Comparator.comparing(InterruptionEntity::getAlarmTime)).collect(Collectors.toList()), DateUtil.parse(param.getStartTime(),DateUtil.PATTERN_DATETIME),DateUtil.parse(param.getEndTime(),DateUtil.PATTERN_DATETIME)); |
|
|
|
|
|
|
|
interruption.setDuration(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
|
|
|
|
|
|
|
return interruption; |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
page.setTotal(map.size()); |
|
|
|
|
|
|
|
page.setRecords(list.stream().sorted(Comparator.comparing(InterruptionVo::getStationId)).skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList())); |
|
|
|
|
|
|
|
return page; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取中断时长 |
|
|
|
|
|
|
|
* @param interruptions |
|
|
|
|
|
|
|
* @param startDate |
|
|
|
|
|
|
|
* @param endDate |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private long innterruptionTime(List<InterruptionEntity> interruptions, Date startDate, Date endDate) { |
|
|
|
|
|
|
|
if(interruptions.size() == 1){ |
|
|
|
|
|
|
|
// 一直中断
|
|
|
|
|
|
|
|
if(interruptions.get(0).getStatus() == 0){ |
|
|
|
|
|
|
|
return endDate.getTime() - interruptions.get(0).getAlarmTime().getTime(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 一直恢复
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
long time=0; |
|
|
|
|
|
|
|
// 遍历累计中断时长
|
|
|
|
|
|
|
|
for(int i = 0; i< interruptions.size() ; i++){ |
|
|
|
|
|
|
|
// 记录为恢复状态 就计算到下次关机的时间差
|
|
|
|
|
|
|
|
if(interruptions.get(i).getStatus() == 1){ |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Date endTime,startTime = interruptions.get(i).getAlarmTime(); |
|
|
|
|
|
|
|
// 遍历至最后一条数据,累计至当前时间
|
|
|
|
|
|
|
|
if(i == interruptions.size() - 1){ |
|
|
|
|
|
|
|
endTime = endDate; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
endTime = interruptions.get(i+1).getAlarmTime(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
time += endTime.getTime() - startTime.getTime(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return time; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 站点数据中断统计详情 |
|
|
|
|
|
|
|
* @param page |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public IPage<InterruptionDetailVo> pageConditionDetail(IPage<InterruptionDetailVo> page, InterruptionParamVo param) { |
|
|
|
|
|
|
|
// 获取中断告警数据
|
|
|
|
|
|
|
|
QueryWrapper<InterruptionEntity> queryWrapper = new QueryWrapper(); |
|
|
|
|
|
|
|
queryWrapper.lambda().in(InterruptionEntity::getType,param.getType()); |
|
|
|
|
|
|
|
queryWrapper.lambda().ge(InterruptionEntity::getCreateTime,param.getStartTime()); |
|
|
|
|
|
|
|
queryWrapper.lambda().le(InterruptionEntity::getCreateTime,param.getEndTime()); |
|
|
|
|
|
|
|
queryWrapper.lambda().orderByAsc(InterruptionEntity::getAlarmTime); |
|
|
|
|
|
|
|
if(!StringUtil.isEmpty(param.getStationId())){ |
|
|
|
|
|
|
|
queryWrapper.lambda().eq(InterruptionEntity::getStationId,param.getStationId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<InterruptionEntity> interruptions = this.list(queryWrapper); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(interruptions)){ |
|
|
|
|
|
|
|
new ArrayList<>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 数据整理
|
|
|
|
|
|
|
|
List<InterruptionDetailVo> details = this.collation(interruptions,param.getStartTime(),param.getEndTime()); |
|
|
|
|
|
|
|
page.setTotal(details.size()); |
|
|
|
|
|
|
|
page.setRecords(details.stream().sorted(Comparator.comparing(InterruptionDetailVo::getStart)).skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList())); |
|
|
|
|
|
|
|
return page; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 告警数据整理 |
|
|
|
|
|
|
|
* @param interruptions |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private List<InterruptionDetailVo> collation(List<InterruptionEntity> interruptions,String startTime,String endTime) { |
|
|
|
|
|
|
|
List<InterruptionEntity> collations = new ArrayList<>(); |
|
|
|
|
|
|
|
// 遍历数据
|
|
|
|
|
|
|
|
for(int i = 0; i< interruptions.size() ; i++){ |
|
|
|
|
|
|
|
// 第一个数据保存下来
|
|
|
|
|
|
|
|
if(i == 0){ |
|
|
|
|
|
|
|
collations.add(interruptions.get(i)); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 遍历数据状态
|
|
|
|
|
|
|
|
Integer status = interruptions.get(i).getStatus(); |
|
|
|
|
|
|
|
// 上一条数据状态
|
|
|
|
|
|
|
|
Integer up_status = interruptions.get(i-1).getStatus(); |
|
|
|
|
|
|
|
if(status.equals(up_status)){ |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
collations.add(interruptions.get(i)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 返回数据集合
|
|
|
|
|
|
|
|
List<InterruptionDetailVo> details = new ArrayList<>(); |
|
|
|
|
|
|
|
int j = 0; |
|
|
|
|
|
|
|
if(1 == collations.get(0).getStatus()){ |
|
|
|
|
|
|
|
j = 1; |
|
|
|
|
|
|
|
for(;j < collations.size() ;j++){ |
|
|
|
|
|
|
|
if(j % 2 == 1){ |
|
|
|
|
|
|
|
InterruptionDetailVo detail = new InterruptionDetailVo(); |
|
|
|
|
|
|
|
detail.setType(collations.get(j).getType()); |
|
|
|
|
|
|
|
detail.setStationId(collations.get(j).getStationId()); |
|
|
|
|
|
|
|
detail.setStationName(collations.get(j).getStationName()); |
|
|
|
|
|
|
|
detail.setStart(collations.get(j).getAlarmTime()); |
|
|
|
|
|
|
|
if( j + 1 == collations.size()){ |
|
|
|
|
|
|
|
detail.setEnd(DateUtil.parse(endTime,DateUtil.PATTERN_DATETIME)); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
detail.setEnd(collations.get(j + 1).getAlarmTime()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
long time = detail.getEnd().getTime() - detail.getStart().getTime(); |
|
|
|
|
|
|
|
detail.setDuration(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
|
|
|
|
|
|
|
details.add(detail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
for(;j < collations.size() ;j++){ |
|
|
|
|
|
|
|
if(j % 2 == 0){ |
|
|
|
|
|
|
|
InterruptionDetailVo detail = new InterruptionDetailVo(); |
|
|
|
|
|
|
|
detail.setType(collations.get(j).getType()); |
|
|
|
|
|
|
|
detail.setStationId(collations.get(j).getStationId()); |
|
|
|
|
|
|
|
detail.setStationName(collations.get(j).getStationName()); |
|
|
|
|
|
|
|
detail.setStart(collations.get(j).getAlarmTime()); |
|
|
|
|
|
|
|
if( j + 1 == collations.size()){ |
|
|
|
|
|
|
|
detail.setEnd(DateUtil.parse(endTime,DateUtil.PATTERN_DATETIME)); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
detail.setEnd(collations.get(j + 1).getAlarmTime()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
long time = detail.getEnd().getTime() - detail.getStart().getTime(); |
|
|
|
|
|
|
|
detail.setDuration(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
|
|
|
|
|
|
|
details.add(detail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return details; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|