feat: 调整枚举表SQL为PostgreSQL格式
This commit is contained in:
36
script/sql/enum.sql
Normal file
36
script/sql/enum.sql
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
DROP TABLE IF EXISTS sys_setting;
|
||||||
|
|
||||||
|
CREATE TABLE sys_setting (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
catalog VARCHAR(200) NOT NULL,
|
||||||
|
type VARCHAR(200) NOT NULL,
|
||||||
|
name VARCHAR(200) NOT NULL,
|
||||||
|
value INTEGER NOT NULL,
|
||||||
|
strvalue VARCHAR(500),
|
||||||
|
sort INTEGER DEFAULT 0,
|
||||||
|
version INTEGER NOT NULL DEFAULT 1,
|
||||||
|
create_time TIMESTAMP,
|
||||||
|
update_time TIMESTAMP,
|
||||||
|
remark VARCHAR(500) DEFAULT '',
|
||||||
|
create_by VARCHAR(64),
|
||||||
|
update_by VARCHAR(64),
|
||||||
|
CONSTRAINT uk_catalog_type_name UNIQUE (catalog, type, name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_sys_setting_catalog_type ON sys_setting (catalog, type);
|
||||||
|
CREATE INDEX idx_sys_setting_sort ON sys_setting (sort);
|
||||||
|
|
||||||
|
COMMENT ON TABLE sys_setting IS '系统枚举类';
|
||||||
|
COMMENT ON COLUMN sys_setting.id IS 'ID';
|
||||||
|
COMMENT ON COLUMN sys_setting.catalog IS '模块';
|
||||||
|
COMMENT ON COLUMN sys_setting.type IS '类型';
|
||||||
|
COMMENT ON COLUMN sys_setting.name IS '名称';
|
||||||
|
COMMENT ON COLUMN sys_setting.value IS '值';
|
||||||
|
COMMENT ON COLUMN sys_setting.strvalue IS '字符串值';
|
||||||
|
COMMENT ON COLUMN sys_setting.sort IS '排序';
|
||||||
|
COMMENT ON COLUMN sys_setting.version IS '版本';
|
||||||
|
COMMENT ON COLUMN sys_setting.create_time IS '创建时间';
|
||||||
|
COMMENT ON COLUMN sys_setting.update_time IS '更新时间';
|
||||||
|
COMMENT ON COLUMN sys_setting.remark IS '备注';
|
||||||
|
COMMENT ON COLUMN sys_setting.create_by IS '创建者';
|
||||||
|
COMMENT ON COLUMN sys_setting.update_by IS '更新者';
|
||||||
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