|
|
|
|
@@ -3,33 +3,29 @@ package com.njcn.device.pq.service.impl;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.njcn.common.pojo.dto.SimpleDTO;
|
|
|
|
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|
|
|
|
import com.njcn.common.pojo.exception.BusinessException;
|
|
|
|
|
import com.njcn.device.pq.enums.DeviceResponseEnum;
|
|
|
|
|
import com.njcn.common.pojo.response.HttpResult;
|
|
|
|
|
import com.njcn.device.pq.mapper.TerminalMaintainMapper;
|
|
|
|
|
import com.njcn.device.pq.mapper.UserMapper;
|
|
|
|
|
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
|
|
|
|
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
|
|
|
|
import com.njcn.device.pq.pojo.param.PqsParam;
|
|
|
|
|
import com.njcn.device.pq.pojo.param.TerminalMainQueryParam;
|
|
|
|
|
import com.njcn.device.pq.pojo.param.TerminalParam;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.Communicate;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.DevMeal;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.DevStrategy;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.Device;
|
|
|
|
|
import com.njcn.device.pq.pojo.param.*;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.*;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.influxdb.DeviceDayFlow;
|
|
|
|
|
import com.njcn.device.pq.pojo.vo.LineFlowMealDetailVO;
|
|
|
|
|
import com.njcn.device.pq.pojo.vo.TerminalDaliyFlowVO;
|
|
|
|
|
import com.njcn.device.pq.pojo.vo.TerminalMaintainVO;
|
|
|
|
|
import com.njcn.device.pq.service.IDevMealService;
|
|
|
|
|
import com.njcn.device.pq.service.IDevStrategyService;
|
|
|
|
|
import com.njcn.device.pq.service.IDeviceService;
|
|
|
|
|
import com.njcn.device.pq.service.TerminalMaintainService;
|
|
|
|
|
import com.njcn.device.pq.service.*;
|
|
|
|
|
import com.njcn.influxdb.param.InfluxDBPublicParam;
|
|
|
|
|
import com.njcn.influxdb.utils.InfluxDbUtils;
|
|
|
|
|
import com.njcn.system.api.DicDataFeignClient;
|
|
|
|
|
import com.njcn.system.enums.DicDataEnum;
|
|
|
|
|
import com.njcn.system.pojo.enums.StatisticsEnum;
|
|
|
|
|
import com.njcn.system.pojo.po.DictData;
|
|
|
|
|
import com.njcn.user.api.DeptFeignClient;
|
|
|
|
|
import com.njcn.web.utils.RequestUtil;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
|
|
@@ -39,7 +35,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -47,6 +43,7 @@ import java.util.stream.Stream;
|
|
|
|
|
/**
|
|
|
|
|
* pqs
|
|
|
|
|
* 终端运维
|
|
|
|
|
*
|
|
|
|
|
* @author cdf
|
|
|
|
|
* @date 2022/5/11
|
|
|
|
|
*/
|
|
|
|
|
@@ -69,6 +66,12 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
|
|
|
|
|
private final InfluxDbUtils influxDbUtils;
|
|
|
|
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
|
|
|
|
private final DicDataFeignClient dicDataFeignClient;
|
|
|
|
|
|
|
|
|
|
private final IPqsTerminalLogsService iPqsTerminalLogsService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TerminalMaintainVO> getTerminalMainList(TerminalMainQueryParam terminalMainQueryParam) {
|
|
|
|
|
List<TerminalMaintainVO> resList = new ArrayList<>();
|
|
|
|
|
@@ -79,10 +82,10 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
SimpleDTO simpleDTO = new SimpleDTO();
|
|
|
|
|
simpleDTO.setCode(StatisticsEnum.POWER_NETWORK.getCode());
|
|
|
|
|
deviceInfoParam.setStatisticalType(simpleDTO);
|
|
|
|
|
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(deviceInfoParam, Objects.isNull(terminalMainQueryParam.getRunFlag())?null: CollUtil.newArrayList(terminalMainQueryParam.getRunFlag()), CollUtil.newArrayList(1));
|
|
|
|
|
if(CollectionUtil.isNotEmpty(generalDeviceDTOList)){
|
|
|
|
|
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(deviceInfoParam, Objects.isNull(terminalMainQueryParam.getRunFlag()) ? null : CollUtil.newArrayList(terminalMainQueryParam.getRunFlag()), CollUtil.newArrayList(1));
|
|
|
|
|
if (CollectionUtil.isNotEmpty(generalDeviceDTOList)) {
|
|
|
|
|
|
|
|
|
|
for(GeneralDeviceDTO generalDeviceDTO:generalDeviceDTOList){
|
|
|
|
|
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
|
|
|
|
|
List<String> devIds = generalDeviceDTO.getDeviceIndexes();
|
|
|
|
|
if (CollectionUtils.isEmpty(devIds)) {
|
|
|
|
|
continue;
|
|
|
|
|
@@ -97,29 +100,30 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
List<TerminalMaintainVO> subList = terminalMaintainMapper.getPqLineGdAndSubList(generalDeviceDTO.getSubIndexes());
|
|
|
|
|
List<TerminalMaintainVO> gdList = terminalMaintainMapper.getPqLineGdAndSubList(generalDeviceDTO.getGdIndexes());
|
|
|
|
|
|
|
|
|
|
dealTerminalData(subList,devList);
|
|
|
|
|
dealTerminalData(gdList,subList);
|
|
|
|
|
dealTerminalData(subList, devList);
|
|
|
|
|
dealTerminalData(gdList, subList);
|
|
|
|
|
terminalMaintainVO.setChildren(gdList);
|
|
|
|
|
resList.add(terminalMaintainVO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resList;
|
|
|
|
|
}
|
|
|
|
|
List<TerminalMaintainVO> dealTerminalData(List<TerminalMaintainVO> parent,List<TerminalMaintainVO> children){
|
|
|
|
|
return parent.stream().peek(item->item.setChildren(getChildren(item.getId(),children))).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<TerminalMaintainVO> dealTerminalData(List<TerminalMaintainVO> parent, List<TerminalMaintainVO> children) {
|
|
|
|
|
return parent.stream().peek(item -> item.setChildren(getChildren(item.getId(), children))).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TerminalMaintainVO> getManageList(List<String> ids, Integer type) {
|
|
|
|
|
if(type == 0){
|
|
|
|
|
if (type == 0) {
|
|
|
|
|
//终端状态管理
|
|
|
|
|
List<TerminalMaintainVO> devList = terminalMaintainMapper.getRunFlagList(ids);
|
|
|
|
|
return assemble(devList);
|
|
|
|
|
}else if(type == 1){
|
|
|
|
|
} else if (type == 1) {
|
|
|
|
|
//流量套餐
|
|
|
|
|
List<TerminalMaintainVO> devList = terminalMaintainMapper.getFlowMealList(ids);
|
|
|
|
|
return assemble(devList);
|
|
|
|
|
}else if(type == 2){
|
|
|
|
|
} else if (type == 2) {
|
|
|
|
|
//流量策略
|
|
|
|
|
List<TerminalMaintainVO> devList = terminalMaintainMapper.getFlowStrategyList(ids);
|
|
|
|
|
return assemble(devList);
|
|
|
|
|
@@ -129,36 +133,98 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateRunFlagManage(TerminalParam terminalParam) {
|
|
|
|
|
//终端状态管理
|
|
|
|
|
List<Device> tem = new ArrayList<>();
|
|
|
|
|
terminalParam.getIds().forEach(item-> {
|
|
|
|
|
Device device = new Device();
|
|
|
|
|
device.setId(item);
|
|
|
|
|
device.setRunFlag(terminalParam.getRunFlag());
|
|
|
|
|
tem.add(device);
|
|
|
|
|
});
|
|
|
|
|
return iDeviceService.updateBatchById(tem);
|
|
|
|
|
//终端状态管理
|
|
|
|
|
List<Device> tem = new ArrayList<>();
|
|
|
|
|
terminalParam.getIds().forEach(item -> {
|
|
|
|
|
Device device = new Device();
|
|
|
|
|
device.setId(item);
|
|
|
|
|
device.setRunFlag(terminalParam.getRunFlag());
|
|
|
|
|
tem.add(device);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QueryWrapper<Device> wrapper = new QueryWrapper<>();
|
|
|
|
|
List<String> idList = tem.stream().map(Device::getId).collect(Collectors.toList());
|
|
|
|
|
wrapper.in("id", idList);
|
|
|
|
|
List<Device> newList = iDeviceService.list(wrapper);
|
|
|
|
|
boolean b = iDeviceService.updateBatchById(tem);
|
|
|
|
|
//添加日志信息
|
|
|
|
|
if (b) {
|
|
|
|
|
List<Device> oldList = iDeviceService.list(wrapper);
|
|
|
|
|
for (Device device : newList) {
|
|
|
|
|
for (Device device1 : oldList) {
|
|
|
|
|
//如果设备id相同,终端运行状态不同
|
|
|
|
|
if (Objects.equals(device1.getId(), device.getId()) && !Objects.equals(device1.getRunFlag(), device.getRunFlag())) {
|
|
|
|
|
//获取用户信息
|
|
|
|
|
String userName = RequestUtil.getUsername();
|
|
|
|
|
String loginName = RequestUtil.getLoginName();
|
|
|
|
|
//String userName = "zbj";
|
|
|
|
|
//String loginName = "njcnser";
|
|
|
|
|
//获取上级信息
|
|
|
|
|
SuperDataParam superDataParam = userMapper.getDeviceSuper(device.getId());
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(userName).append("修改了").append(superDataParam.getUrbanName()).append(" - ")
|
|
|
|
|
.append(superDataParam.getSubName()).append(" - ").append(superDataParam.getDevName()).append(" - 设备的参数;");
|
|
|
|
|
|
|
|
|
|
StringBuilder sbNew = new StringBuilder();
|
|
|
|
|
StringBuilder sbOld = new StringBuilder();
|
|
|
|
|
sbNew.append("操作历史,");
|
|
|
|
|
sbOld.append("修改后参数,");
|
|
|
|
|
String newFlag = "";
|
|
|
|
|
String oldFlag = "";
|
|
|
|
|
if (device.getRunFlag() == 0) {
|
|
|
|
|
newFlag = "投运";
|
|
|
|
|
}else if (device.getRunFlag() == 1){
|
|
|
|
|
newFlag = "热备用";
|
|
|
|
|
}else if (device.getRunFlag() == 2){
|
|
|
|
|
newFlag = "停运";
|
|
|
|
|
}
|
|
|
|
|
if (device1.getRunFlag() == 0) {
|
|
|
|
|
oldFlag = "投运";
|
|
|
|
|
}else if (device1.getRunFlag() == 1){
|
|
|
|
|
oldFlag = "热备用";
|
|
|
|
|
}else if (device1.getRunFlag() == 2){
|
|
|
|
|
oldFlag = "停运";
|
|
|
|
|
}
|
|
|
|
|
sbNew.append("终端运行状态: ").append(newFlag).append(";");
|
|
|
|
|
sbOld.append("终端运行状态: ").append(oldFlag).append(";");
|
|
|
|
|
sb.append(sbNew).append(sbOld);
|
|
|
|
|
HttpResult<DictData> dicDataByCode = dicDataFeignClient.getDicDataByCode(DicDataEnum.LINE_PARAMETER.getCode());
|
|
|
|
|
DictData data = dicDataByCode.getData();
|
|
|
|
|
//创建对象
|
|
|
|
|
PqsTerminalLogs terminalLogsNew = new PqsTerminalLogs();
|
|
|
|
|
terminalLogsNew.setObjIndex(device.getId());
|
|
|
|
|
terminalLogsNew.setTerminalDescribe(sb.toString());
|
|
|
|
|
terminalLogsNew.setCreateBy(loginName);
|
|
|
|
|
terminalLogsNew.setCreateTime(LocalDateTime.now());
|
|
|
|
|
terminalLogsNew.setTerminalType(data.getId());
|
|
|
|
|
terminalLogsNew.setState(1);
|
|
|
|
|
iPqsTerminalLogsService.save(terminalLogsNew);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateFlowMeal(TerminalParam terminalParam) {
|
|
|
|
|
List<DevMeal> tem = new ArrayList<>();
|
|
|
|
|
iDevMealService.removeByIds(terminalParam.getIds());
|
|
|
|
|
terminalParam.getIds().forEach(item-> {
|
|
|
|
|
terminalParam.getIds().forEach(item -> {
|
|
|
|
|
DevMeal devMeal = new DevMeal();
|
|
|
|
|
devMeal.setLineId(item);
|
|
|
|
|
devMeal.setBaseMealId(terminalParam.getBaseMealId());
|
|
|
|
|
devMeal.setReamMealId(terminalParam.getExtendMealId());
|
|
|
|
|
tem.add(devMeal);
|
|
|
|
|
});
|
|
|
|
|
return iDevMealService.saveBatch(tem);
|
|
|
|
|
return iDevMealService.saveBatch(tem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateFlowStrategy(TerminalParam terminalParam) {
|
|
|
|
|
List<DevStrategy> tem = new ArrayList<>();
|
|
|
|
|
iDevStrategyService.removeByIds(terminalParam.getIds());
|
|
|
|
|
terminalParam.getIds().forEach(item-> {
|
|
|
|
|
terminalParam.getIds().forEach(item -> {
|
|
|
|
|
DevStrategy devStrategy = new DevStrategy();
|
|
|
|
|
devStrategy.setLineId(item);
|
|
|
|
|
devStrategy.setStrategyId(terminalParam.getFlowStrategyId());
|
|
|
|
|
@@ -189,11 +255,11 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
List<String> deviceIndexes = new ArrayList<>();
|
|
|
|
|
List<GeneralDeviceDTO> deviceInfoList = generalDeviceService.getDeviceInfo(deviceInfoParam, null, Stream.of(1).collect(Collectors.toList()));
|
|
|
|
|
deviceInfoList.stream().map(GeneralDeviceDTO::getDeviceIndexes).forEach(deviceIndexes::addAll);
|
|
|
|
|
List<LineFlowMealDetailVO> list = terminalMaintainMapper.getMonthFlow(deviceIndexes,DateUtil.beginOfDay(DateUtil.parse(deviceInfoParam.getSearchBeginTime())),DateUtil.endOfDay(DateUtil.parse(deviceInfoParam.getSearchEndTime())));
|
|
|
|
|
List<LineFlowMealDetailVO> list = terminalMaintainMapper.getMonthFlow(deviceIndexes, DateUtil.beginOfDay(DateUtil.parse(deviceInfoParam.getSearchBeginTime())), DateUtil.endOfDay(DateUtil.parse(deviceInfoParam.getSearchEndTime())));
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DeviceDayFlow> getFlowManageDetailFromInfluxDB (TerminalMainQueryParam param) {
|
|
|
|
|
private List<DeviceDayFlow> getFlowManageDetailFromInfluxDB(TerminalMainQueryParam param) {
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(param.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(param.getSearchEndTime()))).append("' and ");
|
|
|
|
|
stringBuilder.append("dev_id ='").append(param.getDevId()).append("'");
|
|
|
|
|
@@ -202,13 +268,13 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
|
|
|
|
|
List<DeviceDayFlow> deviceDayFlow = influxDBResultMapper.toPOJO(result, DeviceDayFlow.class);
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
deviceDayFlow.forEach(t-> t.setDate(formatter.format(Date.from(t.getTime()))));
|
|
|
|
|
deviceDayFlow.forEach(t -> t.setDate(formatter.format(Date.from(t.getTime()))));
|
|
|
|
|
Map<String, List<DeviceDayFlow>> dayFlowMap = deviceDayFlow.stream().collect(Collectors.groupingBy(DeviceDayFlow::getDate));
|
|
|
|
|
List<DeviceDayFlow> list = new ArrayList<>();
|
|
|
|
|
for (Map.Entry<String, List<DeviceDayFlow>> entry : dayFlowMap.entrySet()) {
|
|
|
|
|
DeviceDayFlow dayFlow = new DeviceDayFlow();
|
|
|
|
|
dayFlow.setDevId(entry.getValue().get(0).getDevId());
|
|
|
|
|
BigDecimal bigDecimal = new BigDecimal((float) entry.getValue().stream().mapToInt(DeviceDayFlow::getActualValue).sum() / (float)1024 /(float) 1024);
|
|
|
|
|
BigDecimal bigDecimal = new BigDecimal((float) entry.getValue().stream().mapToInt(DeviceDayFlow::getActualValue).sum() / (float) 1024 / (float) 1024);
|
|
|
|
|
dayFlow.setDailyActualValue(bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
|
|
|
|
|
dayFlow.setDate(entry.getKey());
|
|
|
|
|
list.add(dayFlow);
|
|
|
|
|
@@ -218,25 +284,22 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TerminalMaintainVO> getChildren(String id,List<TerminalMaintainVO> all){
|
|
|
|
|
return all.stream().filter(item->item.getPid().equals(id)).collect(Collectors.toList());
|
|
|
|
|
private List<TerminalMaintainVO> getChildren(String id, List<TerminalMaintainVO> all) {
|
|
|
|
|
return all.stream().filter(item -> item.getPid().equals(id)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TerminalMaintainVO> assemble(List<TerminalMaintainVO> devList){
|
|
|
|
|
List<String> subIds = devList.stream().map(TerminalMaintainVO::getPid).collect(Collectors.toList());
|
|
|
|
|
private List<TerminalMaintainVO> assemble(List<TerminalMaintainVO> devList) {
|
|
|
|
|
List<String> subIds = devList.stream().map(TerminalMaintainVO::getPid).collect(Collectors.toList());
|
|
|
|
|
List<TerminalMaintainVO> subList = terminalMaintainMapper.getPqLineGdAndSubList(subIds);
|
|
|
|
|
List<String> gdIds = subList.stream().map(TerminalMaintainVO::getPid).collect(Collectors.toList());
|
|
|
|
|
List<String> gdIds = subList.stream().map(TerminalMaintainVO::getPid).collect(Collectors.toList());
|
|
|
|
|
List<TerminalMaintainVO> gdList = terminalMaintainMapper.getPqLineGdAndSubList(gdIds);
|
|
|
|
|
List<String> proIds = gdList.stream().map(TerminalMaintainVO::getPid).collect(Collectors.toList());
|
|
|
|
|
List<String> proIds = gdList.stream().map(TerminalMaintainVO::getPid).collect(Collectors.toList());
|
|
|
|
|
List<TerminalMaintainVO> provList = terminalMaintainMapper.getPqLineProvList(proIds);
|
|
|
|
|
|
|
|
|
|
List<TerminalMaintainVO> subTem = subList.stream().peek(item->item.setChildren(getChildren(item.getId(),devList))).collect(Collectors.toList());
|
|
|
|
|
List<TerminalMaintainVO> gdTem = gdList.stream().peek(item->item.setChildren(getChildren(item.getId(),subTem))).collect(Collectors.toList());
|
|
|
|
|
return provList.stream().peek(item->item.setChildren(getChildren(item.getId(),gdTem))).collect(Collectors.toList());
|
|
|
|
|
List<TerminalMaintainVO> subTem = subList.stream().peek(item -> item.setChildren(getChildren(item.getId(), devList))).collect(Collectors.toList());
|
|
|
|
|
List<TerminalMaintainVO> gdTem = gdList.stream().peek(item -> item.setChildren(getChildren(item.getId(), subTem))).collect(Collectors.toList());
|
|
|
|
|
return provList.stream().peek(item -> item.setChildren(getChildren(item.getId(), gdTem))).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|