feat: 添加了15个数据表结构定义,调整了部分数据表的创建语句,更新了数据准备脚本。

This commit is contained in:
筱锋xiao_lfeng 2024-04-16 22:31:30 +08:00
parent 2086361a8d
commit f0f6e53ba2
Signed by: XiaoLFeng
GPG Key ID: F693AA12AABBFA87
19 changed files with 328 additions and 9 deletions

View File

@ -2,8 +2,15 @@ package com.jsl.oa.config.startup;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.FileCopyUtils;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
@Slf4j
@RequiredArgsConstructor
@ -32,4 +39,41 @@ public class PrepareData {
);
}
}
/**
* 检查数据库是否完整
* <hr/>
* 检查数据库是否完整若数据库保持完整则不进行任何操作若数据库不完整将会创建对应的数据表
* @param tableName 数据表名字
*/
public void checkDatabase(String tableName) {
try {
jdbcTemplate.queryForObject(
"SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME = ?",
String.class,
tableName
);
} catch (DataAccessException e) {
log.debug("[Preparation] 创建数据表 {}", tableName);
// 读取文件
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// 读取 resources/mysql 目录下的所有 SQL 文件
Resource resource = resolver.getResource("classpath:/mysql/" + tableName + ".sql");
// 创建数据表
try {
String sql = FileCopyUtils
.copyToString(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8));
// 分割 SQL 语句并执行
jdbcTemplate.execute("USE organize_oa");
String[] sqlStatements = sql.split(";");
for (String statement : sqlStatements) {
if (!statement.trim().isEmpty()) {
jdbcTemplate.execute(statement.trim());
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}

View File

@ -52,13 +52,43 @@ public class StartupConfiguration {
/**
* 对数据库进行完整性检查
* <hr/>
* 对数据库进行完整性检查检查数据库是否有数据缺失等信息
* 对数据库进行完整性检查检查数据库是否出现缺失数据表的情况若出现缺失数据表的情况将会对数据表进行创建若数据保持完整将不进行任何操作
*/
@Bean
@Order(2)
public CommandLineRunner roleDataPreparation() {
public CommandLineRunner checkDatabaseExist() {
return args -> {
log.info("[Preparation] 系统进行数据库完整性检查");
// 数据表的检查
prepareData.checkDatabase("oa_config");
prepareData.checkDatabase("oa_user");
prepareData.checkDatabase("oa_role");
prepareData.checkDatabase("oa_permissions");
prepareData.checkDatabase("oa_news");
prepareData.checkDatabase("oa_project_tags");
prepareData.checkDatabase("oa_project");
prepareData.checkDatabase("oa_project_child");
prepareData.checkDatabase("oa_project_modules");
prepareData.checkDatabase("oa_review");
prepareData.checkDatabase("oa_message");
prepareData.checkDatabase("oa_news_user");
prepareData.checkDatabase("oa_project_daily");
prepareData.checkDatabase("oa_role_permissions");
prepareData.checkDatabase("oa_role_user");
prepareData.checkDatabase("oa_user_tags");
};
}
/**
* 对数据表进行完整性检查
* <hr/>
* 对数据表进行完整性检查检查数据表是否有数据缺失等信息
*/
@Bean
@Order(3)
public CommandLineRunner roleDataPreparation() {
return args -> {
log.info("[Preparation] 系统进行数据表完整性检查");
// 检查角色信息是否完整
prepareData.checkRole("console", "超级管理员");
prepareData.checkRole("principal", "负责人");
@ -73,7 +103,7 @@ public class StartupConfiguration {
* 账户
*/
@Bean
@Order(3)
@Order(4)
public CommandLineRunner defaultConsoleDataPreparation() {
return args -> {
log.info("[Preparation] 系统进行默认超级管理员信息检查");
@ -133,7 +163,7 @@ public class StartupConfiguration {
}
@Bean
@Order(4)
@Order(5)
public CommandLineRunner prepareDefaultConfigData(Gson gson) {
return args -> {
// 检查加密密钥是否存在
@ -180,7 +210,7 @@ public class StartupConfiguration {
* 准备安全密钥用于加密解密等操作
*/
@Bean
@Order(5)
@Order(6)
public CommandLineRunner prepareKey() {
return args -> {
log.info("[Preparation] 系统进行安全密钥准备");

View File

@ -0,0 +1,12 @@
create table oa_config
(
id bigint unsigned auto_increment comment '主键'
primary key,
value varchar(50) not null comment '调用关键字',
data json null comment 'json数据',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
constraint oa_config_value_uindex
unique (value)
)
comment '配置数据表';

View File

@ -0,0 +1,19 @@
create table oa_message
(
id bigint unsigned auto_increment comment '消息主键'
primary key,
uid bigint unsigned not null comment '用户主键',
title varchar(100) not null comment '消息抬头',
text text not null comment '消息正文',
is_delete tinyint(1) default 0 not null comment '消息是否删除',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
deleted_at timestamp null comment '删除时间',
sid bigint unsigned null comment '发送用户id',
type varchar(100) null comment '跳转类型',
to_id int unsigned null comment '跳转的id',
constraint oa_message_oa_user_id_fk
foreign key (uid) references oa_user (id)
on update cascade on delete cascade
)
comment '消息';

View File

@ -0,0 +1,13 @@
create table oa_news
(
id bigint unsigned auto_increment comment '主键'
primary key,
title varchar(255) not null comment '标题',
content text not null comment '内容',
tags varchar(10) null comment '标签(项目,通知)',
likes int default 0 not null comment '点赞数',
comments int default 0 not null comment '评论数',
status tinyint not null comment '状态0草稿1发布2隐藏',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '更新时间'
);

View File

@ -0,0 +1,15 @@
create table oa_news_user
(
id int unsigned auto_increment comment '主键'
primary key,
uid bigint unsigned not null comment '用户id',
nid bigint unsigned not null comment '新闻id',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
constraint oa_news_user_nid_oa_news_id_fk
foreign key (nid) references oa_news (id)
on update cascade,
constraint oa_news_user_uid_oa_user_id_fk
foreign key (uid) references oa_user (id)
on update cascade
);

View File

@ -0,0 +1,14 @@
create table oa_permissions
(
id bigint unsigned auto_increment comment '主键'
primary key,
pid bigint unsigned null comment '权限父id',
name varchar(100) not null comment '权限名称',
code varchar(50) not null comment '权限编码',
type tinyint(1) default 1 not null comment '0为菜单1为权限',
deleted_at timestamp null comment '删除时间(没有删除应当为空)',
constraint oa_permissions_oa_permissions_id_fk
foreign key (pid) references oa_permissions (id)
on update cascade on delete cascade
)
comment '权限表';

View File

@ -0,0 +1,24 @@
create table oa_project
(
id bigint unsigned auto_increment comment '项目id'
primary key,
name varchar(255) not null comment '项目名称',
principal_id bigint unsigned not null comment '项目负责人',
description json null comment '项目描述(技术选择,描述)',
tags json null comment '项目标签项目类型web大数据等',
cycle int unsigned not null comment '项目周期',
work_load int unsigned default '1' not null comment '工作量(人天)',
files json null comment '项目文件',
begin_time datetime default CURRENT_TIMESTAMP not null comment '项目开始时间',
complete_time date null comment '完成时间',
dead_line date not null comment '甲方要求结束',
status varchar(8) default 'progress' not null comment '项目状态draft: 草稿progress: 进行pause: 暂停abnormal: 异常complete: 完成)',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
is_delete tinyint(1) default 0 not null comment '项目是否删除',
constraint oa_project_oa_user_id_fk
foreign key (principal_id) references oa_user (id)
on update cascade
)
comment '项目表';

View File

@ -1,5 +1,3 @@
USE organize_oa;
create table oa_project_child
(
id bigint unsigned auto_increment comment '项目id'

View File

@ -0,0 +1,19 @@
create table oa_project_daily
(
id bigint unsigned auto_increment comment '日报主键'
primary key,
user_id bigint unsigned not null comment '用户id',
project_id bigint unsigned not null comment '项目id',
content text not null comment '日报内容',
daily_time date not null comment '日志发布时间',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
is_delete tinyint(1) default 0 not null comment '是否删除',
constraint oa_project_daily_oa_project_id_fk
foreign key (project_id) references oa_project (id)
on update cascade on delete cascade,
constraint oa_project_daily_oa_user_id_fk
foreign key (user_id) references oa_user (id)
on update cascade
)
comment '项目日报';

View File

@ -1,5 +1,3 @@
USE organize_oa;
create table oa_project_modules
(
id bigint unsigned auto_increment comment '模块id'

View File

@ -0,0 +1,17 @@
create table oa_project_tags
(
id bigint unsigned auto_increment comment '主键id'
primary key,
name varchar(20) not null comment '标签名称',
pid bigint unsigned null comment '父标签id',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
is_delete tinyint(1) default 0 not null comment '是否删除',
constraint oa_project_tags_name_uindex
unique (name),
constraint oa_project_tags_oa_project_tags_id_fk
foreign key (pid) references oa_project_tags (id)
on update cascade on delete cascade
)
comment '项目标签表';

View File

@ -0,0 +1,35 @@
create table oa_review
(
id bigint unsigned auto_increment comment '主键'
primary key,
name varchar(255) not null comment '申请名称',
content longtext not null comment '申请理由',
sender_id bigint unsigned not null comment '申请者用户id',
recipient_id bigint unsigned null comment '审核者用户id',
category tinyint default 1 null comment '审核类别0子系统1子模块',
project_id bigint unsigned not null comment '申请的项目id',
project_child_id bigint unsigned not null comment '申请的子系统id',
project_module_id bigint unsigned null comment '申请的子模块id',
application_time datetime default CURRENT_TIMESTAMP not null comment '申请时间',
review_time datetime null comment '审核时间',
review_result tinyint default 2 not null comment '审核结果0未通过1通过2未审批',
is_delete tinyint default 0 not null comment '是否删除0未删除1已删除',
created_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updated_time datetime null comment '更新时间',
constraint oa_review_recipient_id_oa_user_id_fk
foreign key (recipient_id) references oa_user (id)
on update cascade on delete cascade,
constraint oa_review_sender_id_oa_user_id_fk
foreign key (sender_id) references oa_user (id)
on update cascade on delete cascade
);
create index oa_review_project_id_oa_project_id_fk
on oa_review (project_id);
create index oa_review_project_project_submodule_id_oa_project_work_id_fk
on oa_review (project_module_id);
create index oa_review_project_subsystem_id_oa_project_work_id_fk
on oa_review (project_child_id);

View File

@ -0,0 +1,10 @@
create table oa_role
(
id int unsigned auto_increment comment '角色id'
primary key,
role_name varchar(20) not null comment '角色名称',
display_name varchar(10) null comment '中文描述',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间'
)
comment '角色表';

View File

@ -0,0 +1,10 @@
create table oa_role_permissions
(
rid int unsigned not null comment 'Role ID',
pid bigint unsigned not null comment 'Permission ID',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
primary key (rid, pid)
);
create index oa_role_permission_oa_permissions_id_fk
on oa_role_permissions (pid);

View File

@ -0,0 +1,14 @@
create table oa_role_user
(
uid bigint unsigned not null comment '用户id'
primary key,
rid int unsigned not null comment '角色id',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
constraint oa_role_user_oa_role_id_fk
foreign key (rid) references oa_role (id),
constraint oa_role_user_oa_user_id_fk
foreign key (uid) references oa_user (id)
on update cascade on delete cascade
)
comment '角色用户表';

View File

@ -0,0 +1,34 @@
create table oa_user
(
id bigint unsigned auto_increment comment '主键'
primary key,
job_id char(10) not null comment '工作ID正则表达 "^[STU|TEA|OTH][0-9]{7}"',
username varchar(40) not null comment '用户名',
password varchar(255) not null comment '密码',
address varchar(255) not null comment '用户家庭地址',
phone varchar(11) not null comment '电话',
email varchar(100) not null comment '邮箱',
age tinyint unsigned not null comment '年龄',
signature varchar(50) null comment '一句话描述自己',
sex tinyint unsigned default '0' not null comment '0/1/2:保密/男/女',
avatar text null comment '头像地址',
nickname varchar(20) null comment '昵称',
enabled tinyint(1) default 1 not null comment '账户是否可用',
account_no_expired tinyint(1) default 1 not null comment '账户是否过期',
credentials_no_expired tinyint(1) default 0 not null comment '密码是否过期',
recommend tinyint(1) default 0 not null comment '账户是否被推荐',
account_no_locked tinyint(1) default 1 not null comment '账户是否被锁定',
description text null comment '个人简介',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '更新时间',
is_delete tinyint(1) default 0 not null,
constraint oa_user_email_uindex
unique (email),
constraint oa_user_job_id_uindex
unique (job_id),
constraint oa_user_phone_uindex
unique (phone),
constraint oa_user_username_uindex
unique (username)
)
comment '用户表';

View File

@ -0,0 +1,13 @@
create table oa_user_tags
(
id bigint unsigned auto_increment comment '标签主键'
primary key,
name varchar(20) not null comment '标签名',
pid bigint unsigned null comment '标签父id',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp null comment '修改时间',
is_delete tinyint(1) default 0 not null comment '是否删除',
constraint oa_user_tags_name_uindex
unique (name)
)
comment '用户标签';