Commit 9c6f75c5 authored by frank.xa.zhang's avatar frank.xa.zhang

batch upload for template download -- frank

parent 369d172a
package pwc.taxtech.atms.controller;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.message.ErrorMessage;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.service.impl.DataImportService;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/api/v1/DataImport/")
public class DataImportController extends BaseController {
@Resource
private DataImportService dataImportService;
@ResponseBody
@RequestMapping(value = "RLITExcelFile", method = RequestMethod.POST)
public OperationResultDto importRLITExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
try {
List<String> orgList = (List<String>)JSONArray.parse(orgIds);
String valMsg = valParameter(file,orgList,periodDate);
if(StringUtils.isNotEmpty(valMsg)){
return OperationResultDto.error(valMsg);
}
return dataImportService.importRLITExcelFile(file,orgList, periodDate,importType);
} catch (ServiceException e) {
return OperationResultDto.error(e.getMessage());
} catch (Exception e) {
logger.error("importRLITExcelFile error.", e);
return OperationResultDto.error(ErrorMessage.SystemError);
}
}
private String valParameter(MultipartFile file,List<String> orgList,String periodDate){
if (null == file) {
return ErrorMessage.NoFile;
}
if(orgList.size()<1){
return ErrorMessage.DidntSelectedCompany;
}
if(StringUtils.isEmpty(periodDate)){
return ErrorMessage.DidntSelectedPeriod;
}
return null;
}
}
package pwc.taxtech.atms.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.atms.common.message.ErrorMessage;
import pwc.taxtech.atms.exception.ServiceException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
@RestController
@RequestMapping(value = "api/v1/template/")
public class TemplateController extends BaseController {
@RequestMapping(value = "file/downloadTemplate", method = RequestMethod.GET)
public void fileDownload(HttpServletResponse response) {
//获取网站部署路径(通过ServletContext对象),用于确定下载文件位置,从而实现下载
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName=org_import_template.xlsx");
ServletOutputStream out;
try {
InputStream inputStream = this.getClass().getResourceAsStream("/document/DataImport/org_import_template.xlsx");
out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[512];
while ((b = inputStream.read(buffer)) > 0) {
out.write(buffer, 0, b);
}
inputStream.close();
out.close();
out.flush();
} catch (Exception e) {
e.printStackTrace();
logger.error(String.format("下载批量导入模板异常:%s", e.getMessage()));
throw new ServiceException(ErrorMessage.SystemError);
}
}
// @ResponseBody
// @RequestMapping(value = "upload", method = RequestMethod.POST)
// public OperationResultDto upload(@RequestParam MultipartFile file, @RequestParam String
// projectId, @RequestParam Integer period) {
// try {
// ReportUpload data = new ReportUpload();
// data.setProjectId(projectId);
// data.setPeriod(period);
// reportUploadService.saveData(file, data);
// return OperationResultDto.success();
// } catch (ServiceException e) {
// return OperationResultDto.error(e.getMessage());
// } catch (Exception e) {
// logger.error("importRLITExcelFile error.", e);
// return OperationResultDto.error(ErrorMessage.SystemError);
// }
// }
}
package pwc.taxtech.atms.service.impl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.exception.ServiceException;
import java.util.List;
@Service
public class DataImportService extends BaseService {
public OperationResultDto importRLITExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
// OperationResultDto operationResultDto = new OperationResultDto();
// InputStream inputStream = file.getInputStream();
// Workbook workbook = WorkbookFactory.create(inputStream);
// FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
// throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
// }
// Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
// List<DataImportLog> dataImportLogs = Lists.newArrayList();
// for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
// Sheet sheet = workbook.getSheetAt(i);
// if (isSheetEmpty(sheet)) continue;
// List<RedLetterInfoTable> rlits = generalRLITs(sheet, tmsPeriod, evaluator);
// if (rlits.size() < 1) continue;
// // 根据主体分组处理
// Map<String, List<RedLetterInfoTable>> atsGroupRes =
// rlits.stream().collect(Collectors.groupingBy(RedLetterInfoTable::getSubjectNum));
// atsGroupRes.forEach((k, v) -> processRlits(k, v, orgIds, tmsPeriod, importType, dataImportLogs));
// }
// if (dataImportLogs.size() == 0)
// return OperationResultDto.error(ErrorMessage.NoData);
//
// addDataImportLog(dataImportLogs);
// int isSuccess = (int) dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
// if (isSuccess < 1) {
// return OperationResultDto.error(ErrorMessage.ImportNotMatch);
// }
return operationResultDto.success();
} catch (Exception e) {
e.printStackTrace();
return OperationResultDto.error(e.getMessage());
}
}
}
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