feat: 调整枚举表SQL为PostgreSQL格式
This commit is contained in:
38
src/main/java/com/bruce/common/entity/BaseEntity.java
Normal file
38
src/main/java/com/bruce/common/entity/BaseEntity.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.bruce.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(description = "实体公共基类")
|
||||
public class BaseEntity {
|
||||
|
||||
@Schema(description = "主键ID")
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
@TableField(value = "create_by")
|
||||
private String createBy;
|
||||
|
||||
@Schema(description = "创建时间", example = "2026-05-18 20:00:00")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(value = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "更新者")
|
||||
@TableField(value = "update_by")
|
||||
private String updateBy;
|
||||
|
||||
@Schema(description = "更新时间", example = "2026-05-18 20:00:00")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(value = "update_time")
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
39
src/main/java/com/bruce/common/entity/SysEnum.java
Normal file
39
src/main/java/com/bruce/common/entity/SysEnum.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.bruce.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_setting")
|
||||
@Schema(description = "系统枚举配置")
|
||||
public class SysEnum extends BaseEntity {
|
||||
|
||||
@Schema(description = "模块")
|
||||
private String catalog;
|
||||
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "值")
|
||||
private Integer value;
|
||||
|
||||
@Schema(description = "字符串值")
|
||||
private String strvalue;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "版本")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.bruce.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class EntityStructureTests {
|
||||
|
||||
@Test
|
||||
void baseEntityShouldUseMybatisPlusAssignedIdAndSysEnumShouldContainBusinessFields() throws NoSuchFieldException {
|
||||
Field idField = BaseEntity.class.getDeclaredField("id");
|
||||
TableId tableId = idField.getAnnotation(TableId.class);
|
||||
|
||||
assertNotNull(tableId);
|
||||
assertEquals(IdType.ASSIGN_ID, tableId.type());
|
||||
|
||||
Set<String> fieldNames = Arrays.stream(SysEnum.class.getDeclaredFields())
|
||||
.map(Field::getName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertTrue(fieldNames.contains("catalog"));
|
||||
assertTrue(fieldNames.contains("type"));
|
||||
assertTrue(fieldNames.contains("name"));
|
||||
assertTrue(fieldNames.contains("value"));
|
||||
assertTrue(fieldNames.contains("strvalue"));
|
||||
assertTrue(fieldNames.contains("sort"));
|
||||
assertTrue(fieldNames.contains("version"));
|
||||
assertTrue(fieldNames.contains("remark"));
|
||||
assertTrue(BaseEntity.class.isAssignableFrom(SysEnum.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void entitiesShouldExposeOpenApiSchemaAnnotations() throws NoSuchFieldException {
|
||||
Schema baseSchema = BaseEntity.class.getAnnotation(Schema.class);
|
||||
Schema sysEnumSchema = SysEnum.class.getAnnotation(Schema.class);
|
||||
Schema createTimeSchema = BaseEntity.class.getDeclaredField("createTime").getAnnotation(Schema.class);
|
||||
Schema catalogSchema = SysEnum.class.getDeclaredField("catalog").getAnnotation(Schema.class);
|
||||
|
||||
assertNotNull(baseSchema);
|
||||
assertNotNull(sysEnumSchema);
|
||||
assertNotNull(createTimeSchema);
|
||||
assertNotNull(catalogSchema);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user