Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-tool
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张帅
amos-tool
Commits
35533eef
Commit
35533eef
authored
Aug 16, 2023
by
陈祥烨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新脚本导出
parent
8144ce93
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
37 deletions
+64
-37
RelationResource.java
...om/yeejoin/amos/api/tool/controller/RelationResource.java
+2
-2
DataBaseLinkService.java
...ejoin/amos/api/tool/face/service/DataBaseLinkService.java
+10
-6
RelationService.java
...m/yeejoin/amos/api/tool/face/service/RelationService.java
+27
-11
StudioResourceService.java
...oin/amos/api/tool/face/service/StudioResourceService.java
+3
-18
DataBaseUtils.java
...n/java/com/yeejoin/amos/api/tool/utils/DataBaseUtils.java
+22
-0
No files found.
src/main/java/com/yeejoin/amos/api/tool/controller/RelationResource.java
View file @
35533eef
...
...
@@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletResponse;
@CrossOrigin
@RestController
@Api
(
tags
=
"机构管理Api"
)
@RequestMapping
(
value
=
"/
A
gency"
)
@RequestMapping
(
value
=
"/
a
gency"
)
public
class
RelationResource
{
@Autowired
private
RelationService
relationService
;
...
...
@@ -47,7 +47,7 @@ public class RelationResource {
* @return String
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@GetMapping
(
value
=
"/
outpu
t/{agencyCode}/{sequenceNbrs}"
)
@GetMapping
(
value
=
"/
expor
t/{agencyCode}/{sequenceNbrs}"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"导出"
,
notes
=
"导出"
)
public
ResponseModel
<
String
>
generateSQL
(
...
...
src/main/java/com/yeejoin/amos/api/tool/face/service/DataBaseLinkService.java
View file @
35533eef
...
...
@@ -55,11 +55,11 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
* 编辑
*/
public
DataBaseLinkModel
update
(
DataBaseLinkModel
dataBaseLinkModel
)
throws
Exception
{
DataBaseLinkModel
model
=
this
.
en
cryptPwd
(
dataBaseLinkModel
);
DataBaseLinkModel
model
=
this
.
de
cryptPwd
(
dataBaseLinkModel
);
if
(
this
.
testConnection
(
model
))
{
return
this
.
updateWithModel
(
model
);
return
this
.
updateWithModel
(
encryptPwd
(
model
)
);
}
else
{
return
n
ew
DataBaseLinkModel
()
;
return
n
ull
;
}
}
...
...
@@ -97,12 +97,12 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
public
List
<
AgencyModel
>
queryForAgencyList
()
throws
SQLException
,
IOException
{
Connection
con
=
dataSource
.
getConnection
();
URL
url
=
new
URL
(
con
.
getMetaData
().
getURL
().
replace
(
"jdbc:mysql"
,
"http"
));
(
con
.
getMetaData
().
getURL
().
replace
(
"jdbc:mysql"
,
"http"
));
con
.
close
();
log
.
info
(
url
);
DataBaseLink
dataBaseLink
=
getOne
(
new
QueryWrapper
<
DataBaseLink
>().
eq
(
"IP"
,
url
.
getHost
()));
DataBaseLink
dataBaseLink
=
getOne
(
new
QueryWrapper
<
DataBaseLink
>().
eq
(
"IP"
,
url
.
getHost
()));
DataBaseLinkModel
dataBaseLinkModel
=
new
DataBaseLinkModel
();
Bean
.
toModel
(
dataBaseLink
,
dataBaseLinkModel
);
Bean
.
toModel
(
dataBaseLink
,
dataBaseLinkModel
);
Connection
connection
=
this
.
connectNewDatabase
(
dataBaseLinkModel
);
List
<
Map
<
String
,
Object
>>
maps
=
DataBaseUtils
.
getMaps
(
"SELECT AGENCY_NAME, AGENCY_CODE, AGENCY_DESC FROM privilege_agency;"
,
connection
);
...
...
@@ -180,6 +180,10 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
return
model
;
}
public
DataBaseLinkModel
decryptPwd
(
DataBaseLinkModel
model
)
throws
Exception
{
model
.
setPassWord
(
AESUtils
.
decrypt
(
model
.
getPassWord
()));
return
model
;
}
}
src/main/java/com/yeejoin/amos/api/tool/face/service/RelationService.java
View file @
35533eef
package
com
.
yeejoin
.
amos
.
api
.
tool
.
face
.
service
;
import
com.yeejoin.amos.api.tool.enums.SourceEnum
;
import
com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel
;
import
com.yeejoin.amos.api.tool.face.model.DataBaseNameListModel
;
import
com.yeejoin.amos.api.tool.face.model.RelationModel
;
...
...
@@ -9,6 +10,7 @@ import com.yeejoin.amos.api.tool.face.orm.entity.Relation;
import
com.yeejoin.amos.api.tool.face.orm.entity.TableColumn
;
import
com.yeejoin.amos.api.tool.utils.DataBaseUtils
;
import
org.apache.commons.beanutils.ConvertUtils
;
import
org.apache.commons.lang3.time.DateFormatUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
...
...
@@ -21,6 +23,7 @@ import javax.servlet.http.HttpServletResponse;
import
java.io.*
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -63,8 +66,7 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
DataBaseLinkModel
model
=
dataBaseLinkService
.
queryBySeq
(
nameListModel
.
getParentId
());
model
.
setDbName
(
nameListModel
.
getDbName
());
Connection
connection
=
dataBaseLinkService
.
connectNewDatabase
(
model
);
this
.
insertData
(
connection
,
agencyCode
,
model
.
getDbName
(),
response
);
this
.
insertData
(
connection
,
agencyCode
,
model
.
getDbName
(),
seq
,
response
);
}
}
...
...
@@ -189,7 +191,7 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
/**
* 插入数据
*/
public
void
insertData
(
Connection
connection
,
String
agencyCode
,
String
dbName
,
HttpServletResponse
response
)
throws
SQLException
{
public
void
insertData
(
Connection
connection
,
String
agencyCode
,
String
dbName
,
Long
seq
,
HttpServletResponse
response
)
throws
SQLException
{
try
{
File
directory
=
new
File
(
""
);
// 参数为空
String
coursePath
=
directory
.
getCanonicalPath
();
...
...
@@ -199,16 +201,21 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
if
(!
sqlDirectory
.
exists
())
{
sqlDirectory
.
mkdir
();
}
String
fileName
=
agencyCode
+
"."
+
SUFFIX
;
print
(
seq
.
toString
(),
"开始执行"
,
"start"
);
String
fileName
=
"studio_"
+
DateFormatUtils
.
format
(
new
Date
(),
"yyyyMMdd"
)
+
"."
+
SUFFIX
;
String
sqlFilePath
=
backPath
+
SLASH
+
fileName
;
File
file
=
new
File
(
sqlFilePath
);
FileOutputStream
out
;
OutputStreamWriter
writer
=
null
;
out
=
new
FileOutputStream
(
file
);
writer
=
new
OutputStreamWriter
(
out
,
"utf8"
);
StringBuffer
insertSql
=
new
StringBuffer
();
if
(!
connection
.
isClosed
())
System
.
out
.
println
(
"Succeeded connecting to the Database!"
);
//通过连接获取relation表树形结构
List
<
RelationTreeModel
>
trees
=
this
.
createRelationTree
(
dbName
);
for
(
RelationTreeModel
tree
:
trees
)
{
...
...
@@ -218,12 +225,14 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
for
(
RelationTreeModel
model
:
array
)
{
List
<
RelationTreeModel
>
tableSet
=
tableRelation
(
model
,
array
);
List
<
TableColumn
>
columns
=
DataBaseUtils
.
getTableColumn
(
model
.
getName
(),
connection
);
String
sql
=
this
.
getSelectSQL
(
tableSet
,
model
.
getName
(),
columns
,
agencyCode
).
toString
();
List
<
Map
<
String
,
Object
>>
dataList
=
DataBaseUtils
.
getMaps
(
sql
,
connection
);
System
.
out
.
println
(
sql
);
String
selectSQL
=
this
.
getSelectSQL
(
tableSet
,
model
.
getName
(),
columns
,
agencyCode
).
toString
();
print
(
seq
.
toString
(),
"开始查询"
+
model
.
getName
()+
"表"
,
"running"
);
List
<
Map
<
String
,
Object
>>
dataList
=
DataBaseUtils
.
getMaps
(
selectSQL
,
connection
);
print
(
seq
.
toString
(),
"开始创建"
+
model
.
getName
()+
"表insert语句"
,
"running"
);
System
.
out
.
println
(
selectSQL
);
StringBuffer
insertSQL
=
DataBaseUtils
.
getInsertSQL
(
dataList
,
columns
,
model
.
getName
());
System
.
out
.
println
(
insertSQL
);
if
(!
ObjectUtils
.
isEmpty
(
sql
))
insertSql
.
append
(
insertSQL
);
if
(!
ObjectUtils
.
isEmpty
(
insertSQL
))
insertSql
.
append
(
insertSQL
);
}
}
if
(
insertSql
.
length
()
>
0
)
{
...
...
@@ -232,15 +241,22 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
writer
.
write
(
BR
+
DELIMITER
+
BR
);
writer
.
write
(
insertSql
.
toString
());
writer
.
write
(
BR
+
BR
+
DELIMITER
+
BR
);
print
(
seq
.
toString
(),
"insert语句创建完成..."
,
"running"
);
}
writer
.
flush
();
writer
.
close
();
out
.
close
();
connection
.
close
();
if
(
insertSql
.
length
()
==
0
)
{
print
(
seq
.
toString
(),
"该项目下数据路径字段为空,不支持导出..."
,
"start"
);
return
;
}
download
(
response
,
fileName
,
sqlFilePath
);
print
(
seq
.
toString
(),
"执行结束"
,
"end"
);
}
catch
(
SQLException
|
IOException
e
)
{
e
.
printStackTrace
();
}
connection
.
close
();
}
/**
...
...
src/main/java/com/yeejoin/amos/api/tool/face/service/StudioResourceService.java
View file @
35533eef
...
...
@@ -33,6 +33,8 @@ import java.util.Date;
import
java.util.List
;
import
java.util.Map
;
import
static
com
.
yeejoin
.
amos
.
api
.
tool
.
utils
.
DataBaseUtils
.
print
;
/**
* <p>
* 服务类
...
...
@@ -80,8 +82,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
@Autowired
private
SqlHelper
sqlHelper
;
@Autowired
EmqKeeper
emqKeeper
;
/**
* 列表查询 示例
...
...
@@ -158,7 +159,6 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
writer
.
write
(
BR
+
BR
+
DELIMITER
+
BR
);
print
(
variables
.
get
(
dimension
).
toString
(),
"insert语句创建完成..."
,
"running"
);
}
writer
.
flush
();
writer
.
close
();
out
.
close
();
...
...
@@ -233,21 +233,6 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
out
.
close
();
}
private
void
print
(
String
id
,
String
msg
,
String
step
)
{
String
percent
=
"0"
;
percent
=
ValidationUtil
.
equals
(
step
,
"end"
)
?
"100"
:
ValidationUtil
.
equals
(
step
,
"running"
)
?
"50"
:
"10"
;
JSONObject
event
=
new
JSONObject
();
event
.
put
(
"percent"
,
percent
);
event
.
put
(
"status"
,
"running"
);
event
.
put
(
"logInfo"
,
msg
);
event
.
put
(
"time"
,
DateUtils
.
toDateStr
(
DateUtils
.
format
()));
try
{
emqKeeper
.
getMqttClient
().
publish
(
"/topicTable/solidify/"
+
(
id
.
indexOf
(
','
)
!=
-
1
?
id
.
split
(
","
)[
0
]
:
id
),
event
.
toString
().
getBytes
(),
0
,
false
);
}
catch
(
MqttException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 获取项目列表
...
...
src/main/java/com/yeejoin/amos/api/tool/utils/DataBaseUtils.java
View file @
35533eef
package
com
.
yeejoin
.
amos
.
api
.
tool
.
utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.yeejoin.amos.api.tool.face.orm.entity.TableColumn
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.ObjectUtils
;
import
org.typroject.tyboot.component.emq.EmqKeeper
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.sql.DataSource
;
...
...
@@ -17,6 +21,8 @@ import java.util.*;
public
class
DataBaseUtils
{
static
EmqKeeper
emqKeeper
;
/**
* 数据库备份路径
*/
...
...
@@ -151,6 +157,22 @@ public class DataBaseUtils {
return
sql
;
}
public
static
void
print
(
String
id
,
String
msg
,
String
step
)
{
String
percent
=
"0"
;
percent
=
ValidationUtil
.
equals
(
step
,
"end"
)
?
"100"
:
ValidationUtil
.
equals
(
step
,
"running"
)
?
"50"
:
"10"
;
JSONObject
event
=
new
JSONObject
();
event
.
put
(
"percent"
,
percent
);
event
.
put
(
"status"
,
"running"
);
event
.
put
(
"logInfo"
,
msg
);
event
.
put
(
"time"
,
DateUtils
.
toDateStr
(
DateUtils
.
format
()));
try
{
emqKeeper
.
getMqttClient
().
publish
(
"/topicTable/solidify/"
+
(
id
.
indexOf
(
','
)
!=
-
1
?
id
.
split
(
","
)[
0
]
:
id
),
event
.
toString
().
getBytes
(),
0
,
false
);
}
catch
(
MqttException
e
)
{
e
.
printStackTrace
();
}
}
public
static
<
V
>
Page
<
V
>
listToPage
(
List
<
V
>
list
,
int
current
,
int
size
)
{
//当前页
Page
<
V
>
page
=
new
Page
<>(
current
,
size
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment