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
588c4409
提交
588c4409
authored
9月 07, 2023
作者:
chenshiying
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[新增] 生成sql
上级
9ac3d957
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
581 行增加
和
0 行删除
+581
-0
GeneratorInsertSqlScript.java
...a/com/loit/common/insertSql/GeneratorInsertSqlScript.java
+189
-0
ColumnInfoDTO.java
...ain/java/com/loit/common/insertSql/dto/ColumnInfoDTO.java
+60
-0
LineInfoDTO.java
.../main/java/com/loit/common/insertSql/dto/LineInfoDTO.java
+331
-0
package-info.java
...src/main/java/com/loit/common/insertSql/package-info.java
+1
-0
createSql.xlsx
...t/loit-build-deploy-env/src/main/resources/createSql.xlsx
+0
-0
没有找到文件。
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/insertSql/GeneratorInsertSqlScript.java
0 → 100644
浏览文件 @
588c4409
package
com
.
loit
.
common
.
insertSql
;
import
com.loit.common.insertSql.dto.ColumnInfoDTO
;
import
com.loit.common.insertSql.dto.LineInfoDTO
;
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.commons.beanutils.BeanUtils
;
import
org.apache.http.entity.ContentType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
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.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
public
class
GeneratorInsertSqlScript
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
GeneratorInsertSqlScript
.
class
);
//TODO 1:事件,2:部件
public
static
final
String
CASE_TYPE
=
"2"
;
public
static
final
String
FILE_NAME
=
"loit_bc_process_config_node数据初始化.xlsx"
;
public
static
Map
<
String
,
String
>
columnNameMap
=
new
LinkedHashMap
<>();
public
static
Map
<
String
,
String
>
columnTypeMap
=
new
LinkedHashMap
<>();
public
static
int
maxIndex
=
100
;
public
static
String
tableName
;
protected
static
String
root_path
=
"F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources"
;
public
static
void
main
(
String
[]
args
)
{
try
{
String
filePathStr
=
"F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\"
+
FILE_NAME
;
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
<
LineInfoDTO
>
commandManualDTOList
=
ei
.
getDataList
(
LineInfoDTO
.
class
);
if
(
ListUtil
.
isEmpty
(
commandManualDTOList
))
{
return
;
}
tableName
=
commandManualDTOList
.
get
(
0
).
getCol1
();
LineInfoDTO
columnLineInfo
=
commandManualDTOList
.
get
(
1
);
for
(
int
i
=
0
;
i
<
24
;
i
++)
{
int
index
=
i
+
1
;
String
colName
=
BeanUtils
.
getProperty
(
columnLineInfo
,
"col"
+
index
);
columnNameMap
.
put
(
i
+
""
,
colName
);
}
LineInfoDTO
columnTypeInfo
=
commandManualDTOList
.
get
(
2
);
for
(
int
colIndex
=
0
;
colIndex
<
24
;
colIndex
++)
{
int
index
=
colIndex
+
1
;
String
colName
=
BeanUtils
.
getProperty
(
columnTypeInfo
,
"col"
+
index
);
if
(
StringUtils
.
isNotEmpty
(
colName
))
{
columnTypeMap
.
put
(
colIndex
+
""
,
colName
);
}
}
for
(
int
valueIndex
=
0
;
valueIndex
<
commandManualDTOList
.
size
();
valueIndex
++)
{
if
(
valueIndex
<=
2
)
{
continue
;
}
List
<
ColumnInfoDTO
>
columnInfoList
=
new
ArrayList
<>();
LineInfoDTO
columnValueInfo
=
commandManualDTOList
.
get
(
valueIndex
);
boolean
isDataLine
=
true
;
for
(
int
colIndex
=
0
;
colIndex
<
24
;
colIndex
++)
{
int
index
=
colIndex
+
1
;
String
colValue
=
BeanUtils
.
getProperty
(
columnValueInfo
,
"col"
+
index
);
if
(
index
==
1
&&
StringUtils
.
isEmpty
(
colValue
))
{
isDataLine
=
false
;
break
;
}
String
columnName
=
columnNameMap
.
get
(
colIndex
+
""
);
if
(
StringUtils
.
isEmpty
(
columnName
))
{
continue
;
}
ColumnInfoDTO
columnInfoDTO
=
new
ColumnInfoDTO
();
columnInfoDTO
.
setColumnValue
(
colValue
);
columnInfoDTO
.
setTableName
(
tableName
);
columnInfoDTO
.
setColumnName
(
columnName
);
columnInfoDTO
.
setColumnType
(
columnTypeMap
.
get
(
colIndex
+
""
));
columnInfoList
.
add
(
columnInfoDTO
);
}
if
(
isDataLine
)
{
createInsertSql
(
columnInfoList
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
public
static
void
createInsertSql
(
List
<
ColumnInfoDTO
>
columnInfoList
)
{
StringBuffer
sql
=
new
StringBuffer
(
"INSERT INTO `"
);
sql
.
append
(
tableName
);
sql
.
append
(
"` ("
);
sql
.
append
(
columNameStr
(
columnInfoList
));
sql
.
append
(
") VALUES ("
);
sql
.
append
(
columnValueStr
(
columnInfoList
));
sql
.
append
(
");"
);
System
.
out
.
println
(
sql
.
toString
());
}
public
static
String
columNameStr
(
List
<
ColumnInfoDTO
>
columnInfoList
)
{
StringBuilder
resultBuilder
=
new
StringBuilder
();
for
(
ColumnInfoDTO
columnInfoDTO
:
columnInfoList
)
{
resultBuilder
.
append
(
"`"
+
columnInfoDTO
.
getColumnName
()
+
"`"
).
append
(
", "
);
}
String
result
=
resultBuilder
.
toString
();
if
(
result
.
endsWith
(
", "
))
{
result
=
result
.
substring
(
0
,
result
.
length
()
-
2
);
}
return
result
;
}
public
static
String
columnValueStr
(
List
<
ColumnInfoDTO
>
columnInfoList
)
{
StringBuilder
resultBuilder
=
new
StringBuilder
();
for
(
ColumnInfoDTO
columnInfoDTO
:
columnInfoList
)
{
String
columnType
=
columnInfoDTO
.
getColumnType
();
String
columnValue
=
columnInfoDTO
.
getColumnValue
();
if
(
StringUtils
.
isEmpty
(
columnValue
))
{
resultBuilder
.
append
(
"NULL"
).
append
(
", "
);
continue
;
}
if
(
StringUtils
.
isEmpty
(
columnType
))
{
resultBuilder
.
append
(
"'"
+
columnInfoDTO
.
getColumnValue
()
+
"'"
).
append
(
", "
);
}
else
{
resultBuilder
.
append
(
columnInfoDTO
.
getColumnType
()
+
"'"
+
columnInfoDTO
.
getColumnValue
()
+
"'"
).
append
(
", "
);
}
}
String
result
=
resultBuilder
.
toString
();
if
(
result
.
endsWith
(
", "
))
{
result
=
result
.
substring
(
0
,
result
.
length
()
-
2
);
}
return
result
;
}
}
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/insertSql/dto/ColumnInfoDTO.java
0 → 100644
浏览文件 @
588c4409
package
com
.
loit
.
common
.
insertSql
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
@ApiModel
(
value
=
"CoumnInfoDTO"
,
description
=
"字段信息"
)
public
class
ColumnInfoDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6587921299183759035L
;
@ApiModelProperty
(
value
=
"tableName"
)
private
String
tableName
;
@ApiModelProperty
(
value
=
"columnName"
)
private
String
columnName
;
@ApiModelProperty
(
value
=
"columnType"
)
private
String
columnType
;
@ApiModelProperty
(
value
=
"columnValue"
)
private
String
columnValue
;
public
String
getTableName
()
{
return
tableName
;
}
public
void
setTableName
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
public
String
getColumnName
()
{
return
columnName
;
}
public
void
setColumnName
(
String
columnName
)
{
this
.
columnName
=
columnName
;
}
public
String
getColumnType
()
{
return
columnType
;
}
public
void
setColumnType
(
String
columnType
)
{
this
.
columnType
=
columnType
;
}
public
String
getColumnValue
()
{
return
columnValue
;
}
public
void
setColumnValue
(
String
columnValue
)
{
this
.
columnValue
=
columnValue
;
}
}
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/insertSql/dto/LineInfoDTO.java
0 → 100644
浏览文件 @
588c4409
package
com
.
loit
.
common
.
insertSql
.
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
=
"LineInfoDTO"
,
description
=
"行信息"
)
public
class
LineInfoDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6587921299183759035L
;
@ApiModelProperty
(
value
=
"col1"
)
@ExcelField
(
title
=
"col1"
,
sort
=
1
)
private
String
col1
;
@ApiModelProperty
(
value
=
"col2"
)
@ExcelField
(
title
=
"col2"
,
sort
=
2
)
private
String
col2
;
@ApiModelProperty
(
value
=
"col3"
)
@ExcelField
(
title
=
"col3"
,
sort
=
3
)
private
String
col3
;
@ApiModelProperty
(
value
=
"col4"
)
@ExcelField
(
title
=
"col4"
,
sort
=
4
)
private
String
col4
;
@ApiModelProperty
(
value
=
"col5"
)
@ExcelField
(
title
=
"col5"
,
sort
=
5
)
private
String
col5
;
@ApiModelProperty
(
value
=
"col6"
)
@ExcelField
(
title
=
"col6"
,
sort
=
6
)
private
String
col6
;
@ApiModelProperty
(
value
=
"col7"
)
@ExcelField
(
title
=
"col7"
,
sort
=
7
)
private
String
col7
;
@ApiModelProperty
(
value
=
"col8"
)
@ExcelField
(
title
=
"col8"
,
sort
=
8
)
private
String
col8
;
@ApiModelProperty
(
value
=
"col9"
)
@ExcelField
(
title
=
"col9"
,
sort
=
8
)
private
String
col9
;
@ApiModelProperty
(
value
=
"col10"
)
@ExcelField
(
title
=
"col10"
,
sort
=
8
)
private
String
col10
;
@ApiModelProperty
(
value
=
"col11"
)
@ExcelField
(
title
=
"col11"
,
sort
=
8
)
private
String
col11
;
@ApiModelProperty
(
value
=
"col12"
)
@ExcelField
(
title
=
"col12"
,
sort
=
8
)
private
String
col12
;
@ApiModelProperty
(
value
=
"col13"
)
@ExcelField
(
title
=
"col13"
,
sort
=
8
)
private
String
col13
;
@ApiModelProperty
(
value
=
"col14"
)
@ExcelField
(
title
=
"col14"
,
sort
=
8
)
private
String
col14
;
@ApiModelProperty
(
value
=
"col15"
)
@ExcelField
(
title
=
"col15"
,
sort
=
8
)
private
String
col15
;
@ApiModelProperty
(
value
=
"col16"
)
@ExcelField
(
title
=
"col16"
,
sort
=
8
)
private
String
col16
;
@ApiModelProperty
(
value
=
"col17"
)
@ExcelField
(
title
=
"col17"
,
sort
=
8
)
private
String
col17
;
@ApiModelProperty
(
value
=
"col18"
)
@ExcelField
(
title
=
"col18"
,
sort
=
8
)
private
String
col18
;
@ApiModelProperty
(
value
=
"col19"
)
@ExcelField
(
title
=
"col19"
,
sort
=
8
)
private
String
col19
;
@ApiModelProperty
(
value
=
"col20"
)
@ExcelField
(
title
=
"col20"
,
sort
=
8
)
private
String
col20
;
@ApiModelProperty
(
value
=
"col21"
)
@ExcelField
(
title
=
"col21"
,
sort
=
8
)
private
String
col21
;
@ApiModelProperty
(
value
=
"col22"
)
@ExcelField
(
title
=
"col22"
,
sort
=
8
)
private
String
col22
;
@ApiModelProperty
(
value
=
"col23"
)
@ExcelField
(
title
=
"col23"
,
sort
=
8
)
private
String
col23
;
@ApiModelProperty
(
value
=
"col24"
)
@ExcelField
(
title
=
"col24"
,
sort
=
8
)
private
String
col24
;
public
String
getCol1
()
{
return
col1
;
}
public
void
setCol1
(
String
col1
)
{
this
.
col1
=
col1
;
}
public
String
getCol2
()
{
return
col2
;
}
public
void
setCol2
(
String
col2
)
{
this
.
col2
=
col2
;
}
public
String
getCol3
()
{
return
col3
;
}
public
void
setCol3
(
String
col3
)
{
this
.
col3
=
col3
;
}
public
String
getCol4
()
{
return
col4
;
}
public
void
setCol4
(
String
col4
)
{
this
.
col4
=
col4
;
}
public
String
getCol5
()
{
return
col5
;
}
public
void
setCol5
(
String
col5
)
{
this
.
col5
=
col5
;
}
public
String
getCol6
()
{
return
col6
;
}
public
void
setCol6
(
String
col6
)
{
this
.
col6
=
col6
;
}
public
String
getCol7
()
{
return
col7
;
}
public
void
setCol7
(
String
col7
)
{
this
.
col7
=
col7
;
}
public
String
getCol8
()
{
return
col8
;
}
public
void
setCol8
(
String
col8
)
{
this
.
col8
=
col8
;
}
public
String
getCol9
()
{
return
col9
;
}
public
void
setCol9
(
String
col9
)
{
this
.
col9
=
col9
;
}
public
String
getCol10
()
{
return
col10
;
}
public
void
setCol10
(
String
col10
)
{
this
.
col10
=
col10
;
}
public
String
getCol11
()
{
return
col11
;
}
public
void
setCol11
(
String
col11
)
{
this
.
col11
=
col11
;
}
public
String
getCol12
()
{
return
col12
;
}
public
void
setCol12
(
String
col12
)
{
this
.
col12
=
col12
;
}
public
String
getCol13
()
{
return
col13
;
}
public
void
setCol13
(
String
col13
)
{
this
.
col13
=
col13
;
}
public
String
getCol14
()
{
return
col14
;
}
public
void
setCol14
(
String
col14
)
{
this
.
col14
=
col14
;
}
public
String
getCol15
()
{
return
col15
;
}
public
void
setCol15
(
String
col15
)
{
this
.
col15
=
col15
;
}
public
String
getCol16
()
{
return
col16
;
}
public
void
setCol16
(
String
col16
)
{
this
.
col16
=
col16
;
}
public
String
getCol17
()
{
return
col17
;
}
public
void
setCol17
(
String
col17
)
{
this
.
col17
=
col17
;
}
public
String
getCol18
()
{
return
col18
;
}
public
void
setCol18
(
String
col18
)
{
this
.
col18
=
col18
;
}
public
String
getCol19
()
{
return
col19
;
}
public
void
setCol19
(
String
col19
)
{
this
.
col19
=
col19
;
}
public
String
getCol20
()
{
return
col20
;
}
public
void
setCol20
(
String
col20
)
{
this
.
col20
=
col20
;
}
public
String
getCol21
()
{
return
col21
;
}
public
void
setCol21
(
String
col21
)
{
this
.
col21
=
col21
;
}
public
String
getCol22
()
{
return
col22
;
}
public
void
setCol22
(
String
col22
)
{
this
.
col22
=
col22
;
}
public
String
getCol23
()
{
return
col23
;
}
public
void
setCol23
(
String
col23
)
{
this
.
col23
=
col23
;
}
public
String
getCol24
()
{
return
col24
;
}
public
void
setCol24
(
String
col24
)
{
this
.
col24
=
col24
;
}
public
String
getCol25
()
{
return
col25
;
}
public
void
setCol25
(
String
col25
)
{
this
.
col25
=
col25
;
}
@ApiModelProperty
(
value
=
"col25"
)
@ExcelField
(
title
=
"col25"
,
sort
=
8
)
private
String
col25
;
}
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/insertSql/package-info.java
0 → 100644
浏览文件 @
588c4409
package
com
.
loit
.
common
.
insertSql
;
loit-build-component/loit-build-deploy-env/src/main/resources/createSql.xlsx
浏览文件 @
588c4409
No preview for this file type
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论