From 916a3cbabe4e50062fce61ff6f2f5d46c05dfbd1 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 목, 17 3월 2022 17:47:45 +0900
Subject: [PATCH] - api로 이슈 추가 시 url/ip로 업체 찾는 코드 수정

---
 src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
index 6c22513..67d7586 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
@@ -2,6 +2,7 @@
 
 import kr.wisestone.owl.domain.*;
 import kr.wisestone.owl.mapper.DepartmentMapper;
+import kr.wisestone.owl.repository.UserDepartmentRepository;
 import kr.wisestone.owl.service.*;
 import kr.wisestone.owl.web.condition.DepartmentCondition;
 import kr.wisestone.owl.web.condition.UserCondition;
@@ -40,6 +41,9 @@
     private DepartmentRepository departmentRepository;
 
     @Autowired
+    private UserDepartmentService userDepartmentService;
+
+    @Autowired
     private DepartmentMapper departmentMapper;
 
     @Autowired
@@ -50,6 +54,9 @@
 
     @Autowired
     private ProjectRoleDepartmentService projectRoleDepartmentService;
+
+    @Autowired
+    private IssueDepartmentService issueDepartmentService;
 
     @Autowired
     private ProjectRoleService projectRoleService;
@@ -121,11 +128,28 @@
         }
 
         for (Long id : departmentForm.getRemoveIds()) {
-            if (!this.departmentService.countInDepartment(id)) {
-                this.departmentRepository.deleteById(id);
-            } else {
+            if (this.departmentService.countInDepartment(id)) {
+                //  �궗�슜�옄媛� 遺��꽌�뿉 �냽�빐 �엳�뒗吏� 泥댄겕
                 throw new OwlRuntimeException(
                         this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE));
+
+            } else if (this.workflowDepartmentService.usingDepartment(id)) {
+                //  �썙�겕�뵆濡쒖슦�뿉�꽌 �빐�떦 遺��꽌瑜� �궗�슜�븯怨� �엳�뒗吏� 泥댄겕
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE_IN_WORKFLOW));
+
+            } else if (this.projectRoleDepartmentService.usingDepartment(id)) {
+                //  �봽濡쒖젥�듃�쓽 �떞�떦遺��꽌�씤吏� 泥댄겕
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE_IN_PROJECT));
+
+            } else if (this.issueDepartmentService.usingDepartment(id)) {
+                //  �씠�뒋�쓽 �떞�떦遺��꽌濡� �릺�뼱�엳�뒗吏� 泥댄겕
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE_IN_ISSUE));
+
+            } else {
+                this.departmentRepository.deleteById(id);
             }
         }
         this.departmentRepository.flush();
@@ -233,7 +257,12 @@
 
     @Override
     public boolean countInDepartment(Long id) {
-        return this.departmentMapper.countInDepartment(id) > 0;
+        boolean result = false;
+        List<UserDepartment> usingDepartments = this.userDepartmentService.findByDepartmentId(id);
+        if(usingDepartments != null && usingDepartments.size() > 0){
+            result = true;
+        }
+        return result;
     }
 
     //  DepartmentVos �뜲�씠�꽣瑜� �뿊���뿉�꽌 �몴�떆�븷 �닔 �엳�뒗 �뜲�씠�꽣濡� 蹂�寃쏀븳�떎.

--
Gitblit v1.8.0