Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
loit-build-common
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure
loit-build-common
Commits
06ae5409
提交
06ae5409
authored
8月 02, 2023
作者:
chenshiying
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[新增] 生成sql
上级
1a3a8041
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
269 行增加
和
0 行删除
+269
-0
GeneratorSqlDdlScript.java
...in/java/com/loit/common/script/GeneratorSqlDdlScript.java
+139
-0
SqlDDLDataDTO.java
...c/main/java/com/loit/common/script/dto/SqlDDLDataDTO.java
+130
-0
createSql.xlsx
...t/loit-build-deploy-env/src/main/resources/createSql.xlsx
+0
-0
deployInfo.xlsx
.../loit-build-deploy-env/src/main/resources/deployInfo.xlsx
+0
-0
没有找到文件。
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/script/GeneratorSqlDdlScript.java
0 → 100644
浏览文件 @
06ae5409
package
com
.
loit
.
common
.
script
;
import
com.loit.common.script.dto.BuildEnvEnum
;
import
com.loit.common.script.dto.SqlDDLDataDTO
;
import
com.loit.common.utils.ListUtil
;
import
com.loit.common.utils.StringUtils
;
import
com.loit.common.utils.excel.ImportExcel
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.entity.ContentType
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
@Slf4j
public
class
GeneratorSqlDdlScript
{
protected
static
String
root_path
=
"F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\bin"
;
/**
* 构建环境 生产或者 准生产
* TODO 构建前需修改环境
*/
private
static
BuildEnvEnum
buildEnvEnum
=
BuildEnvEnum
.
PRE_PRODUCT
;
protected
static
String
root_path_jenkins_full
=
root_path
+
"\\jenkinsDeploy"
;
public
static
void
main
(
String
[]
args
)
{
try
{
//String filePathStr = Thread.currentThread().getContextClassLoader().getResource("deployInfo.xlsx").getPath();
String
filePathStr
=
"F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\createSql.xlsx"
;
File
pdfFile
=
new
File
(
filePathStr
);
FileInputStream
fileInputStream
=
new
FileInputStream
(
pdfFile
);
MultipartFile
multipartFile
=
new
MockMultipartFile
(
pdfFile
.
getName
(),
pdfFile
.
getName
(),
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
fileInputStream
);
ImportExcel
ei
=
new
ImportExcel
(
multipartFile
,
0
,
0
);
List
<
SqlDDLDataDTO
>
sqlDDLDataDTOInitList
=
ei
.
getDataList
(
SqlDDLDataDTO
.
class
);
if
(
ListUtil
.
isEmpty
(
sqlDDLDataDTOInitList
))
{
return
;
}
String
tableChineseName
=
""
;
String
tableEnglishName
=
""
;
// 是否自增
boolean
autoIncrement
=
false
;
List
<
SqlDDLDataDTO
>
ddlInfoList
=
new
ArrayList
<>();
for
(
SqlDDLDataDTO
grayVersionDataDTO
:
sqlDDLDataDTOInitList
)
{
String
fieldName
=
grayVersionDataDTO
.
getFieldName
();
if
(
StringUtils
.
isEmpty
(
fieldName
))
{
continue
;
}
ddlInfoList
.
add
(
grayVersionDataDTO
);
if
(
StringUtils
.
isNotEmpty
(
grayVersionDataDTO
.
getTableChineseName
()))
{
tableChineseName
=
grayVersionDataDTO
.
getTableChineseName
();
}
if
(
StringUtils
.
isNotEmpty
(
grayVersionDataDTO
.
getTableEnglishName
()))
{
tableEnglishName
=
grayVersionDataDTO
.
getTableEnglishName
();
}
if
(
StringUtils
.
isNotEmpty
(
grayVersionDataDTO
.
getAutoIncrement
()))
{
autoIncrement
=
"Y"
.
equals
(
grayVersionDataDTO
.
getAutoIncrement
());
}
}
StringBuffer
ddl
=
new
StringBuffer
();
ddl
.
append
(
"CREATE TABLE "
+
"`"
+
tableEnglishName
+
"` ("
+
"\r\n"
);
Iterator
<
SqlDDLDataDTO
>
iterator
=
ddlInfoList
.
iterator
();
while
(
iterator
.
hasNext
())
{
SqlDDLDataDTO
sqlDDLDataDTO
=
iterator
.
next
();
String
fieldName
=
sqlDDLDataDTO
.
getFieldName
();
String
fieldType
=
sqlDDLDataDTO
.
getFieldType
();
String
fieldLength
=
sqlDDLDataDTO
.
getFieldLength
();
if
(
StringUtils
.
isEmpty
(
fieldLength
))
{
fieldLength
=
"0"
;
}
String
fieldComment
=
sqlDDLDataDTO
.
getFieldComment
();
String
ifKey
=
sqlDDLDataDTO
.
getIfKey
();
String
ifnullValue
=
sqlDDLDataDTO
.
getIfnullValue
();
ddl
.
append
(
"`"
+
fieldName
+
"` "
+
fieldType
+
(!
"0"
.
equals
(
fieldLength
)
?
"("
+
fieldLength
+
")"
:
""
)
+
(
"Y"
.
equals
(
autoIncrement
)
?
" PRIMARY KEY "
:
""
)
+
(
"Y"
.
equals
(
autoIncrement
)
?
" AUTO_INCREMENT "
:
""
)
+
(
"N"
.
equals
(
ifnullValue
)
?
" NOT NULL "
:
" DEFAULT NULL"
)
+
" COMMENT '"
+
fieldComment
+
"'"
+
(
iterator
.
hasNext
()
?
",\r\n"
:
"\r\n"
)
);
// if ("Y".equals(ifKey)) {
// autoIncrement = true;
// }
}
if
(
ddl
.
toString
().
endsWith
(
",\r\n"
))
{
ddl
=
ddl
.
deleteCharAt
(
ddl
.
length
()
-
3
);
// ddl.append("\r\n");
}
ddl
.
append
(
") ENGINE=InnoDB "
+
(
autoIncrement
?
"AUTO_INCREMENT=1"
:
""
)
+
" DEFAULT CHARSET=utf8 "
+
(!
""
.
equals
(
tableChineseName
)
?
"COMMENT = '"
+
tableChineseName
+
"'"
:
""
)
+
";\r\n"
);
ddl
.
append
(
"-- --------------------------------------------------------------------------------\r\n"
);
System
.
out
.
println
(
ddl
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
}
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/script/dto/SqlDDLDataDTO.java
0 → 100644
浏览文件 @
06ae5409
package
com
.
loit
.
common
.
script
.
dto
;
import
com.loit.common.utils.excel.annotation.ExcelField
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
@ApiModel
(
value
=
"SqlDDLDataDTO"
,
description
=
"生成建表sqlDTO"
)
public
class
SqlDDLDataDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6587921299183759035L
;
@ApiModelProperty
(
value
=
"表中文名"
)
@ExcelField
(
title
=
"表中文名"
,
sort
=
1
)
private
String
tableChineseName
;
@ApiModelProperty
(
value
=
"表英文名"
)
@ExcelField
(
title
=
"表英文名"
,
sort
=
2
)
private
String
tableEnglishName
;
@ApiModelProperty
(
value
=
"字段注释"
)
@ExcelField
(
title
=
"字段注释"
,
sort
=
3
)
private
String
fieldComment
;
@ApiModelProperty
(
value
=
"字段名"
)
@ExcelField
(
title
=
"字段名"
,
sort
=
4
)
private
String
fieldName
;
@ApiModelProperty
(
value
=
"字段类型"
)
@ExcelField
(
title
=
"字段类型"
,
sort
=
5
)
private
String
fieldType
;
@ApiModelProperty
(
value
=
"字段长度"
)
@ExcelField
(
title
=
"字段长度"
,
sort
=
6
)
private
String
fieldLength
;
@ApiModelProperty
(
value
=
"是否未空"
)
@ExcelField
(
title
=
"是否未空"
,
sort
=
7
)
private
String
ifnullValue
;
@ApiModelProperty
(
value
=
"是否主键"
)
@ExcelField
(
title
=
"是否主键"
,
sort
=
8
)
private
String
ifKey
;
@ApiModelProperty
(
value
=
"是否自动递增"
)
@ExcelField
(
title
=
"是否自动递增"
,
sort
=
9
)
private
String
autoIncrement
;
public
String
getTableEnglishName
()
{
return
tableEnglishName
;
}
public
void
setTableEnglishName
(
String
tableEnglishName
)
{
this
.
tableEnglishName
=
tableEnglishName
;
}
public
String
getTableChineseName
()
{
return
tableChineseName
;
}
public
void
setTableChineseName
(
String
tableChineseName
)
{
this
.
tableChineseName
=
tableChineseName
;
}
public
String
getFieldComment
()
{
return
fieldComment
;
}
public
void
setFieldComment
(
String
fieldComment
)
{
this
.
fieldComment
=
fieldComment
;
}
public
String
getFieldName
()
{
return
fieldName
;
}
public
void
setFieldName
(
String
fieldName
)
{
this
.
fieldName
=
fieldName
;
}
public
String
getFieldType
()
{
return
fieldType
;
}
public
void
setFieldType
(
String
fieldType
)
{
this
.
fieldType
=
fieldType
;
}
public
String
getFieldLength
()
{
return
fieldLength
;
}
public
void
setFieldLength
(
String
fieldLength
)
{
this
.
fieldLength
=
fieldLength
;
}
public
String
getIfnullValue
()
{
return
ifnullValue
;
}
public
void
setIfnullValue
(
String
ifnullValue
)
{
this
.
ifnullValue
=
ifnullValue
;
}
public
String
getIfKey
()
{
return
ifKey
;
}
public
void
setIfKey
(
String
ifKey
)
{
this
.
ifKey
=
ifKey
;
}
public
String
getAutoIncrement
()
{
return
autoIncrement
;
}
public
void
setAutoIncrement
(
String
autoIncrement
)
{
this
.
autoIncrement
=
autoIncrement
;
}
}
loit-build-component/loit-build-deploy-env/src/main/resources/createSql.xlsx
0 → 100644
浏览文件 @
06ae5409
File added
loit-build-component/loit-build-deploy-env/src/main/resources/deployInfo.xlsx
浏览文件 @
06ae5409
No preview for this file type
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论