Commit 1119f37d authored by neo's avatar neo

[dev] FinanceDataUpload impl

parent a4498e97
...@@ -257,9 +257,8 @@ public class CustomsInvoiceController { ...@@ -257,9 +257,8 @@ public class CustomsInvoiceController {
} }
@RequestMapping(value = "ImportCustomsInvoice", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @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(); 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));
} }
} }
...@@ -6,16 +6,38 @@ import org.springframework.http.MediaType; ...@@ -6,16 +6,38 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; 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.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.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 @RestController
@RequestMapping("/api/v1/financeImportData") @RequestMapping("/api/v1/financeImportData")
public class FinanceDataImportController { 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 @Autowired
private FinanceDataImportService financeDataImport; private FinanceDataImportServiceImpl financeDataImport;
@Autowired @Autowired
private IdentityService identityService; private IdentityService identityService;
...@@ -25,68 +47,61 @@ public class FinanceDataImportController { ...@@ -25,68 +47,61 @@ public class FinanceDataImportController {
return ResponseEntity.ok().body(financeDataImport.getBasicValidationResults(identityService.getIdentityUser().getID())); return ResponseEntity.ok().body(financeDataImport.getBasicValidationResults(identityService.getIdentityUser().getID()));
} }
@RequestMapping(value = "importData/financeDataUpload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @RequestMapping(value = "importData/financeDataUpload", method = RequestMethod.POST, produces = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity FinanceDataUpload() { public ResponseEntity FinanceDataUpload(@RequestParam String importMethod, MultipartHttpServletRequest request) {
// string importMethod = HttpContext.Current.Request.Params["importMethod"]; if (request.getFileMap().size() == 0) {
// if (HttpContext.Current.Request.Files.Count == 0) return ResponseEntity.ok(new OperationResultDto(false, "NoFile"));
// { }
// return this.Ok(new OperationResultDto() { Result = false, ResultMsg = "NoFile" });
// } if (StringUtils.isEmpty(importMethod)) {
// return ResponseEntity.ok(new OperationResultDto(false, "importMethod is empty"));
// if (string.IsNullOrEmpty(importMethod)) }
// {
// return this.Ok(new OperationResultDto() { Result = false, ResultMsg = "importMethod is empty" }); if (!IsSameFileExtenstion(request.getFileMap())) {
// } return ResponseEntity.ok(new OperationResultDto(false, "file extension is not same"));
// }
// if (!IsSameFileExtenstion(HttpContext.Current.Request.Files))
// { try {
// return this.Ok(new OperationResultDto() { Result = false, ResultMsg = "file extension is not same" }); OperationResultDto<ImportDataDto> result = new OperationResultDto<>();
// } int uploadFileCount = 0;
// String mappedPath = "";
// try String fileGuid = UUID.randomUUID().toString().toUpperCase();
// { String fileExtension = getExtension(request.getFileMap());
// OperationResultDto<ImportDataDto> result = new OperationResultDto<ImportDataDto>();
// int uploadFileCount = 0;
// string mappedPath = ""; for (MultipartFile file : request.getFileMap().values()) {
// string fileGuid = Guid.NewGuid().ToString().ToUpper(); mappedPath = SetUploadFolderPath(importMethod, fileExtension);
// var firstUploadFile = HttpContext.Current.Request.Files[0]; String fileFullPath = Paths.get(mappedPath, fileGuid + "_" + file.getName()).toString();
// string fileExtension = firstUploadFile.FileName.Substring(firstUploadFile.FileName.LastIndexOf(".") + 1, firstUploadFile.FileName.Length - firstUploadFile.FileName.LastIndexOf(".") - 1); if (SaveFile(file, mappedPath, fileFullPath)) {
// uploadFileCount++;
// for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++) }
// { }
// var file = HttpContext.Current.Request.Files[i];
// mappedPath = SetUploadFolderPath(importMethod, fileExtension); if (uploadFileCount == request.getFileMap().size()) {
// var fileFullPath = Path.Combine(mappedPath, fileGuid + "_" + Path.GetFileName(file.FileName)); result.setResult(true);
// if (SaveFile(file, mappedPath, fileFullPath)) result.setResultMsg("");
// { ImportDataDto dataDto = new ImportDataDto();
// uploadFileCount++; dataDto.Guid = fileGuid;
// } dataDto.Number = uploadFileCount;
// } dataDto.FileExtension = fileExtension;
// result.setData(dataDto);
// if (uploadFileCount == HttpContext.Current.Request.Files.Count)
// { }
// result.Result = true; return ResponseEntity.ok(result);
// result.ResultMsg = string.Empty; } catch (Exception ex) {
// result.Data = new ImportDataDto { Guid = fileGuid, Number = uploadFileCount, FileExtension = fileExtension }; Map<String, String> error = new HashMap<>();
// ex.printStackTrace();
// } error.put(UUID.randomUUID().toString(), ex.getMessage());
// return Ok(result); OperationResultDto<ImportDataDto> errorResult = new OperationResultDto<ImportDataDto>(false, "Upload File error");
// } errorResult.setErrors(error);
// catch (Exception ex) ImportDataDto dataDto = new ImportDataDto();
// { dataDto.Guid = "";
// Dictionary<Guid, string> error = new Dictionary<Guid, string>(); dataDto.Number = 0;
// error.Add(System.Guid.NewGuid(), ex.StackTrace); dataDto.FileExtension = "";
// OperationResultDto<ImportDataDto> errorResult = new OperationResultDto<ImportDataDto>() errorResult.setData(dataDto);
// {
// Result = false, return ResponseEntity.ok(errorResult);
// ResultMsg = "Upload File error", }
// Errors = error,
// Data = new ImportDataDto { Guid = string.Empty, Number = 0, FileExtension = string.Empty }
// };
//
// return Ok(errorResult);
// }
return ResponseEntity.ok().build();
} }
...@@ -204,4 +219,74 @@ public class FinanceDataImportController { ...@@ -204,4 +219,74 @@ public class FinanceDataImportController {
return ResponseEntity.ok().build(); 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();
}
}
} }
package pwc.taxtech.atms.dto.vatdto; package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.vat.entity.CustomsInvoice;
import java.util.List; import java.util.List;
public class ImportCustomsInvoiceDto { public class ImportCustomsInvoiceDto {
public List<CustomsInvoiceDto> CustomsList; public List<CustomsInvoice> CustomsList;
public int ImportType; public int ImportType;
} }
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 ;
}
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);
}
...@@ -124,6 +124,7 @@ public class FileUploadAdapter { ...@@ -124,6 +124,7 @@ public class FileUploadAdapter {
} }
private FileParamBean getQueryStringParameters(MultipartHttpServletRequest request) { private FileParamBean getQueryStringParameters(MultipartHttpServletRequest request) {
FileParamBean param = new FileParamBean(); FileParamBean param = new FileParamBean();
param.fileName = request.getParameter(FILE_NAME); param.fileName = request.getParameter(FILE_NAME);
......
...@@ -18,7 +18,6 @@ import pwc.taxtech.atms.vat.entity.ValidationInfo; ...@@ -18,7 +18,6 @@ import pwc.taxtech.atms.vat.entity.ValidationInfo;
import pwc.taxtech.atms.vat.entity.ValidationInfoExample; import pwc.taxtech.atms.vat.entity.ValidationInfoExample;
import pwc.taxtech.atms.vat.entity.Voucher; import pwc.taxtech.atms.vat.entity.Voucher;
import pwc.taxtech.atms.vat.entity.VoucherExample; import pwc.taxtech.atms.vat.entity.VoucherExample;
import pwc.taxtech.atms.vat.service.FinanceDataImportService;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
...@@ -41,13 +40,12 @@ import static pwc.taxtech.atms.constant.enums.EnumValidationType.ErpBasicCheck; ...@@ -41,13 +40,12 @@ import static pwc.taxtech.atms.constant.enums.EnumValidationType.ErpBasicCheck;
import static pwc.taxtech.atms.constant.enums.ImageType.Alert; import static pwc.taxtech.atms.constant.enums.ImageType.Alert;
@Service @Service
public class FinanceDataImportServiceImpl implements FinanceDataImportService { public class FinanceDataImportServiceImpl {
@Autowired @Autowired
private ValidationInfoMapper validationInfoMapper; private ValidationInfoMapper validationInfoMapper;
@Autowired @Autowired
private VoucherMapper voucherMapper; private VoucherMapper voucherMapper;
@Override
public OperationResultDto<List<DataCheckDto>> getBasicValidationResults(String userId) { public OperationResultDto<List<DataCheckDto>> getBasicValidationResults(String userId) {
Integer number = 1; Integer number = 1;
List<DataCheckDto> results = new ArrayList<>(); List<DataCheckDto> results = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment