|
|
@ -13,10 +13,7 @@ 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.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.time.LocalDateTime; |
|
|
@ -99,9 +96,8 @@ public class StatusController extends BaseController { |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("根据设备Id查询折线图数据") |
|
|
|
@GetMapping("/deviceStatusList") |
|
|
|
public AjaxResult getDeviceStatusList(Long deviceId) { |
|
|
|
|
|
|
|
@GetMapping("/deviceStatusList/{deviceId}") |
|
|
|
public AjaxResult getDeviceStatusList(@PathVariable Long deviceId) { |
|
|
|
LocalDateTime thirtyDaysAgo = LocalDateTime.now().minusDays(30); |
|
|
|
LocalDateTime currentTime = LocalDateTime.now(); |
|
|
|
|
|
|
@ -110,20 +106,22 @@ public class StatusController extends BaseController { |
|
|
|
status.setTime(currentTime); |
|
|
|
status.setDeviceId(deviceId); |
|
|
|
|
|
|
|
List<Status> listStatus = statusService.list(status); |
|
|
|
List<Status> listStatus = statusService.deviceStatusListById(status); |
|
|
|
|
|
|
|
// Group by day and calculate average successRate with two decimal places
|
|
|
|
Map<Integer, Integer> averageSuccessRateByDay = listStatus.stream() |
|
|
|
// Calculate average successRate by day
|
|
|
|
Map<Integer, Double> averageSuccessRateByDay = listStatus.stream() |
|
|
|
.collect(Collectors.groupingBy(s -> s.getTime().getDayOfMonth(), |
|
|
|
Collectors.collectingAndThen( |
|
|
|
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace("%", ""))), |
|
|
|
avg -> Math.round(Float.parseFloat(String.format("%.2f", avg))) |
|
|
|
))); |
|
|
|
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace("%", ""))))); |
|
|
|
|
|
|
|
if (averageSuccessRateByDay.isEmpty()) { |
|
|
|
return AjaxResult.success("暂无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
return AjaxResult.success(averageSuccessRateByDay); |
|
|
|
// 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); |
|
|
|
} |
|
|
|
|
|
|
|
//按类型划分设备
|
|
|
@ -131,6 +129,92 @@ public class StatusController extends BaseController { |
|
|
|
@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", "高清网络枪型固定摄像机"); |
|
|
|