Commit dd31030012c1423eb8c1ccc869f8a672fc50bda7
1 parent
7fbd1447
feat(usr): BrandEntity/UsrUserEntity + Mapper + MyBatisPlusConfig REQ-USR-004
- BrandEntity/UsrUserEntity: @TableName + @TableField (map-underscore-to-camel-case=false) - BrandMapper/UsrUserMapper: extends BaseMapper - MyBatisPlusConfig: @MapperScan + PaginationInnerInterceptor - BrandMapperTest: insert/query/delete against test DB PASS
Showing
6 changed files
with
188 additions
and
0 deletions
backend/src/main/java/com/example/erp/config/MyBatisPlusConfig.java
0 → 100644
| 1 | +package com.example.erp.config; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.annotation.DbType; | |
| 4 | +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | |
| 5 | +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | |
| 6 | +import org.mybatis.spring.annotation.MapperScan; | |
| 7 | +import org.springframework.context.annotation.Bean; | |
| 8 | +import org.springframework.context.annotation.Configuration; | |
| 9 | + | |
| 10 | +@Configuration | |
| 11 | +@MapperScan("com.example.erp.module.*.mapper") | |
| 12 | +public class MyBatisPlusConfig { | |
| 13 | + | |
| 14 | + @Bean | |
| 15 | + public MybatisPlusInterceptor mybatisPlusInterceptor() { | |
| 16 | + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | |
| 17 | + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | |
| 18 | + return interceptor; | |
| 19 | + } | |
| 20 | +} | ... | ... |
backend/src/main/java/com/example/erp/module/usr/entity/BrandEntity.java
0 → 100644
| 1 | +package com.example.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 | +import lombok.Getter; | |
| 8 | +import lombok.Setter; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +@Getter | |
| 13 | +@Setter | |
| 14 | +@TableName("brand") | |
| 15 | +public class BrandEntity { | |
| 16 | + | |
| 17 | + @TableId(value = "iIncrement", type = IdType.AUTO) | |
| 18 | + private Integer iIncrement; | |
| 19 | + | |
| 20 | + @TableField("sId") | |
| 21 | + private String sId; | |
| 22 | + | |
| 23 | + @TableField("sBrandsId") | |
| 24 | + private String sBrandsId; | |
| 25 | + | |
| 26 | + @TableField("sSubsidiaryId") | |
| 27 | + private String sSubsidiaryId; | |
| 28 | + | |
| 29 | + @TableField("tCreateDate") | |
| 30 | + private LocalDateTime tCreateDate; | |
| 31 | + | |
| 32 | + @TableField("sName") | |
| 33 | + private String sName; | |
| 34 | + | |
| 35 | + @TableField("sShortName") | |
| 36 | + private String sShortName; | |
| 37 | + | |
| 38 | + @TableField("sNo") | |
| 39 | + private String sNo; | |
| 40 | +} | ... | ... |
backend/src/main/java/com/example/erp/module/usr/entity/UsrUserEntity.java
0 → 100644
| 1 | +package com.example.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 | +import lombok.Getter; | |
| 8 | +import lombok.Setter; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +@Getter | |
| 13 | +@Setter | |
| 14 | +@TableName("usr_user") | |
| 15 | +public class UsrUserEntity { | |
| 16 | + | |
| 17 | + @TableId(value = "iIncrement", type = IdType.AUTO) | |
| 18 | + private Integer iIncrement; | |
| 19 | + | |
| 20 | + @TableField("sId") | |
| 21 | + private String sId; | |
| 22 | + | |
| 23 | + @TableField("sBrandsId") | |
| 24 | + private String sBrandsId; | |
| 25 | + | |
| 26 | + @TableField("sSubsidiaryId") | |
| 27 | + private String sSubsidiaryId; | |
| 28 | + | |
| 29 | + @TableField("tCreateDate") | |
| 30 | + private LocalDateTime tCreateDate; | |
| 31 | + | |
| 32 | + @TableField("sUserCode") | |
| 33 | + private String sUserCode; | |
| 34 | + | |
| 35 | + @TableField("sUsername") | |
| 36 | + private String sUsername; | |
| 37 | + | |
| 38 | + @TableField("sPasswordHash") | |
| 39 | + private String sPasswordHash; | |
| 40 | + | |
| 41 | + @TableField("sUserType") | |
| 42 | + private String sUserType; | |
| 43 | + | |
| 44 | + @TableField("sLanguage") | |
| 45 | + private String sLanguage; | |
| 46 | + | |
| 47 | + @TableField("bCanEditDoc") | |
| 48 | + private Integer bCanEditDoc; | |
| 49 | + | |
| 50 | + @TableField("bIsDisabled") | |
| 51 | + private Integer bIsDisabled; | |
| 52 | + | |
| 53 | + @TableField("sEmployeeId") | |
| 54 | + private String sEmployeeId; | |
| 55 | + | |
| 56 | + @TableField("sCreatorUsername") | |
| 57 | + private String sCreatorUsername; | |
| 58 | + | |
| 59 | + @TableField("tLastLoginDate") | |
| 60 | + private LocalDateTime tLastLoginDate; | |
| 61 | + | |
| 62 | + @TableField("iLoginFailCount") | |
| 63 | + private Integer iLoginFailCount; | |
| 64 | + | |
| 65 | + @TableField("tLockUntil") | |
| 66 | + private LocalDateTime tLockUntil; | |
| 67 | +} | ... | ... |
backend/src/main/java/com/example/erp/module/usr/mapper/BrandMapper.java
0 → 100644
backend/src/main/java/com/example/erp/module/usr/mapper/UsrUserMapper.java
0 → 100644
backend/src/test/java/com/example/erp/module/usr/BrandMapperTest.java
0 → 100644
| 1 | +package com.example.erp.module.usr; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 4 | +import com.example.erp.module.usr.entity.BrandEntity; | |
| 5 | +import com.example.erp.module.usr.mapper.BrandMapper; | |
| 6 | +import org.junit.jupiter.api.AfterEach; | |
| 7 | +import org.junit.jupiter.api.BeforeEach; | |
| 8 | +import org.junit.jupiter.api.Test; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.boot.test.context.SpringBootTest; | |
| 11 | +import org.springframework.test.context.ActiveProfiles; | |
| 12 | + | |
| 13 | +import java.time.LocalDateTime; | |
| 14 | + | |
| 15 | +import static org.junit.jupiter.api.Assertions.*; | |
| 16 | + | |
| 17 | +@SpringBootTest | |
| 18 | +@ActiveProfiles("test") | |
| 19 | +class BrandMapperTest { | |
| 20 | + | |
| 21 | + @Autowired | |
| 22 | + private BrandMapper brandMapper; | |
| 23 | + | |
| 24 | + @BeforeEach | |
| 25 | + void setUp() { | |
| 26 | + BrandEntity brand = new BrandEntity(); | |
| 27 | + brand.setSId("b-test-mapper-001"); | |
| 28 | + brand.setSNo("TST"); | |
| 29 | + brand.setSName("测试版"); | |
| 30 | + brand.setTCreateDate(LocalDateTime.now()); | |
| 31 | + brandMapper.insert(brand); | |
| 32 | + } | |
| 33 | + | |
| 34 | + @AfterEach | |
| 35 | + void tearDown() { | |
| 36 | + brandMapper.delete(new LambdaQueryWrapper<BrandEntity>().eq(BrandEntity::getSNo, "TST")); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Test | |
| 40 | + void findByNo_returnsCorrectBrand() { | |
| 41 | + BrandEntity found = brandMapper.selectOne( | |
| 42 | + new LambdaQueryWrapper<BrandEntity>().eq(BrandEntity::getSNo, "TST")); | |
| 43 | + assertNotNull(found); | |
| 44 | + assertEquals("测试版", found.getSName()); | |
| 45 | + assertEquals("b-test-mapper-001", found.getSId()); | |
| 46 | + } | |
| 47 | +} | ... | ... |