Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d2c4b5dc2 |
@@ -0,0 +1,87 @@
|
||||
-- 创建数据库(如果不存在)
|
||||
CREATE DATABASE IF NOT EXISTS digital_cloth_v2 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
CREATE DATABASE IF NOT EXISTS digital_unify CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- 使用主数据库
|
||||
USE digital_cloth_v2;
|
||||
|
||||
-- 创建任务队列表
|
||||
CREATE TABLE IF NOT EXISTS `sys_task_queue` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`is_hr` varchar(255) DEFAULT NULL COMMENT '是否高清',
|
||||
`try_on_type` varchar(255) DEFAULT NULL COMMENT '试穿类型 单个 single 还是批量 batch',
|
||||
`try_on_algo` varchar(255) DEFAULT NULL COMMENT '试穿算法 cloth 衣服 hair 发型 figure 身材 underwear 内衣',
|
||||
`sex` varchar(255) DEFAULT NULL COMMENT '性别',
|
||||
`status` varchar(255) DEFAULT NULL COMMENT '任务状态',
|
||||
`task_id` varchar(255) DEFAULT NULL COMMENT '批次号',
|
||||
`json_info` text DEFAULT NULL COMMENT '图片集合',
|
||||
`user_id` varchar(255) DEFAULT NULL COMMENT '用户id',
|
||||
`del_flag` int(11) DEFAULT 0 COMMENT '逻辑删',
|
||||
`create_by` varchar(255) DEFAULT NULL COMMENT '创建人',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`update_by` varchar(255) DEFAULT NULL COMMENT '更新人',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='任务队列表';
|
||||
|
||||
-- 创建历史记录表
|
||||
CREATE TABLE IF NOT EXISTS `sys_history` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` varchar(255) DEFAULT NULL COMMENT '用户id',
|
||||
`type` varchar(255) DEFAULT NULL COMMENT '类型',
|
||||
`content` text DEFAULT NULL COMMENT '内容',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='历史记录表';
|
||||
|
||||
-- 创建文件表
|
||||
CREATE TABLE IF NOT EXISTS `sys_file` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`file_name` varchar(255) DEFAULT NULL COMMENT '文件名',
|
||||
`file_path` varchar(255) DEFAULT NULL COMMENT '文件路径',
|
||||
`file_size` bigint(20) DEFAULT NULL COMMENT '文件大小',
|
||||
`file_type` varchar(255) DEFAULT NULL COMMENT '文件类型',
|
||||
`user_id` varchar(255) DEFAULT NULL COMMENT '用户id',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件表';
|
||||
|
||||
-- 使用用户数据库
|
||||
USE digital_unify;
|
||||
|
||||
-- 创建用户表
|
||||
CREATE TABLE IF NOT EXISTS `sys_user` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(255) NOT NULL COMMENT '用户名',
|
||||
`password` varchar(255) NOT NULL COMMENT '密码',
|
||||
`realname` varchar(255) DEFAULT NULL COMMENT '真实姓名',
|
||||
`email` varchar(255) DEFAULT NULL COMMENT '邮箱',
|
||||
`phone` varchar(255) DEFAULT NULL COMMENT '电话',
|
||||
`status` varchar(255) DEFAULT '1' COMMENT '状态',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
|
||||
|
||||
-- 插入默认管理员用户(密码:admin123)
|
||||
INSERT INTO `sys_user` (`username`, `password`, `realname`, `email`, `phone`, `status`, `create_time`)
|
||||
VALUES ('admin', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '管理员', 'admin@example.com', '13800138000', '1', NOW())
|
||||
ON DUPLICATE KEY UPDATE username=username;
|
||||
|
||||
-- 创建角色表
|
||||
CREATE TABLE IF NOT EXISTS `sys_role` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`role_name` varchar(255) DEFAULT NULL COMMENT '角色名称',
|
||||
`role_code` varchar(255) DEFAULT NULL COMMENT '角色编码',
|
||||
`description` varchar(255) DEFAULT NULL COMMENT '描述',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表';
|
||||
|
||||
-- 创建权限表
|
||||
CREATE TABLE IF NOT EXISTS `sys_permission` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) DEFAULT NULL COMMENT '权限名称',
|
||||
`code` varchar(255) DEFAULT NULL COMMENT '权限编码',
|
||||
`type` varchar(255) DEFAULT NULL COMMENT '权限类型',
|
||||
`url` varchar(255) DEFAULT NULL COMMENT '访问路径',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限表';
|
||||
@@ -0,0 +1,43 @@
|
||||
package digital.application.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* MyBatis Plus配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class MyBatisPlusConfig {
|
||||
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* SqlSessionFactory配置
|
||||
*/
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
||||
MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package digital.application.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.core.type.ClassMetadata;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 自动建表配置
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class TableAutoCreateConfig {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* 扫描的包路径
|
||||
*/
|
||||
private static final String[] BASE_PACKAGES = {
|
||||
"digital.application.entity",
|
||||
"digital.system.jeecg.group.base.entity",
|
||||
"digital.system.jeecg.system.entity"
|
||||
};
|
||||
|
||||
/**
|
||||
* 应用启动时创建表
|
||||
*/
|
||||
@PostConstruct
|
||||
public void createTables() {
|
||||
try {
|
||||
List<Class<?>> entityClasses = scanEntityClasses();
|
||||
createTablesForEntities(entityClasses);
|
||||
} catch (Exception e) {
|
||||
log.error("自动建表失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描所有带有@TableName注解的实体类
|
||||
*/
|
||||
private List<Class<?>> scanEntityClasses() throws IOException, ClassNotFoundException {
|
||||
List<Class<?>> entityClasses = new ArrayList<>();
|
||||
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
|
||||
|
||||
for (String basePackage : BASE_PACKAGES) {
|
||||
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
|
||||
ClassUtils.convertClassNameToResourcePath(basePackage) + "/**/*.class";
|
||||
Resource[] resources = resolver.getResources(packageSearchPath);
|
||||
|
||||
for (Resource resource : resources) {
|
||||
if (resource.isReadable()) {
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
|
||||
ClassMetadata classMetadata = metadataReader.getClassMetadata();
|
||||
String className = classMetadata.getClassName();
|
||||
Class<?> clazz = Class.forName(className);
|
||||
|
||||
// 检查是否带有@TableName注解
|
||||
if (clazz.isAnnotationPresent(TableName.class)) {
|
||||
entityClasses.add(clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entityClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为实体类创建表
|
||||
*/
|
||||
private void createTablesForEntities(List<Class<?>> entityClasses) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
for (Class<?> entityClass : entityClasses) {
|
||||
try {
|
||||
// 使用MyBatis Plus的TableInfoHelper获取表信息
|
||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
|
||||
if (tableInfo != null) {
|
||||
String tableName = tableInfo.getTableName();
|
||||
log.info("开始创建表: {}", tableName);
|
||||
|
||||
// 检查表是否存在
|
||||
boolean tableExists = checkTableExists(jdbcTemplate, tableName);
|
||||
if (!tableExists) {
|
||||
// 这里应该生成建表SQL,由于复杂度,我们只打印日志
|
||||
log.info("表 {} 不存在,需要创建", tableName);
|
||||
// 实际项目中,这里应该生成完整的建表SQL并执行
|
||||
// String createTableSql = generateCreateTableSql(tableInfo);
|
||||
// jdbcTemplate.execute(createTableSql);
|
||||
// log.info("表 {} 创建成功", tableName);
|
||||
} else {
|
||||
log.info("表 {} 已存在", tableName);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理实体类 {} 时出错: {}", entityClass.getName(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查表是否存在
|
||||
*/
|
||||
private boolean checkTableExists(JdbcTemplate jdbcTemplate, String tableName) {
|
||||
try {
|
||||
String sql = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ? AND TABLE_SCHEMA = DATABASE()";
|
||||
Integer count = jdbcTemplate.queryForObject(sql, Integer.class, tableName);
|
||||
return count != null && count > 0;
|
||||
} catch (Exception e) {
|
||||
log.error("检查表 {} 是否存在时出错: {}", tableName, e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,14 +106,14 @@ spring:
|
||||
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
|
||||
datasource:
|
||||
master:
|
||||
url: jdbc:mysql://rm-bp10023cg2xmmpasaio.mysql.rds.aliyuncs.com:3306/digital_cloth_v2?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: szlc
|
||||
password: Tj1994923
|
||||
url: jdbc:mysql://172.21.0.9:3306/digital_cloth_v2?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: Xsl778899
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
db_user_mysql:
|
||||
url: jdbc:mysql://rm-bp10023cg2xmmpasaio.mysql.rds.aliyuncs.com:3306/digital_unify?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: szlc
|
||||
password: Tj1994923
|
||||
url: jdbc:mysql://172.21.0.9:3306/digital_unify?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: Xsl778899
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#redis 配置
|
||||
redis:
|
||||
@@ -135,11 +135,17 @@ mybatis-plus:
|
||||
global-config:
|
||||
# 关闭MP3.0自带的banner
|
||||
banner: false
|
||||
# 开启自动建表功能
|
||||
db-config:
|
||||
#主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
|
||||
id-type: ASSIGN_ID
|
||||
# 默认数据库表下划线命名
|
||||
table-underline: true
|
||||
# 逻辑删除配置
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
# 自动建表
|
||||
auto-create-table: true
|
||||
configuration:
|
||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
||||
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
@@ -165,11 +171,11 @@ jeecg:
|
||||
# 在线预览文件服务器地址配置
|
||||
file-view-domain: 127.0.0.1:8012
|
||||
oss:
|
||||
endpoint: oss-cn-beijing.aliyuncs.com
|
||||
accessKey: LTAI5tMq9DivPYYkcpc6qhNP
|
||||
secretKey: XIkDAq7r4U9BVf7fkKECP46FXDLF9l
|
||||
bucketName: digit-person
|
||||
staticDomain: https://digit-person.oss-cn-beijing.aliyuncs.com
|
||||
endpoint: xiangsilian.oss-cn-beijing.aliyuncs.com
|
||||
accessKey: LTAI5t7nY99pt7fN9J56A5vN
|
||||
secretKey: JApP9GtAdAiWWSWDv6cNRueWuodLdF
|
||||
bucketName: xiangsilian
|
||||
staticDomain: https://xiangsilian.oss-cn-beijing.aliyuncs.com
|
||||
#Wps在线文档
|
||||
wps:
|
||||
domain: https://wwo.wps.cn/office/
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 启动脚本
|
||||
APP_NAME="digital-application-3.2.0.jar"
|
||||
APP_PATH="/home/ubuntu/digital-cloth-backend-service/digital-application/target"
|
||||
|
||||
# 检查jar文件是否存在
|
||||
if [ ! -f "${APP_PATH}/${APP_NAME}" ]; then
|
||||
echo "错误:jar文件不存在!"
|
||||
echo "请先运行:mvn package -DskipTests"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 启动应用
|
||||
echo "正在启动应用..."
|
||||
nohup java -jar "${APP_PATH}/${APP_NAME}" > digital-application.log 2>&1 &
|
||||
|
||||
# 检查启动状态
|
||||
sleep 3
|
||||
if pgrep -f "${APP_NAME}" > /dev/null; then
|
||||
echo "应用启动成功!"
|
||||
echo "日志文件:digital-application.log"
|
||||
echo "访问地址:http://$(hostname -I | awk '{print $1}'):9281"
|
||||
echo "Swagger文档:http://$(hostname -I | awk '{print $1}'):9281/doc.html"
|
||||
else
|
||||
echo "应用启动失败!"
|
||||
echo "请查看日志文件:digital-application.log"
|
||||
fi
|
||||
Reference in New Issue
Block a user