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.
305 lines
15 KiB
305 lines
15 KiB
package com.zc.business.controller;
|
|
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.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.Status;
|
|
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.servlet.http.HttpServletResponse;
|
|
import java.time.LocalDateTime;
|
|
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;
|
|
|
|
//设备列表
|
|
@ApiOperation("设备状态列表按时间和类型")
|
|
@GetMapping ("/tablist")
|
|
public TableDataInfo getTabList(Status status)
|
|
{
|
|
startPage();
|
|
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS);
|
|
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1);
|
|
status.setStartTime(todayStart);
|
|
status.setTime(currentTime);
|
|
List<Status> listStatus = statusService.list(status);
|
|
return getDataTable(listStatus);
|
|
}
|
|
|
|
/**
|
|
* 导出【请填写功能名称】列表
|
|
*/
|
|
|
|
@ApiOperation("设备状态导出")
|
|
@Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, Status status)
|
|
{
|
|
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS);
|
|
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1);
|
|
status.setStartTime(todayStart);
|
|
status.setTime(currentTime);
|
|
List<Status> listStatus = statusService.list(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 type=status.getType();
|
|
List<Status> listStatus = statusService.list(status);
|
|
// List<Status> listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList());
|
|
//根据时间分组
|
|
Map<String, List<Status>> map = listStatus.stream()
|
|
.collect(Collectors.groupingBy(Status -> (Status.getTime().getYear()+"-"+Status.getTime().getMonthValue()+"-"+Status.getTime().getDayOfMonth())));
|
|
//根据类型分组
|
|
// Map<String, List<Status>> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType));
|
|
//生成有序map
|
|
Map<String, List<Status>> mapTime = new TreeMap<>(map);
|
|
Map<String,String> mapSort=new TreeMap<>();
|
|
for (Map.Entry<String, List<Status>> entry : mapTime.entrySet()) {
|
|
List<Status> groupItems = entry.getValue();
|
|
long count = groupItems.stream().filter(iteam -> iteam.getDeviceStatus() == 1).count();
|
|
String onlineRate=String.format("%.2f%%", (double) count / groupItems.size() * 100);
|
|
mapSort.put(entry.getKey(),onlineRate);
|
|
}
|
|
// Map<String, List<Status>> mapStatus = new TreeMap<>(maps);
|
|
return AjaxResult.success(mapSort);
|
|
}
|
|
|
|
|
|
@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<Integer, Double> averageSuccessRateByDay = listStatus.stream()
|
|
.collect(Collectors.groupingBy(s -> s.getTime().getDayOfMonth(),
|
|
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace("%", "")))));
|
|
|
|
if (averageSuccessRateByDay.isEmpty()) {
|
|
return AjaxResult.success("暂无数据");
|
|
}
|
|
|
|
// Round average successRate to two decimal places
|
|
Map<Integer, Double> roundedAverageSuccessRateByDay = averageSuccessRateByDay.entrySet().stream()
|
|
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Math.round(entry.getValue() * 100.0) / 100.0));
|
|
|
|
return AjaxResult.success(roundedAverageSuccessRateByDay);
|
|
}
|
|
|
|
//按类型划分设备
|
|
@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<String,String>> subMap=new HashMap<>();
|
|
|
|
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<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);
|
|
List<DcDevice> list = dcDeviceService.list();
|
|
//已使用数量
|
|
maps.put("sumUseState",String.valueOf(lastEntry.size()));
|
|
//总数
|
|
maps.put("sum",String.valueOf(list.size()));
|
|
subMap.put("全部设备",maps);
|
|
|
|
return AjaxResult.success(subMap);
|
|
}
|
|
|
|
|
|
}
|
|
|