opt:1.更新后台管理首页看板功能
This commit is contained in:
@@ -4,6 +4,8 @@ import org.nl.api.task.core.OneClickOperationRequestParam;
|
||||
import org.nl.api.task.core.TaskRequestParam;
|
||||
import org.nl.response.WebResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/11
|
||||
@@ -93,4 +95,12 @@ public interface TaskAPI {
|
||||
* @return
|
||||
*/
|
||||
WebResponse oneClickOperation(OneClickOperationRequestParam param,String source);
|
||||
|
||||
/**
|
||||
* 按时间范围查询任务数据(用于看板统计)
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 任务列表
|
||||
*/
|
||||
Map<String, Object> queryTasksByTimeRange(String startTime, String endTime);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ public class MapInfoController {
|
||||
@PostMapping("/syncCurrentMapData")
|
||||
@Log("同步当前地图最新数据")
|
||||
public ResponseEntity<Object> syncCurrentMapData() {
|
||||
return new ResponseEntity<>(null,HttpStatus.OK);
|
||||
return new ResponseEntity<>(mapService.syncCurrentMapData(),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,5 +7,16 @@ import org.nl.response.WebResponse;
|
||||
* 2025/12/18
|
||||
*/
|
||||
public interface MapService {
|
||||
/**
|
||||
* 获取当前地图信息
|
||||
* @return
|
||||
*/
|
||||
WebResponse queryCurrentMapInfo();
|
||||
|
||||
/**
|
||||
* 同步当前地图数据
|
||||
* @return
|
||||
*/
|
||||
WebResponse syncCurrentMapData();
|
||||
|
||||
}
|
||||
|
||||
@@ -149,4 +149,10 @@ public class MapServiceImpl implements MapService {
|
||||
);
|
||||
return WebResponse.requestParamOk(mapInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponse syncCurrentMapData() {
|
||||
init();
|
||||
return WebResponse.requestOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.nl.monitor.dashboard.controller;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.nl.monitor.dashboard.service.DashboardService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/3/20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dashboard")
|
||||
public class DashboardController {
|
||||
|
||||
@Resource
|
||||
private DashboardService dashboardService;
|
||||
|
||||
@GetMapping("/queryDashboardData")
|
||||
public ResponseEntity<Object> queryDashboardData(@RequestParam String timeRange) {
|
||||
return new ResponseEntity<>(dashboardService.queryDashboardData(timeRange), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.nl.monitor.dashboard.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/3/20
|
||||
*/
|
||||
@Data
|
||||
public class DashboardDataDto {
|
||||
|
||||
/**
|
||||
* 总任务数
|
||||
*/
|
||||
private Long totalTasks;
|
||||
|
||||
/**
|
||||
* 执行中的任务数
|
||||
*/
|
||||
private Long executingTasks;
|
||||
|
||||
/**
|
||||
* 已完成的任务数
|
||||
*/
|
||||
private Long completedTasks;
|
||||
|
||||
/**
|
||||
* 已取消的任务数
|
||||
*/
|
||||
private Long canceledTasks;
|
||||
|
||||
/**
|
||||
* 完成率 (%)
|
||||
*/
|
||||
private Double completionRate;
|
||||
|
||||
/**
|
||||
* 取消率 (%)
|
||||
*/
|
||||
private Double cancellationRate;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.monitor.dashboard.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/3/20
|
||||
*/
|
||||
@Data
|
||||
public class DashboardQueryParam {
|
||||
|
||||
/**
|
||||
* 时间范围类型: today(今天), week(一周), month(一个月)
|
||||
*/
|
||||
private String timeRange;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.nl.monitor.dashboard.service;
|
||||
|
||||
import org.nl.response.WebResponse;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/3/20
|
||||
*/
|
||||
public interface DashboardService {
|
||||
|
||||
/**
|
||||
* 查询看板数据
|
||||
* @param timeRange 时间范围: today(今天), week(一周), month(一个月)
|
||||
* @return 看板数据
|
||||
*/
|
||||
WebResponse queryDashboardData(String timeRange);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.nl.monitor.dashboard.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.api.task.api.TaskAPI;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.monitor.dashboard.dto.DashboardDataDto;
|
||||
import org.nl.monitor.dashboard.service.DashboardService;
|
||||
import org.nl.response.WebResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/3/20
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DashboardServiceImpl implements DashboardService {
|
||||
|
||||
@Resource
|
||||
private TaskAPI taskAPI;
|
||||
|
||||
@Override
|
||||
public WebResponse queryDashboardData(String timeRange) {
|
||||
if (StrUtil.isBlank(timeRange)) {
|
||||
throw new BadRequestException(LangProcess.msg("param_is_null"));
|
||||
}
|
||||
|
||||
// 获取时间范围
|
||||
String[] timeRange_arr = getTimeRange(timeRange);
|
||||
String startTime = timeRange_arr[0];
|
||||
String endTime = timeRange_arr[1];
|
||||
|
||||
// 从数据库查询指定时间范围内的任务统计数据
|
||||
Map<String, Object> statisticsData = taskAPI.queryTasksByTimeRange(startTime, endTime);
|
||||
|
||||
// 构建返回数据
|
||||
DashboardDataDto dto = new DashboardDataDto();
|
||||
dto.setTotalTasks(((Number) statisticsData.get("totalTasks")).longValue());
|
||||
dto.setExecutingTasks(((Number) statisticsData.get("executingTasks")).longValue());
|
||||
dto.setCompletedTasks(((Number) statisticsData.get("completedTasks")).longValue());
|
||||
dto.setCanceledTasks(((Number) statisticsData.get("canceledTasks")).longValue());
|
||||
dto.setCompletionRate(((Number) statisticsData.get("completionRate")).doubleValue());
|
||||
dto.setCancellationRate(((Number) statisticsData.get("cancellationRate")).doubleValue());
|
||||
|
||||
return WebResponse.requestParamOk(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间范围获取开始和结束时间
|
||||
* @return [startTime, endTime]
|
||||
*/
|
||||
private String[] getTimeRange(String timeRange) {
|
||||
Date now = new Date();
|
||||
Date startDate;
|
||||
Date endDate = now;
|
||||
|
||||
switch (timeRange) {
|
||||
case "today":
|
||||
startDate = DateUtil.beginOfDay(now);
|
||||
break;
|
||||
case "week":
|
||||
startDate = DateUtil.offsetDay(DateUtil.beginOfDay(now), -7);
|
||||
break;
|
||||
case "month":
|
||||
startDate = DateUtil.offsetDay(DateUtil.beginOfDay(now), -30);
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException("Invalid timeRange: " + timeRange);
|
||||
}
|
||||
|
||||
return new String[]{DateUtil.formatDateTime(startDate), DateUtil.formatDateTime(endDate)};
|
||||
}
|
||||
}
|
||||
@@ -167,4 +167,36 @@ public class TaskAPIProvider implements TaskAPI {
|
||||
public WebResponse oneClickOperation(OneClickOperationRequestParam param, String source) {
|
||||
return taskService.oneClickOperation(param, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryTasksByTimeRange(String startTime, String endTime) {
|
||||
List<Task> taskList = taskService.queryTasksByTimeRange(startTime, endTime);
|
||||
|
||||
// 统计数据
|
||||
long totalTasks = taskList.size();
|
||||
long executingTasks = taskList.stream()
|
||||
.filter(task -> TaskStatusEnum.EXECUTING.getCode().equals(task.getStatus()))
|
||||
.count();
|
||||
long completedTasks = taskList.stream()
|
||||
.filter(task -> TaskStatusEnum.FINISHED.getCode().equals(task.getStatus()))
|
||||
.count();
|
||||
long canceledTasks = taskList.stream()
|
||||
.filter(task -> TaskStatusEnum.CANCELED.getCode().equals(task.getStatus()))
|
||||
.count();
|
||||
|
||||
// 计算完成率和取消率
|
||||
double completionRate = totalTasks > 0 ? (completedTasks * 100.0 / totalTasks) : 0;
|
||||
double cancellationRate = totalTasks > 0 ? (canceledTasks * 100.0 / totalTasks) : 0;
|
||||
|
||||
// 构建统计数据 Map
|
||||
Map<String, Object> statisticsData = new java.util.HashMap<>();
|
||||
statisticsData.put("totalTasks", totalTasks);
|
||||
statisticsData.put("executingTasks", executingTasks);
|
||||
statisticsData.put("completedTasks", completedTasks);
|
||||
statisticsData.put("canceledTasks", canceledTasks);
|
||||
statisticsData.put("completionRate", Math.round(completionRate * 100.0) / 100.0);
|
||||
statisticsData.put("cancellationRate", Math.round(cancellationRate * 100.0) / 100.0);
|
||||
|
||||
return statisticsData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,4 +81,12 @@ public interface TaskService extends IService<Task>{
|
||||
*/
|
||||
WebResponse createCruiseTask(CreateCruiseTaskRequestParam param);
|
||||
|
||||
/**
|
||||
* 按时间范围查询任务数据(用于看板统计)
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 任务列表
|
||||
*/
|
||||
List<Task> queryTasksByTimeRange(String startTime, String endTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -359,4 +359,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper,Task> implements Tas
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> queryTasksByTimeRange(String startTime, String endTime) {
|
||||
return taskMapper.selectList(new LambdaQueryWrapper<>(Task.class)
|
||||
.ge(StrUtil.isNotBlank(startTime), Task::getCreate_time, startTime)
|
||||
.le(StrUtil.isNotBlank(endTime), Task::getCreate_time, endTime)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user