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 { ...@@ -281,7 +281,7 @@ public class ScenarioServiceImpl implements ScenarioService {
Cell cell = row.getCell(i); Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(fileHeaderList.get(i).split("#")[0])) { if (!cell.getStringCellValue().equals(fileHeaderList.get(i).split("#")[0])) {
result.put("file", file); result.put("file", file);
result.put("message", BundleUtils.getLangString("common.invalidTemplate", locale)); result.put("code", Constants.FILE_UPLOAD_RESP_CODE.INVALID_FORMAT);
return result; return result;
} }
} }
...@@ -289,7 +289,7 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -289,7 +289,7 @@ public class ScenarioServiceImpl implements ScenarioService {
//kt file du lieu rong //kt file du lieu rong
if (sheet.getPhysicalNumberOfRows() == 2) { 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); result.put("file", file);
return result; return result;
} else { } else {
...@@ -385,7 +385,7 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -385,7 +385,7 @@ public class ScenarioServiceImpl implements ScenarioService {
isValid = false; isValid = false;
} else { } else {
// isValid = true; // isValid = true;
resultCell.setCellValue("Ok"); resultCell.setCellValue(BundleUtils.getLangString("ok"));
} }
sb = new StringBuilder(); sb = new StringBuilder();
} }
...@@ -395,23 +395,22 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -395,23 +395,22 @@ public class ScenarioServiceImpl implements ScenarioService {
if (isValid) { if (isValid) {
List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId); List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId);
lstQuestion.forEach(question -> { lstQuestion.forEach(question -> {
questionService.add(question); // questionService.add(question);
}); });
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos); workbook.write(fos);
result.put("file", file); result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importSuccess", locale)); result.put("code", Constants.FILE_UPLOAD_RESP_CODE.SUCCESS);
} else { } else {
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos); workbook.write(fos);
result.put("file", file); result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importFailed", locale)); result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
} }
} catch (Exception ex) { } catch (Exception ex) {
logger.info(ex.getMessage(), 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; return result;
} }
......
...@@ -47,4 +47,11 @@ public class Constants { ...@@ -47,4 +47,11 @@ public class Constants {
public interface MIME_TYPE { public interface MIME_TYPE {
String EXCEL_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; 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 { ...@@ -120,14 +120,10 @@ public class ScenarioController {
String path = saveUploadFile(file); String path = saveUploadFile(file);
Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId()); Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId());
File fileExport = (File) map.get("file"); File fileExport = (File) map.get("file");
String message = (String) map.get("message"); String code = (String) map.get("code");
ResultDTO resultDTO= new ResultDTO();
resultDTO.setErrorCode("00");
resultDTO.setDescription(message);
resultDTO.setData(fileExport);
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX); headers.add("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX);
headers.add("Message", message); headers.add("Message", code);
return ResponseEntity.ok() return ResponseEntity.ok()
.headers(headers) .headers(headers)
.body(Files.readAllBytes(fileExport.toPath())); .body(Files.readAllBytes(fileExport.toPath()));
......
server: server:
port: 1111 port: 9999
spring: spring:
application: application:
name: campaign name: campaign
......
...@@ -134,3 +134,5 @@ scenario.required.required="Require is required" ...@@ -134,3 +134,5 @@ scenario.required.required="Require is required"
scenario.default.required="Default is required" scenario.default.required="Default is required"
scenario.mappingQuestion.invalid="Mapping question invalid" 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" ...@@ -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.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ệ" 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