济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

446 lines
22 KiB

package com.zc.business.controller;
import com.github.pagehelper.util.StringUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
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.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;
@Api(tags="设备状态")
@RestController
@RequestMapping("/system/status")
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
//设备列表
@ApiOperation("设备状态列表按时间和类型")
@GetMapping ("/tablist")
public TableDataInfo getTabList(Status status)
{
startPage();
status.setTypes(status.getType().split(","));
List<Status> listStatus = statusService.listStatusByTypes(status);
return getDataTable(listStatus);
}
/**
* 导出【请填写功能名称】列表
*/
@ApiOperation("设备状态导出")
@Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Status status)
{
status.setTypes(status.getType().split(","));
List<Status> listStatus = statusService.export(status);
ExcelUtil<Status> util = new ExcelUtil<>(Status.class);
util.exportExcel(response, listStatus, "设备状态列表");
}
//按时间划分设备柱状图
@ApiOperation("设备状态柱状图按时间和类型")
@GetMapping("/list")
public AjaxResult getStatusList(Status status) {
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1);
status.setStartTime(todayStart);
status.setTime(currentTime);
String[] types = status.getType().split(",");
status.setTypes(types);
Map<String, Map<String, String>> maps = new HashMap<>();
List<Status> statuses = statusService.getStatusList(status);
for (String type : types) {
Map<String, String> collect = statuses.stream().filter(item -> Objects.equals(item.getType(), type))
.collect(Collectors.toMap(
item -> item.getTime().getYear() + "-" + item.getTime().getMonthValue() + "-" + 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(30);
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("yyyy-MM-dd");
String formattedDate = s.getTime().format(formatter);
return formattedDate;
},
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace("%", "")))));
if (averageSuccessRateByDay.isEmpty()) {
return AjaxResult.success("暂无数据");
}
averageSuccessRateByDay.keySet().forEach(item -> {
BigDecimal bigDecimal = new BigDecimal(averageSuccessRateByDay.get(item));
averageSuccessRateByDay.put(item, bigDecimal.setScale(2, 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("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);
status.setUseState(1);
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<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", "0%");
//在线率
maps.put("sucessRate", "0%");
//离线率
maps.put("failRate", "0%");
//已使用数量
maps.put("sumUseState", "0");
//总数
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("%", ""))) // 去掉%,并转换为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(), 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("%", ""))) // 去掉%,并转换为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);
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 = {"全部设备","高清网络枪型固定摄像机","高清网络球形摄像机","桥下高清网络球形摄像机","360°全景摄像机","180°全景摄像机",
"门架式可变信息标志","雨棚可变信息标志","站前悬臂式可变信息标志","气象检测器","路段语音广播系统","护栏碰撞预警系统","毫米波雷达",
"合流区预警系统","激光疲劳唤醒","一类交通量调查站","智能行车诱导系统","智能设备箱"};
orderRule= Arrays.toString(rules).replace("[","").replace("]","").replace(" ","");
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(1);
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("暂无数据");
}
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", "0%");
//在线率
maps.put("sucessRate", "0%");
//离线率
maps.put("failRate", "0%");
//已使用数量
maps.put("sumUseState", "0");
//总数
maps.put("sum", stringIntegerMap.stream().filter(iteam -> Objects.equals(String.valueOf(iteam.get("id")), String.valueOf(key.getId()))).collect(Collectors.toList()).get(0).get("number"));
subMap.put(key.getSectionName(), maps);
} else {
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", stringIntegerMap.stream().filter(iteam -> Objects.equals(String
.valueOf(iteam.get("id")), String.valueOf(key.getId()))).collect(Collectors.toList()).get(0).get("number"));
subMap.put(key.getSectionName(), maps);
}
});
return AjaxResult.success(subMap);
}
}