diff --git a/src/main/java/com/zsc/edu/gateway/modules/message/controller/UserNoticeController.java b/src/main/java/com/zsc/edu/gateway/modules/message/controller/UserNoticeController.java index 44c2c77..54bb2cf 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/message/controller/UserNoticeController.java +++ b/src/main/java/com/zsc/edu/gateway/modules/message/controller/UserNoticeController.java @@ -48,7 +48,6 @@ public class UserNoticeController { * @param query 查询参数 * @return 分页数据 */ - @DataPermission(tableAlias = "su") @GetMapping("/self") public IPage selfPage(Page pageParam, @AuthenticationPrincipal UserDetailsImpl userDetails, UserNoticeQuery query) { query.userId = userDetails.id; diff --git a/src/test/java/com/zsc/edu/gateway/rest/iot/ProductControllerTest.java b/src/test/java/com/zsc/edu/gateway/rest/iot/ProductControllerTest.java index 7e89efa..1bc0177 100644 --- a/src/test/java/com/zsc/edu/gateway/rest/iot/ProductControllerTest.java +++ b/src/test/java/com/zsc/edu/gateway/rest/iot/ProductControllerTest.java @@ -55,12 +55,25 @@ public class ProductControllerTest extends MockMvcConfigBase { product1.setId(1L); product2 = ProductBuilder.bProduct().name("Product 2").productType("Description 2").deptId(2L).createId(1L).build(); product2.setId(2L); - product3 = ProductBuilder.bProduct().name("Product 3").productType("Description 3").deptId(2L).createId(1L).build(); + product3 = ProductBuilder.bProduct().name("Product 3").productType("Description 3").deptId(2L).createId(2L).build(); product3.setId(3L); product4 = ProductBuilder.bProduct().name("Product 4").productType("Description 4").deptId(3L).createId(2L).build(); product4.setId(4L); } + private UserDetailsImpl createUserDetails(DataScopeType dataScopeType) { + Dept dept = new Dept(); + dept.setId(2L); + Role role = new Role(); + role.setId(50L); + role.setDataScope(dataScopeType); + userDetails.setId(1L); + userDetails.setDept(dept); + userDetails.setRole(role); + userDetails.setDataScopeDeptIds(Set.of(2L)); + return userDetails; + } + @Test void create() throws Exception { ProductDto dto = new ProductDto(); @@ -81,15 +94,6 @@ public class ProductControllerTest extends MockMvcConfigBase { @Test void listWithDataScopeALL() throws Exception { - Dept dept = new Dept(); - dept.setId(2L); - Role role = new Role(); - role.setId(50L); - role.setDataScope(DataScopeType.DATA_SCOPE_ALL); - userDetails.setId(1L); - userDetails.setDept(dept); - userDetails.setRole(role); - userDetails.setDataScopeDeptIds(Set.of(2L)); // 创建测试数据 List products = Lists.newArrayList(product1, product2, product3, product4); Page pageResult = new Page<>(); @@ -99,7 +103,7 @@ public class ProductControllerTest extends MockMvcConfigBase { when(service.page(any(Page.class), any())).thenReturn(pageResult); // 执行 GET 请求并验证响应 mockMvc.perform(get("/api/rest/product") - .with(user(userDetails))) + .with(user(createUserDetails(DataScopeType.DATA_SCOPE_ALL)))) .andExpect(status().isOk()) .andExpect(jsonPath("$.records.length()").value(products.size())) .andExpect(jsonPath("$.total").value(products.size())) @@ -113,7 +117,7 @@ public class ProductControllerTest extends MockMvcConfigBase { .andExpect(jsonPath("$.records[3].deptId").value(3L)) .andExpect(jsonPath("$.records[0].createId").value(1L)) .andExpect(jsonPath("$.records[1].createId").value(1L)) - .andExpect(jsonPath("$.records[2].createId").value(1L)) + .andExpect(jsonPath("$.records[2].createId").value(2L)) .andExpect(jsonPath("$.records[3].createId").value(2L)) .andDo(print()); // 验证 service.page 方法确实被调用了一次 @@ -122,15 +126,6 @@ public class ProductControllerTest extends MockMvcConfigBase { @Test void listWithDataScopeDept() throws Exception { - Dept dept = new Dept(); - dept.setId(2L); - Role role = new Role(); - role.setId(50L); - role.setDataScope(DataScopeType.DATA_SCOPE_DEPT); - userDetails.setId(1L); - userDetails.setDept(dept); - userDetails.setRole(role); - userDetails.setDataScopeDeptIds(Set.of(2L)); // 创建测试数据 List products = Lists.newArrayList(product1, product2, product3); Page pageResult = new Page<>(); @@ -140,7 +135,7 @@ public class ProductControllerTest extends MockMvcConfigBase { when(service.page(any(Page.class), any())).thenReturn(pageResult); // 执行 GET 请求并验证响应 mockMvc.perform(get("/api/rest/product") - .with(user(userDetails))) + .with(user(createUserDetails(DataScopeType.DATA_SCOPE_DEPT)))) .andExpect(status().isOk()) .andExpect(jsonPath("$.records.length()").value(products.size())) .andExpect(jsonPath("$.total").value(products.size())) @@ -152,7 +147,7 @@ public class ProductControllerTest extends MockMvcConfigBase { .andExpect(jsonPath("$.records[2].deptId").value(2L)) .andExpect(jsonPath("$.records[0].createId").value(1L)) .andExpect(jsonPath("$.records[1].createId").value(1L)) - .andExpect(jsonPath("$.records[2].createId").value(1L)) + .andExpect(jsonPath("$.records[2].createId").value(2L)) .andDo(print()); // 验证 service.page 方法确实被调用了一次 verify(service).page(any(Page.class), any()); @@ -160,15 +155,6 @@ public class ProductControllerTest extends MockMvcConfigBase { @Test void listWithDataScopeDeptAndChild() throws Exception { - Dept dept = new Dept(); - dept.setId(2L); - Role role = new Role(); - role.setId(50L); - role.setDataScope(DataScopeType.DATA_SCOPE_DEPT_AND_CHILD); - userDetails.setId(1L); - userDetails.setDept(dept); - userDetails.setRole(role); - userDetails.setDataScopeDeptIds(Set.of(2L)); // 创建测试数据 List products = Lists.newArrayList(product1, product2, product3, product4); Page pageResult = new Page<>(); @@ -178,7 +164,7 @@ public class ProductControllerTest extends MockMvcConfigBase { when(service.page(any(Page.class), any())).thenReturn(pageResult); // 执行 GET 请求并验证响应 mockMvc.perform(get("/api/rest/product") - .with(user(userDetails))) + .with(user(createUserDetails(DataScopeType.DATA_SCOPE_DEPT_AND_CHILD)))) .andExpect(status().isOk()) .andExpect(jsonPath("$.records.length()").value(products.size())) .andExpect(jsonPath("$.total").value(products.size())) @@ -192,7 +178,7 @@ public class ProductControllerTest extends MockMvcConfigBase { .andExpect(jsonPath("$.records[3].deptId").value(3L)) .andExpect(jsonPath("$.records[0].createId").value(1L)) .andExpect(jsonPath("$.records[1].createId").value(1L)) - .andExpect(jsonPath("$.records[2].createId").value(1L)) + .andExpect(jsonPath("$.records[2].createId").value(2L)) .andExpect(jsonPath("$.records[3].createId").value(2L)) .andDo(print()); // 验证 service.page 方法确实被调用了一次 @@ -201,17 +187,8 @@ public class ProductControllerTest extends MockMvcConfigBase { @Test void listWithDataScopeSelf() throws Exception { - Dept dept = new Dept(); - dept.setId(2L); - Role role = new Role(); - role.setId(50L); - role.setDataScope(DataScopeType.DATA_SCOPE_SELF); - userDetails.setId(1L); - userDetails.setDept(dept); - userDetails.setRole(role); - userDetails.setDataScopeDeptIds(Set.of(2L)); // 创建测试数据 - List products = Lists.newArrayList(product1, product2, product3); + List products = Lists.newArrayList(product1, product2); Page pageResult = new Page<>(); pageResult.setRecords(products); pageResult.setTotal(products.size()); @@ -219,19 +196,16 @@ public class ProductControllerTest extends MockMvcConfigBase { when(service.page(any(Page.class), any())).thenReturn(pageResult); // 执行 GET 请求并验证响应 mockMvc.perform(get("/api/rest/product") - .with(user(userDetails))) + .with(user(createUserDetails(DataScopeType.DATA_SCOPE_SELF)))) .andExpect(status().isOk()) .andExpect(jsonPath("$.records.length()").value(products.size())) .andExpect(jsonPath("$.total").value(products.size())) .andExpect(jsonPath("$.records[0].id").value(product1.getId())) .andExpect(jsonPath("$.records[1].id").value(product2.getId())) - .andExpect(jsonPath("$.records[2].id").value(product3.getId())) .andExpect(jsonPath("$.records[0].deptId").value(2L)) .andExpect(jsonPath("$.records[1].deptId").value(2L)) - .andExpect(jsonPath("$.records[2].deptId").value(2L)) .andExpect(jsonPath("$.records[0].createId").value(1L)) .andExpect(jsonPath("$.records[1].createId").value(1L)) - .andExpect(jsonPath("$.records[2].createId").value(1L)) .andDo(print()); // 验证 service.page 方法确实被调用了一次 verify(service).page(any(Page.class), any());