From 4cf3a3bb497238e0e2e521e2f4c14d9592994089 Mon Sep 17 00:00:00 2001 From: zichun Date: Thu, 30 Apr 2026 10:47:04 +0800 Subject: [PATCH] feat(usr): tUserPermission entity + mapper REQ-USR-001 --- backend/src/main/java/com/xly/erp/module/usr/entity/UserPermission.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/src/main/java/com/xly/erp/module/usr/mapper/UserPermissionMapper.java | 7 +++++++ backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 backend/src/main/java/com/xly/erp/module/usr/entity/UserPermission.java create mode 100644 backend/src/main/java/com/xly/erp/module/usr/mapper/UserPermissionMapper.java diff --git a/backend/src/main/java/com/xly/erp/module/usr/entity/UserPermission.java b/backend/src/main/java/com/xly/erp/module/usr/entity/UserPermission.java new file mode 100644 index 0000000..1009c33 --- /dev/null +++ b/backend/src/main/java/com/xly/erp/module/usr/entity/UserPermission.java @@ -0,0 +1,53 @@ +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("tUserPermission") +public class UserPermission { + + @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("iUserId") + private Integer iUserId; + + @TableField("iCategoryId") + private Integer iCategoryId; + + @TableField("sCreatedBy") + private String sCreatedBy; + + 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 Integer getIUserId() { return iUserId; } + public void setIUserId(Integer iUserId) { this.iUserId = iUserId; } + public Integer getICategoryId() { return iCategoryId; } + public void setICategoryId(Integer iCategoryId) { this.iCategoryId = iCategoryId; } + public String getSCreatedBy() { return sCreatedBy; } + public void setSCreatedBy(String sCreatedBy) { this.sCreatedBy = sCreatedBy; } +} diff --git a/backend/src/main/java/com/xly/erp/module/usr/mapper/UserPermissionMapper.java b/backend/src/main/java/com/xly/erp/module/usr/mapper/UserPermissionMapper.java new file mode 100644 index 0000000..c1741ae --- /dev/null +++ b/backend/src/main/java/com/xly/erp/module/usr/mapper/UserPermissionMapper.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.UserPermission; + +public interface UserPermissionMapper 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 index 55e1f94..435ede2 100644 --- 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 @@ -1,6 +1,7 @@ package com.xly.erp.module.usr.mapper; import com.xly.erp.module.usr.entity.User; +import com.xly.erp.module.usr.entity.UserPermission; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,6 +24,9 @@ class UserMapperIT { private UserMapper userMapper; @Autowired + private UserPermissionMapper userPermissionMapper; + + @Autowired private JdbcTemplate jdbcTemplate; @BeforeEach @@ -32,6 +36,7 @@ class UserMapperIT { "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_%'"); + jdbcTemplate.update("DELETE FROM tPermissionCategory WHERE sCategoryCode LIKE 'sp_test_%'"); } @Test @@ -59,6 +64,35 @@ class UserMapperIT { .isInstanceOf(DuplicateKeyException.class); } + @Test + void userPermissionInsert_persistsRowWithUserAndCategory() { + User u = newUser("sp_test_perm_user", "权限关联用户"); + userMapper.insert(u); + + jdbcTemplate.update( + "INSERT INTO tPermissionCategory (sBrandsId, sSubsidiaryId, tCreateDate, sCategoryCode, sCategoryName, " + + "iSortOrder, sCreatedBy, bDeleted) " + + "VALUES ('XLY','XLY', NOW(), 'sp_test_pc', '权限分类1', 0, 'STUB_ADMIN', 0)"); + Integer catId = jdbcTemplate.queryForObject( + "SELECT iIncrement FROM tPermissionCategory WHERE sCategoryCode = 'sp_test_pc'", Integer.class); + + UserPermission rel = new UserPermission(); + rel.setSBrandsId("XLY"); + rel.setSSubsidiaryId("XLY"); + rel.setTCreateDate(LocalDateTime.now()); + rel.setIUserId(u.getIIncrement()); + rel.setICategoryId(catId); + rel.setSCreatedBy("STUB_ADMIN"); + int rows = userPermissionMapper.insert(rel); + assertThat(rows).isEqualTo(1); + assertThat(rel.getIIncrement()).isNotNull(); + + Integer count = jdbcTemplate.queryForObject( + "SELECT COUNT(1) FROM tUserPermission WHERE iUserId = ? AND iCategoryId = ?", + Integer.class, u.getIIncrement(), catId); + assertThat(count).isEqualTo(1); + } + private User newUser(String userNo, String userName) { User u = new User(); u.setSBrandsId("XLY"); -- libgit2 0.22.2