Commit b96ba80c30a83dcfc87606e304bfe613aeaa5482
1 parent
ad147797
feat(usr): USR 模块 entity + mapper (User/UserPermission/Employee/Permission) REQ-USR-001
Showing
9 changed files
with
228 additions
and
0 deletions
backend/src/main/java/com/xly/test4/module/usr/entity/Employee.java
0 → 100644
| 1 | +package com.xly.test4.module.usr.entity; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import lombok.AllArgsConstructor; | ||
| 7 | +import lombok.Builder; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import lombok.NoArgsConstructor; | ||
| 10 | + | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Data | ||
| 14 | +@Builder | ||
| 15 | +@NoArgsConstructor | ||
| 16 | +@AllArgsConstructor | ||
| 17 | +@TableName("tEmployee") | ||
| 18 | +public class Employee { | ||
| 19 | + | ||
| 20 | + @TableId(value = "iIncrement", type = IdType.AUTO) | ||
| 21 | + private Integer iIncrement; | ||
| 22 | + | ||
| 23 | + private String sId; | ||
| 24 | + private String sBrandsId; | ||
| 25 | + private String sSubsidiaryId; | ||
| 26 | + private LocalDateTime tCreateDate; | ||
| 27 | + | ||
| 28 | + private String sEmployeeCode; | ||
| 29 | + private String sEmployeeName; | ||
| 30 | + private String sDepartment; | ||
| 31 | + private Integer iIsDisabled; | ||
| 32 | + private LocalDateTime tUpdateDate; | ||
| 33 | +} |
backend/src/main/java/com/xly/test4/module/usr/entity/Permission.java
0 → 100644
| 1 | +package com.xly.test4.module.usr.entity; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import lombok.AllArgsConstructor; | ||
| 7 | +import lombok.Builder; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import lombok.NoArgsConstructor; | ||
| 10 | + | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Data | ||
| 14 | +@Builder | ||
| 15 | +@NoArgsConstructor | ||
| 16 | +@AllArgsConstructor | ||
| 17 | +@TableName("tPermission") | ||
| 18 | +public class Permission { | ||
| 19 | + | ||
| 20 | + @TableId(value = "iIncrement", type = IdType.AUTO) | ||
| 21 | + private Integer iIncrement; | ||
| 22 | + | ||
| 23 | + private String sId; | ||
| 24 | + private String sBrandsId; | ||
| 25 | + private String sSubsidiaryId; | ||
| 26 | + private LocalDateTime tCreateDate; | ||
| 27 | + | ||
| 28 | + private String sCategory; | ||
| 29 | + private String sCategoryName; | ||
| 30 | + private String sDescription; | ||
| 31 | + private Integer iIsDisabled; | ||
| 32 | + private LocalDateTime tUpdateDate; | ||
| 33 | +} |
backend/src/main/java/com/xly/test4/module/usr/entity/User.java
0 → 100644
| 1 | +package com.xly.test4.module.usr.entity; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import lombok.AllArgsConstructor; | ||
| 7 | +import lombok.Builder; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import lombok.NoArgsConstructor; | ||
| 10 | + | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Data | ||
| 14 | +@Builder | ||
| 15 | +@NoArgsConstructor | ||
| 16 | +@AllArgsConstructor | ||
| 17 | +@TableName("tUser") | ||
| 18 | +public class User { | ||
| 19 | + | ||
| 20 | + @TableId(value = "iIncrement", type = IdType.AUTO) | ||
| 21 | + private Integer iIncrement; | ||
| 22 | + | ||
| 23 | + private String sId; | ||
| 24 | + private String sBrandsId; | ||
| 25 | + private String sSubsidiaryId; | ||
| 26 | + private LocalDateTime tCreateDate; | ||
| 27 | + | ||
| 28 | + private String sUserCode; | ||
| 29 | + private String sUserName; | ||
| 30 | + private Integer iEmployeeId; | ||
| 31 | + private String sUserType; | ||
| 32 | + private String sLanguage; | ||
| 33 | + private Integer iCanEditDoc; | ||
| 34 | + private String sPasswordHash; | ||
| 35 | + private Integer iIsDisabled; | ||
| 36 | + private LocalDateTime tLastLoginDate; | ||
| 37 | + private Integer iLoginFailCount; | ||
| 38 | + private LocalDateTime tLockedUntil; | ||
| 39 | + private String sCreatedBy; | ||
| 40 | + private LocalDateTime tUpdateDate; | ||
| 41 | +} |
backend/src/main/java/com/xly/test4/module/usr/entity/UserPermission.java
0 → 100644
| 1 | +package com.xly.test4.module.usr.entity; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import lombok.AllArgsConstructor; | ||
| 7 | +import lombok.Builder; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import lombok.NoArgsConstructor; | ||
| 10 | + | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Data | ||
| 14 | +@Builder | ||
| 15 | +@NoArgsConstructor | ||
| 16 | +@AllArgsConstructor | ||
| 17 | +@TableName("tUserPermission") | ||
| 18 | +public class UserPermission { | ||
| 19 | + | ||
| 20 | + @TableId(value = "iIncrement", type = IdType.AUTO) | ||
| 21 | + private Integer iIncrement; | ||
| 22 | + | ||
| 23 | + private String sId; | ||
| 24 | + private String sBrandsId; | ||
| 25 | + private String sSubsidiaryId; | ||
| 26 | + private LocalDateTime tCreateDate; | ||
| 27 | + | ||
| 28 | + private Integer iUserId; | ||
| 29 | + private Integer iPermissionId; | ||
| 30 | + private String sGrantedBy; | ||
| 31 | +} |
backend/src/main/java/com/xly/test4/module/usr/mapper/EmployeeMapper.java
0 → 100644
backend/src/main/java/com/xly/test4/module/usr/mapper/PermissionMapper.java
0 → 100644
backend/src/main/java/com/xly/test4/module/usr/mapper/UserMapper.java
0 → 100644
backend/src/main/java/com/xly/test4/module/usr/mapper/UserPermissionMapper.java
0 → 100644
backend/src/test/java/com/xly/test4/module/usr/mapper/UserMapperIT.java
0 → 100644
| 1 | +package com.xly.test4.module.usr.mapper; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 4 | +import com.xly.test4.module.usr.entity.User; | ||
| 5 | +import org.junit.jupiter.api.Test; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 8 | + | ||
| 9 | +import static org.assertj.core.api.Assertions.assertThat; | ||
| 10 | + | ||
| 11 | +@SpringBootTest | ||
| 12 | +class UserMapperIT { | ||
| 13 | + | ||
| 14 | + @Autowired | ||
| 15 | + private UserMapper userMapper; | ||
| 16 | + | ||
| 17 | + @Test | ||
| 18 | + void insertAndSelectById_columnsMappedCorrectly() { | ||
| 19 | + User user = User.builder() | ||
| 20 | + .sUserCode("UMIT-001") | ||
| 21 | + .sUserName("usermapperit_001") | ||
| 22 | + .sUserType("NORMAL") | ||
| 23 | + .sLanguage("zh-CN") | ||
| 24 | + .iCanEditDoc(0) | ||
| 25 | + .sPasswordHash("$2y$10$placeholderHashForMapperTestOnly_XXXXXXXXXXXXXXXXXXXXXXXX") | ||
| 26 | + .iIsDisabled(0) | ||
| 27 | + .iLoginFailCount(0) | ||
| 28 | + .sBrandsId("BR-T") | ||
| 29 | + .sSubsidiaryId("SUB-T") | ||
| 30 | + .sCreatedBy("system") | ||
| 31 | + .build(); | ||
| 32 | + | ||
| 33 | + int affected = userMapper.insert(user); | ||
| 34 | + assertThat(affected).isEqualTo(1); | ||
| 35 | + assertThat(user.getIIncrement()).isNotNull(); | ||
| 36 | + | ||
| 37 | + User loaded = userMapper.selectById(user.getIIncrement()); | ||
| 38 | + assertThat(loaded.getSUserCode()).isEqualTo("UMIT-001"); | ||
| 39 | + assertThat(loaded.getSUserName()).isEqualTo("usermapperit_001"); | ||
| 40 | + assertThat(loaded.getSUserType()).isEqualTo("NORMAL"); | ||
| 41 | + assertThat(loaded.getSLanguage()).isEqualTo("zh-CN"); | ||
| 42 | + assertThat(loaded.getICanEditDoc()).isZero(); | ||
| 43 | + assertThat(loaded.getIIsDisabled()).isZero(); | ||
| 44 | + assertThat(loaded.getSBrandsId()).isEqualTo("BR-T"); | ||
| 45 | + assertThat(loaded.getSSubsidiaryId()).isEqualTo("SUB-T"); | ||
| 46 | + assertThat(loaded.getSCreatedBy()).isEqualTo("system"); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Test | ||
| 50 | + void seedAdminLoadable_byUserName() { | ||
| 51 | + User admin = userMapper.selectOne(new LambdaQueryWrapper<User>() | ||
| 52 | + .eq(User::getSUserName, "admin")); | ||
| 53 | + | ||
| 54 | + assertThat(admin).isNotNull(); | ||
| 55 | + assertThat(admin.getSUserType()).isEqualTo("ADMIN"); | ||
| 56 | + assertThat(admin.getSBrandsId()).isEqualTo("BR-DEFAULT"); | ||
| 57 | + assertThat(admin.getSSubsidiaryId()).isEqualTo("SUB-DEFAULT"); | ||
| 58 | + assertThat(admin.getIIsDisabled()).isZero(); | ||
| 59 | + assertThat(admin.getSPasswordHash()).startsWith("$2"); | ||
| 60 | + assertThat(admin.getSPasswordHash()).hasSize(60); | ||
| 61 | + } | ||
| 62 | +} |