Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zgzx
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
zgzx
Commits
c0a7c122
提交
c0a7c122
authored
9月 09, 2019
作者:
renjiancai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
13fbf352
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
0 行增加
和
709 行删除
+0
-709
DatabaseController.java
.../zrqx/resource/bg/controller/task/DatabaseController.java
+0
-709
没有找到文件。
com.zrqx.resource/src/main/java/com/zrqx/resource/bg/controller/task/DatabaseController.java
deleted
100644 → 0
浏览文件 @
13fbf352
package
com
.
zrqx
.
resource
.
bg
.
controller
.
task
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.text.DecimalFormat
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.zip.ZipOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.zrqx.core.constant.resource.ResourceRequestPath
;
import
com.zrqx.core.enums.AllResourceTypeEnum
;
import
com.zrqx.core.util.datatype.UUIDUtil
;
import
com.zrqx.core.util.zip.ZipUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
/**
* 视频库Controller
*/
@RestController
@RequestMapping
(
ResourceRequestPath
.
BG
+
ResourceRequestPath
.
DATABASE
)
@Api
(
description
=
"资源管理-导出任务"
)
public
class
DatabaseController
{
private
String
url
=
"jdbc:mysql://192.168.2.229:3306/zygj-resource"
;
private
String
fileurl
=
"jdbc:mysql://192.168.2.229:3306/fileinfo"
;
private
String
userName
=
"root"
;
private
String
password
=
"root"
;
@ApiOperation
(
value
=
"批量导出文件"
,
notes
=
"批量导出文件"
)
@GetMapping
(
value
=
ResourceRequestPath
.
FILE
)
public
String
getAllFile
(
String
codes
,
String
resourceType
,
HttpServletRequest
request
)
throws
Exception
{
HttpSession
session
=
request
.
getSession
();
session
.
setAttribute
(
"percentage"
,
"0%"
);
String
basePath
=
"/opt/upload/zygj/"
;
String
zipPath
=
"zip/"
+
UUIDUtil
.
getUUID
()
+
".zip"
;
String
zipFileName
=
basePath
+
zipPath
;
ZipOutputStream
out
=
new
ZipOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
zipFileName
)));
Set
<
String
>
filesPath
=
new
HashSet
<
String
>();
Set
<
String
>
fileList
=
new
HashSet
<
String
>();
StringBuffer
fileNames
=
new
StringBuffer
();
if
(
codes
.
contains
(
","
))
{
for
(
String
code
:
codes
.
split
(
","
))
{
fileList
.
addAll
(
getAllFileName
(
code
,
resourceType
));
}
}
else
{
fileList
=
getAllFileName
(
codes
,
resourceType
);
}
for
(
String
fileName
:
fileList
)
{
fileNames
.
append
(
"'"
).
append
(
fileName
).
append
(
"',"
);
}
fileNames
=
fileNames
.
deleteCharAt
(
fileNames
.
length
()
-
1
);
try
(
Connection
conn
=
DriverManager
.
getConnection
(
fileurl
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select * from fileinfo where fileName in ("
+
fileNames
+
")"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
String
path
=
resultSet
.
getString
(
"path"
);
String
fileName
=
resultSet
.
getString
(
"fileName"
);
String
originalFileName
=
resultSet
.
getString
(
"originalFileName"
);
String
suffixName
=
resultSet
.
getString
(
"suffixName"
);
File
file
=
new
File
(
basePath
+
path
+
"/"
+
originalFileName
);
if
(!
file
.
exists
())
{
file
=
new
File
(
basePath
+
path
+
"/"
+
fileName
+
suffixName
);
if
(
file
.
exists
())
{
filesPath
.
add
(
path
+
"/"
+
fileName
+
suffixName
);
}
}
else
{
filesPath
.
add
(
path
+
"/"
+
originalFileName
);
}
}
}
}
int
allsize
=
filesPath
.
size
();
int
i
=
0
;
System
.
out
.
println
(
filesPath
.
size
());
for
(
String
filePath
:
filesPath
)
{
ZipUtil
.
compress
(
out
,
new
File
(
basePath
+
filePath
),
filePath
);
i
=
i
+
1
;
DecimalFormat
df
=
new
DecimalFormat
(
"0.00"
);
session
.
setAttribute
(
"percentage"
,
df
.
format
((
float
)
i
/
allsize
*
100
)+
"%"
);
}
out
.
close
();
return
zipPath
;
}
@ApiOperation
(
value
=
"获取导出文件百分比"
,
notes
=
"获取导出文件百分比"
)
@GetMapping
(
value
=
ResourceRequestPath
.
PERCENTAGE
)
public
Object
getpercentage
(
HttpServletRequest
request
)
{
return
request
.
getSession
().
getAttribute
(
"percentage"
);
}
@ApiOperation
(
value
=
"批量导出sql"
,
notes
=
"批量导出sql"
)
@GetMapping
(
value
=
ResourceRequestPath
.
SQL
)
public
boolean
getAllSQL
(
String
codes
,
String
resourceType
)
throws
Exception
{
// 后置path
String
path
=
"/opt/sql/"
;
File
folder
=
new
File
(
path
);
if
(!
folder
.
exists
())
{
folder
.
mkdir
();
}
// 前置路径
String
command
=
"/usr/bin/mysqldump -f -c -q "
;
Process
process
=
null
;
String
fileinfo
=
"-uroot -proot -t -h192.168.2.229 fileinfo"
;
String
resource
=
"-uroot -proot -t -h192.168.2.229 zygj-resource"
;
// 导出fileinfo库
Set
<
String
>
fileList
=
new
HashSet
<
String
>();
if
(
codes
.
contains
(
","
))
{
for
(
String
code
:
codes
.
split
(
","
))
{
fileList
.
addAll
(
getAllFileName
(
code
,
resourceType
));
}
}
else
{
fileList
=
getAllFileName
(
codes
,
resourceType
);
}
StringBuffer
files
=
new
StringBuffer
();
for
(
String
file
:
fileList
)
{
files
.
append
(
"'"
).
append
(
file
).
append
(
"',"
);
}
if
(
files
.
length
()
>
0
)
{
files
=
files
.
deleteCharAt
(
files
.
length
()
-
1
);
}
String
cmdfileinfo
=
command
+
fileinfo
+
" fileinfo --where \"fileName in ("
+
files
+
")\" > "
+
path
+
"fileinfo.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdfileinfo
});
process
.
waitFor
();
// 导出 resource库
// 附件库
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
ANNEX
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_annex_library r inner join res_annex_library_diy_type rt on r.id =rt.annexid where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_annex_library_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"annextype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_annex_library r inner join res_annex_library_diy_type rt on r.id =rt.annexid where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_annex_library_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"annextype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdannex
=
command
+
resource
+
" res_annex_library --where \"id in ("
+
ids
+
")\" > "
+
path
+
"annex.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannex
});
process
.
waitFor
();
String
cmdannexcontent
=
command
+
resource
+
" res_annex_library_label_content_diy_type --where \"annexId in ("
+
ids
+
")\" > "
+
path
+
"annexcontent.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannexcontent
});
process
.
waitFor
();
}
}
// 音频
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
AUDIO
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_audio_Library r inner join res_audio_Library_diy_type rt on r.id =rt.audioid where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_audio_Library_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"audiotype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_audio_library r inner join res_audio_library_diy_type rt on r.id =rt.audioid where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_audio_library_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"audiotype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdannex
=
command
+
resource
+
" res_audio_library --where \"id in ("
+
ids
+
")\" > "
+
path
+
"audio.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannex
});
process
.
waitFor
();
String
cmdannexcontent
=
command
+
resource
+
" res_audio_library_label_content_diy_type --where \"audioId in ("
+
ids
+
")\" > "
+
path
+
"audiocontent.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannexcontent
});
process
.
waitFor
();
}
}
// 图片
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
IMAGE
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_image_Library r inner join res_image_Library_diy_type rt on r.id =rt.ilid where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_image_Library_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"audiotype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_image_Library r inner join res_image_Library_diy_type rt on r.id =rt.ilid where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_image_Library_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"imagetype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdannex
=
command
+
resource
+
" res_image_Library --where \"id in ("
+
ids
+
")\" > "
+
path
+
"image.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannex
});
process
.
waitFor
();
String
cmdannexcontent
=
command
+
resource
+
" res_image_Library_label_content_diy_type --where \"imageId in ("
+
ids
+
")\" > "
+
path
+
"imagecontent.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannexcontent
});
process
.
waitFor
();
}
}
// pdf
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
PDF
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_pdf_Library r inner join res_pdf_Library_diy_type rt on r.id =rt.plid where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_pdf_Library_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"pdftype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_pdf_Library r inner join res_pdf_Library_diy_type rt on r.id =rt.plid where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_pdf_Library_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"pdftype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdannex
=
command
+
resource
+
" res_audio_library --where \"id in ("
+
ids
+
")\" > "
+
path
+
"pdf.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannex
});
process
.
waitFor
();
}
}
// 视频
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
VIDEO
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_video_Library r inner join res_video_Library_diy_type rt on r.id =rt.vlid where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_video_Library_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"videotype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_video_library r inner join res_video_library_diy_type rt on r.id =rt.vlid where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_video_library_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"videotype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdannex
=
command
+
resource
+
" res_video_library --where \"id in ("
+
ids
+
")\" > "
+
path
+
"video.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannex
});
process
.
waitFor
();
String
cmdannexcontent
=
command
+
resource
+
" res_video_library_label_content_diy_type --where \"vlid in ("
+
ids
+
")\" > "
+
path
+
"videocontent.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannexcontent
});
process
.
waitFor
();
}
}
// 文章
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
ARTICLE
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_article_Library r inner join res_article_Library_diy_type rt on r.id =rt.alid where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_article_Library_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"articletype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_article_library r inner join res_article_library_diy_type rt on r.id =rt.alid where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_article_library_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"articletype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdannex
=
command
+
resource
+
" res_article_library --where \"id in ("
+
ids
+
")\" > "
+
path
+
"article.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannex
});
process
.
waitFor
();
String
cmdannexcontent
=
command
+
resource
+
" res_article_library_label_content_diy_type --where \"vlid in ("
+
ids
+
")\" > "
+
path
+
"articlecontent.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannexcontent
});
process
.
waitFor
();
}
}
// 图书
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
BOOK
.
getCode
().
toString
()))
{
StringBuffer
ids
=
new
StringBuffer
();
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
if
(
codes
.
contains
(
","
))
{
String
[]
codeStr
=
codes
.
split
(
","
);
String
sql
=
"select r.id from res_ebook r inner join res_ebook_diy_type rt on r.id =rt.ebookId where"
;
String
sql1
=
""
;
for
(
String
code
:
codeStr
)
{
sql
+=
" rt.code like '"
+
code
+
"%' or"
;
sql1
+=
" code like '"
+
code
+
"%' or"
;
}
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
2
);
sql1
=
sql1
.
substring
(
0
,
sql1
.
length
()
-
2
);
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_ebook_diy_type --where \""
+
sql1
+
"\" > "
+
path
+
"ebooktype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
else
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.id from res_ebook r inner join res_ebook_diy_type rt on r.id =rt.ebookId where rt.code like '"
+
codes
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
ids
.
append
(
"'"
).
append
(
resultSet
.
getString
(
"id"
)).
append
(
"',"
);
}
}
String
cmdannextype
=
command
+
resource
+
" res_ebook_diy_type --where \"code like '"
+
codes
+
"%'\" > "
+
path
+
"ebooktype.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdannextype
});
process
.
waitFor
();
}
}
if
(
ids
.
length
()
>
0
)
{
ids
=
ids
.
deleteCharAt
(
ids
.
length
()
-
1
);
String
cmdbook
=
command
+
resource
+
" res_book --where \"id in ("
+
ids
+
")\" > "
+
path
+
"book.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdbook
});
process
.
waitFor
();
String
cmdebook
=
command
+
resource
+
" res_ebook --where \"id in ("
+
ids
+
")\" > "
+
path
+
"ebook.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdebook
});
process
.
waitFor
();
String
cmdebookcontent
=
command
+
resource
+
" res_ebook_label_content_diy_type --where \"vlid in ("
+
ids
+
")\" > "
+
path
+
"ebookcontent.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdebookcontent
});
process
.
waitFor
();
String
cmdchapter
=
command
+
resource
+
" res_chapter_library --where \"bookid in ("
+
ids
+
")\" > "
+
path
+
"chapter.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdchapter
});
process
.
waitFor
();
String
cmdarticle
=
command
+
resource
+
" res_article_library --where \"bookid in ("
+
ids
+
")\" > "
+
path
+
"bookarticle.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdarticle
});
process
.
waitFor
();
String
cmdimage
=
command
+
resource
+
" res_image_library --where \"bookid in ("
+
ids
+
")\" > "
+
path
+
"bookimage.sql"
;
process
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
cmdimage
});
process
.
waitFor
();
}
}
return
true
;
}
/**
* 获取全部文件名称
*
* @param code
* @param resourceType
* @return
* @throws SQLException
*/
private
Set
<
String
>
getAllFileName
(
String
code
,
String
resourceType
)
throws
SQLException
{
Set
<
String
>
fileList
=
new
HashSet
<
String
>();
// 附件
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
ANNEX
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.annex,r.cover from res_annex_library r inner join res_annex_library_diy_type rt on r.id =rt.annexid where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"annex"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"annex"
));
}
if
(
resultSet
.
getString
(
"cover"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"cover"
));
}
}
}
}
}
// 文章
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
ARTICLE
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.pdf,r.img from res_article_library r inner join res_article_library_diy_type rt on r.id =rt.alid where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"pdf"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"pdf"
));
}
if
(
resultSet
.
getString
(
"img"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"img"
));
}
}
}
}
}
// 音频
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
AUDIO
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.audio,r.cover from res_audio_Library r inner join res_audio_library_diy_type rt on r.id =rt.audioid where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"audio"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"audio"
));
}
if
(
resultSet
.
getString
(
"cover"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"cover"
));
}
}
}
}
}
// 图片
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
IMAGE
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.image,r.image_sl from res_image_library r inner join res_image_library_diy_type rt on r.id =rt.ilid where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"image"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"image"
));
}
if
(
resultSet
.
getString
(
"image_sl"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"image_sl"
));
}
}
}
}
}
// pdf
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
PDF
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.pdf from res_pdf_library r inner join res_pdf_library_diy_type rt on r.id =rt.plid where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"pdf"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"pdf"
));
}
}
}
}
}
// 视频
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
VIDEO
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.video,r.cover from res_video_library r inner join res_video_library_diy_type rt on r.id =rt.vlid where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"video"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"video"
));
}
if
(
resultSet
.
getString
(
"cover"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"cover"
));
}
}
}
}
}
// 图书
if
(
resourceType
==
null
||
resourceType
.
contains
(
AllResourceTypeEnum
.
BOOK
.
getCode
().
toString
()))
{
try
(
Connection
conn
=
DriverManager
.
getConnection
(
url
,
userName
,
password
))
{
try
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select r.bookCover,r.fileName,r.xmlFile,r.pdfFile,r.cssPath from res_ebook r inner join res_ebook_diy_type rt on r.id =rt.ebookId where rt.code like '"
+
code
+
"%'"
))
{
ResultSet
resultSet
=
ps
.
executeQuery
();
while
(
resultSet
.
next
())
{
if
(
resultSet
.
getString
(
"bookCover"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"bookCover"
));
}
if
(
resultSet
.
getString
(
"fileName"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"fileName"
));
}
if
(
resultSet
.
getString
(
"xmlFile"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"xmlFile"
));
}
if
(
resultSet
.
getString
(
"pdfFile"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"pdfFile"
));
}
if
(
resultSet
.
getString
(
"cssPath"
)
!=
null
)
{
fileList
.
add
(
resultSet
.
getString
(
"cssPath"
));
}
}
}
}
}
return
fileList
;
}
public
static
void
main
(
String
[]
args
)
{
String
zipFileName
=
"D:/opt/upload/zip/"
+
UUIDUtil
.
getUUID
()
+
".zip"
;
ZipOutputStream
out
;
try
{
out
=
new
ZipOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
zipFileName
)));
ZipUtil
.
compress
(
out
,
new
File
(
"D:/opt/upload/2019/01/10/646b2e94810a4417b4a240b03b7ff3dc.txt"
),
"2019/01/10/646b2e94810a4417b4a240b03b7ff3dc.txt"
);
out
.
close
();
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论