添加接口
This commit is contained in:
parent
69c9c37b7e
commit
35fdc4ada3
|
|
@ -2,12 +2,12 @@ package com.ruoyi.task.controller;
|
|||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.task.api.domain.TaskDTO;
|
||||
import com.ruoyi.task.api.domain.TaskStatQueryVO;
|
||||
import com.ruoyi.task.service.dto.TaskQueryDTO;
|
||||
import com.ruoyi.task.api.enums.StatusEnum;
|
||||
import com.ruoyi.task.service.api.ITaskService;
|
||||
import com.ruoyi.task.controller.convert.TaskControllerConvert;
|
||||
import com.ruoyi.task.controller.convert.TaskStatControllerConvert;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -102,5 +102,22 @@ public class TaskController extends BaseController
|
|||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按年统计任务
|
||||
*/
|
||||
@PostMapping("/stat/year")
|
||||
public R<com.ruoyi.task.api.domain.TaskStatByYearDTO> getTaskStatByYear(@RequestBody TaskStatQueryVO queryDTO)
|
||||
{
|
||||
return R.ok(TaskStatControllerConvert.fromYear(taskService.getTaskStatByYear(TaskStatControllerConvert.toQuery(queryDTO))));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按年月统计任务
|
||||
*/
|
||||
@PostMapping("/stat/month")
|
||||
public R<com.ruoyi.task.api.domain.TaskStatByMonthDTO> getTaskStatByMonth(@RequestBody TaskStatQueryVO queryDTO)
|
||||
{
|
||||
return R.ok(TaskStatControllerConvert.fromMonth(taskService.getTaskStatByMonth(TaskStatControllerConvert.toQuery(queryDTO))));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.ruoyi.task.controller.convert;
|
||||
|
||||
import com.ruoyi.task.api.domain.TaskStatQueryVO;
|
||||
|
||||
/**
|
||||
* 任务统计Controller转换器
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-03-09
|
||||
*/
|
||||
public class TaskStatControllerConvert {
|
||||
|
||||
/**
|
||||
* API 查询DTO 转 服务查询DTO
|
||||
*/
|
||||
public static com.ruoyi.task.service.dto.TaskStatQueryServiceDTO toQuery(TaskStatQueryVO apiDTO) {
|
||||
if (apiDTO == null) return null;
|
||||
com.ruoyi.task.service.dto.TaskStatQueryServiceDTO dto = new com.ruoyi.task.service.dto.TaskStatQueryServiceDTO();
|
||||
dto.setYear(apiDTO.getYear());
|
||||
dto.setMonth(apiDTO.getMonth());
|
||||
dto.setTaskCategory(apiDTO.getTaskCategory());
|
||||
dto.setTaskType(apiDTO.getTaskType());
|
||||
dto.setStatus(apiDTO.getStatus());
|
||||
dto.setRouteId(apiDTO.getRouteId());
|
||||
dto.setUavId(apiDTO.getUavId());
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务按年统计DTO 转 API 按年统计DTO
|
||||
*/
|
||||
public static com.ruoyi.task.api.domain.TaskStatByYearDTO fromYear(com.ruoyi.task.service.dto.TaskStatByYearServiceDTO dto) {
|
||||
if (dto == null) return null;
|
||||
com.ruoyi.task.api.domain.TaskStatByYearDTO apiDTO = new com.ruoyi.task.api.domain.TaskStatByYearDTO();
|
||||
apiDTO.setTotal(dto.getTotal());
|
||||
apiDTO.setMonths(dto.getMonths());
|
||||
return apiDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务按月统计DTO 转 API 按月统计DTO
|
||||
*/
|
||||
public static com.ruoyi.task.api.domain.TaskStatByMonthDTO fromMonth(com.ruoyi.task.service.dto.TaskStatByMonthServiceDTO dto) {
|
||||
if (dto == null) return null;
|
||||
com.ruoyi.task.api.domain.TaskStatByMonthDTO apiDTO = new com.ruoyi.task.api.domain.TaskStatByMonthDTO();
|
||||
apiDTO.setTotal(dto.getTotal());
|
||||
apiDTO.setDays(dto.getDays());
|
||||
return apiDTO;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,9 @@ package com.ruoyi.task.service.api;
|
|||
import com.ruoyi.task.api.enums.StatusEnum;
|
||||
import com.ruoyi.task.service.dto.TaskDTO;
|
||||
import com.ruoyi.task.service.dto.TaskQueryDTO;
|
||||
import com.ruoyi.task.service.dto.TaskStatQueryServiceDTO;
|
||||
import com.ruoyi.task.service.dto.TaskStatByYearServiceDTO;
|
||||
import com.ruoyi.task.service.dto.TaskStatByMonthServiceDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -78,4 +81,18 @@ public interface ITaskService {
|
|||
* @return 是否成功
|
||||
*/
|
||||
boolean updateTaskStatus(Long taskId, StatusEnum status);
|
||||
|
||||
/**
|
||||
* 按年统计任务
|
||||
* @param queryDTO 查询条件
|
||||
* @return 按年统计结果
|
||||
*/
|
||||
TaskStatByYearServiceDTO getTaskStatByYear(TaskStatQueryServiceDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 按年月统计任务
|
||||
* @param queryDTO 查询条件
|
||||
* @return 按年月统计结果
|
||||
*/
|
||||
TaskStatByMonthServiceDTO getTaskStatByMonth(TaskStatQueryServiceDTO queryDTO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package com.ruoyi.task.service.dto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 按年月统计任务DTO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-03-09
|
||||
*/
|
||||
public class TaskStatByMonthServiceDTO {
|
||||
|
||||
/** 总数 */
|
||||
private Integer total;
|
||||
|
||||
/** 每日统计 key:日期(1-31) value:任务数量 */
|
||||
private Map<Integer, Integer> days;
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getDays() {
|
||||
return days;
|
||||
}
|
||||
|
||||
public void setDays(Map<Integer, Integer> days) {
|
||||
this.days = days;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.ruoyi.task.service.dto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 按年统计任务DTO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-03-09
|
||||
*/
|
||||
public class TaskStatByYearServiceDTO {
|
||||
|
||||
/** 总数 */
|
||||
private Integer total;
|
||||
|
||||
/** 每月统计 key:月份(1-12) value:任务数量 */
|
||||
private Map<Integer, Integer> months;
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getMonths() {
|
||||
return months;
|
||||
}
|
||||
|
||||
public void setMonths(Map<Integer, Integer> months) {
|
||||
this.months = months;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.ruoyi.task.service.dto;
|
||||
|
||||
import com.ruoyi.task.api.enums.StatusEnum;
|
||||
import com.ruoyi.task.api.enums.TaskCategoryEnum;
|
||||
import com.ruoyi.task.api.enums.TaskTypeEnum;
|
||||
|
||||
/**
|
||||
* 任务统计查询DTO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-03-09
|
||||
*/
|
||||
public class TaskStatQueryServiceDTO {
|
||||
|
||||
/** 年份 */
|
||||
private Integer year;
|
||||
|
||||
/** 月份 */
|
||||
private Integer month;
|
||||
|
||||
/** 任务类别 */
|
||||
private TaskCategoryEnum taskCategory;
|
||||
|
||||
/** 任务类型 */
|
||||
private TaskTypeEnum taskType;
|
||||
|
||||
/** 状态 */
|
||||
private StatusEnum status;
|
||||
|
||||
/** 航线ID */
|
||||
private Long routeId;
|
||||
|
||||
/** 无人机ID */
|
||||
private String uavId;
|
||||
|
||||
public Integer getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(Integer year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Integer getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public void setMonth(Integer month) {
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
public TaskCategoryEnum getTaskCategory() {
|
||||
return taskCategory;
|
||||
}
|
||||
|
||||
public void setTaskCategory(TaskCategoryEnum taskCategory) {
|
||||
this.taskCategory = taskCategory;
|
||||
}
|
||||
|
||||
public TaskTypeEnum getTaskType() {
|
||||
return taskType;
|
||||
}
|
||||
|
||||
public void setTaskType(TaskTypeEnum taskType) {
|
||||
this.taskType = taskType;
|
||||
}
|
||||
|
||||
public StatusEnum getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(StatusEnum status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getRouteId() {
|
||||
return routeId;
|
||||
}
|
||||
|
||||
public void setRouteId(Long routeId) {
|
||||
this.routeId = routeId;
|
||||
}
|
||||
|
||||
public String getUavId() {
|
||||
return uavId;
|
||||
}
|
||||
|
||||
public void setUavId(String uavId) {
|
||||
this.uavId = uavId;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,10 +7,16 @@ import com.ruoyi.task.service.api.ITaskService;
|
|||
import com.ruoyi.task.service.convert.TaskDTOConvert;
|
||||
import com.ruoyi.task.service.dto.TaskDTO;
|
||||
import com.ruoyi.task.service.dto.TaskQueryDTO;
|
||||
import com.ruoyi.task.service.dto.TaskStatQueryServiceDTO;
|
||||
import com.ruoyi.task.service.dto.TaskStatByYearServiceDTO;
|
||||
import com.ruoyi.task.service.dto.TaskStatByMonthServiceDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class TaskServiceImpl implements ITaskService {
|
||||
|
|
@ -160,4 +166,71 @@ public class TaskServiceImpl implements ITaskService {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskStatByYearServiceDTO getTaskStatByYear(TaskStatQueryServiceDTO queryDTO) {
|
||||
Task task = new Task();
|
||||
task.setRouteId(queryDTO.getRouteId());
|
||||
task.setUavId(queryDTO.getUavId());
|
||||
task.setStatus(queryDTO.getStatus());
|
||||
task.setTaskCategory(queryDTO.getTaskCategory());
|
||||
task.setTaskType(queryDTO.getTaskType());
|
||||
|
||||
List<Task> tasks = taskDomain.getTaskList(task);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Map<Integer, Integer> months = new HashMap<>();
|
||||
int total = 0;
|
||||
|
||||
for (Task t : tasks) {
|
||||
if (t.getStartTime() != null) {
|
||||
calendar.setTime(t.getStartTime());
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
if (year == queryDTO.getYear()) {
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
months.put(month, months.getOrDefault(month, 0) + 1);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TaskStatByYearServiceDTO result = new TaskStatByYearServiceDTO();
|
||||
result.setTotal(total);
|
||||
result.setMonths(months);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskStatByMonthServiceDTO getTaskStatByMonth(TaskStatQueryServiceDTO queryDTO) {
|
||||
Task task = new Task();
|
||||
task.setRouteId(queryDTO.getRouteId());
|
||||
task.setUavId(queryDTO.getUavId());
|
||||
task.setStatus(queryDTO.getStatus());
|
||||
task.setTaskCategory(queryDTO.getTaskCategory());
|
||||
task.setTaskType(queryDTO.getTaskType());
|
||||
|
||||
List<Task> tasks = taskDomain.getTaskList(task);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Map<Integer, Integer> days = new HashMap<>();
|
||||
int total = 0;
|
||||
|
||||
for (Task t : tasks) {
|
||||
if (t.getStartTime() != null) {
|
||||
calendar.setTime(t.getStartTime());
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
if (year == queryDTO.getYear() && month == queryDTO.getMonth()) {
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
days.put(day, days.getOrDefault(day, 0) + 1);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TaskStatByMonthServiceDTO result = new TaskStatByMonthServiceDTO();
|
||||
result.setTotal(total);
|
||||
result.setDays(days);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue