Commit 38fbdcd0ab540ef081a96095e4e0b3dc9248f050
1 parent
2bd4442c
feat(mod): tModule entity + mapper REQ-MOD-001
Showing
4 changed files
with
196 additions
and
0 deletions
backend/src/main/java/com/xly/erp/common/security/SecurityConfig.java
| 1 | package com.xly.erp.common.security; | 1 | package com.xly.erp.common.security; |
| 2 | 2 | ||
| 3 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
| 3 | import org.springframework.context.annotation.Bean; | 4 | import org.springframework.context.annotation.Bean; |
| 4 | import org.springframework.context.annotation.Configuration; | 5 | import org.springframework.context.annotation.Configuration; |
| 5 | import org.springframework.http.HttpMethod; | 6 | import org.springframework.http.HttpMethod; |
| @@ -9,6 +10,7 @@ import org.springframework.security.web.SecurityFilterChain; | @@ -9,6 +10,7 @@ import org.springframework.security.web.SecurityFilterChain; | ||
| 9 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | 10 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
| 10 | 11 | ||
| 11 | @Configuration | 12 | @Configuration |
| 13 | +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) | ||
| 12 | public class SecurityConfig { | 14 | public class SecurityConfig { |
| 13 | 15 | ||
| 14 | private final JwtAuthenticationFilter jwtFilter; | 16 | private final JwtAuthenticationFilter jwtFilter; |
backend/src/main/java/com/xly/erp/module/mod/entity/Module.java
0 → 100644
| 1 | +package com.xly.erp.module.mod.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("tModule") | ||
| 11 | +public class Module { | ||
| 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("sDisplayType") | ||
| 29 | + private String sDisplayType; | ||
| 30 | + | ||
| 31 | + @TableField("sProcedureName") | ||
| 32 | + private String sProcedureName; | ||
| 33 | + | ||
| 34 | + @TableField("sModuleType") | ||
| 35 | + private String sModuleType; | ||
| 36 | + | ||
| 37 | + @TableField("sManageDeptEn") | ||
| 38 | + private String sManageDeptEn; | ||
| 39 | + | ||
| 40 | + @TableField("bShowPermission") | ||
| 41 | + private Boolean bShowPermission; | ||
| 42 | + | ||
| 43 | + @TableField("sModuleNameZh") | ||
| 44 | + private String sModuleNameZh; | ||
| 45 | + | ||
| 46 | + @TableField("iParentId") | ||
| 47 | + private Integer iParentId; | ||
| 48 | + | ||
| 49 | + @TableField("iSortOrder") | ||
| 50 | + private Integer iSortOrder; | ||
| 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 getSDisplayType() { return sDisplayType; } | ||
| 75 | + public void setSDisplayType(String sDisplayType) { this.sDisplayType = sDisplayType; } | ||
| 76 | + public String getSProcedureName() { return sProcedureName; } | ||
| 77 | + public void setSProcedureName(String sProcedureName) { this.sProcedureName = sProcedureName; } | ||
| 78 | + public String getSModuleType() { return sModuleType; } | ||
| 79 | + public void setSModuleType(String sModuleType) { this.sModuleType = sModuleType; } | ||
| 80 | + public String getSManageDeptEn() { return sManageDeptEn; } | ||
| 81 | + public void setSManageDeptEn(String sManageDeptEn) { this.sManageDeptEn = sManageDeptEn; } | ||
| 82 | + public Boolean getBShowPermission() { return bShowPermission; } | ||
| 83 | + public void setBShowPermission(Boolean bShowPermission) { this.bShowPermission = bShowPermission; } | ||
| 84 | + public String getSModuleNameZh() { return sModuleNameZh; } | ||
| 85 | + public void setSModuleNameZh(String sModuleNameZh) { this.sModuleNameZh = sModuleNameZh; } | ||
| 86 | + public Integer getIParentId() { return iParentId; } | ||
| 87 | + public void setIParentId(Integer iParentId) { this.iParentId = iParentId; } | ||
| 88 | + public Integer getISortOrder() { return iSortOrder; } | ||
| 89 | + public void setISortOrder(Integer iSortOrder) { this.iSortOrder = iSortOrder; } | ||
| 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/mod/mapper/ModuleMapper.java
0 → 100644
| 1 | +package com.xly.erp.module.mod.mapper; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | +import com.xly.erp.module.mod.entity.Module; | ||
| 5 | +import org.apache.ibatis.annotations.Param; | ||
| 6 | +import org.apache.ibatis.annotations.Select; | ||
| 7 | + | ||
| 8 | +public interface ModuleMapper extends BaseMapper<Module> { | ||
| 9 | + | ||
| 10 | + @Select("SELECT 1 FROM tModule WHERE iIncrement = #{id} AND bDeleted = 0 LIMIT 1") | ||
| 11 | + Integer findActiveFlagById(@Param("id") Integer iIncrement); | ||
| 12 | + | ||
| 13 | + default boolean existsActiveById(Integer iIncrement) { | ||
| 14 | + return findActiveFlagById(iIncrement) != null; | ||
| 15 | + } | ||
| 16 | +} |
backend/src/test/java/com/xly/erp/module/mod/mapper/ModuleMapperIT.java
0 → 100644
| 1 | +package com.xly.erp.module.mod.mapper; | ||
| 2 | + | ||
| 3 | +import com.xly.erp.module.mod.entity.Module; | ||
| 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.jdbc.core.JdbcTemplate; | ||
| 10 | +import org.springframework.test.context.ActiveProfiles; | ||
| 11 | + | ||
| 12 | +import java.time.LocalDateTime; | ||
| 13 | + | ||
| 14 | +import static org.assertj.core.api.Assertions.assertThat; | ||
| 15 | + | ||
| 16 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
| 17 | +@ActiveProfiles("test") | ||
| 18 | +class ModuleMapperIT { | ||
| 19 | + | ||
| 20 | + @Autowired | ||
| 21 | + private ModuleMapper moduleMapper; | ||
| 22 | + | ||
| 23 | + @Autowired | ||
| 24 | + private JdbcTemplate jdbcTemplate; | ||
| 25 | + | ||
| 26 | + @BeforeEach | ||
| 27 | + @AfterEach | ||
| 28 | + void cleanup() { | ||
| 29 | + jdbcTemplate.update("DELETE FROM tModule WHERE sProcedureName LIKE 'sp_test_%'"); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Test | ||
| 33 | + void insertAndSelectById_persistsAllStandardCols() { | ||
| 34 | + Module m = newModule("sp_test_insert", "插入用例", null); | ||
| 35 | + int rows = moduleMapper.insert(m); | ||
| 36 | + assertThat(rows).isEqualTo(1); | ||
| 37 | + assertThat(m.getIIncrement()).isNotNull(); | ||
| 38 | + | ||
| 39 | + Module loaded = moduleMapper.selectById(m.getIIncrement()); | ||
| 40 | + assertThat(loaded.getSProcedureName()).isEqualTo("sp_test_insert"); | ||
| 41 | + assertThat(loaded.getSBrandsId()).isEqualTo("XLY"); | ||
| 42 | + assertThat(loaded.getSSubsidiaryId()).isEqualTo("XLY"); | ||
| 43 | + assertThat(loaded.getSDisplayType()).isEqualTo("手机端"); | ||
| 44 | + assertThat(loaded.getSModuleNameZh()).isEqualTo("插入用例"); | ||
| 45 | + assertThat(loaded.getBDeleted()).isFalse(); | ||
| 46 | + assertThat(loaded.getBShowPermission()).isFalse(); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Test | ||
| 50 | + void existsActiveById_trueForAlive_falseForDeleted() { | ||
| 51 | + Module alive = newModule("sp_test_alive", "活的", null); | ||
| 52 | + moduleMapper.insert(alive); | ||
| 53 | + | ||
| 54 | + Module dead = newModule("sp_test_dead", "死的", null); | ||
| 55 | + dead.setBDeleted(true); | ||
| 56 | + moduleMapper.insert(dead); | ||
| 57 | + | ||
| 58 | + assertThat(moduleMapper.existsActiveById(alive.getIIncrement())).isTrue(); | ||
| 59 | + assertThat(moduleMapper.existsActiveById(dead.getIIncrement())).isFalse(); | ||
| 60 | + assertThat(moduleMapper.existsActiveById(99999999)).isFalse(); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + private Module newModule(String procedureName, String nameZh, Integer parentId) { | ||
| 64 | + Module m = new Module(); | ||
| 65 | + m.setSBrandsId("XLY"); | ||
| 66 | + m.setSSubsidiaryId("XLY"); | ||
| 67 | + m.setTCreateDate(LocalDateTime.now()); | ||
| 68 | + m.setSDisplayType("手机端"); | ||
| 69 | + m.setSProcedureName(procedureName); | ||
| 70 | + m.setSModuleType("业务模块"); | ||
| 71 | + m.setSManageDeptEn("IT"); | ||
| 72 | + m.setBShowPermission(false); | ||
| 73 | + m.setSModuleNameZh(nameZh); | ||
| 74 | + m.setIParentId(parentId); | ||
| 75 | + m.setISortOrder(0); | ||
| 76 | + m.setSCreatedBy("STUB_ADMIN"); | ||
| 77 | + m.setBDeleted(false); | ||
| 78 | + return m; | ||
| 79 | + } | ||
| 80 | +} |