Commit 6579afa3 authored by neo.wang's avatar neo.wang

Merge branch 'dev_neo3' into 'dev'

Dev neo3

See merge request root/atms!95
parents 6a09ce9a ad11e28d
......@@ -33,6 +33,9 @@ public final class Constant {
public static final String IMAGE_PATH_SUCCESS = CURRENT_IMAGE_PATH + File.separator + "success.png";
public static final String IMAGE_PATH_WARN = CURRENT_IMAGE_PATH + File.separator + "warning1.png";
public static final String FILE_NAME = "filename";
public static final String TEMP_FILE_NAME = "tempFileName";
public static final boolean DEFAULT_RESULT = true;
......
......@@ -20,6 +20,6 @@ public class FileUploadController {
@RequestMapping(value = "NewFile", method = RequestMethod.POST, produces = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity getInputInvoiceTreeViewData(MultipartHttpServletRequest request) {
return fileUploadAdapter.upload(request, EnumModule.TrailBalance, USER_ID_FOR_UPLOAD);
return fileUploadAdapter.upload(request);
}
}
......@@ -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;
......@@ -33,6 +33,8 @@ import java.util.UUID;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static pwc.taxtech.atms.constant.Constant.FILE_NAME;
import static pwc.taxtech.atms.constant.Constant.TEMP_FILE_NAME;
@RestController
@RequestMapping(value = "api/v1/outputInvoiceImport")
......@@ -116,10 +118,13 @@ 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 period, MultipartHttpServletRequest request) {
String userID = identityService.getIdentityUser().getID();
String fullPath = fileUploadAdapter.uploadEvidence(this, EnumModule.Evidence, UUID.randomUUID().toString());
if (!StringUtil.isNotEmpty(fullPath)) {
String fullPath = fileUploadAdapter.uploadEvidence(request, EnumModule.Evidence, userID);
if (StringUtil.isNotEmpty(fullPath)) {
String fileName = request.getParameter(FILE_NAME);
String tempFileName = request.getParameter(TEMP_FILE_NAME);
ImportFile fileDto = new ImportFile();
fileDto.setFileID(tempFileName.substring(1, tempFileName.length() - 5));
fileDto.setFilePath(fullPath);
......@@ -140,14 +145,12 @@ 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));
}
private String GetExtension(String file) {
return file.substring(file.lastIndexOf(".") + 1, file.length()
- file.lastIndexOf("."));
return file.substring(file.lastIndexOf(".") + 1, file.length());
}
}
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,8 @@ 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;
import static pwc.taxtech.atms.constant.Constant.FILE_NAME;
import static pwc.taxtech.atms.constant.Constant.TEMP_FILE_NAME;
@Service
public class FileUploadAdapter {
......@@ -32,8 +30,10 @@ public class FileUploadAdapter {
@Value("${max_file_length}")
private String maxFileSize;
static final String FILE_NAME = "filename";
public static final String TEMP_FILE_NAME = "tempFileName";
private String _baseFolder;
public static FileParamBean CacheFileBean;
public static final String CHUNK_NUMBER = "_chunkNumber";
public static final String CHUNK_SIZE = "_chunkSize";
public static final String TOTAL_SIZE = "_totalSize";
......@@ -51,12 +51,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);
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 +77,7 @@ public class FileUploadAdapter {
boolean isFirsChunk;
}
public ResponseEntity upload(MultipartHttpServletRequest request, EnumModule trailBalance, UUID userIdForUpload) {
public synchronized ResponseEntity upload(MultipartHttpServletRequest request) {
if (request.getFileMap().size() <= 0) return ResponseEntity.badRequest().body("NoFile");
FileParamBean paramBean = getQueryStringParameters(request);
if (!paramBean.result) return ResponseEntity.badRequest().body("ParametersInvalid");
......@@ -111,6 +120,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 +163,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