From 4fd246e32166938d7f86c7ab236ed554a2bc9fef Mon Sep 17 00:00:00 2001
From: wyu <kknd09321@nate.com>
Date: 월, 08 11월 2021 16:14:03 +0900
Subject: [PATCH] 업체 관리 백엔드 추가

---
 src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java |   73 +++++++++++++++++++++++-------------
 1 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java
index 405cfe5..6f6306d 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java
@@ -2,15 +2,11 @@
 
 import kr.wisestone.owl.constant.Constants;
 import kr.wisestone.owl.constant.MsgConstants;
-import kr.wisestone.owl.domain.User;
-import kr.wisestone.owl.domain.UserWorkspace;
-import kr.wisestone.owl.domain.Workspace;
+import kr.wisestone.owl.domain.*;
 import kr.wisestone.owl.exception.OwlRuntimeException;
 import kr.wisestone.owl.mapper.UserWorkspaceMapper;
 import kr.wisestone.owl.repository.UserWorkspaceRepository;
-import kr.wisestone.owl.service.UserService;
-import kr.wisestone.owl.service.UserWorkspaceService;
-import kr.wisestone.owl.service.WorkspaceService;
+import kr.wisestone.owl.service.*;
 import kr.wisestone.owl.util.CommonUtil;
 import kr.wisestone.owl.util.ConvertUtil;
 import kr.wisestone.owl.vo.ResPage;
@@ -39,6 +35,12 @@
 
     @Autowired
     private UserService userService;
+
+    @Autowired
+    private UserLevelService userLevelService;
+
+    @Autowired
+    private DepartmentManageService departmentManageService;
 
     @Autowired
     private UserWorkspaceMapper userWorkspaceMapper;
@@ -104,32 +106,51 @@
     public void modifyUserWorkspace(UserWorkspaceForm userWorkspaceForm) {
         UserWorkspace userWorkspace = this.getUserWorkspace(userWorkspaceForm.getId());
 
+        User user = userWorkspace.getUser();
+
+        // �궗�슜�옄 �벑湲� 蹂�寃�
+        UserLevel currentUserlevel = user.getUserLevel();
+        if (currentUserlevel.getId() != userWorkspaceForm.getLevelId()) {
+            UserLevel userLevel = this.userLevelService.getUserLevel(userWorkspaceForm.getLevelId());
+            user.setUserLevel(userLevel);
+            userWorkspace.setUser(user);
+        }
+
+        // 遺��꽌 蹂�寃�
+        DepartmentManage currentDepartment = user.getDepartmentManage();
+        if (currentDepartment == null || (userWorkspaceForm.getDepartmentId() != null && currentDepartment.getId() != userWorkspaceForm.getDepartmentId())) {
+            // 遺��꽌紐� 蹂�寃쎌떆
+            DepartmentManage departmentManage = this.departmentManageService.getDepartment(userWorkspaceForm.getDepartmentId());
+            user.setDepartmentManage(departmentManage);
+            userWorkspace.setUser(user);
+        }
+
         //  李몄뿬濡� �긽�깭瑜� 蹂�寃쏀븯�젮怨� �븷�븣
-        if (!userWorkspace.getUseYn()) {
-            Integer maxUserCount = userWorkspace.getWorkspace().getMaxUser();  //  理쒕� �궗�슜�옄
-            Integer activeUserCount = this.countByWorkspaceIdAndUseYn(userWorkspace.getWorkspace().getId(), true);
+        if (userWorkspace.getUseYn() != userWorkspaceForm.getUseYn()) {
+            if (!userWorkspace.getUseYn()) {
+                Integer maxUserCount = userWorkspace.getWorkspace().getMaxUser();  //  理쒕� �궗�슜�옄
+                Integer activeUserCount = this.countByWorkspaceIdAndUseYn(userWorkspace.getWorkspace().getId(), true);
 
-            //  理쒕� �궗�슜�옄 - �쁽�옱 李몄뿬 �궗�슜�옄媛� 0蹂대떎 �겕�떎硫� 李몄뿬 �긽�깭濡� 蹂�寃�
-            if ((maxUserCount - activeUserCount) < 1) {
-                throw new OwlRuntimeException(
-                        this.messageAccessor.getMessage(MsgConstants.WORKSPACE_MAX_USER_EXCESS_NOT_INCLUDE));
-            }
-        }
-        else {
-            User user = userWorkspace.getUser();
-            //  李몄뿬 ��湲� �궗�슜�옄媛� �쁽�옱 �빐�떦 �뾽臾� 怨듦컙�쓣 �궗�슜�븯怨� �엳�쓣 寃쎌슦 利됱떆 �빐�떦 �뾽臾� 怨듦컙�뿉�꽌 �뒘湲곌쾶 �븳�떎.
-            if (user.getLastWorkspaceId().equals(userWorkspace.getWorkspace().getId())){
-                //  �뾽臾� 怨듦컙�뿉 李몄뿬�븯�뜕 �궗�슜�옄�뿉寃� �젣�쇅 �븣由� 諛� �솕硫� �깉濡쒓퀬移�
-                this.simpMessagingTemplate.convertAndSendToUser(user.getAccount(), "/notification/workspace-disabled", this.messageAccessor.getMessage(MsgConstants.WORKSPACE_OUT, userWorkspace.getWorkspace().getName()));
-            }
+                //  理쒕� �궗�슜�옄 - �쁽�옱 李몄뿬 �궗�슜�옄媛� 0蹂대떎 �겕�떎硫� 李몄뿬 �긽�깭濡� 蹂�寃�
+                if ((maxUserCount - activeUserCount) < 1) {
+                    throw new OwlRuntimeException(
+                            this.messageAccessor.getMessage(MsgConstants.WORKSPACE_MAX_USER_EXCESS_NOT_INCLUDE));
+                }
+            } else {
+                user = userWorkspace.getUser();
+                //  李몄뿬 ��湲� �궗�슜�옄媛� �쁽�옱 �빐�떦 �뾽臾� 怨듦컙�쓣 �궗�슜�븯怨� �엳�쓣 寃쎌슦 利됱떆 �빐�떦 �뾽臾� 怨듦컙�뿉�꽌 �뒘湲곌쾶 �븳�떎.
+                if (user.getLastWorkspaceId().equals(userWorkspace.getWorkspace().getId())) {
+                    //  �뾽臾� 怨듦컙�뿉 李몄뿬�븯�뜕 �궗�슜�옄�뿉寃� �젣�쇅 �븣由� 諛� �솕硫� �깉濡쒓퀬移�
+                    this.simpMessagingTemplate.convertAndSendToUser(user.getAccount(), "/notification/workspace-disabled", this.messageAccessor.getMessage(MsgConstants.WORKSPACE_OUT, userWorkspace.getWorkspace().getName()));
+                }
 
-            //  李몄뿬 ��湲� �긽�깭濡� 蹂�寃쏀븯硫� �빐�떦 �궗�슜�옄�쓽 留덉�留� �젒洹� �뾽臾� 怨듦컙�뒗 �옄�떊�씠 愿�由ы븯�뒗 �뾽臾� 怨듦컙濡� 蹂�寃쏀븳�떎.
-            this.userService.updateLastMyWorkspace(user);
+                //  李몄뿬 ��湲� �긽�깭濡� 蹂�寃쏀븯硫� �빐�떦 �궗�슜�옄�쓽 留덉�留� �젒洹� �뾽臾� 怨듦컙�뒗 �옄�떊�씠 愿�由ы븯�뒗 �뾽臾� 怨듦컙濡� 蹂�寃쏀븳�떎.
+                this.userService.updateLastMyWorkspace(user);
+            }
+            userWorkspace.setUseYn(!userWorkspace.getUseYn());
         }
 
-        userWorkspace.setUseYn(!userWorkspace.getUseYn());
         this.userWorkspaceRepository.saveAndFlush(userWorkspace);
-
     }
 
 

--
Gitblit v1.8.0