Commit d14c3bf39df32c59e6f7ebfd6459c47e334520f4
1 parent
5c070b81
feat(mod): module entity and mapper REQ-MOD-001
Showing
4 changed files
with
160 additions
and
0 deletions
backend/src/main/java/com/xly/erp/module/mod/entity/ModuleEntity.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 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 业务模块定义。表 {@code tModule}(详见 docs/03-数据库设计文档.md § tModule)。 | |
| 13 | + * | |
| 14 | + * <p>字段名沿用 docs/03 的匈牙利前缀命名(i/s/t/b),保持 schema 与 Java 字段一一对应, | |
| 15 | + * 避免双向映射歧义。@TableField 显式声明列名以兼容 MyBatis-Plus 默认的下划线转换关闭场景。</p> | |
| 16 | + */ | |
| 17 | +@Data | |
| 18 | +@TableName("tModule") | |
| 19 | +public class ModuleEntity { | |
| 20 | + | |
| 21 | + @TableId(value = "iIncrement", type = IdType.AUTO) | |
| 22 | + private Integer iIncrement; | |
| 23 | + | |
| 24 | + @TableField("sId") | |
| 25 | + private String sId; | |
| 26 | + | |
| 27 | + @TableField("sBrandsId") | |
| 28 | + private String sBrandsId; | |
| 29 | + | |
| 30 | + @TableField("sSubsidiaryId") | |
| 31 | + private String sSubsidiaryId; | |
| 32 | + | |
| 33 | + @TableField("tCreateDate") | |
| 34 | + private LocalDateTime tCreateDate; | |
| 35 | + | |
| 36 | + @TableField("sDisplayType") | |
| 37 | + private String sDisplayType; | |
| 38 | + | |
| 39 | + @TableField("sProcedureName") | |
| 40 | + private String sProcedureName; | |
| 41 | + | |
| 42 | + @TableField("sModuleType") | |
| 43 | + private String sModuleType; | |
| 44 | + | |
| 45 | + @TableField("sManageDeptEn") | |
| 46 | + private String sManageDeptEn; | |
| 47 | + | |
| 48 | + @TableField("bShowPermission") | |
| 49 | + private Boolean bShowPermission; | |
| 50 | + | |
| 51 | + @TableField("sModuleNameZh") | |
| 52 | + private String sModuleNameZh; | |
| 53 | + | |
| 54 | + @TableField("iParentId") | |
| 55 | + private Integer iParentId; | |
| 56 | + | |
| 57 | + @TableField("iSortOrder") | |
| 58 | + private Integer iSortOrder; | |
| 59 | + | |
| 60 | + @TableField("sCreatedBy") | |
| 61 | + private String sCreatedBy; | |
| 62 | + | |
| 63 | + @TableField("bDeleted") | |
| 64 | + private Boolean bDeleted; | |
| 65 | + | |
| 66 | + @TableField("tDeletedDate") | |
| 67 | + private LocalDateTime tDeletedDate; | |
| 68 | + | |
| 69 | + @TableField("sDeletedBy") | |
| 70 | + private String sDeletedBy; | |
| 71 | +} | ... | ... |
backend/src/main/java/com/xly/erp/module/mod/mapper/ModuleMapper.java
0 → 100644
backend/src/main/resources/mapper/mod/ModuleMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="com.xly.erp.module.mod.mapper.ModuleMapper"> | |
| 4 | + <!-- REQ-MOD-001 仅使用 BaseMapper 默认 SQL;后续 REQ 按需扩展自定义查询 --> | |
| 5 | +</mapper> | ... | ... |
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 4 | +import com.xly.erp.module.mod.entity.ModuleEntity; | |
| 5 | +import org.junit.jupiter.api.Test; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.boot.test.context.SpringBootTest; | |
| 8 | +import org.springframework.test.annotation.Rollback; | |
| 9 | +import org.springframework.test.context.ActiveProfiles; | |
| 10 | +import org.springframework.transaction.annotation.Transactional; | |
| 11 | + | |
| 12 | +import java.time.LocalDateTime; | |
| 13 | + | |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 15 | + | |
| 16 | +@SpringBootTest | |
| 17 | +@ActiveProfiles("test") | |
| 18 | +@Transactional | |
| 19 | +@Rollback | |
| 20 | +class ModuleMapperIT { | |
| 21 | + | |
| 22 | + @Autowired ModuleMapper moduleMapper; | |
| 23 | + | |
| 24 | + @Test | |
| 25 | + void insertAndSelectById_persistsAllFields() { | |
| 26 | + ModuleEntity e = new ModuleEntity(); | |
| 27 | + e.setSDisplayType("前端业务"); | |
| 28 | + e.setSProcedureName("sp_audit_test_" + System.nanoTime()); | |
| 29 | + e.setSModuleType("USR"); | |
| 30 | + e.setSManageDeptEn("IT"); | |
| 31 | + e.setBShowPermission(false); | |
| 32 | + e.setSModuleNameZh("测试模块"); | |
| 33 | + e.setIParentId(null); | |
| 34 | + e.setISortOrder(0); | |
| 35 | + e.setBDeleted(false); | |
| 36 | + e.setTCreateDate(LocalDateTime.now()); | |
| 37 | + | |
| 38 | + int rows = moduleMapper.insert(e); | |
| 39 | + assertThat(rows).isEqualTo(1); | |
| 40 | + assertThat(e.getIIncrement()).isNotNull().isPositive(); | |
| 41 | + | |
| 42 | + ModuleEntity loaded = moduleMapper.selectById(e.getIIncrement()); | |
| 43 | + assertThat(loaded).isNotNull(); | |
| 44 | + assertThat(loaded.getSDisplayType()).isEqualTo("前端业务"); | |
| 45 | + assertThat(loaded.getSProcedureName()).isEqualTo(e.getSProcedureName()); | |
| 46 | + assertThat(loaded.getSModuleType()).isEqualTo("USR"); | |
| 47 | + assertThat(loaded.getSManageDeptEn()).isEqualTo("IT"); | |
| 48 | + assertThat(loaded.getBShowPermission()).isFalse(); | |
| 49 | + assertThat(loaded.getSModuleNameZh()).isEqualTo("测试模块"); | |
| 50 | + assertThat(loaded.getIParentId()).isNull(); | |
| 51 | + assertThat(loaded.getISortOrder()).isZero(); | |
| 52 | + assertThat(loaded.getBDeleted()).isFalse(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Test | |
| 56 | + void selectCountByProcedureName_returnsExisting() { | |
| 57 | + String name = "sp_audit_uniq_" + System.nanoTime(); | |
| 58 | + ModuleEntity e = new ModuleEntity(); | |
| 59 | + e.setSDisplayType("接口"); | |
| 60 | + e.setSProcedureName(name); | |
| 61 | + e.setSModuleType("MOD"); | |
| 62 | + e.setSManageDeptEn("IT"); | |
| 63 | + e.setBShowPermission(false); | |
| 64 | + e.setSModuleNameZh("唯一性检测"); | |
| 65 | + e.setISortOrder(0); | |
| 66 | + e.setBDeleted(false); | |
| 67 | + e.setTCreateDate(LocalDateTime.now()); | |
| 68 | + moduleMapper.insert(e); | |
| 69 | + | |
| 70 | + Long count = moduleMapper.selectCount( | |
| 71 | + new LambdaQueryWrapper<ModuleEntity>() | |
| 72 | + .eq(ModuleEntity::getSProcedureName, name) | |
| 73 | + .eq(ModuleEntity::getBDeleted, false) | |
| 74 | + ); | |
| 75 | + assertThat(count).isEqualTo(1L); | |
| 76 | + } | |
| 77 | +} | ... | ... |