|
|
|
@ -5,10 +5,13 @@ import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import com.shxy.xymanager_common.bean.ServiceBody;
|
|
|
|
|
import com.shxy.xymanager_common.dto.DyLineAndTerminalWithHeartDto;
|
|
|
|
|
import com.shxy.xymanager_common.dto.*;
|
|
|
|
|
import com.shxy.xymanager_common.entity.DyLevel;
|
|
|
|
|
import com.shxy.xymanager_common.dto.TerminalsWithHeart;
|
|
|
|
|
import com.shxy.xymanager_common.entity.TerminalStatus;
|
|
|
|
|
import com.shxy.xymanager_common.entity.Terminals;
|
|
|
|
|
import com.shxy.xymanager_common.enums.CommonStatus;
|
|
|
|
|
import com.shxy.xymanager_common.exception.Asserts;
|
|
|
|
|
import com.shxy.xymanager_common.model.DyLineTreeListModel;
|
|
|
|
@ -16,6 +19,9 @@ import com.shxy.xymanager_common.model.DyListModel;
|
|
|
|
|
import com.shxy.xymanager_common.util.MyDateUtils;
|
|
|
|
|
import com.shxy.xymanager_common.vo.TestVo;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.DyLevelDao;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.TerminalStatusDao;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.TerminalsDao;
|
|
|
|
|
import com.shxy.xymanager_service.service.CacheService;
|
|
|
|
|
import com.shxy.xymanager_service.service.DyLevelService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -25,6 +31,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 装置通道实现层
|
|
|
|
@ -39,6 +47,12 @@ public class DyLevelServiceImpl implements DyLevelService {
|
|
|
|
|
@Value("${heart.time}")
|
|
|
|
|
public Integer hearttime;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
CacheService cacheService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TerminalsDao terminalsDao;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取电压线路树状接口
|
|
|
|
|
*
|
|
|
|
@ -47,13 +61,15 @@ public class DyLevelServiceImpl implements DyLevelService {
|
|
|
|
|
@Override
|
|
|
|
|
public ServiceBody<DyLineTreeListModel> getdyTreeList() {
|
|
|
|
|
DyLineTreeListModel model = new DyLineTreeListModel();
|
|
|
|
|
List<DyLineAndTerminalWithHeartDto> list = dyLevelDao.selectTreeList(CommonStatus.EFFECTIVE.value());
|
|
|
|
|
/*List<DyLineAndTerminalWithHeartDto> list = dyLevelDao.selectTreeList(CommonStatus.EFFECTIVE.value());*/
|
|
|
|
|
List<DyLineAndTerminalWithHeartDto> list = Lists.newArrayList();
|
|
|
|
|
getDyList(list);
|
|
|
|
|
boolean empty = CollectionUtil.isEmpty(list);
|
|
|
|
|
if (empty) {
|
|
|
|
|
model.setList(new ArrayList<>());
|
|
|
|
|
} else {
|
|
|
|
|
List<DyLineTreeListModel.DyListBean> beans = BeanUtil.copyToList(list, DyLineTreeListModel.DyListBean.class, CopyOptions.create().ignoreCase());
|
|
|
|
|
for (int i = 0; i < beans.size(); i++) {
|
|
|
|
|
/*for (int i = 0; i < beans.size(); i++) {
|
|
|
|
|
for (int j = 0; j < beans.get(i).getList().size(); j++) {
|
|
|
|
|
for (int k = 0; k < beans.get(i).getList().get(j).getList().size(); k++) {
|
|
|
|
|
// beans.get(i).getList().get(j).getList().get(k).setName(list.get(i).getList().get(j).getList().get(k).getDisplayName());
|
|
|
|
@ -73,12 +89,69 @@ public class DyLevelServiceImpl implements DyLevelService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
model.setList(beans);
|
|
|
|
|
}
|
|
|
|
|
return Asserts.success(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void getDyList(List<DyLineAndTerminalWithHeartDto> list) {
|
|
|
|
|
List<LineAndTerminalWithHeartDto> lineList = Lists.newArrayList();
|
|
|
|
|
Map<Integer, Terminals> terminalsMap = cacheService.getTerminalMap();
|
|
|
|
|
List<Terminals> termList = terminalsMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
Map<Integer, TerminalStatus> statusMap = Maps.newHashMap();
|
|
|
|
|
List<TerminalStatus> terminalStatusDtos = terminalsDao.getTerminalStatus(termList);
|
|
|
|
|
for (TerminalStatus status : terminalStatusDtos) {
|
|
|
|
|
statusMap.put(status.getTermId(), status);
|
|
|
|
|
}
|
|
|
|
|
Map<Integer, TowerDto> towerMap = cacheService.getTowerMap();
|
|
|
|
|
List<TowerDto> towerList = towerMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
Map<Integer, TowerDto> towerByLineMap = Maps.newHashMap();
|
|
|
|
|
for (TowerDto item : towerList) {
|
|
|
|
|
towerByLineMap.put(item.getLineId(), item);
|
|
|
|
|
}
|
|
|
|
|
termList.stream().forEach(var->{
|
|
|
|
|
if(null!=statusMap.get(var.getId())&&null!=statusMap.get(var.getId()).getLastHeartbeat()) {
|
|
|
|
|
long time = MyDateUtils.TimeSecond2MillSecond(statusMap.get(var.getId()).getLastHeartbeat().longValue());
|
|
|
|
|
DateTime date = MyDateUtils.date(time);
|
|
|
|
|
long between = MyDateUtils.between(MyDateUtils.getNowDate(), date, DateUnit.MINUTE);
|
|
|
|
|
if (between > hearttime) {
|
|
|
|
|
var.setOnlinestatus(CommonStatus.DELETE.value());
|
|
|
|
|
} else {
|
|
|
|
|
var.setOnlinestatus(CommonStatus.EFFECTIVE.value());
|
|
|
|
|
}
|
|
|
|
|
var.setLastheartbeat(statusMap.get(var.getId()).getLastHeartbeat().longValue());
|
|
|
|
|
}
|
|
|
|
|
if(null!=towerByLineMap.get(var.getLineid())) {
|
|
|
|
|
var.setTowerid(towerByLineMap.get(var.getLineid()).getId());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Map<Integer, List<Terminals>> termByLineIdMap = termList.stream().collect(Collectors.groupingBy(Terminals::getLineid));
|
|
|
|
|
Map<Integer, List<LineAndDyNameDto>> map = cacheService.getDyMap();
|
|
|
|
|
map.forEach((key, value) -> {
|
|
|
|
|
DyLineAndTerminalWithHeartDto dyDto = new DyLineAndTerminalWithHeartDto();
|
|
|
|
|
dyDto.setId(key);
|
|
|
|
|
dyDto.setName(value.get(0).getName());
|
|
|
|
|
dyDto.setDyValue(value.get(0).getDyValue());
|
|
|
|
|
for(LineAndDyNameDto line:value) {
|
|
|
|
|
List<TerminalsWithHeart> terminalList = Lists.newArrayList();
|
|
|
|
|
if(null!=termByLineIdMap.get(line.getId())) {
|
|
|
|
|
terminalList = BeanUtil.copyToList(termByLineIdMap.get(line.getId()), TerminalsWithHeart.class, CopyOptions.create().ignoreCase());
|
|
|
|
|
}
|
|
|
|
|
LineAndTerminalWithHeartDto lineDto = new LineAndTerminalWithHeartDto();
|
|
|
|
|
lineDto.setBsManufacturer(line.getBsManufacturer());
|
|
|
|
|
lineDto.setDyLevel(line.getDyLevelId());
|
|
|
|
|
lineDto.setName(line.getName());
|
|
|
|
|
lineDto.setId(line.getId());
|
|
|
|
|
lineDto.setList(terminalList);
|
|
|
|
|
lineList.add(lineDto);
|
|
|
|
|
}
|
|
|
|
|
dyDto.setList(lineList);
|
|
|
|
|
list.add(dyDto);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取电压等级列表
|
|
|
|
|