diff --git a/backend/src/main/java/com/xly/erp/module/usr/entity/User.java b/backend/src/main/java/com/xly/erp/module/usr/entity/User.java new file mode 100644 index 0000000..651cea1 --- /dev/null +++ b/backend/src/main/java/com/xly/erp/module/usr/entity/User.java @@ -0,0 +1,98 @@ +package com.xly.erp.module.usr.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +import java.time.LocalDateTime; + +@TableName("tUser") +public class User { + + @TableId(value = "iIncrement", type = IdType.AUTO) + private Integer iIncrement; + + @TableField("sId") + private String sId; + + @TableField("sBrandsId") + private String sBrandsId; + + @TableField("sSubsidiaryId") + private String sSubsidiaryId; + + @TableField("tCreateDate") + private LocalDateTime tCreateDate; + + @TableField("sUserNo") + private String sUserNo; + + @TableField("sUserName") + private String sUserName; + + @TableField("iStaffId") + private Integer iStaffId; + + @TableField("sUserType") + private String sUserType; + + @TableField("sLanguage") + private String sLanguage; + + @TableField("bCanModifyDocs") + private Boolean bCanModifyDocs; + + @TableField("sPasswordHash") + private String sPasswordHash; + + @TableField("tLastLoginDate") + private LocalDateTime tLastLoginDate; + + @TableField("sCreatedBy") + private String sCreatedBy; + + @TableField("bDeleted") + private Boolean bDeleted; + + @TableField("tDeletedDate") + private LocalDateTime tDeletedDate; + + @TableField("sDeletedBy") + private String sDeletedBy; + + public Integer getIIncrement() { return iIncrement; } + public void setIIncrement(Integer iIncrement) { this.iIncrement = iIncrement; } + public String getSId() { return sId; } + public void setSId(String sId) { this.sId = sId; } + public String getSBrandsId() { return sBrandsId; } + public void setSBrandsId(String sBrandsId) { this.sBrandsId = sBrandsId; } + public String getSSubsidiaryId() { return sSubsidiaryId; } + public void setSSubsidiaryId(String sSubsidiaryId) { this.sSubsidiaryId = sSubsidiaryId; } + public LocalDateTime getTCreateDate() { return tCreateDate; } + public void setTCreateDate(LocalDateTime tCreateDate) { this.tCreateDate = tCreateDate; } + public String getSUserNo() { return sUserNo; } + public void setSUserNo(String sUserNo) { this.sUserNo = sUserNo; } + public String getSUserName() { return sUserName; } + public void setSUserName(String sUserName) { this.sUserName = sUserName; } + public Integer getIStaffId() { return iStaffId; } + public void setIStaffId(Integer iStaffId) { this.iStaffId = iStaffId; } + public String getSUserType() { return sUserType; } + public void setSUserType(String sUserType) { this.sUserType = sUserType; } + public String getSLanguage() { return sLanguage; } + public void setSLanguage(String sLanguage) { this.sLanguage = sLanguage; } + public Boolean getBCanModifyDocs() { return bCanModifyDocs; } + public void setBCanModifyDocs(Boolean bCanModifyDocs) { this.bCanModifyDocs = bCanModifyDocs; } + public String getSPasswordHash() { return sPasswordHash; } + public void setSPasswordHash(String sPasswordHash) { this.sPasswordHash = sPasswordHash; } + public LocalDateTime getTLastLoginDate() { return tLastLoginDate; } + public void setTLastLoginDate(LocalDateTime tLastLoginDate) { this.tLastLoginDate = tLastLoginDate; } + public String getSCreatedBy() { return sCreatedBy; } + public void setSCreatedBy(String sCreatedBy) { this.sCreatedBy = sCreatedBy; } + public Boolean getBDeleted() { return bDeleted; } + public void setBDeleted(Boolean bDeleted) { this.bDeleted = bDeleted; } + public LocalDateTime getTDeletedDate() { return tDeletedDate; } + public void setTDeletedDate(LocalDateTime tDeletedDate) { this.tDeletedDate = tDeletedDate; } + public String getSDeletedBy() { return sDeletedBy; } + public void setSDeletedBy(String sDeletedBy) { this.sDeletedBy = sDeletedBy; } +} diff --git a/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java b/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java new file mode 100644 index 0000000..1333a45 --- /dev/null +++ b/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java @@ -0,0 +1,7 @@ +package com.xly.erp.module.usr.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xly.erp.module.usr.entity.User; + +public interface UserMapper extends BaseMapper { +} diff --git a/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java b/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java new file mode 100644 index 0000000..55e1f94 --- /dev/null +++ b/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java @@ -0,0 +1,77 @@ +package com.xly.erp.module.usr.mapper; + +import com.xly.erp.module.usr.entity.User; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ActiveProfiles; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) +@ActiveProfiles("test") +class UserMapperIT { + + @Autowired + private UserMapper userMapper; + + @Autowired + private JdbcTemplate jdbcTemplate; + + @BeforeEach + @AfterEach + void cleanup() { + jdbcTemplate.update( + "DELETE FROM tUserPermission WHERE iUserId IN " + + "(SELECT iIncrement FROM tUser WHERE sUserNo LIKE 'sp_test_%')"); + jdbcTemplate.update("DELETE FROM tUser WHERE sUserNo LIKE 'sp_test_%'"); + } + + @Test + void insertAndSelectById_persistsAllStandardCols() { + User u = newUser("sp_test_u1", "用户1"); + int rows = userMapper.insert(u); + assertThat(rows).isEqualTo(1); + assertThat(u.getIIncrement()).isNotNull(); + + User loaded = userMapper.selectById(u.getIIncrement()); + assertThat(loaded.getSUserNo()).isEqualTo("sp_test_u1"); + assertThat(loaded.getSUserName()).isEqualTo("用户1"); + assertThat(loaded.getSBrandsId()).isEqualTo("XLY"); + assertThat(loaded.getSPasswordHash()).startsWith("$2a$"); + assertThat(loaded.getBDeleted()).isFalse(); + assertThat(loaded.getSUserType()).isEqualTo("普通用户"); + } + + @Test + void uniqueUserNoConstraint_rejectsDuplicate() { + userMapper.insert(newUser("sp_test_dup", "首次")); + User second = newUser("sp_test_dup", "第二次"); + second.setSUserName("sp_test_other_name"); + assertThatThrownBy(() -> userMapper.insert(second)) + .isInstanceOf(DuplicateKeyException.class); + } + + private User newUser(String userNo, String userName) { + User u = new User(); + u.setSBrandsId("XLY"); + u.setSSubsidiaryId("XLY"); + u.setTCreateDate(LocalDateTime.now()); + u.setSUserNo(userNo); + u.setSUserName(userName); + u.setSUserType("普通用户"); + u.setSLanguage("zh"); + u.setBCanModifyDocs(false); + u.setSPasswordHash("$2a$10$stubhashstubhashstubhashstubhashstubhashstubhashstubhash"); + u.setSCreatedBy("STUB_ADMIN"); + u.setBDeleted(false); + return u; + } +}