Commit 910b93b7 authored by Vu Duy Anh's avatar Vu Duy Anh

anhvd commit scenario import services

parent eccfdb95
......@@ -281,7 +281,7 @@ public class ScenarioServiceImpl implements ScenarioService {
Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(fileHeaderList.get(i).split("#")[0])) {
result.put("file", file);
result.put("message", BundleUtils.getLangString("common.invalidTemplate", locale));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.INVALID_FORMAT);
return result;
}
}
......@@ -289,7 +289,7 @@ public class ScenarioServiceImpl implements ScenarioService {
//kt file du lieu rong
if (sheet.getPhysicalNumberOfRows() == 2) {
result.put("message", BundleUtils.getLangString("customer.noData", locale));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.EMPTY);
result.put("file", file);
return result;
} else {
......@@ -385,7 +385,7 @@ public class ScenarioServiceImpl implements ScenarioService {
isValid = false;
} else {
// isValid = true;
resultCell.setCellValue("Ok");
resultCell.setCellValue(BundleUtils.getLangString("ok"));
}
sb = new StringBuilder();
}
......@@ -395,23 +395,22 @@ public class ScenarioServiceImpl implements ScenarioService {
if (isValid) {
List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId);
lstQuestion.forEach(question -> {
questionService.add(question);
// questionService.add(question);
});
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importSuccess", locale));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.SUCCESS);
} else {
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importFailed", locale));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
}
} catch (Exception ex) {
logger.info(ex.getMessage(), ex);
result.put("message", BundleUtils.getLangString("customer.errorValidate", locale));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
}
logger.info("Import Questions result:", result);
return result;
}
......
......@@ -47,4 +47,11 @@ public class Constants {
public interface MIME_TYPE {
String EXCEL_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
public interface FILE_UPLOAD_RESP_CODE {
String SUCCESS = "00";
String ERROR = "01";
String INVALID_FORMAT = "02";
String EMPTY = "03";
}
}
......@@ -120,14 +120,10 @@ public class ScenarioController {
String path = saveUploadFile(file);
Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId());
File fileExport = (File) map.get("file");
String message = (String) map.get("message");
ResultDTO resultDTO= new ResultDTO();
resultDTO.setErrorCode("00");
resultDTO.setDescription(message);
resultDTO.setData(fileExport);
String code = (String) map.get("code");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX);
headers.add("Message", message);
headers.add("Message", code);
return ResponseEntity.ok()
.headers(headers)
.body(Files.readAllBytes(fileExport.toPath()));
......
server:
port: 1111
port: 9999
spring:
application:
name: campaign
......
......@@ -134,3 +134,5 @@ scenario.required.required="Require is required"
scenario.default.required="Default is required"
scenario.mappingQuestion.invalid="Mapping question invalid"
ok="Imported"
error="Error"
......@@ -136,6 +136,9 @@ scenario.required.required="Trường Bắt buộc bắt buộc nhập"
scenario.default.required="Trường Mặc định bắt buộc nhập"
scenario.mappingQuestion.invalid="Câu hỏi liên kết không hợp lệ"
ok="Thành công"
error="Thất bại"
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