From 77165150ee2695ec1cf1622bfd5ffa9b99317865 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 수, 26 1월 2022 10:55:34 +0900
Subject: [PATCH] - 업체명 중복 체크 - 업종 중분류만 입력하고 대분류 미입력 시 오류 메시지 - 업체 수정 시 오류 해결

---
 src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java |   61 +++++++++++++++++++++++-------
 1 files changed, 46 insertions(+), 15 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 e6ee02f..6fc161b 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java
@@ -81,6 +81,8 @@
     // �뾽泥� 異붽�
     @Override
     public CompanyField addCompany(CompanyFieldForm companyFieldForm) {
+        //  �뾽泥대챸 以묐났 泥댄겕
+        this.verifyTitle(companyFieldForm.getName(), null);
         //  url �쑀�슚�꽦 泥댄겕
         this.verifyUrl(companyFieldForm.getUrl(), null);
 
@@ -109,7 +111,7 @@
     private void verifyUrl(String url, Long id) {
         if (StringUtils.isEmpty(url)) {
             throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_NOT_URL));
+                    this.messageAccessor.getMessage(MsgConstants.COMPANY_NOT_URL));
         }
         CompanyField companyField;
 
@@ -121,7 +123,7 @@
 
         if (companyField != null) {
             throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_USED_URL));
+                    this.messageAccessor.getMessage(MsgConstants.COMPANY_USED_URL));
         }
     }
 
@@ -218,6 +220,8 @@
     // �뾽泥� �젙濡쒕�� �닔�젙�븳�떎.
     @Override
     public void modifyCompany(CompanyFieldForm companyFieldForm) {
+        //  �뾽泥대챸 �쑀�슚�꽦 泥댄겕
+        this.verifyTitle(companyFieldForm.getName(), companyFieldForm.getId());
         //  url �쑀�슚�꽦 泥댄겕
         this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId());
 
@@ -236,10 +240,12 @@
             companyFieldForm.setEmail(emails.trim());
         }
 
-        CompanyFieldCategory companyFieldCategory = this.companyFieldCategoryService.find(companyFieldForm.getChildSectorId());
-        if (!companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) {
-            throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.PARENT_SECTOR_NOT_EQUAL));
+        if (companyFieldForm.getChildSectorId() != null) {
+            CompanyFieldCategory companyFieldCategory = this.companyFieldCategoryService.find(companyFieldForm.getChildSectorId());
+            if (!companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) {
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.PARENT_SECTOR_NOT_EQUAL));
+            }
         }
 
         CompanyField companyField = ConvertUtil.copyProperties(companyFieldForm, CompanyField.class);
@@ -382,7 +388,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);
@@ -443,7 +449,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) {
@@ -525,6 +530,7 @@
                     if (cellNullCheck(cell)) {
                         this.setCompanyFormStatus(cell, statusMaps, companyFieldForm, rowIndex);
                     }
+                    break;
 
                 case 12:
                     // 鍮꾧퀬
@@ -568,10 +574,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"));
         }
     }
@@ -658,7 +673,7 @@
         String title = CommonUtil.convertExcelStringToCell(cell);
 
         //  �뾽泥대챸 �쑀�슚�꽦 泥댄겕
-        this.verifyTitle(title);
+        this.verifyTitle(title, null);
         companyFieldForm.setName(title);
     }
 
@@ -677,15 +692,31 @@
     }
 
     //  �뾽泥대챸 �쑀�슚�꽦 泥댄겕
-    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));
         }
     }
 
@@ -817,13 +848,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