Commit 5ecface9b525366ee23ded191c6995a9b26548cd

Authored by zichun
1 parent 144c524e

feat(usr): tUser entity + mapper REQ-USR-001

backend/src/main/java/com/xly/erp/module/usr/entity/User.java 0 → 100644
  1 +package com.xly.erp.module.usr.entity;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.IdType;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +
  8 +import java.time.LocalDateTime;
  9 +
  10 +@TableName("tUser")
  11 +public class User {
  12 +
  13 + @TableId(value = "iIncrement", type = IdType.AUTO)
  14 + private Integer iIncrement;
  15 +
  16 + @TableField("sId")
  17 + private String sId;
  18 +
  19 + @TableField("sBrandsId")
  20 + private String sBrandsId;
  21 +
  22 + @TableField("sSubsidiaryId")
  23 + private String sSubsidiaryId;
  24 +
  25 + @TableField("tCreateDate")
  26 + private LocalDateTime tCreateDate;
  27 +
  28 + @TableField("sUserNo")
  29 + private String sUserNo;
  30 +
  31 + @TableField("sUserName")
  32 + private String sUserName;
  33 +
  34 + @TableField("iStaffId")
  35 + private Integer iStaffId;
  36 +
  37 + @TableField("sUserType")
  38 + private String sUserType;
  39 +
  40 + @TableField("sLanguage")
  41 + private String sLanguage;
  42 +
  43 + @TableField("bCanModifyDocs")
  44 + private Boolean bCanModifyDocs;
  45 +
  46 + @TableField("sPasswordHash")
  47 + private String sPasswordHash;
  48 +
  49 + @TableField("tLastLoginDate")
  50 + private LocalDateTime tLastLoginDate;
  51 +
  52 + @TableField("sCreatedBy")
  53 + private String sCreatedBy;
  54 +
  55 + @TableField("bDeleted")
  56 + private Boolean bDeleted;
  57 +
  58 + @TableField("tDeletedDate")
  59 + private LocalDateTime tDeletedDate;
  60 +
  61 + @TableField("sDeletedBy")
  62 + private String sDeletedBy;
  63 +
  64 + public Integer getIIncrement() { return iIncrement; }
  65 + public void setIIncrement(Integer iIncrement) { this.iIncrement = iIncrement; }
  66 + public String getSId() { return sId; }
  67 + public void setSId(String sId) { this.sId = sId; }
  68 + public String getSBrandsId() { return sBrandsId; }
  69 + public void setSBrandsId(String sBrandsId) { this.sBrandsId = sBrandsId; }
  70 + public String getSSubsidiaryId() { return sSubsidiaryId; }
  71 + public void setSSubsidiaryId(String sSubsidiaryId) { this.sSubsidiaryId = sSubsidiaryId; }
  72 + public LocalDateTime getTCreateDate() { return tCreateDate; }
  73 + public void setTCreateDate(LocalDateTime tCreateDate) { this.tCreateDate = tCreateDate; }
  74 + public String getSUserNo() { return sUserNo; }
  75 + public void setSUserNo(String sUserNo) { this.sUserNo = sUserNo; }
  76 + public String getSUserName() { return sUserName; }
  77 + public void setSUserName(String sUserName) { this.sUserName = sUserName; }
  78 + public Integer getIStaffId() { return iStaffId; }
  79 + public void setIStaffId(Integer iStaffId) { this.iStaffId = iStaffId; }
  80 + public String getSUserType() { return sUserType; }
  81 + public void setSUserType(String sUserType) { this.sUserType = sUserType; }
  82 + public String getSLanguage() { return sLanguage; }
  83 + public void setSLanguage(String sLanguage) { this.sLanguage = sLanguage; }
  84 + public Boolean getBCanModifyDocs() { return bCanModifyDocs; }
  85 + public void setBCanModifyDocs(Boolean bCanModifyDocs) { this.bCanModifyDocs = bCanModifyDocs; }
  86 + public String getSPasswordHash() { return sPasswordHash; }
  87 + public void setSPasswordHash(String sPasswordHash) { this.sPasswordHash = sPasswordHash; }
  88 + public LocalDateTime getTLastLoginDate() { return tLastLoginDate; }
  89 + public void setTLastLoginDate(LocalDateTime tLastLoginDate) { this.tLastLoginDate = tLastLoginDate; }
  90 + public String getSCreatedBy() { return sCreatedBy; }
  91 + public void setSCreatedBy(String sCreatedBy) { this.sCreatedBy = sCreatedBy; }
  92 + public Boolean getBDeleted() { return bDeleted; }
  93 + public void setBDeleted(Boolean bDeleted) { this.bDeleted = bDeleted; }
  94 + public LocalDateTime getTDeletedDate() { return tDeletedDate; }
  95 + public void setTDeletedDate(LocalDateTime tDeletedDate) { this.tDeletedDate = tDeletedDate; }
  96 + public String getSDeletedBy() { return sDeletedBy; }
  97 + public void setSDeletedBy(String sDeletedBy) { this.sDeletedBy = sDeletedBy; }
  98 +}
backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java 0 → 100644
  1 +package com.xly.erp.module.usr.mapper;
  2 +
  3 +import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  4 +import com.xly.erp.module.usr.entity.User;
  5 +
  6 +public interface UserMapper extends BaseMapper<User> {
  7 +}
backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java 0 → 100644
  1 +package com.xly.erp.module.usr.mapper;
  2 +
  3 +import com.xly.erp.module.usr.entity.User;
  4 +import org.junit.jupiter.api.AfterEach;
  5 +import org.junit.jupiter.api.BeforeEach;
  6 +import org.junit.jupiter.api.Test;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.boot.test.context.SpringBootTest;
  9 +import org.springframework.dao.DuplicateKeyException;
  10 +import org.springframework.jdbc.core.JdbcTemplate;
  11 +import org.springframework.test.context.ActiveProfiles;
  12 +
  13 +import java.time.LocalDateTime;
  14 +
  15 +import static org.assertj.core.api.Assertions.assertThat;
  16 +import static org.assertj.core.api.Assertions.assertThatThrownBy;
  17 +
  18 +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
  19 +@ActiveProfiles("test")
  20 +class UserMapperIT {
  21 +
  22 + @Autowired
  23 + private UserMapper userMapper;
  24 +
  25 + @Autowired
  26 + private JdbcTemplate jdbcTemplate;
  27 +
  28 + @BeforeEach
  29 + @AfterEach
  30 + void cleanup() {
  31 + jdbcTemplate.update(
  32 + "DELETE FROM tUserPermission WHERE iUserId IN "
  33 + + "(SELECT iIncrement FROM tUser WHERE sUserNo LIKE 'sp_test_%')");
  34 + jdbcTemplate.update("DELETE FROM tUser WHERE sUserNo LIKE 'sp_test_%'");
  35 + }
  36 +
  37 + @Test
  38 + void insertAndSelectById_persistsAllStandardCols() {
  39 + User u = newUser("sp_test_u1", "用户1");
  40 + int rows = userMapper.insert(u);
  41 + assertThat(rows).isEqualTo(1);
  42 + assertThat(u.getIIncrement()).isNotNull();
  43 +
  44 + User loaded = userMapper.selectById(u.getIIncrement());
  45 + assertThat(loaded.getSUserNo()).isEqualTo("sp_test_u1");
  46 + assertThat(loaded.getSUserName()).isEqualTo("用户1");
  47 + assertThat(loaded.getSBrandsId()).isEqualTo("XLY");
  48 + assertThat(loaded.getSPasswordHash()).startsWith("$2a$");
  49 + assertThat(loaded.getBDeleted()).isFalse();
  50 + assertThat(loaded.getSUserType()).isEqualTo("普通用户");
  51 + }
  52 +
  53 + @Test
  54 + void uniqueUserNoConstraint_rejectsDuplicate() {
  55 + userMapper.insert(newUser("sp_test_dup", "首次"));
  56 + User second = newUser("sp_test_dup", "第二次");
  57 + second.setSUserName("sp_test_other_name");
  58 + assertThatThrownBy(() -> userMapper.insert(second))
  59 + .isInstanceOf(DuplicateKeyException.class);
  60 + }
  61 +
  62 + private User newUser(String userNo, String userName) {
  63 + User u = new User();
  64 + u.setSBrandsId("XLY");
  65 + u.setSSubsidiaryId("XLY");
  66 + u.setTCreateDate(LocalDateTime.now());
  67 + u.setSUserNo(userNo);
  68 + u.setSUserName(userName);
  69 + u.setSUserType("普通用户");
  70 + u.setSLanguage("zh");
  71 + u.setBCanModifyDocs(false);
  72 + u.setSPasswordHash("$2a$10$stubhashstubhashstubhashstubhashstubhashstubhashstubhash");
  73 + u.setSCreatedBy("STUB_ADMIN");
  74 + u.setBDeleted(false);
  75 + return u;
  76 + }
  77 +}