feat(ops): refactor-order-operations
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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.service.OrderDetailVO;
|
||||
import com.viewsh.module.ops.service.OrderQueryService;
|
||||
import com.viewsh.module.ops.service.OrderSummaryVO;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.viewsh.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 管理后台 - 工单中心 Controller
|
||||
* <p>
|
||||
* 工单中心提供综合查询能力,支持所有业务类型的工单查询
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@Tag(name = "管理后台 - 工单中心")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ops/order-center")
|
||||
@Validated
|
||||
public class OrderCenterController {
|
||||
|
||||
@Resource
|
||||
private OrderQueryService orderQueryService;
|
||||
|
||||
@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<PageResult<OrderSummaryVO>> 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()
|
||||
.withPage(page)
|
||||
.withSize(size)
|
||||
.withOrderType(orderType)
|
||||
.withStatus(status)
|
||||
.withPriority(priority)
|
||||
.withAreaId(areaId)
|
||||
.withAssigneeId(assigneeId)
|
||||
.withOrderCode(orderCode)
|
||||
.withTitle(title);
|
||||
|
||||
PageResult<OrderSummaryVO> result = orderQueryService.queryPage(query);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
@Operation(summary = "工单详情查询")
|
||||
@Parameter(name = "id", description = "工单ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('ops:order-center:query')")
|
||||
public CommonResult<OrderDetailVO> getDetail(@PathVariable("id") Long id) {
|
||||
OrderDetailVO detail = orderQueryService.getDetail(id);
|
||||
return success(detail);
|
||||
}
|
||||
|
||||
@GetMapping("/stats")
|
||||
@Operation(summary = "工单统计")
|
||||
@Parameter(name = "groupBy", description = "分组维度(status:按状态统计)", required = false)
|
||||
@PreAuthorize("@ss.hasPermission('ops:order-center:query')")
|
||||
public CommonResult<Map<String, Object>> getStats(
|
||||
@RequestParam(value = "groupBy", required = false) String groupBy) {
|
||||
|
||||
Map<String, Object> stats = orderQueryService.getStats(groupBy);
|
||||
return success(stats);
|
||||
}
|
||||
}
|
||||
@@ -140,4 +140,11 @@ viewsh:
|
||||
tenant: # 多租户相关配置项
|
||||
enable: true
|
||||
|
||||
--- #################### 工单相关配置 ####################
|
||||
|
||||
ops:
|
||||
order:
|
||||
datacenter-id: 1 # 数据中心ID(0-31)
|
||||
machine-id: 1 # 机器ID(0-31)
|
||||
|
||||
debug: false
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
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;
|
||||
import com.viewsh.module.ops.service.OrderQueryService;
|
||||
import com.viewsh.module.ops.service.OrderSummaryVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* 工单中心控制器测试
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OrderCenterControllerTest {
|
||||
|
||||
@Mock
|
||||
private OrderQueryService orderQueryService;
|
||||
|
||||
@InjectMocks
|
||||
private OrderCenterController controller;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryPage_Success() {
|
||||
// Given
|
||||
OrderSummaryVO vo = OrderSummaryVO.builder()
|
||||
.id(1L)
|
||||
.orderCode("CLEAN-20250119-0001")
|
||||
.orderType("CLEAN")
|
||||
.title("2楼电梯厅保洁")
|
||||
.status(WorkOrderStatusEnum.PENDING.getStatus())
|
||||
.priority(PriorityEnum.P2.getPriority())
|
||||
.areaId(100L)
|
||||
.createTime(LocalDateTime.now())
|
||||
.extInfo(new HashMap<>())
|
||||
.build();
|
||||
|
||||
PageResult<OrderSummaryVO> pageResult = new PageResult<>(List.of(vo), 1L);
|
||||
|
||||
when(orderQueryService.queryPage(any())).thenReturn(pageResult);
|
||||
|
||||
// When
|
||||
CommonResult<PageResult<OrderSummaryVO>> result = controller.queryPage(
|
||||
1, 20, "CLEAN", null, null, null, null, null, null);
|
||||
|
||||
// Then
|
||||
assertTrue(result.isSuccess());
|
||||
assertNotNull(result.getData());
|
||||
assertEquals(1, result.getData().getList().size());
|
||||
assertEquals("CLEAN-20250119-0001", result.getData().getList().get(0).getOrderCode());
|
||||
|
||||
verify(orderQueryService, times(1)).queryPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryPage_WithMultipleFilters() {
|
||||
// Given
|
||||
PageResult<OrderSummaryVO> emptyResult = new PageResult<>(List.of(), 0L);
|
||||
when(orderQueryService.queryPage(any())).thenReturn(emptyResult);
|
||||
|
||||
// When
|
||||
controller.queryPage(1, 20, "CLEAN", "PENDING",
|
||||
PriorityEnum.P2.getPriority(), 100L, null, null, null);
|
||||
|
||||
// Then
|
||||
verify(orderQueryService, times(1)).queryPage(argThat(query ->
|
||||
query.getOrderType().equals("CLEAN") &&
|
||||
query.getStatus().equals("PENDING") &&
|
||||
query.getPriority().equals(PriorityEnum.P2.getPriority()) &&
|
||||
query.getAreaId().equals(100L)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDetail_Success() {
|
||||
// Given
|
||||
OrderDetailVO vo = OrderDetailVO.builder()
|
||||
.id(1L)
|
||||
.orderCode("CLEAN-20250119-0001")
|
||||
.orderType("CLEAN")
|
||||
.title("2楼电梯厅保洁")
|
||||
.status(WorkOrderStatusEnum.PENDING.getStatus())
|
||||
.priority(PriorityEnum.P2.getPriority())
|
||||
.areaId(100L)
|
||||
.extInfo(new HashMap<>())
|
||||
.build();
|
||||
|
||||
when(orderQueryService.getDetail(1L)).thenReturn(vo);
|
||||
|
||||
// When
|
||||
CommonResult<OrderDetailVO> result = controller.getDetail(1L);
|
||||
|
||||
// Then
|
||||
assertTrue(result.isSuccess());
|
||||
assertNotNull(result.getData());
|
||||
assertEquals(1L, result.getData().getId());
|
||||
assertEquals("CLEAN-20250119-0001", result.getData().getOrderCode());
|
||||
|
||||
verify(orderQueryService, times(1)).getDetail(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDetail_NotFound_ThrowsException() {
|
||||
// Given
|
||||
when(orderQueryService.getDetail(999L))
|
||||
.thenThrow(new RuntimeException("工单不存在"));
|
||||
|
||||
// When & Then
|
||||
assertThrows(RuntimeException.class, () -> controller.getDetail(999L));
|
||||
|
||||
verify(orderQueryService, times(1)).getDetail(999L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetStats_Success() {
|
||||
// Given
|
||||
Map<String, Object> stats = new HashMap<>();
|
||||
stats.put("CLEAN", 50L);
|
||||
stats.put("SECURITY", 30L);
|
||||
|
||||
when(orderQueryService.getStats(null)).thenReturn(stats);
|
||||
|
||||
// When
|
||||
CommonResult<Map<String, Object>> result = controller.getStats(null);
|
||||
|
||||
// Then
|
||||
assertTrue(result.isSuccess());
|
||||
assertNotNull(result.getData());
|
||||
assertEquals(50L, result.getData().get("CLEAN"));
|
||||
assertEquals(30L, result.getData().get("SECURITY"));
|
||||
|
||||
verify(orderQueryService, times(1)).getStats(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetStats_WithGroupByStatus() {
|
||||
// Given
|
||||
Map<String, Object> stats = new HashMap<>();
|
||||
Map<String, Long> cleanStatus = new HashMap<>();
|
||||
cleanStatus.put("PENDING", 10L);
|
||||
cleanStatus.put("COMPLETED", 20L);
|
||||
stats.put("CLEAN", cleanStatus);
|
||||
|
||||
when(orderQueryService.getStats("status")).thenReturn(stats);
|
||||
|
||||
// When
|
||||
CommonResult<Map<String, Object>> result = controller.getStats("status");
|
||||
|
||||
// Then
|
||||
assertTrue(result.isSuccess());
|
||||
assertNotNull(result.getData());
|
||||
assertNotNull(result.getData().get("CLEAN"));
|
||||
|
||||
verify(orderQueryService, times(1)).getStats("status");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryPage_DefaultPageAndSize() {
|
||||
// Given
|
||||
PageResult<OrderSummaryVO> emptyResult = new PageResult<>(List.of(), 0L);
|
||||
when(orderQueryService.queryPage(any())).thenReturn(emptyResult);
|
||||
|
||||
// When: 不传分页参数
|
||||
controller.queryPage(null, null, null, null, null, null, null, null, null);
|
||||
|
||||
// Then: 应该使用默认值
|
||||
verify(orderQueryService, times(1)).queryPage(argThat(query ->
|
||||
query.getPage() == 1 && query.getSize() == 20
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user