济菏高速数据中心代码

488 lines
27 KiB

package com.zc.business.controller;
import com.github.pagehelper.util.StringUtil;
import com.ruoyi.common.annotation.Log;
1 year ago
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
1 year ago
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcRoadSection;
import com.zc.business.domain.Status;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcRoadSectionService;
import com.zc.business.service.impl.DcDeviceServiceImpl;
import com.zc.business.service.impl.StatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
1 year ago
@Api(tags = "设备状态")
@RestController
9 months ago
//@RequestMapping("/system/status")
1 year ago
public class StatusController extends BaseController {
@Autowired
private StatusService statusService;
@Autowired
private DcDeviceServiceImpl dcDeviceService;
@Resource
private RedisCache redisCache;
@Resource
private IDcRoadSectionService dcRoadSectionService;
private static final String ORDERRULE = "orderRule";//排序策略key
//设备列表
1 year ago
@ApiOperation("设备状态列表按时间和类型")
@GetMapping("/tablist")
public TableDataInfo getTabList(Status status) {
if (status.getDeviceName() != null) {
status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
}
startPage();
String type = status.getType();
if (type != null) {
status.setTypes(type.split(UniversalEnum.COMMA.getValue()));
}
List<Status> listStatus = statusService.listStatusByTypes(status);
1 year ago
return getDataTable(listStatus);
}
/**
* 导出请填写功能名称列表
*/
@ApiOperation("设备状态导出")
@Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Status status) {
if (status.getDeviceName() != null) {
status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
}
String type = status.getType();
if (type != null) {
status.setTypes(type.split(UniversalEnum.COMMA.getValue()));
}
List<Status> listStatus = statusService.export(status);
ExcelUtil<Status> util = new ExcelUtil<>(Status.class);
util.exportExcel(response, listStatus, UniversalEnum.DEVICE_STATUS_LIST.getValue());
}
//按时间划分设备柱状图
1 year ago
@ApiOperation("设备状态柱状图按时间和类型")
@GetMapping("/list")
public AjaxResult getStatusList(Status status) {
if (status.getDeviceName() != null) {
status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
}
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(UniversalEnum.ONE.getNumber());
status.setStartTime(todayStart);
status.setTime(currentTime);
String statusType = status.getType();
String[] types = null;
if (statusType != null) {
types = statusType.split(UniversalEnum.COMMA.getValue());
status.setTypes(types);
}
Map<String, Map<String, String>> maps = new HashMap<>();
List<Status> statuses = statusService.getStatusList(status);
if (types != null) {
for (String type : types) {
Map<String, String> collect = statuses.stream().filter(item -> Objects.equals(item.getType(), type))
.collect(Collectors.toMap(
item -> item.getTime().getYear() + UniversalEnum.SHORT_BAR.getValue() + item.getTime().getMonthValue() + UniversalEnum.SHORT_BAR.getValue() + item.getTime().getDayOfMonth(),
Status::getSuccessRate
));
maps.put(type, collect);
}
}
return AjaxResult.success(maps);
}
//按时间划分设备柱状图
@ApiOperation("更新缓存规则")
@GetMapping("/rule")
public AjaxResult setRule(String rule) {
redisCache.setCacheObject(ORDERRULE, rule);
return AjaxResult.success();
}
@ApiOperation("根据设备Id查询折线图数据")
@GetMapping("/deviceStatusList/{deviceId}")
public AjaxResult getDeviceStatusList(@PathVariable Long deviceId) {
LocalDateTime thirtyDaysAgo = LocalDateTime.now().minusDays(UniversalEnum.THIRTY.getNumber());
LocalDateTime currentTime = LocalDateTime.now();
Status status = new Status();
status.setStartTime(thirtyDaysAgo);
status.setTime(currentTime);
status.setDeviceId(deviceId);
List<Status> listStatus = statusService.deviceStatusListById(status);
// Calculate average successRate by day
Map<String, Double> averageSuccessRateByDay = listStatus.stream()
.collect(Collectors.groupingBy(s -> {
// 使用 DateTimeFormatter 格式化日期
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
String formattedDate = s.getTime().format(formatter);
return formattedDate;
},
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue())))));
if (averageSuccessRateByDay.isEmpty()) {
return AjaxResult.success(UniversalEnum.NO_DATA_AVAILABLE.getValue());
}
averageSuccessRateByDay.keySet().forEach(item -> {
BigDecimal bigDecimal = new BigDecimal(averageSuccessRateByDay.get(item));
averageSuccessRateByDay.put(item, bigDecimal.setScale(UniversalEnum.TWO.getNumber(), RoundingMode.HALF_UP).doubleValue());
});
return AjaxResult.success(new TreeMap<>(averageSuccessRateByDay));
}
//按类型划分设备
@ApiOperation("设备状态列表按类型")
@GetMapping("/type")
public AjaxResult getTypeList() {
//DcDevice dcDevice = new DcDevice();
//dcDevice.setUseState(1);
//List<DcDevice> dcDeviceList = dcDeviceService.numberOfDevicesByType(dcDevice);
//HashMap<String, String> itemTypeMap = new HashMap<>();
//itemTypeMap.put("1-1", "高清网络枪型固定摄像机");
//itemTypeMap.put("1-2", "高清网络球形摄像机");
//itemTypeMap.put("1-3", "桥下高清网络球形摄像机");
//itemTypeMap.put("1-4", "360°全景摄像机");
//itemTypeMap.put("1-5", "180°全景摄像机");
//itemTypeMap.put("2-1", "门架式可变信息标志");
//itemTypeMap.put("2-3", "雨棚可变信息标志");
//itemTypeMap.put("2-4", "站前悬臂式可变信息标志");
//itemTypeMap.put("3", "气象检测器");
//itemTypeMap.put("5", "路段语音广播系统");
//itemTypeMap.put("6", "护栏碰撞预警系统");
//itemTypeMap.put("7", "毫米波雷达");
//itemTypeMap.put("8", "合流区预警系统");
//itemTypeMap.put("10", "激光疲劳唤醒");
//itemTypeMap.put("11", "一类交通量调查站");
//itemTypeMap.put("12", "智能行车诱导系统");
//itemTypeMap.put("13", "智能设备箱");
//LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
//LocalDateTime currentTime = LocalDateTime.now();
//Status status = new Status();
//status.setStartTime(todayStart);
//status.setTime(currentTime);
//List<Status> listStatus = statusService.list(status);
////根据时间分组
//Map<Integer, List<Status>> map = listStatus.stream()
// .collect(Collectors.groupingBy(Status -> Status.getTime().getHour()));
//if(StringUtils.isEmpty(map)){
// return AjaxResult.success("暂无数据");
//}
//Map<Integer, List<Status>> ipMap = new TreeMap<>(map);
//Integer lastKey = Collections.max(ipMap.keySet());
//List<Status> lastEntry = ipMap.get(lastKey);
//Map<String, List<Status>> typeMap = lastEntry.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType));
//Map<String,Map<String,String>> subMap=new HashMap<>();
//Long sumUseState = 0L;
//for (Map.Entry<String, List<Status>> entrys : typeMap.entrySet()) {
// Map<String, String> maps=new HashMap<>();
// List<Status> groupItems = entrys.getValue();
// double lostRate = groupItems.stream()
// .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double
// .average().getAsDouble();
// double sucessRate = groupItems.stream()
// .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double
// .average().getAsDouble();
// String failRate=String.format("%.2f", (100-sucessRate))+"%";
// //丢包率
// maps.put("lostRate",String.format("%.2f", lostRate)+"%");
// //在线率
// maps.put("sucessRate",String.format("%.2f", sucessRate)+"%");
// //离线率
// maps.put("failRate",failRate);
// //已使用数量
// List<String> collect = dcDeviceList.stream().filter(item -> Objects.equals(item.getDeviceType(), entrys.getKey())).map(DcDevice::getSumAll).collect(Collectors.toList());
// String useStateNum = collect.size() > 0 ? String.valueOf(collect.get(0)) : "0";
// sumUseState += Long.valueOf(useStateNum);
// maps.put("sumUseState",useStateNum);
// //总数
// maps.put("sum",String.valueOf(groupItems.size()));
// if(itemTypeMap.get(entrys.getKey())!=null) {
// subMap.put(itemTypeMap.get(entrys.getKey()), maps);
// }
//}
//Map<String, String> maps=new HashMap<>();
//double lostRate = lastEntry.stream()
// .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double
// .average().getAsDouble();
//double sucessRate = lastEntry.stream()
// .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double
// .average().getAsDouble();
//String failRate=String.format("%.2f", (100-sucessRate))+"%";
////丢包率
//maps.put("lostRate",String.format("%.2f", lostRate)+"%");
////在线率
//maps.put("sucessRate",String.format("%.2f", sucessRate)+"%");
////离线率
//maps.put("failRate",failRate);
////已使用数量
//maps.put("sumUseState", String.valueOf(sumUseState));
////总数
//maps.put("sum",String.valueOf(lastEntry.size()));
//subMap.put("全部设备",maps);
List<DcDevice> dcDeviceList = dcDeviceService.numberOfDevicesByType();
HashMap<String, String> itemTypeMap = new HashMap<>();
itemTypeMap.put(UniversalEnum.ONE_ONE.getValue(), UniversalEnum.HD_NETWORK_GUN_TYPE_FIXED_CAMERA.getValue());
itemTypeMap.put(UniversalEnum.ONE_TWO.getValue(), UniversalEnum.HD_NETWORK_SPHERICAL_CAMERA.getValue());
itemTypeMap.put(UniversalEnum.ONE_THREE.getValue(), UniversalEnum.UNDER_THE_BRIDGE_HD_NETWORK_SPHERICAL_CAMERA.getValue());
itemTypeMap.put(UniversalEnum.ONE_FOUR.getValue(), UniversalEnum.THREE_HUNDRED_SIXTY_PANORAMIC_CAMERA.getValue());
itemTypeMap.put(UniversalEnum.ONE_FIVE.getValue(), UniversalEnum.ONE_HUNDRED_EIGHTY_PANORAMIC_CAMERA.getValue());
itemTypeMap.put(UniversalEnum.TWO_ONE.getValue(), UniversalEnum.GANTRY_TYPE_VARIABLE_MESSAGE_SIGN.getValue());
itemTypeMap.put(UniversalEnum.TWO_TWO.getValue(), UniversalEnum.VARIABLE_MESSAGE_SIGN_IN_FRONT_OF_STATION.getValue());
itemTypeMap.put(UniversalEnum.TWO_THREE.getValue(), UniversalEnum.AWNING_VARIABLE_INFORMATION_SIGN.getValue());
itemTypeMap.put(UniversalEnum.TWO_FOUR.getValue(), UniversalEnum.CANTILEVER_VARIABLE_INFORMATION_SIGN_IN_FRONT_OF_STATION.getValue());
itemTypeMap.put(UniversalEnum.THREE.getValue(), UniversalEnum.METEOROLOGICAL_DETECTOR.getValue());
itemTypeMap.put(UniversalEnum.FIVE.getValue(), UniversalEnum.SECTION_VOICE_BROADCAST_SYSTEM.getValue());
itemTypeMap.put(UniversalEnum.SIX.getValue(), UniversalEnum.GUARDRAIL_COLLISION_WARNING_SYSTEM.getValue());
itemTypeMap.put(UniversalEnum.SEVEN.getValue(), UniversalEnum.MILLIMETER_WAVE_RADAR.getValue());
itemTypeMap.put(UniversalEnum.EIGHT.getValue(), UniversalEnum.CONFLUENCE_AREA_EARLY_WARNING_SYSTEM.getValue());
itemTypeMap.put(UniversalEnum.TEN.getValue(), UniversalEnum.LASER_FATIGUE_AWAKENING.getValue());
itemTypeMap.put(UniversalEnum.ELEVEN.getValue(), UniversalEnum.CLASS_I_TRAFFIC_SURVEY_STATION.getValue());
itemTypeMap.put(UniversalEnum.TWELVE.getValue(), UniversalEnum.INTELLIGENT_DRIVING_GUIDANCE_SYSTEM.getValue());
itemTypeMap.put(UniversalEnum.THIRTEEN.getValue(), UniversalEnum.SMART_DEVICE_BOX.getValue());
itemTypeMap.put(UniversalEnum.FIFTEEN.getValue(), UniversalEnum.SOLAR_PANEL.getValue());
itemTypeMap.put(UniversalEnum.SIXTEEN.getValue(), UniversalEnum.REMOTE_COMPUTER.getValue());
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = LocalDateTime.now();
Status status = new Status();
status.setStartTime(todayStart);
status.setTime(currentTime);
status.setUseState(UniversalEnum.ONE.getNumber());
List<Status> listStatus = statusService.list(status);
//根据时间分组
Map<Integer, List<Status>> map = listStatus.stream()
.collect(Collectors.groupingBy(Status -> Status.getTime().getHour()));
if (StringUtils.isEmpty(map)) {
return AjaxResult.success(UniversalEnum.NO_DATA_AVAILABLE.getValue());
}
Map<Integer, List<Status>> ipMap = new TreeMap<>(map);
Integer lastKey = Collections.max(ipMap.keySet());
List<Status> lastEntry = ipMap.get(lastKey);
Map<String, List<Status>> typeMap = lastEntry.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType));
Map<String, Map<Object, Object>> subMap = new HashMap<>();
itemTypeMap.forEach((key, value) -> {
Map<Object, Object> maps = new HashMap<>();
List<Status> groupItems = typeMap.get(key);
if (groupItems == null) {
//丢包率
maps.put("lostRate", UniversalEnum.ZERO_PERCENT.getValue());
//在线率
maps.put("sucessRate", UniversalEnum.ZERO_PERCENT.getValue());
//离线率
maps.put("failRate", UniversalEnum.ZERO_PERCENT.getValue());
//已使用数量
maps.put("sumUseState", UniversalEnum.ZERO.getValue());
//总数
maps.put("sum", String.valueOf(dcDeviceList.stream().filter(item -> Objects.equals(item.getDeviceType(), key)).map(DcDevice::getSumAll).collect(Collectors.toList()).get(0)));
subMap.put(itemTypeMap.get(key), maps);
} else {
double lostRate = groupItems.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double
.average().getAsDouble();
double sucessRate = groupItems.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double
.average().getAsDouble();
String failRate = String.format("%.2f", (UniversalEnum.ONE_HUNDRED.getNumber() - sucessRate)) + UniversalEnum.PER_CENT.getValue();
//丢包率
maps.put("lostRate", String.format("%.2f", lostRate) + UniversalEnum.PER_CENT.getValue());
//在线率
maps.put("sucessRate", String.format("%.2f", sucessRate) + UniversalEnum.PER_CENT.getValue());
//离线率
maps.put("failRate", failRate);
//已使用数量
maps.put("sumUseState", String.valueOf(groupItems.size()));
//总数
maps.put("sum", String.valueOf(dcDeviceList.stream().filter(item -> Objects.equals(item.getDeviceType(), key)).map(DcDevice::getSumAll).collect(Collectors.toList()).get(0)));
subMap.put(itemTypeMap.get(key), maps);
}
});
//for (Map.Entry<String, List<Status>> entrys : typeMap.entrySet()) {
// Map<String, String> maps=new HashMap<>();
// List<Status> groupItems = entrys.getValue();
// double lostRate = groupItems.stream()
// .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double
// .average().getAsDouble();
// double sucessRate = groupItems.stream()
// .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double
// .average().getAsDouble();
// String failRate=String.format("%.2f", (100-sucessRate))+"%";
// //丢包率
// maps.put("lostRate",String.format("%.2f", lostRate)+"%");
// //在线率
// maps.put("sucessRate",String.format("%.2f", sucessRate)+"%");
// //离线率
// maps.put("failRate",failRate);
// //已使用数量
// maps.put("sumUseState",String.valueOf(groupItems.size()));
// //总数
// maps.put("sum", String.valueOf(dcDeviceList.stream().filter(item -> Objects.equals(item.getDeviceType(), entrys.getKey())).map(DcDevice::getSumAll).collect(Collectors.toList()).get(0)));
// if(itemTypeMap.get(entrys.getKey())!=null) {
// subMap.put(itemTypeMap.get(entrys.getKey()), maps);
//
// }
//}
Map<Object, Object> maps = new HashMap<>();
double lostRate = lastEntry.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double
.average().getAsDouble();
double sucessRate = lastEntry.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double
.average().getAsDouble();
String failRate = String.format("%.2f", (UniversalEnum.ONE_HUNDRED.getNumber() - sucessRate)) + UniversalEnum.PER_CENT.getValue();
//丢包率
maps.put("lostRate", String.format("%.2f", lostRate) + UniversalEnum.PER_CENT.getValue());
//在线率
maps.put("sucessRate", String.format("%.2f", sucessRate) + UniversalEnum.PER_CENT.getValue());
//离线率
maps.put("failRate", failRate);
List<DcDevice> list = dcDeviceService.list();
//已使用数量
maps.put("sumUseState", String.valueOf(lastEntry.size()));
//总数
maps.put("sum", String.valueOf(list.size()));
subMap.put("全部设备", maps);
Map<Object, Object> ruleMap = new HashMap<>();
String orderRule = redisCache.getCacheObject(ORDERRULE);
if (StringUtil.isNotEmpty(orderRule)) {
ruleMap.put("rule", orderRule);
subMap.put("排序规则", ruleMap);
} else {
String[] rules = {UniversalEnum.ALL_EQUIPMENT.getValue(),
UniversalEnum.HD_NETWORK_GUN_TYPE_FIXED_CAMERA.getValue(),
UniversalEnum.HD_NETWORK_SPHERICAL_CAMERA.getValue(),
UniversalEnum.UNDER_THE_BRIDGE_HD_NETWORK_SPHERICAL_CAMERA.getValue(),
UniversalEnum.THREE_HUNDRED_SIXTY_PANORAMIC_CAMERA.getValue(),
UniversalEnum.ONE_HUNDRED_EIGHTY_PANORAMIC_CAMERA.getValue(),
UniversalEnum.GANTRY_TYPE_VARIABLE_MESSAGE_SIGN.getValue(),
UniversalEnum.AWNING_VARIABLE_INFORMATION_SIGN.getValue(),
UniversalEnum.VARIABLE_MESSAGE_SIGN_IN_FRONT_OF_STATION.getValue(),
UniversalEnum.CANTILEVER_VARIABLE_INFORMATION_SIGN_IN_FRONT_OF_STATION.getValue(),
UniversalEnum.METEOROLOGICAL_DETECTOR.getValue(),
UniversalEnum.SECTION_VOICE_BROADCAST_SYSTEM.getValue(),
UniversalEnum.GUARDRAIL_COLLISION_WARNING_SYSTEM.getValue(),
UniversalEnum.MILLIMETER_WAVE_RADAR.getValue(),
UniversalEnum.CONFLUENCE_AREA_EARLY_WARNING_SYSTEM.getValue(),
UniversalEnum.LASER_FATIGUE_AWAKENING.getValue(),
UniversalEnum.CLASS_I_TRAFFIC_SURVEY_STATION.getValue(),
UniversalEnum.INTELLIGENT_DRIVING_GUIDANCE_SYSTEM.getValue(),
UniversalEnum.SMART_DEVICE_BOX.getValue(),
UniversalEnum.SOLAR_PANEL.getValue(),
UniversalEnum.REMOTE_COMPUTER.getValue()
};
orderRule = Arrays.toString(rules).replace(UniversalEnum.LEFT_CENTER_BRACKET.getValue(), UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.CLOSE_CENTER_BRACKET.getValue(), UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.EMPTY_STRING.getValue());
ruleMap.put("rule", orderRule);
subMap.put("排序规则", ruleMap);
}
return AjaxResult.success(subMap);
}
//设备状态列表按路段
@ApiOperation("设备状态列表按路段")
@GetMapping("/section")
public AjaxResult getSectionList() {
List<Map<String, String>> stringIntegerMap = dcDeviceService.countTheNumberOfEligibleItems();
List<DcRoadSection> dcRoadSections = dcRoadSectionService.selectDcRoadSectionList(new DcRoadSection());
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = LocalDateTime.now();
Status status = new Status();
status.setStartTime(todayStart);
status.setTime(currentTime);
status.setUseState(UniversalEnum.ONE.getNumber());
List<Status> listStatus = statusService.listStatusBySection(status);
//根据时间分组
Map<Integer, List<Status>> map = listStatus.stream()
.collect(Collectors.groupingBy(Status -> Status.getTime().getHour()));
if (StringUtils.isEmpty(map)) {
return AjaxResult.success(UniversalEnum.NO_DATA_AVAILABLE.getValue());
}
Map<Integer, List<Status>> ipMap = new TreeMap<>(map);
Integer lastKey = Collections.max(ipMap.keySet());
List<Status> lastEntry = ipMap.get(lastKey);
Map<String, List<Status>> typeMap = lastEntry.stream().filter(iteam -> iteam.getSectionId() != null).collect(Collectors.groupingBy(Status::getSectionId));
Map<String, Map<Object, Object>> subMap = new HashMap<>();
dcRoadSections.forEach((key) -> {
Map<Object, Object> maps = new HashMap<>();
List<Status> groupItems = typeMap.get(String.valueOf(key.getId()));
if (groupItems == null) {
//丢包率
maps.put("lostRate", UniversalEnum.ZERO_PERCENT.getValue());
//在线率
maps.put("sucessRate", UniversalEnum.ZERO_PERCENT.getValue());
//离线率
maps.put("failRate", UniversalEnum.ZERO_PERCENT.getValue());
//已使用数量
maps.put("sumUseState", UniversalEnum.ZERO.getValue());
//总数
maps.put("sum", stringIntegerMap.stream().filter(iteam -> Objects.equals(String.valueOf(iteam.get("id")), String.valueOf(key.getId()))).collect(Collectors.toList()).get(UniversalEnum.ZERO.getNumber()).get("number"));
subMap.put(key.getSectionName(), maps);
} else {
double lostRate = groupItems.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double
.average().getAsDouble();
double sucessRate = groupItems.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double
.average().getAsDouble();
String failRate = String.format("%.2f", (UniversalEnum.ONE_HUNDRED.getNumber() - sucessRate)) + UniversalEnum.PER_CENT.getValue();
//丢包率
maps.put("lostRate", String.format("%.2f", lostRate) + UniversalEnum.PER_CENT.getValue());
//在线率
maps.put("sucessRate", String.format("%.2f", sucessRate) + UniversalEnum.PER_CENT.getValue());
//离线率
maps.put("failRate", failRate);
//已使用数量
maps.put("sumUseState", String.valueOf(groupItems.size()));
//总数
maps.put("sum", stringIntegerMap.stream().filter(iteam -> Objects.equals(String
.valueOf(iteam.get("id")), String.valueOf(key.getId()))).collect(Collectors.toList()).get(UniversalEnum.ZERO.getNumber()).get("number"));
subMap.put(key.getSectionName(), maps);
}
});
return AjaxResult.success(subMap);
}
}