Commit c7187f34 authored by neo's avatar neo

[dev] ouput vourcher item file upalod impl

parent 4e43b5d6
......@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import pwc.taxtech.atms.constant.enums.EnumModule;
import pwc.taxtech.atms.dto.PagingResultDto;
import pwc.taxtech.atms.dto.vatdto.ImportOutputInvoiceDto;
......@@ -116,9 +116,9 @@ public class OutputInvoiceController {
}
@RequestMapping(value = "UploadEvidenceFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity UploadEvidenceFile(String fileName, String tempFileName, String period) {
public ResponseEntity UploadEvidenceFile(String fileName, String tempFileName, String period, MultipartHttpServletRequest request) {
String userID = identityService.getIdentityUser().getID();
String fullPath = fileUploadAdapter.uploadEvidence(this, EnumModule.Evidence, UUID.randomUUID().toString());
String fullPath = fileUploadAdapter.uploadEvidence(request, EnumModule.Evidence, userID);
if (!StringUtil.isNotEmpty(fullPath)) {
ImportFile fileDto = new ImportFile();
fileDto.setFileID(tempFileName.substring(1, tempFileName.length() - 5));
......@@ -140,8 +140,7 @@ public class OutputInvoiceController {
}
@RequestMapping(value = "queryOutputInvoiceItemList/{invoiceID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity QueryOutputInvoiceItemList(@PathVariable String invoiceID)
{
public ResponseEntity QueryOutputInvoiceItemList(@PathVariable String invoiceID) {
return ResponseEntity.ok(outputInvoiceService.QueryOutputInvoiceItemList(invoiceID));
}
......
package pwc.taxtech.atms.vat.service.impl;
import org.apache.xmlbeans.impl.store.Path;
import org.reflections.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import pwc.taxtech.atms.constant.enums.EnumModule;
import pwc.taxtech.atms.controller.OutputInvoiceController;
import java.io.File;
import java.io.FileNotFoundException;
......@@ -23,7 +20,6 @@ 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
public class FileUploadAdapter {
......@@ -33,6 +29,8 @@ public class FileUploadAdapter {
private String maxFileSize;
static final String FILE_NAME = "filename";
private String _baseFolder;
public static FileParamBean CacheFileBean;
public static final String TEMP_FILE_NAME = "tempFileName";
public static final String CHUNK_NUMBER = "_chunkNumber";
public static final String CHUNK_SIZE = "_chunkSize";
......@@ -51,12 +49,21 @@ public class FileUploadAdapter {
return null;
}
public String uploadEvidence(OutputInvoiceController outputInvoiceController, EnumModule evidence, String s) {
return null;
public synchronized String uploadEvidence(MultipartHttpServletRequest request, EnumModule evidence, String userId) {
try {
upload(request, evidence, UUID.fromString(userId));
String uploadFile = combine(_baseFolder, CacheFileBean.tempFileName);
if (CacheFileBean.isLastChunk) {
return uploadFile;
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
static class FileParamBean {
String fileName;
String tempFileName;
long chunkNumber;
......@@ -68,7 +75,7 @@ public class FileUploadAdapter {
boolean isFirsChunk;
}
public ResponseEntity upload(MultipartHttpServletRequest request, EnumModule trailBalance, UUID userIdForUpload) {
public synchronized ResponseEntity upload(MultipartHttpServletRequest request, EnumModule trailBalance, UUID userIdForUpload) {
if (request.getFileMap().size() <= 0) return ResponseEntity.badRequest().body("NoFile");
FileParamBean paramBean = getQueryStringParameters(request);
if (!paramBean.result) return ResponseEntity.badRequest().body("ParametersInvalid");
......@@ -111,6 +118,7 @@ public class FileUploadAdapter {
File tempFile = new File(tempPath);
tempFile.renameTo(completeFile);
CacheFileBean = paramBean;
LOGGER.info("{} upload to temp folder sucess", paramBean.fileName);
}
} else {
......@@ -153,6 +161,7 @@ public class FileUploadAdapter {
if (!file.exists()) file.mkdirs();
}
_baseFolder = uploadFolder;
return uploadFolder;
}
......
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