Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jgjk
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
任建宇
jgjk
Commits
031101b5
提交
031101b5
authored
3月 19, 2021
作者:
liupengfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
69e8d0f5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
65 行增加
和
8 行删除
+65
-8
ExcelBookExportVo.java
...main/java/com/zrqx/file/commons/vo/ExcelBookExportVo.java
+6
-6
EpubController.java
...rc/main/java/com/zrqx/file/controller/EpubController.java
+59
-2
没有找到文件。
app/file/src/main/java/com/zrqx/file/commons/vo/ExcelBookExportVo.java
浏览文件 @
031101b5
...
...
@@ -25,22 +25,22 @@ public class ExcelBookExportVo extends ImportVo{
@ExcelResources
(
title
=
"正丛书名"
,
order
=
4
)
private
String
bookSeries
;
@ExcelResources
(
title
=
"第一责任者及著作方式
"
,
order
=
5
)
@ExcelResources
(
title
=
"第一责任者及著作方式"
,
order
=
5
)
private
String
executiveEditor
;
@ExcelResources
(
title
=
"版次及其他版本形式
"
,
order
=
5
)
@ExcelResources
(
title
=
"版次及其他版本形式
"
,
order
=
6
)
private
String
revision
;
@ExcelResources
(
title
=
"印次
"
,
order
=
5
)
@ExcelResources
(
title
=
"印次
"
,
order
=
7
)
private
String
printNo
;
@ExcelResources
(
title
=
"主题词"
,
order
=
5
)
@ExcelResources
(
title
=
"主题词"
,
order
=
8
)
private
String
keywords
;
@ExcelResources
(
title
=
"分类号"
,
order
=
5
)
@ExcelResources
(
title
=
"分类号"
,
order
=
9
)
private
String
midpicid
;
@ExcelResources
(
title
=
"内容提要
"
,
order
=
5
)
@ExcelResources
(
title
=
"内容提要
"
,
order
=
10
)
private
String
synopsis
;
}
app/file/src/main/java/com/zrqx/file/controller/EpubController.java
浏览文件 @
031101b5
...
...
@@ -4,7 +4,9 @@ import javax.servlet.http.HttpServletRequest;
import
com.zrqx.core.client.vo.ImportLabelVo
;
import
com.zrqx.core.util.excelutil.ExcelUtil
;
import
com.zrqx.core.util.excelutil.ImportUtil
;
import
com.zrqx.file.commons.model.AppVersionRecord
;
import
com.zrqx.file.commons.vo.ExcelBookExportVo
;
import
com.zrqx.file.service.AppVersionService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -41,6 +43,9 @@ public class EpubController {
@Autowired
private
ImportUtil
importUtil
;
@Autowired
private
AppVersionService
appVersionService
;
private
EpubVo
ev
=
new
EpubVo
();
@ApiOperation
(
value
=
"epub上传 返回token"
)
...
...
@@ -59,7 +64,6 @@ public class EpubController {
}
catch
(
Exception
e
)
{
throw
new
BaseException
(
"epub上传失败"
);
}
return
token
;
}
...
...
@@ -87,7 +91,9 @@ public class EpubController {
if
(
StringUtils
.
isNotBlank
(
f
.
getIsbn
())){
String
isbn
=
f
.
getIsbn
().
trim
();
try
{
String
destUrl
=
"http://192.168.0.209/file/"
+
isbn
+
"/"
+
isbn
+
".epub"
;
String
destUrl
=
"http://192.168.2.247/file/book/"
+
isbn
+
"/epub/"
+
isbn
+
".epub"
;
//String path = "E:\\epub\\"+s;
//testIO(destUrl,isbn+".epub",path);
HttpURLConnection
httpUrl
=
(
HttpURLConnection
)
new
URL
(
destUrl
).
openConnection
();
httpUrl
.
connect
();
File
epubFile
=
inputStreamToFile
(
httpUrl
.
getInputStream
(),
isbn
+
".epub"
);
...
...
@@ -97,6 +103,10 @@ public class EpubController {
tokenList
.
add
(
token
);
redis
.
set
(
token
,
ev
);
}
catch
(
Exception
e
)
{
AppVersionRecord
appVersionRecord
=
new
AppVersionRecord
();
appVersionRecord
.
setFilePath
(
f
.
getIsbn
());
appVersionRecord
.
setDescription
(
f
.
getName
());
appVersionService
.
insert
(
appVersionRecord
);
logger
.
error
(
"---------------------------------图书信息"
+
isbn
);
}
}
...
...
@@ -104,6 +114,8 @@ public class EpubController {
return
tokenList
;
}
/**
* 工具类
* inputStream 转 File
...
...
@@ -124,6 +136,51 @@ public class EpubController {
ins
.
close
();
return
file
;
}
/**
* 从网络Url中下载文件
* @param urlStr 下载文件路径
* @param fileName 文件名称包含类型
* @param savePath 保存本地的路径
* @throws IOException
*/
public
void
testIO
(
String
urlStr
,
String
fileName
,
String
savePath
)
throws
IOException
{
URL
url
=
new
URL
(
urlStr
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
//设置超时间为5秒
conn
.
setConnectTimeout
(
5
*
1000
);
//防止屏蔽程序抓取而返回403错误
conn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
);
//得到输入流
InputStream
inputStream
=
conn
.
getInputStream
();
//创建保存路径
File
saveDir
=
new
File
(
savePath
);
if
(!
saveDir
.
exists
())
{
saveDir
.
mkdir
();
}
//创建文件
File
file
=
new
File
(
saveDir
+
File
.
separator
+
fileName
);
//使用内存输出流的方式
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
//将输入流写入到内存输出流中
byte
[]
buff
=
new
byte
[
4096
];
int
len
=
-
1
;
while
((
len
=
inputStream
.
read
(
buff
))
!=
-
1
)
{
baos
.
write
(
buff
,
0
,
len
);
}
byte
[]
getData
=
baos
.
toByteArray
();
//文件输出流
FileOutputStream
fout
=
new
FileOutputStream
(
file
);
//将内存输出流写入磁盘
fout
.
write
(
getData
);
//关闭输出输入流
fout
.
close
();
//这里可以关闭,也可以不关闭,因为ByteArrayOutputStream的close方法是一个空实现,所以关闭也没有意义。
baos
.
close
();
inputStream
.
close
();
System
.
out
.
println
(
"info:"
+
url
+
" download success"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论