From 2efe89b4912553eddb4c26103e6ce4e93b52649f Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 금, 26 11월 2021 15:56:06 +0900
Subject: [PATCH] 이슈 테이블설정

---
 src/main/java/kr/wisestone/owl/service/impl/ProjectServiceImpl.java |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/ProjectServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/ProjectServiceImpl.java
index 28299c9..adf2ad1 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/ProjectServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/ProjectServiceImpl.java
@@ -15,7 +15,6 @@
 import kr.wisestone.owl.util.CommonUtil;
 import kr.wisestone.owl.util.ConvertUtil;
 import kr.wisestone.owl.util.DateUtil;
-import kr.wisestone.owl.util.MapUtil;
 import kr.wisestone.owl.vo.*;
 import kr.wisestone.owl.web.condition.ProjectCondition;
 import kr.wisestone.owl.web.form.ProjectForm;
@@ -407,7 +406,7 @@
             this.setProjectUser(projectVo, false);
             
             //  �봽濡쒖젥�듃�뿉 李몄뿬�븯�뒗 遺��꽌 �꽭�똿
-            //this.setProjectDepartment(projectVo);
+            this.setProjectDepartment(projectVo);
 
             //  �뾽臾닿났媛� �떞�떦�옄�뒗 紐⑤뱺 �봽濡쒖젥�듃瑜� �닔�젙/�궘�젣�븷 �닔 �엳�뼱�빞 �븳�떎.
             if (this.userWorkspaceService.checkWorkspaceManager()) {
@@ -500,7 +499,7 @@
                 case "01": //  �봽濡쒖젥�듃�뿉 李몄뿬�븯�뒗 �궗�슜�옄, 愿�由ъ옄 �젙蹂대�� �뀑�똿�븳�떎.
                     this.setProjectUser(projectVo, true);
                     this.setProjectUser(projectVo, false);
-                    //this.setProjectDepartment(projectVo); //遺��꽌 �젙蹂� �꽭�똿
+                    this.setProjectDepartment(projectVo); //遺��꽌 �젙蹂� �꽭�똿
                     break;
             }
         }
@@ -537,6 +536,7 @@
         Map<String, Object> changeProjectManagerNotifications = this.modifyProjectManagers(project, projectForm, ProjectRole.TYPE_MANAGER);
         //  �씪諛� �궗�슜�옄 蹂�寃�
         Map<String, Object> changeProjectUserNotifications = this.modifyProjectManagers(project, projectForm, ProjectRole.TYPE_DEFAULT);
+        Map<String, Object> changeProjectDepartmentNotifications = this.modifyProjectDepartments(project, projectForm);
         ConvertUtil.copyProperties(projectForm, project, "id", "projectType");
 
         this.projectRepository.saveAndFlush(project);
@@ -728,6 +728,37 @@
 
     }
 
+    //  愿�由ъ옄瑜� 蹂�寃쏀븳�떎.
+    private Map<String, Object> modifyProjectDepartments(Project project, ProjectForm projectForm) {
+        ProjectRole projectRole = this.projectRoleService.findByProjectIdAndRoleType(project.getId(), ProjectRole.TYPE_DEFAULT);
+        List<Department> oldDepartment = Lists.newArrayList();
+        List<Department> newDepartment = Lists.newArrayList();
+        Map<String, Object> results = new HashMap<>();
+
+        for (ProjectRoleDepartment projectRoleDepartment : projectRole.getProjectRoleDepartments()) {
+            Department department = projectRoleDepartment.getDepartment();
+            oldDepartment.add(department);
+            department.removeProjectRole(projectRole);
+        }
+        projectRole.getProjectRoleDepartments().clear();
+
+        for (Long departmentId : projectForm.getDepartmentIds()) {
+            Department department = this.departmentService.getDepartment(departmentId);
+            department.addProjectRole(projectRole);
+        }
+
+        //  �젣�쇅 ���긽�옄 李얘린, oldManager �뿉�뒗 �엳�뒗�뜲 newManager �뿉 �뾾�쑝硫� �젣�쇅 ���긽
+        List<String> excludeDepartments = this.systemEmailService.notificationDepartmentChange(oldDepartment, newDepartment);
+        //  李몄뿬 ���긽�옄 李얘린, newManager �뿉�뒗 �엳�뒗�뜲 oldManager �뿉 �뾾�쑝硫� 珥덈�諛쏆� ���긽
+        List<String> includeDepartments = this.systemEmailService.notificationDepartmentChange(newDepartment, oldDepartment);
+
+        results.put("excludeDepartments", excludeDepartments);
+        results.put("includeDepartments", includeDepartments);
+
+        return results;
+
+    }
+
     //  �봽濡쒖젥�듃 李몄뿬, �젣�쇅 �넻吏� �젙蹂대�� 以묐났�쑝濡� �굹媛�吏� �븡�룄濡� 泥댄겕�븳�떎.
     private void notificationProjectRoleUser(Map<String, Object> changeProjectManagerNotifications, Map<String, Object> changeProjectUserNotifications, Project project) {
         List<String> projectManagerExcludeUsers = (List<String>) changeProjectManagerNotifications.get("excludeUsers");  //  愿�由ъ옄 �젣�쇅 �궗�슜�옄

--
Gitblit v1.8.0