Commit 4cf3a3bb497238e0e2e521e2f4c14d9592994089

Authored by zichun
1 parent 56294ee0

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

backend/src/main/java/com/xly/erp/module/usr/entity/UserPermission.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("tUserPermission")
  11 +public class UserPermission {
  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("iUserId")
  29 + private Integer iUserId;
  30 +
  31 + @TableField("iCategoryId")
  32 + private Integer iCategoryId;
  33 +
  34 + @TableField("sCreatedBy")
  35 + private String sCreatedBy;
  36 +
  37 + public Integer getIIncrement() { return iIncrement; }
  38 + public void setIIncrement(Integer iIncrement) { this.iIncrement = iIncrement; }
  39 + public String getSId() { return sId; }
  40 + public void setSId(String sId) { this.sId = sId; }
  41 + public String getSBrandsId() { return sBrandsId; }
  42 + public void setSBrandsId(String sBrandsId) { this.sBrandsId = sBrandsId; }
  43 + public String getSSubsidiaryId() { return sSubsidiaryId; }
  44 + public void setSSubsidiaryId(String sSubsidiaryId) { this.sSubsidiaryId = sSubsidiaryId; }
  45 + public LocalDateTime getTCreateDate() { return tCreateDate; }
  46 + public void setTCreateDate(LocalDateTime tCreateDate) { this.tCreateDate = tCreateDate; }
  47 + public Integer getIUserId() { return iUserId; }
  48 + public void setIUserId(Integer iUserId) { this.iUserId = iUserId; }
  49 + public Integer getICategoryId() { return iCategoryId; }
  50 + public void setICategoryId(Integer iCategoryId) { this.iCategoryId = iCategoryId; }
  51 + public String getSCreatedBy() { return sCreatedBy; }
  52 + public void setSCreatedBy(String sCreatedBy) { this.sCreatedBy = sCreatedBy; }
  53 +}
... ...
backend/src/main/java/com/xly/erp/module/usr/mapper/UserPermissionMapper.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.UserPermission;
  5 +
  6 +public interface UserPermissionMapper extends BaseMapper<UserPermission> {
  7 +}
... ...
backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java
1 1 package com.xly.erp.module.usr.mapper;
2 2  
3 3 import com.xly.erp.module.usr.entity.User;
  4 +import com.xly.erp.module.usr.entity.UserPermission;
4 5 import org.junit.jupiter.api.AfterEach;
5 6 import org.junit.jupiter.api.BeforeEach;
6 7 import org.junit.jupiter.api.Test;
... ... @@ -23,6 +24,9 @@ class UserMapperIT {
23 24 private UserMapper userMapper;
24 25  
25 26 @Autowired
  27 + private UserPermissionMapper userPermissionMapper;
  28 +
  29 + @Autowired
26 30 private JdbcTemplate jdbcTemplate;
27 31  
28 32 @BeforeEach
... ... @@ -32,6 +36,7 @@ class UserMapperIT {
32 36 "DELETE FROM tUserPermission WHERE iUserId IN "
33 37 + "(SELECT iIncrement FROM tUser WHERE sUserNo LIKE 'sp_test_%')");
34 38 jdbcTemplate.update("DELETE FROM tUser WHERE sUserNo LIKE 'sp_test_%'");
  39 + jdbcTemplate.update("DELETE FROM tPermissionCategory WHERE sCategoryCode LIKE 'sp_test_%'");
35 40 }
36 41  
37 42 @Test
... ... @@ -59,6 +64,35 @@ class UserMapperIT {
59 64 .isInstanceOf(DuplicateKeyException.class);
60 65 }
61 66  
  67 + @Test
  68 + void userPermissionInsert_persistsRowWithUserAndCategory() {
  69 + User u = newUser("sp_test_perm_user", "权限关联用户");
  70 + userMapper.insert(u);
  71 +
  72 + jdbcTemplate.update(
  73 + "INSERT INTO tPermissionCategory (sBrandsId, sSubsidiaryId, tCreateDate, sCategoryCode, sCategoryName, "
  74 + + "iSortOrder, sCreatedBy, bDeleted) "
  75 + + "VALUES ('XLY','XLY', NOW(), 'sp_test_pc', '权限分类1', 0, 'STUB_ADMIN', 0)");
  76 + Integer catId = jdbcTemplate.queryForObject(
  77 + "SELECT iIncrement FROM tPermissionCategory WHERE sCategoryCode = 'sp_test_pc'", Integer.class);
  78 +
  79 + UserPermission rel = new UserPermission();
  80 + rel.setSBrandsId("XLY");
  81 + rel.setSSubsidiaryId("XLY");
  82 + rel.setTCreateDate(LocalDateTime.now());
  83 + rel.setIUserId(u.getIIncrement());
  84 + rel.setICategoryId(catId);
  85 + rel.setSCreatedBy("STUB_ADMIN");
  86 + int rows = userPermissionMapper.insert(rel);
  87 + assertThat(rows).isEqualTo(1);
  88 + assertThat(rel.getIIncrement()).isNotNull();
  89 +
  90 + Integer count = jdbcTemplate.queryForObject(
  91 + "SELECT COUNT(1) FROM tUserPermission WHERE iUserId = ? AND iCategoryId = ?",
  92 + Integer.class, u.getIIncrement(), catId);
  93 + assertThat(count).isEqualTo(1);
  94 + }
  95 +
62 96 private User newUser(String userNo, String userName) {
63 97 User u = new User();
64 98 u.setSBrandsId("XLY");
... ...