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
51821c29
Commit
51821c29
authored
Jun 19, 2018
by
neo.wang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev_neo2' into 'dev'
[DEV] get file content upload file See merge request root/atms!26
parents
00e5666c
2e04d14f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
280 additions
and
6 deletions
+280
-6
Constant.java
...api/src/main/java/pwc/taxtech/atms/constant/Constant.java
+5
-0
VATCommon.java
...pi/src/main/java/pwc/taxtech/atms/constant/VATCommon.java
+9
-0
TBDataImportController.java
...a/pwc/taxtech/atms/controller/TBDataImportController.java
+36
-0
NPOIHelper.java
...-api/src/main/java/pwc/taxtech/atms/utils/NPOIHelper.java
+137
-0
DataImportModel.java
...c/main/java/pwc/taxtech/atms/vat/dao/DataImportModel.java
+69
-0
FileUploadAdapter.java
.../pwc/taxtech/atms/vat/service/impl/FileUploadAdapter.java
+24
-6
No files found.
atms-api/src/main/java/pwc/taxtech/atms/constant/Constant.java
View file @
51821c29
...
...
@@ -24,4 +24,8 @@ public final class Constant {
public
static
final
UUID
USER_ID_FOR_UPLOAD
=
UUID
.
fromString
(
"64D39CF7-467E-4414-B334-AA4B55A4E2B3"
);
public
static
final
String
UPLOAD_FOLDER_NAME
=
"Upload"
;
public
static
final
String
CURRENT_USER_HOME
=
"~"
;
public
static
final
String
CURRENT_USER_UPLOAD_FOLDER
=
CURRENT_USER_HOME
+
File
.
separator
+
UPLOAD_FOLDER_NAME
;
public
static
final
boolean
DEFAULT_RESULT
=
true
;
}
\ No newline at end of file
atms-api/src/main/java/pwc/taxtech/atms/constant/VATCommon.java
0 → 100644
View file @
51821c29
package
pwc
.
taxtech
.
atms
.
constant
;
public
class
VATCommon
{
public
static
final
String
Const_ImportFileError
=
"文件为空或者格式不正确"
;
public
static
final
int
inValidNum
=
-
1
;
public
static
final
String
ValidationExisted
=
"validation existed"
;
public
static
final
String
ReValidate
=
"revalidate"
;
public
static
final
int
WholeYearPeriod
=
-
1
;
}
atms-api/src/main/java/pwc/taxtech/atms/controller/TBDataImportController.java
View file @
51821c29
...
...
@@ -3,8 +3,10 @@ package pwc.taxtech.atms.controller;
import
com.alibaba.fastjson.JSONObject
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HttpStatus
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
pwc.taxtech.atms.common.CommonUtils
;
import
pwc.taxtech.atms.dto.OperationResultDto
;
...
...
@@ -14,8 +16,16 @@ import pwc.taxtech.atms.dto.vatdto.*;
import
pwc.taxtech.atms.service.DataImportService
;
import
pwc.taxtech.atms.service.ICitTBDataImportService
;
import
pwc.taxtech.atms.service.IdentityService
;
import
pwc.taxtech.atms.utils.NPOIHelper
;
import
pwc.taxtech.atms.vat.dao.DataImportModel
;
import
pwc.taxtech.atms.vat.service.TBDataImportService
;
import
pwc.taxtech.atms.vat.service.impl.FileUploadAdapter
;
import
javax.ws.rs.core.Response
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -36,6 +46,8 @@ public class TBDataImportController {
private
DataImportService
dataImportService
;
@Autowired
private
IdentityService
identityService
;
@Autowired
private
FileUploadAdapter
fileUploadAdapter
;
@RequestMapping
(
value
=
"GetBalanceDataForDisplay"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
...
...
@@ -384,6 +396,7 @@ public class TBDataImportController {
identityService
.
getIdentityUser
().
getID
()
);
}
@RequestMapping
(
value
=
"GetParentCodesForDisplay"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
@ResponseBody
String
GetParentCodesForDisplay
(
String
category
)
{
...
...
@@ -433,5 +446,28 @@ public class TBDataImportController {
initParentCodeTree
(
tempNode
.
getChildren
(),
jsonParentCodesLookup
.
getAcctCode
(),
sources
);
}
}
@ApiOperation
(
value
=
"getFileContent"
,
notes
=
""
)
@RequestMapping
(
value
=
"FileContent/{tempFileName}/{selectedSheetIndex}/{topRowNumber}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
getFileContent
(
@PathVariable
String
tempFileName
,
@PathVariable
Integer
selectedSheetIndex
,
@PathVariable
Integer
topRowNumber
)
{
DataImportModel
dataImportModel
;
String
fullFilePath
=
fileUploadAdapter
.
getLastFilePathByFileName
(
tempFileName
);
if
(
fullFilePath
!=
null
)
{
try
(
FileInputStream
fis
=
new
FileInputStream
(
new
File
(
fullFilePath
));)
{
dataImportModel
=
NPOIHelper
.
renderTBDataTableFromExcel
(
fis
,
selectedSheetIndex
,
0
,
true
,
topRowNumber
);
dataImportModel
.
setSelectedSheetIndex
(
selectedSheetIndex
);
return
ResponseEntity
.
ok
(
dataImportModel
);
}
catch
(
FileNotFoundException
e
)
{
//TODO: replace exception filter (neo)
e
.
printStackTrace
();
return
ResponseEntity
.
status
(
HttpStatus
.
SC_INTERNAL_SERVER_ERROR
).
build
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
ResponseEntity
.
status
(
HttpStatus
.
SC_INTERNAL_SERVER_ERROR
).
build
();
}
}
else
{
return
ResponseEntity
.
ok
().
build
();
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/utils/NPOIHelper.java
0 → 100644
View file @
51821c29
package
pwc
.
taxtech
.
atms
.
utils
;
import
org.apache.poi.hssf.usermodel.HSSFDateUtil
;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException
;
import
org.apache.poi.ss.usermodel.Cell
;
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.xssf.usermodel.XSSFFormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
pwc.taxtech.atms.constant.VATCommon
;
import
pwc.taxtech.atms.vat.dao.DataImportModel
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
NUMERIC
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
DEFAULT_RESULT
;
public
class
NPOIHelper
{
public
static
DataImportModel
renderTBDataTableFromExcel
(
FileInputStream
fis
,
Integer
selectedSheetIndex
,
int
headerRowIndex
,
boolean
haveHeader
,
Integer
topRowNumber
)
{
DataImportModel
dataImportModel
=
new
DataImportModel
();
Workbook
workbook
=
null
;
try
{
workbook
=
WorkbookFactory
.
create
(
fis
);
Sheet
sheet
=
workbook
.
getSheetAt
(
selectedSheetIndex
);
dataImportModel
.
setDataList
(
new
ArrayList
<>());
dataImportModel
.
setSheetNameList
(
new
ArrayList
<>());
dataImportModel
.
setResult
(
DEFAULT_RESULT
);
try
{
//TODO:should be replace by biz exception (neo)
if
(!(
workbook
instanceof
XSSFWorkbook
))
throw
new
RuntimeException
(
"not support workbook type"
);
XSSFFormulaEvaluator
eva
=
new
XSSFFormulaEvaluator
((
XSSFWorkbook
)
workbook
);
int
numberOfSheets
=
workbook
.
getNumberOfSheets
();
for
(
int
index
=
0
;
index
<
numberOfSheets
;
index
++)
{
dataImportModel
.
getSheetNameList
().
add
(
workbook
.
getSheetAt
(
index
).
getSheetName
());
}
//判断文件是否为空
if
(
sheet
.
getPhysicalNumberOfRows
()
==
0
)
{
dataImportModel
.
setResult
(
false
);
dataImportModel
.
setResultMsg
(
VATCommon
.
Const_ImportFileError
);
}
else
{
//var headerRow = sheet.GetRow(HeaderRowIndex);
int
cellCount
=
0
;
for
(
int
i
=
0
;
i
<=
sheet
.
getLastRowNum
();
i
++)
{
Row
row
=
sheet
.
getRow
(
i
);
if
(
row
!=
null
&&
row
.
getPhysicalNumberOfCells
()
>
cellCount
)
{
cellCount
=
row
.
getPhysicalNumberOfCells
();
}
}
List
<
String
>
rowList
=
new
ArrayList
<>();
//dataImportModel.dataList.Add(rowList);
dataImportModel
.
setLastRowIndex
(
sheet
.
getLastRowNum
());
int
RowStart
=
sheet
.
getFirstRowNum
();
for
(
int
i
=
RowStart
;
i
<=
sheet
.
getLastRowNum
();
i
++)
{
Row
row
=
sheet
.
getRow
(
i
);
if
(
row
!=
null
)
{
rowList
=
getOutputInvoiceRowValueList
(
eva
,
row
,
cellCount
);
dataImportModel
.
getDataList
().
add
(
rowList
);
}
}
}
}
catch
(
Exception
ex
)
{
dataImportModel
.
setResult
(
false
);
dataImportModel
.
setResultMsg
(
VATCommon
.
Const_ImportFileError
);
}
if
(
topRowNumber
>
0
)
{
//第一行为列头的话就多输出一行
int
topNum
=
haveHeader
?
topRowNumber
+
1
:
topRowNumber
;
dataImportModel
.
setDataList
(
dataImportModel
.
getDataList
().
subList
(
0
,
topNum
));
}
return
dataImportModel
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvalidFormatException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
private
static
List
<
String
>
getOutputInvoiceRowValueList
(
XSSFFormulaEvaluator
eva
,
Row
row
,
int
cellCount
)
{
List
<
String
>
rowList
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
cellCount
;
j
++)
{
if
(
row
.
getCell
(
j
)
!=
null
)
{
rowList
.
add
(
getStringCellValue
(
eva
,
row
.
getCell
(
j
)));
}
else
{
rowList
.
add
(
null
);
}
}
return
rowList
;
}
private
static
String
getStringCellValue
(
XSSFFormulaEvaluator
eva
,
Cell
cell
)
{
// 获取单元格数据内容为字符串类型的数据
DateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
strCell
=
""
;
switch
(
cell
.
getCellTypeEnum
())
{
case
NUMERIC:
if
(
HSSFDateUtil
.
isCellDateFormatted
(
cell
))
{
strCell
=
sdf
.
format
(
cell
.
getDateCellValue
());
}
else
{
strCell
=
cell
.
getNumericCellValue
()
+
""
;
}
break
;
case
FORMULA:
try
{
if
(
eva
.
evaluate
(
cell
).
getCellTypeEnum
()
==
NUMERIC
)
{
strCell
=
eva
.
evaluate
(
cell
).
getNumberValue
()
+
""
;
}
else
{
strCell
=
eva
.
evaluate
(
cell
).
getStringValue
();
}
}
catch
(
Exception
ex
)
{
strCell
=
"#N/A"
;
}
break
;
default
:
strCell
=
cell
.
toString
();
break
;
}
return
strCell
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/dao/DataImportModel.java
0 → 100644
View file @
51821c29
package
pwc
.
taxtech
.
atms
.
vat
.
dao
;
import
java.util.List
;
public
class
DataImportModel
{
private
List
<
String
>
sheetNameList
;
private
List
<
List
<
String
>>
dataList
;
private
List
<
String
>
mappingResult
;
private
int
selectedSheetIndex
;
private
int
lastRowIndex
;
private
Boolean
result
;
private
String
resultMsg
;
public
List
<
String
>
getSheetNameList
()
{
return
sheetNameList
;
}
public
void
setSheetNameList
(
List
<
String
>
sheetNameList
)
{
this
.
sheetNameList
=
sheetNameList
;
}
public
List
<
List
<
String
>>
getDataList
()
{
return
dataList
;
}
public
void
setDataList
(
List
<
List
<
String
>>
dataList
)
{
this
.
dataList
=
dataList
;
}
public
List
<
String
>
getMappingResult
()
{
return
mappingResult
;
}
public
void
setMappingResult
(
List
<
String
>
mappingResult
)
{
this
.
mappingResult
=
mappingResult
;
}
public
int
getSelectedSheetIndex
()
{
return
selectedSheetIndex
;
}
public
void
setSelectedSheetIndex
(
int
selectedSheetIndex
)
{
this
.
selectedSheetIndex
=
selectedSheetIndex
;
}
public
int
getLastRowIndex
()
{
return
lastRowIndex
;
}
public
void
setLastRowIndex
(
int
lastRowIndex
)
{
this
.
lastRowIndex
=
lastRowIndex
;
}
public
Boolean
getResult
()
{
return
result
;
}
public
void
setResult
(
Boolean
result
)
{
this
.
result
=
result
;
}
public
String
getResultMsg
()
{
return
resultMsg
;
}
public
void
setResultMsg
(
String
resultMsg
)
{
this
.
resultMsg
=
resultMsg
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/FileUploadAdapter.java
View file @
51821c29
...
...
@@ -21,6 +21,7 @@ import java.util.Calendar;
import
java.util.Date
;
import
java.util.UUID
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
CURRENT_USER_UPLOAD_FOLDER
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
UPLOAD_FOLDER_NAME
;
@Service
...
...
@@ -38,6 +39,17 @@ public class FileUploadAdapter {
private
boolean
containsSubFolder
=
true
;
//TODO this should not use val should use parameter(neo)
public
String
getLastFilePathByFileName
(
String
tempFileName
)
{
String
uploadFolder
=
combine
(
CURRENT_USER_UPLOAD_FOLDER
,
getSubFolder
());
String
fileFullPath
=
combine
(
uploadFolder
,
tempFileName
);
if
(
new
File
(
fileFullPath
).
exists
())
{
return
fileFullPath
;
}
return
null
;
}
static
class
FileParamBean
{
String
fileName
;
...
...
@@ -127,13 +139,9 @@ public class FileUploadAdapter {
}
private
String
prepareFolder
()
{
String
uploadFolder
=
String
.
format
(
"~"
+
File
.
separator
+
"%s"
,
UPLOAD_FOLDER_NAME
)
;
String
uploadFolder
=
CURRENT_USER_UPLOAD_FOLDER
;
if
(
containsSubFolder
)
{
Calendar
now
=
Calendar
.
getInstance
();
now
.
setTime
(
new
Date
());
String
subUploadFolder
=
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
now
.
get
(
Calendar
.
MONTH
),
now
.
get
(
Calendar
.
DATE
));
uploadFolder
=
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
uploadFolder
,
subUploadFolder
);
uploadFolder
=
combine
(
uploadFolder
,
getSubFolder
());
File
file
=
new
File
(
uploadFolder
);
if
(!
file
.
exists
())
file
.
mkdirs
();
...
...
@@ -141,4 +149,14 @@ public class FileUploadAdapter {
return
uploadFolder
;
}
private
String
getSubFolder
()
{
Calendar
now
=
Calendar
.
getInstance
();
now
.
setTime
(
new
Date
());
return
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
now
.
get
(
Calendar
.
MONTH
),
now
.
get
(
Calendar
.
DATE
));
}
private
String
combine
(
String
parent
,
String
child
)
{
return
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
parent
,
child
);
}
}
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