diff --git a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryService.java b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryService.java index b187e9d..9da784c 100644 --- a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryService.java +++ b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryService.java @@ -3,7 +3,11 @@ package com.viewsh.module.ops.service; import com.viewsh.framework.common.pojo.PageParam; import com.viewsh.framework.common.pojo.PageResult; import com.viewsh.module.ops.dal.dataobject.workorder.OpsOrderDO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import java.util.List; import java.util.Map; /** @@ -51,145 +55,29 @@ public interface OrderQueryService { /** * 工单查询条件 */ + @Data + @EqualsAndHashCode(callSuper = true) class OrderQuery extends PageParam { - /** - * 工单类型(可选) - */ + + @Schema(description = "工单类型", example = "CLEAN") private String orderType; - /** - * 工单状态(可选) - */ - private String status; + @Schema(description = "工单状态,支持多选", example = "PENDING,DISPATCHED") + private List status; - /** - * 优先级(可选) - */ + @Schema(description = "优先级(0=P0/1=P1/2=P2)", example = "1") private Integer priority; - /** - * 区域ID(可选) - */ + @Schema(description = "区域ID", example = "100") private Long areaId; - /** - * 执行人ID(可选) - */ + @Schema(description = "执行人ID", example = "30001") private Long assigneeId; - /** - * 工单编号模糊查询(可选) - */ + @Schema(description = "工单编号(模糊查询)", example = "WO2025") private String orderCode; - /** - * 标题模糊查询(可选) - */ + @Schema(description = "标题(模糊查询)", example = "A栋") private String title; - - public String getOrderType() { - return orderType; - } - - public void setOrderType(String orderType) { - this.orderType = orderType; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public Integer getPriority() { - return priority; - } - - public void setPriority(Integer priority) { - this.priority = priority; - } - - public Long getAreaId() { - return areaId; - } - - public void setAreaId(Long areaId) { - this.areaId = areaId; - } - - public Long getAssigneeId() { - return assigneeId; - } - - public void setAssigneeId(Long assigneeId) { - this.assigneeId = assigneeId; - } - - public String getOrderCode() { - return orderCode; - } - - public void setOrderCode(String orderCode) { - this.orderCode = orderCode; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public static OrderQuery builder() { - return new OrderQuery(); - } - - public OrderQuery withPageNo(Integer pageNo) { - this.setPageNo(pageNo); - return this; - } - - public OrderQuery withPageSize(Integer pageSize) { - this.setPageSize(pageSize); - return this; - } - - public OrderQuery withOrderType(String orderType) { - this.orderType = orderType; - return this; - } - - public OrderQuery withStatus(String status) { - this.status = status; - return this; - } - - public OrderQuery withPriority(Integer priority) { - this.priority = priority; - return this; - } - - public OrderQuery withAreaId(Long areaId) { - this.areaId = areaId; - return this; - } - - public OrderQuery withAssigneeId(Long assigneeId) { - this.assigneeId = assigneeId; - return this; - } - - public OrderQuery withOrderCode(String orderCode) { - this.orderCode = orderCode; - return this; - } - - public OrderQuery withTitle(String title) { - this.title = title; - return this; - } } } diff --git a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryServiceImpl.java b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryServiceImpl.java index 091860e..af47d9b 100644 --- a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryServiceImpl.java +++ b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/OrderQueryServiceImpl.java @@ -39,7 +39,7 @@ public class OrderQueryServiceImpl implements OrderQueryService { // 1. 构建查询条件 LambdaQueryWrapperX wrapper = new LambdaQueryWrapperX() .eqIfPresent(OpsOrderDO::getOrderType, query.getOrderType()) - .eqIfPresent(OpsOrderDO::getStatus, query.getStatus()) + .inIfPresent(OpsOrderDO::getStatus, query.getStatus()) .eqIfPresent(OpsOrderDO::getPriority, query.getPriority()) .eqIfPresent(OpsOrderDO::getAreaId, query.getAreaId()) .eqIfPresent(OpsOrderDO::getAssigneeId, query.getAssigneeId()) @@ -126,7 +126,9 @@ public class OrderQueryServiceImpl implements OrderQueryService { .status(order.getStatus()) .areaId(order.getAreaId()) .location(order.getLocation()) + .sourceType(order.getSourceType()) .assigneeId(order.getAssigneeId()) + .assigneeName(order.getAssigneeName()) .startTime(order.getStartTime()) .endTime(order.getEndTime()) .createTime(order.getCreateTime()) diff --git a/viewsh-module-ops/viewsh-module-ops-server/src/main/java/com/viewsh/module/ops/controller/admin/OrderCenterController.java b/viewsh-module-ops/viewsh-module-ops-server/src/main/java/com/viewsh/module/ops/controller/admin/OrderCenterController.java index 0a3ab97..88b7434 100644 --- a/viewsh-module-ops/viewsh-module-ops-server/src/main/java/com/viewsh/module/ops/controller/admin/OrderCenterController.java +++ b/viewsh-module-ops/viewsh-module-ops-server/src/main/java/com/viewsh/module/ops/controller/admin/OrderCenterController.java @@ -2,6 +2,8 @@ package com.viewsh.module.ops.controller.admin; import com.viewsh.framework.common.pojo.CommonResult; import com.viewsh.framework.common.pojo.PageResult; +import com.viewsh.module.ops.api.clean.QuickStatsRespDTO; +import com.viewsh.module.ops.environment.service.dashboard.CleanDashboardService; import com.viewsh.module.ops.service.OrderDetailVO; import com.viewsh.module.ops.service.OrderQueryService; import com.viewsh.module.ops.service.OrderSummaryVO; @@ -9,7 +11,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -35,39 +39,14 @@ public class OrderCenterController { @Resource private OrderQueryService orderQueryService; + @Autowired(required = false) + private CleanDashboardService cleanDashboardService; + @GetMapping("/page") @Operation(summary = "工单中心分页查询") - @Parameter(name = "page", description = "页码", required = false) - @Parameter(name = "size", description = "每页大小", required = false) - @Parameter(name = "orderType", description = "工单类型", required = false) - @Parameter(name = "status", description = "工单状态", required = false) - @Parameter(name = "priority", description = "优先级", required = false) - @Parameter(name = "areaId", description = "区域ID", required = false) - @Parameter(name = "assigneeId", description = "执行人ID", required = false) @PreAuthorize("@ss.hasPermission('ops:order-center:query')") - public CommonResult> queryPage( - @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, - @RequestParam(value = "size", required = false, defaultValue = "20") Integer size, - @RequestParam(value = "orderType", required = false) String orderType, - @RequestParam(value = "status", required = false) String status, - @RequestParam(value = "priority", required = false) Integer priority, - @RequestParam(value = "areaId", required = false) Long areaId, - @RequestParam(value = "assigneeId", required = false) Long assigneeId, - @RequestParam(value = "orderCode", required = false) String orderCode, - @RequestParam(value = "title", required = false) String title) { - - OrderQueryService.OrderQuery query = OrderQueryService.OrderQuery.builder() - .withPageNo(page) - .withPageSize(size) - .withOrderType(orderType) - .withStatus(status) - .withPriority(priority) - .withAreaId(areaId) - .withAssigneeId(assigneeId) - .withOrderCode(orderCode) - .withTitle(title); - - PageResult result = orderQueryService.queryPage(query); + public CommonResult> queryPage(@Valid OrderQueryService.OrderQuery reqVO) { + PageResult result = orderQueryService.queryPage(reqVO); return success(result); } @@ -90,4 +69,22 @@ public class OrderCenterController { Map stats = orderQueryService.getStats(groupBy); return success(stats); } + + @GetMapping("/quick-stats") + @Operation(summary = "快速统计") + @PreAuthorize("@ss.hasPermission('ops:order-center:query')") + public CommonResult getQuickStats() { + if (cleanDashboardService == null) { + log.warn("[getQuickStats] CleanDashboardService 未注入,返回默认值"); + return success(QuickStatsRespDTO.builder() + .pendingCount(0) + .inProgressCount(0) + .completedTodayCount(0) + .onlineBadgeCount(0) + .build()); + } + + QuickStatsRespDTO stats = cleanDashboardService.getQuickStats(); + return success(stats); + } } diff --git a/viewsh-module-ops/viewsh-module-ops-server/src/test/java/com/viewsh/module/ops/controller/admin/OrderCenterControllerTest.java b/viewsh-module-ops/viewsh-module-ops-server/src/test/java/com/viewsh/module/ops/controller/admin/OrderCenterControllerTest.java index d3a197e..07bf8ba 100644 --- a/viewsh-module-ops/viewsh-module-ops-server/src/test/java/com/viewsh/module/ops/controller/admin/OrderCenterControllerTest.java +++ b/viewsh-module-ops/viewsh-module-ops-server/src/test/java/com/viewsh/module/ops/controller/admin/OrderCenterControllerTest.java @@ -2,8 +2,6 @@ package com.viewsh.module.ops.controller.admin; import com.viewsh.framework.common.pojo.CommonResult; import com.viewsh.framework.common.pojo.PageResult; -import com.viewsh.module.ops.dal.dataobject.workorder.OpsOrderDO; -import com.viewsh.module.ops.dal.mysql.workorder.OpsOrderMapper; import com.viewsh.module.ops.enums.PriorityEnum; import com.viewsh.module.ops.enums.WorkOrderStatusEnum; import com.viewsh.module.ops.service.OrderDetailVO; @@ -25,9 +23,8 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** * 工单中心控制器测试 @@ -66,12 +63,14 @@ class OrderCenterControllerTest { .build(); PageResult pageResult = new PageResult<>(List.of(vo), 1L); - when(orderQueryService.queryPage(any())).thenReturn(pageResult); // When - CommonResult> result = controller.queryPage( - 1, 20, "CLEAN", null, null, null, null, null, null); + OrderQueryService.OrderQuery reqVO = new OrderQueryService.OrderQuery(); + reqVO.setPageNo(1); + reqVO.setPageSize(20); + reqVO.setOrderType("CLEAN"); + CommonResult> result = controller.queryPage(reqVO); // Then assertTrue(result.isSuccess()); @@ -89,18 +88,42 @@ class OrderCenterControllerTest { when(orderQueryService.queryPage(any())).thenReturn(emptyResult); // When - controller.queryPage(1, 20, "CLEAN", "PENDING", - PriorityEnum.P2.getPriority(), 100L, null, null, null); + OrderQueryService.OrderQuery reqVO = new OrderQueryService.OrderQuery(); + reqVO.setPageNo(1); + reqVO.setPageSize(20); + reqVO.setOrderType("CLEAN"); + reqVO.setStatus(List.of("PENDING")); + reqVO.setPriority(PriorityEnum.P2.getPriority()); + reqVO.setAreaId(100L); + controller.queryPage(reqVO); // Then verify(orderQueryService, times(1)).queryPage(argThat(query -> query.getOrderType().equals("CLEAN") && - query.getStatus().equals("PENDING") && + query.getStatus().equals(List.of("PENDING")) && query.getPriority().equals(PriorityEnum.P2.getPriority()) && query.getAreaId().equals(100L) )); } + @Test + void testQueryPage_WithMultipleStatus() { + // Given + PageResult emptyResult = new PageResult<>(List.of(), 0L); + when(orderQueryService.queryPage(any())).thenReturn(emptyResult); + + // When + OrderQueryService.OrderQuery reqVO = new OrderQueryService.OrderQuery(); + reqVO.setStatus(List.of("PENDING", "DISPATCHED", "ARRIVED")); + controller.queryPage(reqVO); + + // Then + verify(orderQueryService, times(1)).queryPage(argThat(query -> + query.getStatus().size() == 3 && + query.getStatus().containsAll(List.of("PENDING", "DISPATCHED", "ARRIVED")) + )); + } + @Test void testGetDetail_Success() { // Given @@ -190,12 +213,13 @@ class OrderCenterControllerTest { PageResult emptyResult = new PageResult<>(List.of(), 0L); when(orderQueryService.queryPage(any())).thenReturn(emptyResult); - // When: 不传分页参数 - controller.queryPage(null, null, null, null, null, null, null, null, null); + // When: 不传分页参数,使用 PageParam 默认值 + OrderQueryService.OrderQuery reqVO = new OrderQueryService.OrderQuery(); + controller.queryPage(reqVO); - // Then: 应该使用默认值 + // Then: PageParam 默认值 pageNo=1, pageSize=10 verify(orderQueryService, times(1)).queryPage(argThat(query -> - query.getPageNo() == 1 && query.getPageSize() == 20 + query.getPageNo() == 1 && query.getPageSize() == 10 )); } }