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
1119f37d
Commit
1119f37d
authored
Jul 22, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev] FinanceDataUpload impl
parent
a4498e97
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
81 deletions
+166
-81
CustomsInvoiceController.java
...pwc/taxtech/atms/controller/CustomsInvoiceController.java
+2
-3
FinanceDataImportController.java
.../taxtech/atms/controller/FinanceDataImportController.java
+149
-64
ImportCustomsInvoiceDto.java
.../pwc/taxtech/atms/dto/vatdto/ImportCustomsInvoiceDto.java
+3
-1
ImportDataDto.java
.../main/java/pwc/taxtech/atms/dto/vatdto/ImportDataDto.java
+10
-0
FinanceDataImportService.java
...wc/taxtech/atms/vat/service/FinanceDataImportService.java
+0
-10
FileUploadAdapter.java
.../pwc/taxtech/atms/vat/service/impl/FileUploadAdapter.java
+1
-0
FinanceDataImportServiceImpl.java
...h/atms/vat/service/impl/FinanceDataImportServiceImpl.java
+1
-3
No files found.
atms-api/src/main/java/pwc/taxtech/atms/controller/CustomsInvoiceController.java
View file @
1119f37d
...
...
@@ -257,9 +257,8 @@ public class CustomsInvoiceController {
}
@RequestMapping
(
value
=
"ImportCustomsInvoice"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
ResponseEntity
ImportBalanceList
(
@RequestBody
ImportCustomsInvoiceDto
importDto
)
{
public
ResponseEntity
ImportBalanceList
(
@RequestBody
ImportCustomsInvoiceDto
importDto
)
{
String
userId
=
identityService
.
getIdentityUser
().
getID
();
return
ResponseEntity
.
ok
(
customsInvoiceService
.
ImportCustomsInvoice
(
importDto
.
CustomsList
,
importDto
.
ImportType
,
userId
));
return
ResponseEntity
.
ok
(
customsInvoiceService
.
ImportCustomsInvoice
(
importDto
.
CustomsList
,
importDto
.
ImportType
,
userId
));
}
}
atms-api/src/main/java/pwc/taxtech/atms/controller/FinanceDataImportController.java
View file @
1119f37d
...
...
@@ -6,16 +6,38 @@ import org.springframework.http.MediaType;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.thymeleaf.util.StringUtils
;
import
pwc.taxtech.atms.dto.OperationResultDto
;
import
pwc.taxtech.atms.dto.vatdto.ImportDataDto
;
import
pwc.taxtech.atms.service.IdentityService
;
import
pwc.taxtech.atms.vat.service.FinanceDataImportService
;
import
pwc.taxtech.atms.vat.service.impl.FinanceDataImportServiceImpl
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
@RestController
@RequestMapping
(
"/api/v1/financeImportData"
)
public
class
FinanceDataImportController
{
private
final
static
String
ImportMethod_OneClick
=
"oneClick"
;
private
final
static
String
OneClickUploadPath
=
"~/FinanceDataUpload/OneClickFile"
;
private
final
static
String
UniversalUploadExcelPath
=
"~/FinanceDataUpload/UniversalExcelFile"
;
private
final
static
String
UniversalUploadCsvPath
=
"~/FinanceDataUpload/UniversalCsvlFile"
;
@Autowired
private
FinanceDataImportService
financeDataImport
;
private
FinanceDataImportService
Impl
financeDataImport
;
@Autowired
private
IdentityService
identityService
;
...
...
@@ -25,68 +47,61 @@ public class FinanceDataImportController {
return
ResponseEntity
.
ok
().
body
(
financeDataImport
.
getBasicValidationResults
(
identityService
.
getIdentityUser
().
getID
()));
}
@RequestMapping
(
value
=
"importData/financeDataUpload"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
ResponseEntity
FinanceDataUpload
()
{
// string importMethod = HttpContext.Current.Request.Params["importMethod"];
// if (HttpContext.Current.Request.Files.Count == 0)
// {
// return this.Ok(new OperationResultDto() { Result = false, ResultMsg = "NoFile" });
// }
//
// if (string.IsNullOrEmpty(importMethod))
// {
// return this.Ok(new OperationResultDto() { Result = false, ResultMsg = "importMethod is empty" });
// }
//
// if (!IsSameFileExtenstion(HttpContext.Current.Request.Files))
// {
// return this.Ok(new OperationResultDto() { Result = false, ResultMsg = "file extension is not same" });
// }
//
// try
// {
// OperationResultDto<ImportDataDto> result = new OperationResultDto<ImportDataDto>();
// int uploadFileCount = 0;
// string mappedPath = "";
// string fileGuid = Guid.NewGuid().ToString().ToUpper();
// var firstUploadFile = HttpContext.Current.Request.Files[0];
// string fileExtension = firstUploadFile.FileName.Substring(firstUploadFile.FileName.LastIndexOf(".") + 1, firstUploadFile.FileName.Length - firstUploadFile.FileName.LastIndexOf(".") - 1);
//
// for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
// {
// var file = HttpContext.Current.Request.Files[i];
// mappedPath = SetUploadFolderPath(importMethod, fileExtension);
// var fileFullPath = Path.Combine(mappedPath, fileGuid + "_" + Path.GetFileName(file.FileName));
// if (SaveFile(file, mappedPath, fileFullPath))
// {
// uploadFileCount++;
// }
// }
//
// if (uploadFileCount == HttpContext.Current.Request.Files.Count)
// {
// result.Result = true;
// result.ResultMsg = string.Empty;
// result.Data = new ImportDataDto { Guid = fileGuid, Number = uploadFileCount, FileExtension = fileExtension };
//
// }
// return Ok(result);
// }
// catch (Exception ex)
// {
// Dictionary<Guid, string> error = new Dictionary<Guid, string>();
// error.Add(System.Guid.NewGuid(), ex.StackTrace);
// OperationResultDto<ImportDataDto> errorResult = new OperationResultDto<ImportDataDto>()
// {
// Result = false,
// ResultMsg = "Upload File error",
// Errors = error,
// Data = new ImportDataDto { Guid = string.Empty, Number = 0, FileExtension = string.Empty }
// };
//
// return Ok(errorResult);
// }
return
ResponseEntity
.
ok
().
build
();
@RequestMapping
(
value
=
"importData/financeDataUpload"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
public
ResponseEntity
FinanceDataUpload
(
@RequestParam
String
importMethod
,
MultipartHttpServletRequest
request
)
{
if
(
request
.
getFileMap
().
size
()
==
0
)
{
return
ResponseEntity
.
ok
(
new
OperationResultDto
(
false
,
"NoFile"
));
}
if
(
StringUtils
.
isEmpty
(
importMethod
))
{
return
ResponseEntity
.
ok
(
new
OperationResultDto
(
false
,
"importMethod is empty"
));
}
if
(!
IsSameFileExtenstion
(
request
.
getFileMap
()))
{
return
ResponseEntity
.
ok
(
new
OperationResultDto
(
false
,
"file extension is not same"
));
}
try
{
OperationResultDto
<
ImportDataDto
>
result
=
new
OperationResultDto
<>();
int
uploadFileCount
=
0
;
String
mappedPath
=
""
;
String
fileGuid
=
UUID
.
randomUUID
().
toString
().
toUpperCase
();
String
fileExtension
=
getExtension
(
request
.
getFileMap
());
for
(
MultipartFile
file
:
request
.
getFileMap
().
values
())
{
mappedPath
=
SetUploadFolderPath
(
importMethod
,
fileExtension
);
String
fileFullPath
=
Paths
.
get
(
mappedPath
,
fileGuid
+
"_"
+
file
.
getName
()).
toString
();
if
(
SaveFile
(
file
,
mappedPath
,
fileFullPath
))
{
uploadFileCount
++;
}
}
if
(
uploadFileCount
==
request
.
getFileMap
().
size
())
{
result
.
setResult
(
true
);
result
.
setResultMsg
(
""
);
ImportDataDto
dataDto
=
new
ImportDataDto
();
dataDto
.
Guid
=
fileGuid
;
dataDto
.
Number
=
uploadFileCount
;
dataDto
.
FileExtension
=
fileExtension
;
result
.
setData
(
dataDto
);
}
return
ResponseEntity
.
ok
(
result
);
}
catch
(
Exception
ex
)
{
Map
<
String
,
String
>
error
=
new
HashMap
<>();
ex
.
printStackTrace
();
error
.
put
(
UUID
.
randomUUID
().
toString
(),
ex
.
getMessage
());
OperationResultDto
<
ImportDataDto
>
errorResult
=
new
OperationResultDto
<
ImportDataDto
>(
false
,
"Upload File error"
);
errorResult
.
setErrors
(
error
);
ImportDataDto
dataDto
=
new
ImportDataDto
();
dataDto
.
Guid
=
""
;
dataDto
.
Number
=
0
;
dataDto
.
FileExtension
=
""
;
errorResult
.
setData
(
dataDto
);
return
ResponseEntity
.
ok
(
errorResult
);
}
}
...
...
@@ -204,4 +219,74 @@ public class FinanceDataImportController {
return
ResponseEntity
.
ok
().
build
();
}
private
Boolean
IsSameFileExtenstion
(
Map
<
String
,
MultipartFile
>
files
)
{
Set
<
String
>
extension
=
new
HashSet
<>();
for
(
MultipartFile
file
:
files
.
values
())
{
extension
.
add
(
file
.
getName
().
substring
(
file
.
getName
().
lastIndexOf
(
"."
)
+
1
,
file
.
getName
().
length
()
-
file
.
getName
().
lastIndexOf
(
"."
)));
}
if
(
extension
.
size
()
==
1
)
{
return
true
;
}
else
{
return
false
;
}
}
private
String
getExtension
(
Map
<
String
,
MultipartFile
>
files
)
{
MultipartFile
file
=
files
.
values
().
stream
().
findFirst
().
get
();
return
file
.
getName
().
substring
(
file
.
getName
().
lastIndexOf
(
"."
)
+
1
,
file
.
getName
().
length
()
-
file
.
getName
().
lastIndexOf
(
"."
));
}
private
String
SetUploadFolderPath
(
String
importMethod
,
String
fileExtension
)
{
String
folderPath
=
""
;
if
(
importMethod
==
ImportMethod_OneClick
)
{
folderPath
=
OneClickUploadPath
;
}
else
{
if
(
fileExtension
==
"csv"
)
{
folderPath
=
UniversalUploadCsvPath
;
}
if
(
fileExtension
==
"xls"
||
fileExtension
==
"xlsx"
)
{
folderPath
=
UniversalUploadExcelPath
;
}
}
return
folderPath
;
}
private
Boolean
SaveFile
(
MultipartFile
file
,
String
mappedPath
,
String
fileFullPath
)
{
Map
<
String
,
String
>
error
=
new
HashMap
<>();
try
{
if
(!
new
File
(
mappedPath
).
exists
())
{
new
File
(
mappedPath
).
mkdirs
();
}
SaveAs
(
file
,
fileFullPath
);
}
catch
(
Exception
ex
)
{
return
false
;
}
return
true
;
}
private
void
SaveAs
(
MultipartFile
file
,
String
fileFullPath
)
{
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
new
File
(
fileFullPath
));
InputStream
inputStream
=
file
.
getInputStream
();)
{
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
,
0
,
buffer
.
length
))
>
0
)
{
fos
.
write
(
buffer
,
0
,
bytesRead
);
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/dto/vatdto/ImportCustomsInvoiceDto.java
View file @
1119f37d
package
pwc
.
taxtech
.
atms
.
dto
.
vatdto
;
import
pwc.taxtech.atms.vat.entity.CustomsInvoice
;
import
java.util.List
;
public
class
ImportCustomsInvoiceDto
{
public
List
<
CustomsInvoice
Dto
>
CustomsList
;
public
List
<
CustomsInvoice
>
CustomsList
;
public
int
ImportType
;
}
atms-api/src/main/java/pwc/taxtech/atms/dto/vatdto/ImportDataDto.java
0 → 100644
View file @
1119f37d
package
pwc
.
taxtech
.
atms
.
dto
.
vatdto
;
public
class
ImportDataDto
{
public
Boolean
Result
;
public
String
Guid
;
public
Integer
Number
;
public
String
FileExtension
;
public
String
FileName
;
public
String
ErrorMsg
;
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/FinanceDataImportService.java
deleted
100644 → 0
View file @
a4498e97
package
pwc
.
taxtech
.
atms
.
vat
.
service
;
import
pwc.taxtech.atms.dto.OperationResultDto
;
import
pwc.taxtech.atms.dto.vatdto.DataCheckDto
;
import
java.util.List
;
public
interface
FinanceDataImportService
{
OperationResultDto
<
List
<
DataCheckDto
>>
getBasicValidationResults
(
String
userId
);
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/FileUploadAdapter.java
View file @
1119f37d
...
...
@@ -124,6 +124,7 @@ public class FileUploadAdapter {
}
private
FileParamBean
getQueryStringParameters
(
MultipartHttpServletRequest
request
)
{
FileParamBean
param
=
new
FileParamBean
();
param
.
fileName
=
request
.
getParameter
(
FILE_NAME
);
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/FinanceDataImportServiceImpl.java
View file @
1119f37d
...
...
@@ -18,7 +18,6 @@ import pwc.taxtech.atms.vat.entity.ValidationInfo;
import
pwc.taxtech.atms.vat.entity.ValidationInfoExample
;
import
pwc.taxtech.atms.vat.entity.Voucher
;
import
pwc.taxtech.atms.vat.entity.VoucherExample
;
import
pwc.taxtech.atms.vat.service.FinanceDataImportService
;
import
sun.misc.BASE64Encoder
;
import
javax.imageio.ImageIO
;
...
...
@@ -41,13 +40,12 @@ import static pwc.taxtech.atms.constant.enums.EnumValidationType.ErpBasicCheck;
import
static
pwc
.
taxtech
.
atms
.
constant
.
enums
.
ImageType
.
Alert
;
@Service
public
class
FinanceDataImportServiceImpl
implements
FinanceDataImportService
{
public
class
FinanceDataImportServiceImpl
{
@Autowired
private
ValidationInfoMapper
validationInfoMapper
;
@Autowired
private
VoucherMapper
voucherMapper
;
@Override
public
OperationResultDto
<
List
<
DataCheckDto
>>
getBasicValidationResults
(
String
userId
)
{
Integer
number
=
1
;
List
<
DataCheckDto
>
results
=
new
ArrayList
<>();
...
...
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