Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
da9f5117
Commit
da9f5117
authored
Apr 16, 2019
by
chase
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge 档案管理
parent
9b2aaa06
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
44 deletions
+130
-44
pom.xml
atms-api/pom.xml
+11
-1
TaxDocumentController.java
...va/pwc/taxtech/atms/controller/TaxDocumentController.java
+11
-38
TaxDocumentServiceImpl.java
...pwc/taxtech/atms/service/impl/TaxDocumentServiceImpl.java
+103
-0
tax-document-list.ctrl.js
...ocumentManage/tax-document-list/tax-document-list.ctrl.js
+5
-5
No files found.
atms-api/pom.xml
View file @
da9f5117
...
...
@@ -426,7 +426,17 @@
<artifactId>
lombok
</artifactId>
<version>
1.18.0
</version>
</dependency>
<!--PDF转换为图片-->
<dependency>
<groupId>
org.apache.pdfbox
</groupId>
<artifactId>
fontbox
</artifactId>
<version>
2.0.1
</version>
</dependency>
<dependency>
<groupId>
org.apache.pdfbox
</groupId>
<artifactId>
pdfbox
</artifactId>
<version>
2.0.1
</version>
</dependency>
</dependencies>
<profiles>
...
...
atms-api/src/main/java/pwc/taxtech/atms/controller/TaxDocumentController.java
View file @
da9f5117
...
...
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
import
net.sf.json.JSONNull
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -31,10 +30,9 @@ import pwc.taxtech.atms.thirdparty.ExcelUtil;
import
pwc.taxtech.atms.vat.entity.FileUpload
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -112,13 +110,14 @@ public class TaxDocumentController {
}
/**
* 读取PDF
使用base64 解析
* 读取PDF
转换为图片
*
*/
@PostMapping
(
"/previewPDF"
)
@ResponseBody
public
String
previewPDF
(
@RequestBody
TaxDocumentDto
taxDocumentDto
)
{
InputStream
is
=
null
;
public
void
previewPDF
(
@RequestBody
TaxDocumentDto
taxDocumentDto
)
{
taxDocumentService
.
previewPDF
(
taxDocumentDto
.
getPath
());
/*InputStream is = null;
ByteArrayOutputStream os = null;
try {
//根据url地址 获取文件输入流
...
...
@@ -149,7 +148,9 @@ public class TaxDocumentController {
} catch (IOException e) {
e.printStackTrace();
}
}
}*/
}
@RequestMapping
(
"exportExcel"
)
@ResponseBody
...
...
@@ -246,7 +247,7 @@ public class TaxDocumentController {
try
{
JSONArray
dataArray
=
new
JSONArray
();
//根据url地址 获取文件输入流
InputStream
is
=
getInputStreamByUrl
(
taxDocumentDto
.
getPath
());
InputStream
is
=
taxDocumentService
.
getInputStreamByUrl
(
taxDocumentDto
.
getPath
());
InputStream
inStream
=
is
;
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
inStream
);
// 循环工作表Sheet 将数据解析后 存入json对象
...
...
@@ -392,32 +393,4 @@ public class TaxDocumentController {
dataArray
.
add
(
sheetJson
);
}
}
/**
* 根据url地址 获取输入流
* @param url
* @return
* @throws IOException
*/
private
InputStream
getInputStreamByUrl
(
String
url
)
throws
IOException
{
URL
httpurl
=
new
URL
(
URLDecoder
.
decode
(
url
,
"UTF-8"
));
InputStream
is
;
HttpURLConnection
httpConn
=(
HttpURLConnection
)
httpurl
.
openConnection
();
httpConn
.
setDoOutput
(
true
);
// 使用 URL 连接进行输出
httpConn
.
setDoInput
(
true
);
// 使用 URL 连接进行输入
httpConn
.
setUseCaches
(
false
);
// 忽略缓存
httpConn
.
setRequestMethod
(
"GET"
);
// 设置URL请求方法
//可设置请求头
httpConn
.
setRequestProperty
(
"Content-Type"
,
"application/octet-stream"
);
httpConn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
// 维持长连接
httpConn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
httpConn
.
connect
();
if
(
httpConn
.
getResponseCode
()
>=
400
)
{
is
=
httpConn
.
getErrorStream
();
}
else
{
is
=
httpConn
.
getInputStream
();
}
return
is
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/service/impl/TaxDocumentServiceImpl.java
View file @
da9f5117
...
...
@@ -6,6 +6,8 @@ import com.google.common.collect.Maps;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -26,7 +28,9 @@ import pwc.taxtech.atms.vat.entity.FileUpload;
import
pwc.taxtech.atms.vat.entity.ReportFileUpload
;
import
javax.annotation.Resource
;
import
javax.imageio.ImageIO
;
import
javax.servlet.http.HttpServletResponse
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
...
...
@@ -428,6 +432,21 @@ public class TaxDocumentServiceImpl {
}
}
public
void
previewPDF
(
String
path
)
{
String
imageType
=
"PNG"
;
OutputStream
sos
=
null
;
try
{
PDFToImg
(
sos
,
path
,
getPDFNum
(
path
),
imageType
);
}
catch
(
IOException
e
)
{
log
.
error
(
"PDF转换图片异常: "
+
e
.
getMessage
());
}
finally
{
try
{
sos
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"关闭输出流异常: "
+
e
.
getMessage
());
}
}
}
public
void
downloadAllFile
(
HttpServletResponse
response
,
List
<
Long
>
ids
)
{
//如果只选择了一个附件,则不打包
if
(
null
!=
ids
&&
ids
.
size
()
==
1
)
{
...
...
@@ -1114,4 +1133,88 @@ public class TaxDocumentServiceImpl {
return
false
;
}
}
/**
* 获取PDF总页数
* @throws IOException
*/
public
int
getPDFNum
(
String
fileUrl
)
throws
IOException
{
PDDocument
pdDocument
=
null
;
int
pages
=
0
;
try
{
pdDocument
=
getPDDocument
(
fileUrl
);
pages
=
pdDocument
.
getNumberOfPages
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
pdDocument
!=
null
)
{
pdDocument
.
close
();
}
}
return
pages
;
}
/**
* PDF转图片 根据页码一页一页转
* @throws IOException
* imgType:转换后的图片类型 jpg,png
*/
private
void
PDFToImg
(
OutputStream
sos
,
String
fileUrl
,
int
page
,
String
imgType
)
throws
IOException
{
PDDocument
pdDocument
=
null
;
/* dpi越大转换后越清晰,相对转换速度越慢 */
int
dpi
=
100
;
try
{
pdDocument
=
getPDDocument
(
fileUrl
);
PDFRenderer
renderer
=
new
PDFRenderer
(
pdDocument
);
int
pages
=
pdDocument
.
getNumberOfPages
();
if
(
page
<=
pages
&&
page
>
0
)
{
BufferedImage
image
=
renderer
.
renderImageWithDPI
(
page
,
dpi
);
ImageIO
.
write
(
image
,
imgType
,
sos
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
pdDocument
!=
null
)
{
pdDocument
.
close
();
}
}
}
private
PDDocument
getPDDocument
(
String
fileUrl
)
throws
IOException
{
InputStream
inputStream
=
getInputStreamByUrl
(
fileUrl
);
return
PDDocument
.
load
(
inputStream
);
}
/**
* 根据url地址 获取输入流
* @param url
* @return
* @throws IOException
*/
public
InputStream
getInputStreamByUrl
(
String
url
)
throws
IOException
{
URL
httpurl
=
new
URL
(
URLDecoder
.
decode
(
url
,
"UTF-8"
));
InputStream
is
;
HttpURLConnection
httpConn
=(
HttpURLConnection
)
httpurl
.
openConnection
();
httpConn
.
setDoOutput
(
true
);
// 使用 URL 连接进行输出
httpConn
.
setDoInput
(
true
);
// 使用 URL 连接进行输入
httpConn
.
setUseCaches
(
false
);
// 忽略缓存
httpConn
.
setRequestMethod
(
"GET"
);
// 设置URL请求方法
//可设置请求头
httpConn
.
setRequestProperty
(
"Content-Type"
,
"application/octet-stream"
);
httpConn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
// 维持长连接
httpConn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
httpConn
.
connect
();
if
(
httpConn
.
getResponseCode
()
>=
400
)
{
is
=
httpConn
.
getErrorStream
();
}
else
{
is
=
httpConn
.
getInputStream
();
}
return
is
;
}
}
atms-web/src/main/webapp/app/taxDocumentManage/tax-document-list/tax-document-list.ctrl.js
View file @
da9f5117
...
...
@@ -516,7 +516,7 @@ taxDocumentManageModule.controller('taxDocumentListController',
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
$translate
.
instant
(
'Confirm'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel
4Tax
'
),
closeOnConfirm
:
true
,
closeOnCancel
:
true
},
...
...
@@ -595,7 +595,7 @@ taxDocumentManageModule.controller('taxDocumentListController',
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
$translate
.
instant
(
'Confirm'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel
4Tax
'
),
closeOnConfirm
:
true
,
closeOnCancel
:
true
},
...
...
@@ -700,7 +700,7 @@ taxDocumentManageModule.controller('taxDocumentListController',
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
$translate
.
instant
(
'Confirm'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel
4Tax
'
),
closeOnConfirm
:
true
,
closeOnCancel
:
true
},
...
...
@@ -1079,7 +1079,7 @@ taxDocumentManageModule.directive('multiFileUploader', function () {
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
$translate
.
instant
(
'Confirm'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel
4Tax
'
),
closeOnConfirm
:
true
,
closeOnCancel
:
true
},
...
...
@@ -1273,7 +1273,7 @@ taxDocumentManageModule.directive('multiFileUploader', function () {
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
$translate
.
instant
(
'Confirm'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel'
),
cancelButtonText
:
$translate
.
instant
(
'Cancel
4Tax
'
),
closeOnConfirm
:
true
,
closeOnCancel
:
true
},
...
...
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