From bd78ee158df93958380a6cc2460316fd87ed9713 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 화, 08 2월 2022 11:39:08 +0900
Subject: [PATCH] - 이슈 임포트 시 IP주소 정규식 표현 체크 - 업체 추가 시 url을 입력하지 않을 경우 중복 체크 하는 오류 수정

---
 src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java |  117 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 75 insertions(+), 42 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 6fc161b..f0b018b 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java
@@ -83,8 +83,11 @@
     public CompanyField addCompany(CompanyFieldForm companyFieldForm) {
         //  �뾽泥대챸 以묐났 泥댄겕
         this.verifyTitle(companyFieldForm.getName(), null);
-        //  url �쑀�슚�꽦 泥댄겕
-        this.verifyUrl(companyFieldForm.getUrl(), null);
+
+        if (companyFieldForm.getUrl() != null) {
+            //  url �쑀�슚�꽦 泥댄겕
+            this.verifyUrl(companyFieldForm.getUrl(), null);
+        }
 
         if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) {
             String tels = companyFieldForm.getTelList().toString();
@@ -109,21 +112,22 @@
 
     //  url �쑀�슚�꽦 泥댄겕
     private void verifyUrl(String url, Long id) {
-        if (StringUtils.isEmpty(url)) {
+        /*if (StringUtils.isEmpty(url)) {
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.COMPANY_NOT_URL));
-        }
-        CompanyField companyField;
+        }*/
+        if (!StringUtils.isEmpty(url)) {
+            CompanyField companyField;
+            if(id == null){
+                companyField = this.companyFieldRepository.findByUrl(url);
+            } else {
+                companyField = this.companyFieldRepository.findByUrlAndIdNot(url,id);
+            }
 
-        if(id == null){
-            companyField = this.companyFieldRepository.findByUrl(url);
-        } else {
-            companyField = this.companyFieldRepository.findByUrlAndIdNot(url,id);
-        }
-
-        if (companyField != null) {
-            throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.COMPANY_USED_URL));
+            if (companyField != null) {
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.COMPANY_USED_URL));
+            }
         }
     }
 
@@ -222,8 +226,11 @@
     public void modifyCompany(CompanyFieldForm companyFieldForm) {
         //  �뾽泥대챸 �쑀�슚�꽦 泥댄겕
         this.verifyTitle(companyFieldForm.getName(), companyFieldForm.getId());
-        //  url �쑀�슚�꽦 泥댄겕
-        this.verifyUrl(companyFieldForm.getUrl(), 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();
@@ -242,7 +249,7 @@
 
         if (companyFieldForm.getChildSectorId() != null) {
             CompanyFieldCategory companyFieldCategory = this.companyFieldCategoryService.find(companyFieldForm.getChildSectorId());
-            if (!companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) {
+            if (companyFieldCategory != null && !companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) {
                 throw new OwlRuntimeException(
                         this.messageAccessor.getMessage(MsgConstants.PARENT_SECTOR_NOT_EQUAL));
             }
@@ -437,9 +444,34 @@
      * @param cell Cell
      * @return boolean
      */
-    private Boolean cellNullCheck (Cell cell) {
-        return cell != null && cell.getStringCellValue() != null && cell.getCellType() != Cell.CELL_TYPE_BLANK;
+    private Boolean cellNullCheck (Cell cell, int rowIndex) {
+        boolean result = false;
+        
+        //  臾몄옄�삎�떇�씤吏� 泥댄겕
+        if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK && cell.getCellType() != cell.CELL_TYPE_STRING) {
+            throw new OwlRuntimeException(
+                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_NOT_STRING_TYPE, rowIndex));
+        }
+
+        //  怨듬갚 �젣嫄�
+        if (cell != null && cell.getCellType() == cell.CELL_TYPE_STRING && cell.getStringCellValue() != null) {
+            cell.setCellValue(cell.getStringCellValue().trim());
+        }
+
+        if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK && cell.getCellType() == cell.CELL_TYPE_STRING
+                && cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {
+            result = true;
+        }
+
+        return result;
     }
+
+    /*private void telTypeCheck (Cell cell, int rowIndex) {
+        if (cell != null && 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,
@@ -459,82 +491,85 @@
 
                 case 1:
                     //  url
-                    this.setCompanyFormUrl(cell, companyFieldForm, rowIndex);
+                    if (cellNullCheck(cell, rowIndex)) {
+                        this.setCompanyFormUrl(cell, companyFieldForm, rowIndex);
+                    }
                     break;
 
                 case 2:
                     // isp紐�
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormIspName(cell, ispFieldMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 3:
                     // �샇�뒪�똿紐�
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormHostingName(cell, hostingFieldMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 4:
                     // �뿰�씫泥�
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
+                        //this.telTypeCheck(cell, rowIndex);
                         this.setCompanyFormTel(cell, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 5:
                     // �씠硫붿씪
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormEmail(cell, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 6:
                     // �떞�떦�옄
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormManager(cell, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 7:
                     // 湲곗뾽援щ텇
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormCompanyType(cell, companyTypeMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 8:
                     // �뾽醫�(��遺꾨쪟)
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormParentSector(cell, parentSectorMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 9:
                     // �뾽醫�(以묐텇瑜�)
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormChildSector(cell, childSectorMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 10:
                     // 吏��뿭
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormRegion(cell, regionMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 11:
                     // �긽�깭
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormStatus(cell, statusMaps, companyFieldForm, rowIndex);
                     }
                     break;
 
                 case 12:
                     // 鍮꾧퀬
-                    if (cellNullCheck(cell)) {
+                    if (cellNullCheck(cell, rowIndex)) {
                         this.setCompanyFormMemo(cell, companyFieldForm, rowIndex);
                     }
                     break;
@@ -665,7 +700,7 @@
     }
 
     private void setCompanyFormName(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) {
-        if (cell == null) {
+        if (!cellNullCheck(cell, rowIndex)) {
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_COMPANY_NAME_IS_NULL, rowIndex));
         }
@@ -678,17 +713,15 @@
     }
 
     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);
-        if (url.contains(" ")) {
-            url = url.replace(" ", "");
-        }
-        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);
+        }
     }
 
     //  �뾽泥대챸 �쑀�슚�꽦 泥댄겕

--
Gitblit v1.8.0