Commit 32dcaa252ad4a1e77c38f1bc19b452d12df6207f
1 parent
cc1cdb94
feat(usr): 添加 PageVO / UserListQueryDTO / UserListItemVO REQ-USR-003
Showing
4 changed files
with
96 additions
and
0 deletions
backend/src/main/java/com/example/erp/common/vo/PageVO.java
0 → 100644
| 1 | +package com.example.erp.common.vo; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 4 | +import lombok.Getter; | ||
| 5 | +import lombok.Setter; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +@Getter | ||
| 10 | +@Setter | ||
| 11 | +public class PageVO<T> { | ||
| 12 | + | ||
| 13 | + private long total; | ||
| 14 | + private long page; | ||
| 15 | + private long pageSize; | ||
| 16 | + private List<T> list; | ||
| 17 | + | ||
| 18 | + public static <T> PageVO<T> of(IPage<T> iPage) { | ||
| 19 | + PageVO<T> vo = new PageVO<>(); | ||
| 20 | + vo.total = iPage.getTotal(); | ||
| 21 | + vo.page = iPage.getCurrent(); | ||
| 22 | + vo.pageSize = iPage.getSize(); | ||
| 23 | + vo.list = iPage.getRecords(); | ||
| 24 | + return vo; | ||
| 25 | + } | ||
| 26 | +} |
backend/src/main/java/com/example/erp/module/usr/dto/UserListQueryDTO.java
0 → 100644
| 1 | +package com.example.erp.module.usr.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Getter; | ||
| 4 | +import lombok.Setter; | ||
| 5 | + | ||
| 6 | +@Getter | ||
| 7 | +@Setter | ||
| 8 | +public class UserListQueryDTO { | ||
| 9 | + | ||
| 10 | + private String queryField = "username"; | ||
| 11 | + private String matchType = "contains"; | ||
| 12 | + private String queryValue; | ||
| 13 | + private int page = 1; | ||
| 14 | + private int pageSize = 20; | ||
| 15 | +} |
backend/src/main/java/com/example/erp/module/usr/vo/UserListItemVO.java
0 → 100644
| 1 | +package com.example.erp.module.usr.vo; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonProperty; | ||
| 4 | +import lombok.Getter; | ||
| 5 | +import lombok.Setter; | ||
| 6 | + | ||
| 7 | +import java.time.LocalDateTime; | ||
| 8 | + | ||
| 9 | +@Getter | ||
| 10 | +@Setter | ||
| 11 | +public class UserListItemVO { | ||
| 12 | + | ||
| 13 | + @JsonProperty("sId") | ||
| 14 | + private String sId; | ||
| 15 | + | ||
| 16 | + @JsonProperty("sUsername") | ||
| 17 | + private String sUsername; | ||
| 18 | + | ||
| 19 | + @JsonProperty("sUserCode") | ||
| 20 | + private String sUserCode; | ||
| 21 | + | ||
| 22 | + @JsonProperty("sUserType") | ||
| 23 | + private String sUserType; | ||
| 24 | + | ||
| 25 | + @JsonProperty("sLanguage") | ||
| 26 | + private String sLanguage; | ||
| 27 | + | ||
| 28 | + @JsonProperty("bIsDisabled") | ||
| 29 | + private Integer bIsDisabled; | ||
| 30 | + | ||
| 31 | + @JsonProperty("tLastLoginDate") | ||
| 32 | + private LocalDateTime tLastLoginDate; | ||
| 33 | + | ||
| 34 | + @JsonProperty("sCreatorUsername") | ||
| 35 | + private String sCreatorUsername; | ||
| 36 | + | ||
| 37 | + @JsonProperty("tCreateDate") | ||
| 38 | + private LocalDateTime tCreateDate; | ||
| 39 | + | ||
| 40 | + @JsonProperty("sStaffName") | ||
| 41 | + private String sStaffName; | ||
| 42 | + | ||
| 43 | + @JsonProperty("sDepartment") | ||
| 44 | + private String sDepartment; | ||
| 45 | +} |
backend/src/test/java/com/example/erp/module/usr/UserServiceTest.java
| @@ -3,6 +3,7 @@ package com.example.erp.module.usr; | @@ -3,6 +3,7 @@ package com.example.erp.module.usr; | ||
| 3 | import com.example.erp.common.exception.BizException; | 3 | import com.example.erp.common.exception.BizException; |
| 4 | import com.example.erp.config.UserPrincipal; | 4 | import com.example.erp.config.UserPrincipal; |
| 5 | import com.example.erp.module.usr.dto.UserCreateReqDTO; | 5 | import com.example.erp.module.usr.dto.UserCreateReqDTO; |
| 6 | +import com.example.erp.module.usr.dto.UserListQueryDTO; | ||
| 6 | import com.example.erp.module.usr.entity.StaffEntity; | 7 | import com.example.erp.module.usr.entity.StaffEntity; |
| 7 | import com.example.erp.module.usr.entity.UsrUserEntity; | 8 | import com.example.erp.module.usr.entity.UsrUserEntity; |
| 8 | import com.example.erp.module.usr.entity.UserPermissionEntity; | 9 | import com.example.erp.module.usr.entity.UserPermissionEntity; |
| @@ -108,6 +109,15 @@ class UserServiceTest { | @@ -108,6 +109,15 @@ class UserServiceTest { | ||
| 108 | } | 109 | } |
| 109 | 110 | ||
| 110 | @Test | 111 | @Test |
| 112 | + void getUserList_queryDtoDefaults() { | ||
| 113 | + UserListQueryDTO q = new UserListQueryDTO(); | ||
| 114 | + assertEquals("username", q.getQueryField()); | ||
| 115 | + assertEquals("contains", q.getMatchType()); | ||
| 116 | + assertEquals(20, q.getPageSize()); | ||
| 117 | + assertEquals(1, q.getPage()); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Test | ||
| 111 | void createUser_invalidEmployeeId_throws40001() { | 121 | void createUser_invalidEmployeeId_throws40001() { |
| 112 | req.setEmployeeId("bad-staff-id"); | 122 | req.setEmployeeId("bad-staff-id"); |
| 113 | when(userMapper.selectCount(any())).thenReturn(0L); | 123 | when(userMapper.selectCount(any())).thenReturn(0L); |