|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
//按类型划分设备
|
|
|
|