엑셀 업로드 오류 분기처리
This commit is contained in:
@@ -21,6 +21,14 @@ class ExcelSaveAdminController {
|
|||||||
|
|
||||||
@PostMapping("/api/settings/admin/excelUpload")
|
@PostMapping("/api/settings/admin/excelUpload")
|
||||||
ResponseEntity<?> excelUploadSaveAdmin(@RequestParam("file") MultipartFile file ) throws IOException {
|
ResponseEntity<?> excelUploadSaveAdmin(@RequestParam("file") MultipartFile file ) throws IOException {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(excelSaveAdminPortIn.operate(file));
|
try {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(excelSaveAdminPortIn.operate(file));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("엑셀 파일 처리 중 오류가 발생했습니다: " + e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||||
|
.body("잘못된 데이터 형식입니다: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,16 +188,16 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|||||||
private String getUiCode(Cell cell,List<UICodeElement> uiCodeElementList,String codeId){
|
private String getUiCode(Cell cell,List<UICodeElement> uiCodeElementList,String codeId){
|
||||||
if (cell == null) return "";
|
if (cell == null) return "";
|
||||||
try {
|
try {
|
||||||
String cellValue = cell.getStringCellValue().trim();
|
String cellValue = cell.getStringCellValue().trim();
|
||||||
String[] cellValueParts = cellValue.split("\\.");
|
String[] cellValueParts = cellValue.split("\\.");
|
||||||
|
|
||||||
return uiCodeElementList.stream().filter(code -> {
|
return uiCodeElementList.stream().filter(code -> {
|
||||||
if(cellValueParts.length == 1 ) return code.getCodeText().equals(codeId+"."+cellValueParts[0]) || code.getCodeText().equals(cellValueParts[0]) ;
|
if(cellValueParts.length == 1 ) return code.getCodeText().equals(codeId+"."+cellValueParts[0]) || code.getCodeText().equals(cellValueParts[0]) ;
|
||||||
if(cellValueParts.length == 2 ) return code.getId().equals(codeId+"."+cellValueParts[0]) || code.getCodeText().equals(cellValueParts[1]) ;
|
if(cellValueParts.length == 2 ) return code.getId().equals(codeId+"."+cellValueParts[0]) || code.getCodeText().equals(cellValueParts[1]) ;
|
||||||
return Boolean.parseBoolean(null);
|
return Boolean.parseBoolean(null);
|
||||||
} )
|
} )
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(UICodeElement::getId).orElse("");
|
.map(UICodeElement::getId).orElse("");
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|||||||
|
|
||||||
ExcelUploadContactVO contactVO = new ExcelUploadContactVO();
|
ExcelUploadContactVO contactVO = new ExcelUploadContactVO();
|
||||||
|
|
||||||
if(contact[2].length() == 4) {
|
if(contact.length == 3 && contact[2].length() == 4) {
|
||||||
if (contact[0].equals("010") || contact[0].equals("011")) {
|
if (contact[0].equals("010") || contact[0].equals("011")) {
|
||||||
contactVO.setPhone(getCellValue(cell));
|
contactVO.setPhone(getCellValue(cell));
|
||||||
contactVO.setPhoneLast(contact[2]);
|
contactVO.setPhoneLast(contact[2]);
|
||||||
|
|||||||
@@ -19,7 +19,14 @@ class ExcelUploadCreateHouseholdController {
|
|||||||
|
|
||||||
@PostMapping(path = "/api/household/excelUpload")
|
@PostMapping(path = "/api/household/excelUpload")
|
||||||
ResponseEntity<?> operate(@RequestParam("file") MultipartFile file ) throws IOException {
|
ResponseEntity<?> operate(@RequestParam("file") MultipartFile file ) throws IOException {
|
||||||
|
try {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(excelUploadCreateHouseholdPortIn.operate(file));
|
return ResponseEntity.status(HttpStatus.OK).body(excelUploadCreateHouseholdPortIn.operate(file));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("엑셀 파일 처리 중 오류가 발생했습니다: " + e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||||
|
.body("잘못된 데이터 형식입니다: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,11 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
function showAdminExcelUploadModal() {
|
function showAdminExcelUploadModal() {
|
||||||
const modal = document.querySelector(".modal02");
|
const modal = document.querySelector(".modal-admin-excel");
|
||||||
|
const fileInput = document.getElementById("file");
|
||||||
|
if (fileInput) {
|
||||||
|
fileInput.value = '';
|
||||||
|
}
|
||||||
modal.ui.open();
|
modal.ui.open();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -248,17 +252,22 @@
|
|||||||
alert("총 "+res.total+"건 중에 "+res.success+"건 등록되었습니다.");
|
alert("총 "+res.total+"건 중에 "+res.success+"건 등록되었습니다.");
|
||||||
},
|
},
|
||||||
statusCode: {
|
statusCode: {
|
||||||
422: (res) => {
|
400:() => {
|
||||||
const resJson = res.responseJSON;
|
ajaxUtil._hideWaiting();
|
||||||
$(input).parent().find('.invalid-feedback').text(resJson.message);
|
alert("잘못된 엑셀파일입니다.");
|
||||||
$(input).addClass('is-invalid');
|
document.querySelector(".modal-admin-excel").ui.close();
|
||||||
|
},
|
||||||
|
500: () => {
|
||||||
|
ajaxUtil._hideWaiting();
|
||||||
|
alert("엑셀 업로드에 실패하였습니다.");
|
||||||
|
document.querySelector(".modal-admin-excel").ui.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
document.querySelector(".modal02").ui.close();
|
document.querySelector(".modal-admin-excel").ui.close();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
layout:decorate="~{layout/layout}">
|
layout:decorate="~{layout/layout}">
|
||||||
|
|
||||||
<div class="layer-wrap" th:fragment="modalFragment">
|
<div class="layer-wrap" th:fragment="modalFragment">
|
||||||
<div class="component-modal modal02" id="test" data-props-dimm-click="true" data-state="close">
|
<div class="component-modal modal01 modal-admin-excel" id="test" data-props-dimm-click="true" data-state="close">
|
||||||
<div class="modal-dimm"></div>
|
<div class="modal-dimm"></div>
|
||||||
<div class="modal-frame">
|
<div class="modal-frame">
|
||||||
<div class="modal-container type-small">
|
<div class="modal-container type-small">
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
// 임가방문정보 모달창 띄우기
|
// 임가방문정보 모달창 띄우기
|
||||||
const showExcelHouseholdModal = () => {
|
const showExcelHouseholdModal = () => {
|
||||||
document.querySelector(".modal-excel-household").ui.open();
|
document.querySelector(".modal-excel-household").ui.open();
|
||||||
|
const fileInput = document.getElementById("householdFile");
|
||||||
|
if (fileInput) {
|
||||||
|
fileInput.value = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 임가방문정보 등록
|
// 임가방문정보 등록
|
||||||
@@ -72,15 +76,19 @@
|
|||||||
},
|
},
|
||||||
success(res) {
|
success(res) {
|
||||||
ajaxUtil._hideWaiting(); // 로딩바 hide
|
ajaxUtil._hideWaiting(); // 로딩바 hide
|
||||||
|
|
||||||
alert("총 "+res.total+"건 중에 "+res.success+"건 등록되었습니다.");
|
alert("총 "+res.total+"건 중에 "+res.success+"건 등록되었습니다.");
|
||||||
document.querySelector(".modal-excel-household").ui.close();
|
document.querySelector(".modal-excel-household").ui.close();
|
||||||
},
|
},
|
||||||
statusCode: {
|
statusCode: {
|
||||||
422: (res) => {
|
400: () => {
|
||||||
const resJson = res.responseJSON;
|
ajaxUtil._hideWaiting();
|
||||||
$(input).parent().find('.invalid-feedback').text(resJson.message);
|
alert("잘못된 엑셀파일입니다.");
|
||||||
$(input).addClass('is-invalid');
|
document.querySelector(".modal-excel-household").ui.close();
|
||||||
|
},
|
||||||
|
500: () => {
|
||||||
|
ajaxUtil._hideWaiting();
|
||||||
|
alert("엑셀 업로드에 실패하였습니다.");
|
||||||
|
document.querySelector(".modal-excel-household").ui.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user