From b548d49284bc36f5016cba913bb6ac55d8a5e340 Mon Sep 17 00:00:00 2001 From: 이민희 <mhlee@maprex.co.kr> Date: 금, 28 1월 2022 17:40:12 +0900 Subject: [PATCH] 엑셀 임포트 시 코드 수정 --- src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java | 243 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 171 insertions(+), 72 deletions(-) diff --git a/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java index dcb513d..56499a8 100644 --- a/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java +++ b/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java @@ -81,8 +81,13 @@ // �뾽泥� 異붽� @Override public CompanyField addCompany(CompanyFieldForm companyFieldForm) { - // url �쑀�슚�꽦 泥댄겕 - this.verifyUrl(companyFieldForm.getUrl(), null); + // �뾽泥대챸 以묐났 泥댄겕 + this.verifyTitle(companyFieldForm.getName(), null); + + if (companyFieldForm.getUrl() != null) { + // url �쑀�슚�꽦 泥댄겕 + this.verifyUrl(companyFieldForm.getUrl(), null); + } if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { String tels = companyFieldForm.getTelList().toString(); @@ -107,12 +112,11 @@ // url �쑀�슚�꽦 泥댄겕 private void verifyUrl(String url, Long id) { - if (StringUtils.isEmpty(url)) { + /*if (StringUtils.isEmpty(url)) { throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_NOT_URL)); - } + this.messageAccessor.getMessage(MsgConstants.COMPANY_NOT_URL)); + }*/ CompanyField companyField; - if(id == null){ companyField = this.companyFieldRepository.findByUrl(url); } else { @@ -121,7 +125,7 @@ if (companyField != null) { throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_USED_URL)); + this.messageAccessor.getMessage(MsgConstants.COMPANY_USED_URL)); } } @@ -140,6 +144,47 @@ public List<Map<String, Object>> find(CompanyFieldCondition condition) { return this.companyFieldMapper.find(condition); + } + + // 紐⑤뱺 �뾽泥댁젙蹂대�� 議고쉶�븳�떎. �씠�뒋 �뿊�� import �뿉�꽌 �궗�슜 + @Override + @Transactional(readOnly = true) + public List<CompanyField> findAll() { + return this.companyFieldRepository.findAll(); + } + + /** + * companyFieldCategory Name �꽕�젙 + * @param companyFieldVo CompanyFieldVo + * @param companyField CompanyField + */ + @Override + public CompanyFieldVo CreateCompanyFieldCategory(CompanyFieldVo companyFieldVo, CompanyField companyField) { + if (companyField.getCompanyTypeId() != null && companyField.getCompanyTypeId() != -1) { + CompanyFieldCategory companyType = this.companyFieldCategoryService.find(companyField.getCompanyTypeId()); + if (companyType != null) { + companyFieldVo.setCompanyTypeName(companyType.getUseValue()); + } + } + if (companyField.getParentSectorId() != null && companyField.getParentSectorId() != -1) { + CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(companyField.getParentSectorId()); + if (parentSector != null) { + companyFieldVo.setParentSectorName(parentSector.getUseValue()); + } + } + if (companyField.getChildSectorId() != null && companyField.getChildSectorId() != -1) { + CompanyFieldCategory childSector = this.companyFieldCategoryService.find(companyField.getChildSectorId()); + if (childSector != null) { + companyFieldVo.setChildSectorName(childSector.getUseValue()); + } + } + if (companyField.getRegionId() != null && companyField.getRegionId() != -1) { + CompanyFieldCategory region = this.companyFieldCategoryService.find(companyField.getRegionId()); + if (region != null) { + companyFieldVo.setRegionName(region.getUseValue()); + } + } + return companyFieldVo; } // �뾽泥� �긽�꽭 議고쉶�븳�떎. @@ -166,36 +211,7 @@ ispFieldVo = ConvertUtil.copyProperties(ispField, IspFieldVo.class); hostingFieldVo = ConvertUtil.copyProperties(hostingField, HostingFieldVo.class); - if (companyField.getCompanyTypeId() != null && companyField.getCompanyTypeId() != -1) { - CompanyFieldCategory companyType = this.companyFieldCategoryService.find(companyField.getCompanyTypeId()); - if (companyType != null) { - companyFieldVo.setCompanyTypeName(companyType.getUseValue()); - } - } - if (companyField.getParentSectorId() != null && companyField.getParentSectorId() != -1) { - CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(companyField.getParentSectorId()); - if (parentSector != null) { - companyFieldVo.setParentSectorName(parentSector.getUseValue()); - } - } - if (companyField.getChildSectorId() != null && companyField.getChildSectorId() != -1) { - CompanyFieldCategory childSector = this.companyFieldCategoryService.find(companyField.getChildSectorId()); - if (childSector != null) { - companyFieldVo.setChildSectorName(childSector.getUseValue()); - } - } - if (companyField.getRegionId() != null && companyField.getRegionId() != -1) { - CompanyFieldCategory region = this.companyFieldCategoryService.find(companyField.getRegionId()); - if (region != null) { - companyFieldVo.setRegionName(region.getUseValue()); - } - } - /*if (companyField.getStatusId() != null && companyField.getStatusId() != -1) { - CompanyFieldCategory status = this.companyFieldCategoryService.find(companyField.getStatusId()); - if (status != null) { - companyFieldVo.setStatusName(status.getUseValue()); - } - }*/ + CreateCompanyFieldCategory(companyFieldVo, companyField); companyFieldVo.setIspFieldVo(ispFieldVo); companyFieldVo.setHostingFieldVo(hostingFieldVo); @@ -206,8 +222,13 @@ // �뾽泥� �젙濡쒕�� �닔�젙�븳�떎. @Override public void modifyCompany(CompanyFieldForm companyFieldForm) { - // url �쑀�슚�꽦 泥댄겕 - this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId()); + // �뾽泥대챸 �쑀�슚�꽦 泥댄겕 + this.verifyTitle(companyFieldForm.getName(), companyFieldForm.getId()); + + if (companyFieldForm.getUrl() != null) { + // url �쑀�슚�꽦 泥댄겕 + this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId()); + } if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { String tels = companyFieldForm.getTelList().toString(); @@ -222,6 +243,14 @@ emails = emails.substring(1, emails.indexOf("]")); } companyFieldForm.setEmail(emails.trim()); + } + + if (companyFieldForm.getChildSectorId() != null) { + CompanyFieldCategory companyFieldCategory = this.companyFieldCategoryService.find(companyFieldForm.getChildSectorId()); + if (companyFieldCategory != null && !companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) { + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.PARENT_SECTOR_NOT_EQUAL)); + } } CompanyField companyField = ConvertUtil.copyProperties(companyFieldForm, CompanyField.class); @@ -364,7 +393,7 @@ for (int rowIndex = 0; rowIndex < lastRowNum; rowIndex++) { // 0踰덉� �뿤�뜑�뒗 臾댁떆�븳�떎. Row row = sheet.getRow(rowIndex); - // �뿤�뜑 �젙蹂대�� 異붿텧�븳�떎 - �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� 媛��졇�삤湲� �쐞�빐 + // �뿤�뜑 �젙蹂대�� 異붿텧�븳�떎 if (rowIndex == 1) { for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) { Cell cell = row.getCell(cellIndex); @@ -408,6 +437,25 @@ } } + /** + * cell NULL 泥댄겕 �븿�닔 + * @param cell Cell + * @return boolean + */ + private Boolean cellNullCheck (Cell cell) { + if (cell != null && cell.getStringCellValue() != null) { + cell.setCellValue(cell.getStringCellValue().trim());//�� 媛� 怨듬갚 �젣嫄� + } + return cell != null && cell.getStringCellValue() != null && !cell.getStringCellValue().equals("") && cell.getCellType() != Cell.CELL_TYPE_BLANK; + } + + private void telTypeCheck (Cell cell, int rowIndex) { + if (cell.getCellType() != cell.CELL_TYPE_STRING) { + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_TEL_NOT_STRING_TYPE, rowIndex)); + } + } + // �뿊�� �븘�뱶�뿉 �엳�뒗 �젙蹂대�� �뾽泥� form �쑝濡� �삷湲대떎. private CompanyFieldForm setCompanyFieldFormToExcelField(Row row, int rowIndex, Map<String, IspField> ispFieldMaps, Map<String, HostingField> hostingFieldMaps, Map<String, Map<String, Object>> companyTypeMaps, Map<String, Map<String, Object>> parentSectorMaps, @@ -416,7 +464,6 @@ CompanyFieldForm companyFieldForm = new CompanyFieldForm(); companyFieldForm.setRegisterId(this.webAppUtil.getLoginId()); - // �젣紐�, �궡�슜, �봽濡쒖젥�듃 �궎, �씠�뒋 ���엯, �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦�옄, �떆�옉�씪, 醫낅즺�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 for (int cellIndex = 0; cellIndex < headers.size(); cellIndex++) { Cell cell = row.getCell(cellIndex); switch (cellIndex) { @@ -427,81 +474,85 @@ case 1: // url - this.setCompanyFormUrl(cell, companyFieldForm, rowIndex); + if (cellNullCheck(cell)) { + this.setCompanyFormUrl(cell, companyFieldForm, rowIndex); + } break; case 2: // isp紐� - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormIspName(cell, ispFieldMaps, companyFieldForm, rowIndex); } break; case 3: // �샇�뒪�똿紐� - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormHostingName(cell, hostingFieldMaps, companyFieldForm, rowIndex); } break; case 4: // �뿰�씫泥� - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { + this.telTypeCheck(cell, rowIndex); // �뀓�뒪�듃 �삎�떇 泥댄겕 this.setCompanyFormTel(cell, companyFieldForm, rowIndex); } break; case 5: // �씠硫붿씪 - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormEmail(cell, companyFieldForm, rowIndex); } break; case 6: // �떞�떦�옄 - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormManager(cell, companyFieldForm, rowIndex); } break; case 7: // 湲곗뾽援щ텇 - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormCompanyType(cell, companyTypeMaps, companyFieldForm, rowIndex); } break; case 8: // �뾽醫�(��遺꾨쪟) - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormParentSector(cell, parentSectorMaps, companyFieldForm, rowIndex); } break; case 9: // �뾽醫�(以묐텇瑜�) - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormChildSector(cell, childSectorMaps, companyFieldForm, rowIndex); } break; case 10: // 吏��뿭 - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormRegion(cell, regionMaps, companyFieldForm, rowIndex); } break; case 11: // �긽�깭 - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormStatus(cell, statusMaps, companyFieldForm, rowIndex); } + break; case 12: // 鍮꾧퀬 - if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + if (cellNullCheck(cell)) { this.setCompanyFormMemo(cell, companyFieldForm, rowIndex); } break; @@ -541,10 +592,19 @@ private void setCompanyFormChildSector(Cell cell, Map<String, Map<String, Object>> childSectorMaps, CompanyFieldForm companyFieldForm, int rowIndex) { if (cell != null) { Map<String, Object> childSectorMap = childSectorMaps.get(CommonUtil.convertExcelStringToCell(cell)); + + // ��遺꾨쪟 �뾾�씠 以묐텇瑜섎쭔 �엯�젰�뻽�쓣寃쎌슦 + if (companyFieldForm.getParentSectorId() == null) { + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PARENT_SECTOR_IS_NULL, rowIndex)); + } + + // 以묐텇瑜섍� ��遺꾨쪟�뿉 �냽�빐�엳吏� �븡�뒗 寃쎌슦 if (!companyFieldForm.getParentSectorId().equals(MapUtil.getLong(childSectorMap, "parentId"))) { throw new OwlRuntimeException( this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PARENT_SECTOR_NOT_EQUAL, rowIndex)); } + companyFieldForm.setChildSectorId(MapUtil.getLong(childSectorMap, "id")); } } @@ -579,19 +639,29 @@ private void setCompanyFormEmail(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { if (cell != null) { - companyFieldForm.setEmail(CommonUtil.convertExcelStringToCell(cell)); + String email = CommonUtil.convertExcelStringToCell(cell); + if (CommonUtil.convertExcelStringToCell(cell).contains(" ")) { + email = CommonUtil.convertExcelStringToCell(cell).replace(" ", ""); + } + companyFieldForm.setEmail(email); } } private void setCompanyFormTel(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { if (cell != null) { - companyFieldForm.setTel(CommonUtil.convertExcelStringToCell(cell)); + String tel = CommonUtil.convertExcelStringToCell(cell); + if (tel.contains("-")) { + tel = tel.replace("-", ""); + } + if (tel.contains(" ")) { + tel = tel.replace(" ", ""); + } + companyFieldForm.setTel(tel); } } private void setCompanyFormHostingName(Cell cell, Map<String, HostingField> hostingFieldMaps, CompanyFieldForm companyFieldForm, int rowIndex) { if (cell != null) { - HostingField hostingField = hostingFieldMaps.get(CommonUtil.convertExcelStringToCell(cell)); if (hostingField == null) { throw new OwlRuntimeException( @@ -603,7 +673,6 @@ private void setCompanyFormIspName(Cell cell, Map<String, IspField> ispFieldMaps, CompanyFieldForm companyFieldForm, int rowIndex) { if (cell != null) { - IspField ispField = ispFieldMaps.get(CommonUtil.convertExcelStringToCell(cell)); if (ispField == null) { throw new OwlRuntimeException( @@ -614,7 +683,7 @@ } private void setCompanyFormName(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { - if (cell == null) { + if (!cellNullCheck(cell)) { throw new OwlRuntimeException( this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_COMPANY_NAME_IS_NULL, rowIndex)); } @@ -622,31 +691,48 @@ String title = CommonUtil.convertExcelStringToCell(cell); // �뾽泥대챸 �쑀�슚�꽦 泥댄겕 - this.verifyTitle(title); + this.verifyTitle(title, null); companyFieldForm.setName(title); } private void setCompanyFormUrl(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { - if (cell == null) { - throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_URL_IS_NULL, rowIndex)); - } - String url = CommonUtil.convertExcelStringToCell(cell); - this.verifyUrl(url, null); //url �쑀�슚�꽦 寃��궗 + if (cell != null) { + String url = CommonUtil.convertExcelStringToCell(cell); + if (url.contains(" ")) { + url = url.replace(" ", ""); + } + this.verifyUrl(url, null); //url �쑀�슚�꽦 寃��궗 - companyFieldForm.setUrl(url); + companyFieldForm.setUrl(url); + } } // �뾽泥대챸 �쑀�슚�꽦 泥댄겕 - private void verifyTitle(String title) { - if (StringUtils.isEmpty(title)) { + private void verifyTitle(String title, Long id) { + List<CompanyField> companyFields = new ArrayList<>(); + + // �뾽泥대챸 以묐났 泥댄겕 + + if (id != null) { //�닔�젙 �씪 寃쎌슦 + companyFields = this.companyFieldRepository.findByNameAndIdNot(title, id); + } else { // 異붽� �씪 寃쎌슦 + companyFields = this.companyFieldRepository.findByName(title); + } + if (companyFields != null && companyFields.size() > 0) { throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.ISSUE_NO_TITLE)); + this.messageAccessor.getMessage(MsgConstants.COMPANY_NAME_ALREADY_IN_USE)); } + // �뾽泥대챸 鍮덇컪 泥댄겕 + if (StringUtils.isEmpty(title)) { + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.COMPANY_NO_TITLE)); + } + + // �뾽泥대챸 湲몄씠 泥댄겕 if (title.length() > 300) { throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.ISSUE_TITLE_MAX_LENGTH_OUT)); + this.messageAccessor.getMessage(MsgConstants.COMPANY_NAME_MAX_LENGTH_OUT)); } } @@ -667,6 +753,19 @@ CompanyFieldCondition companyFieldCondition = CompanyFieldCondition.make(conditions); List<Map<String, Object>> results = this.companyFieldMapper.find(companyFieldCondition); + CompanyFieldVo companyFieldVo = new CompanyFieldVo(); + + if (results != null && results.size() > 0) { + for (Map<String, Object> result : results) { + CompanyField companyField = ConvertUtil.convertMapToClass(result, CompanyField.class); + CompanyFieldVo companyFieldVo2 = CreateCompanyFieldCategory(companyFieldVo, companyField); + + result.put("companyTypeName", companyFieldVo2.getCompanyTypeName()); + result.put("parentSectorName", companyFieldVo2.getParentSectorName()); + result.put("childSectorName", companyFieldVo2.getChildSectorName()); + result.put("regionName", companyFieldVo2.getRegionName()); + } + } List<CompanyFieldVo> companyFieldVos = ConvertUtil.convertListToListClass(results, CompanyFieldVo.class); // code_ko_KR �뿉 code紐� �꽕�젙 @@ -765,13 +864,13 @@ public CompanyField getCompany(Long id) { if (id == null) { throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_NOT_EXIST)); + this.messageAccessor.getMessage(MsgConstants.COMPANY_NOT_EXIST)); } CompanyField companyField = this.findOne(id); if (companyField == null) { throw new OwlRuntimeException( - this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_NOT_EXIST)); + this.messageAccessor.getMessage(MsgConstants.COMPANY_NOT_EXIST)); } return companyField; } -- Gitblit v1.8.0