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
69c03978
Commit
69c03978
authored
Jul 18, 2018
by
frank.xa.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed ftp get file too slow issue
parent
e6495005
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
79 additions
and
33 deletions
+79
-33
pom.xml
atms-api/pom.xml
+6
-0
FtpService.java
...src/main/java/pwc/taxtech/atms/common/ftp/FtpService.java
+30
-0
TemplateController.java
.../java/pwc/taxtech/atms/controller/TemplateController.java
+1
-1
FTPFileSystemServiceImpl.java
...c/taxtech/atms/service/impl/FTPFileSystemServiceImpl.java
+1
-1
ReportGeneratorImpl.java
...wc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
+37
-29
VatAbstractService.java
...pwc/taxtech/atms/vat/service/impl/VatAbstractService.java
+3
-0
FSJZ.java
.../taxtech/atms/vat/service/impl/report/functions/FSJZ.java
+0
-1
FunctionBase.java
.../atms/vat/service/impl/report/functions/FunctionBase.java
+1
-1
No files found.
atms-api/pom.xml
View file @
69c03978
...
...
@@ -321,6 +321,12 @@
<artifactId>
lombok
</artifactId>
<version>
1.18.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.5
</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.eclipse.jetty.aggregate</groupId>-->
<!--<artifactId>jetty-all</artifactId>-->
...
...
atms-api/src/main/java/pwc/taxtech/atms/common/ftp/FtpService.java
View file @
69c03978
...
...
@@ -2,6 +2,10 @@ package pwc.taxtech.atms.common.ftp;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.net.ftp.FTPClient
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
pwc.taxtech.atms.exception.ServiceException
;
...
...
@@ -16,6 +20,8 @@ public class FtpService {
String
ftpRootPath
;
private
String
requestPrefix
=
"http://"
;
public
void
upload
(
String
filePath
,
String
fileName
,
InputStream
inputStream
)
throws
Exception
{
String
upPath
;
try
(
WrapFtpClient
wrapFtpClient
=
new
WrapFtpClient
(
config
))
{
...
...
@@ -109,4 +115,28 @@ public class FtpService {
ftpRootPath
=
wrapFtpClient
.
ftpClient
.
printWorkingDirectory
();
}
public
InputStream
getFtpFileWithStaticUrl
(
String
fileUrl
)
throws
IOException
{
if
(
StringUtils
.
isBlank
(
fileUrl
))
{
return
null
;
}
if
(
StringUtils
.
isNotBlank
(
config
.
getFtpHost
()))
{
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
HttpGet
httpGet
=
new
HttpGet
(
requestPrefix
+
config
.
getFtpHost
()
+
"/"
+
fileUrl
);
CloseableHttpResponse
response
=
null
;
try
{
response
=
client
.
execute
(
httpGet
);
if
(
response
.
getStatusLine
().
getStatusCode
()==
200
)
{
return
response
.
getEntity
().
getContent
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
//client.close();
//response.close();
}
}
return
null
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/controller/TemplateController.java
View file @
69c03978
...
...
@@ -68,7 +68,7 @@ public class TemplateController extends BaseController {
if
(
template
.
getIsSystemType
())
{
inputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
templateFile
));
}
else
{
inputStream
=
ftpService
.
download
(
templatePath
);
inputStream
=
ftpService
.
getFtpFileWithStaticUrl
(
templatePath
);
}
//客户端保存的文件名
String
customFileName
=
"template_"
+
DateTime
.
now
().
toString
(
"yyyyMMddHHmmss"
)
+
".xlsx"
;
...
...
atms-api/src/main/java/pwc/taxtech/atms/service/impl/FTPFileSystemServiceImpl.java
View file @
69c03978
...
...
@@ -23,6 +23,6 @@ public class FTPFileSystemServiceImpl implements FileSystemService {
@Override
public
InputStream
downloadUserTemplate
(
String
filePath
)
throws
Exception
{
return
ftpService
.
download
(
filePath
);
return
ftpService
.
getFtpFileWithStaticUrl
(
filePath
);
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
View file @
69c03978
...
...
@@ -6,12 +6,7 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction;
import
org.apache.poi.ss.formula.udf.AggregatingUDFFinder
;
import
org.apache.poi.ss.formula.udf.DefaultUDFFinder
;
import
org.apache.poi.ss.formula.udf.UDFFinder
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.WorkbookFactory
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -29,14 +24,9 @@ import pwc.taxtech.atms.vat.service.ReportGenerator;
import
pwc.taxtech.atms.vat.service.impl.report.functions.*
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
EMPTY
;
...
...
@@ -75,11 +65,11 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
List
<
PeriodCellTemplateConfig
>
periodCellTemplateConfigList
=
periodCellTemplateConfigMapper
.
selectByExample
(
periodCellTemplateConfigExample
);
Map
<
String
,
String
>
templateCodeAndPath
=
new
HashMap
<>();
periodTemplateList
.
forEach
(
a
->
templateCodeAndPath
.
put
(
a
.
getCode
(),
getTemplatePath
(
a
.
getPath
())));
Optional
<
Workbook
>
workbook
=
createWorkBookWithExcelFileList
(
templateCodeAndPath
);
//
Map<String, String> templateCodeAndPath = new HashMap<>();
//
periodTemplateList.forEach(a -> templateCodeAndPath.put(a.getCode(), getTemplatePath(a.getPath())));
Optional
<
Workbook
>
workbook
=
createWorkBookWithExcelFileList
(
periodTemplateList
);
if
(
workbook
!=
null
)
{
if
(
workbook
.
isPresent
()
)
{
Workbook
newWorkbook
=
workbook
.
get
();
FormulaContext
formulaContext
=
new
FormulaContext
();
formulaContext
.
setFormulaAgent
(
formulaAgent
);
...
...
@@ -248,23 +238,41 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
* @param templates 模板code和模板路径 键值对
* @return 工作簿workbook
*/
private
Optional
<
Workbook
>
createWorkBookWithExcelFileList
(
Map
<
String
,
String
>
templates
)
{
private
Optional
<
Workbook
>
createWorkBookWithExcelFileList
(
List
<
PeriodTemplate
>
templates
)
{
Workbook
workbook
=
new
XSSFWorkbook
();
try
{
String
filePath
=
this
.
getClass
().
getResource
(
""
).
toURI
().
getPath
();
String
tempPath
=
filePath
.
substring
(
0
,
filePath
.
indexOf
(
"classes"
)
+
"\\classes"
.
length
());
templates
.
forEach
((
code
,
path
)
->
{
File
file
=
new
File
(
tempPath
+
path
);
try
{
Workbook
tWorkbook
=
WorkbookFactory
.
create
(
file
);
POIUtil
.
cloneSheet
(
tWorkbook
.
getSheetAt
(
0
),
workbook
.
createSheet
(
code
));
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvalidFormatException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
templates
.
forEach
(
a
->
{
Workbook
tWorkbook
=
null
;
File
file
=
null
;
if
(
a
.
getIsSystemType
())
{
file
=
new
File
(
tempPath
+
a
.
getPath
());
try
{
tWorkbook
=
WorkbookFactory
.
create
(
file
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvalidFormatException
e
)
{
e
.
printStackTrace
();
}
}
else
{
InputStream
is
=
null
;
try
{
is
=
ftpService
.
getFtpFileWithStaticUrl
(
a
.
getPath
());
tWorkbook
=
WorkbookFactory
.
create
(
is
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
is
!=
null
)
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
POIUtil
.
cloneSheet
(
tWorkbook
.
getSheetAt
(
0
),
workbook
.
createSheet
(
a
.
getCode
()));
});
return
Optional
.
of
(
workbook
);
}
catch
(
Exception
e
)
{
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/VatAbstractService.java
View file @
69c03978
...
...
@@ -3,6 +3,7 @@ package pwc.taxtech.atms.vat.service.impl;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
pwc.taxtech.atms.common.ftp.FtpService
;
import
pwc.taxtech.atms.dao.*
;
import
pwc.taxtech.atms.dao.dao.ProjectDao
;
import
pwc.taxtech.atms.service.impl.DistributedIDService
;
...
...
@@ -82,5 +83,7 @@ public class VatAbstractService {
public
CellCommentMapper
cellCommentMapper
;
@Autowired
public
KeyValueConfigMapper
keyValueConfigMapper
;
@Autowired
public
FtpService
ftpService
;
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FSJZ.java
View file @
69c03978
...
...
@@ -34,7 +34,6 @@ import java.util.List;
/// <param name="keyParam">摘要(未实现)</param>
public
class
FSJZ
extends
FunctionBase
implements
FreeRefFunction
{
public
FSJZ
(
FormulaContext
formulaContext
)
{
super
(
formulaContext
);
}
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FunctionBase.java
View file @
69c03978
...
...
@@ -21,7 +21,7 @@ import java.util.List;
public
class
FunctionBase
{
protected
final
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
public
static
final
BigDecimal
[]
defaultTaxRates
=
{
new
BigDecimal
(
"0.17"
),
new
BigDecimal
(
"0.13"
)
,
new
BigDecimal
(
"0.11"
),
new
BigDecimal
(
"0.06"
),
new
BigDecimal
(
"
0.05"
),
new
BigDecimal
(
"0.03"
)};
,
new
BigDecimal
(
"0.11"
),
new
BigDecimal
(
"0.06"
),
new
BigDecimal
(
"0.05"
),
new
BigDecimal
(
"0.03"
)};
protected
FormulaContext
formulaContext
;
final
FormulaAgent
agent
;
...
...
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