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 |   79 +++++++++++++++++++++++++--------------
 1 files changed, 50 insertions(+), 29 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 f830917..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;
@@ -75,17 +77,17 @@
     public List<UserWorkspaceVo> findUserWorkspace(Map<String, Object> resJsonData,
                                                    UserWorkspaceCondition condition, Pageable pageable) {
 
-        UserWorkspace userWorkspace = this.findMyWorkspace(this.webAppUtil.getLoginId()); //濡쒓렇�씤�븳 �븘�씠�뵒
+        UserWorkspace userWorkspace = this.findMyWorkspace(this.webAppUtil.getLoginId());
         Workspace myWorkspace = userWorkspace.getWorkspace();
         condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
         condition.setPageSize(pageable.getPageSize());
         condition.setWorkspaceId(myWorkspace.getId());
-        condition.setAccount(CommonUtil.encryptAES128(condition.getAccount()));
+        condition.setAccount(CommonUtil.encryptAES128(condition.getAccount())); //怨꾩젙 �븫�샇�솕(�븘�닔 �룞�옉)
 
         List<Map<String, Object>> results = this.userWorkspaceMapper.find(condition);
         Long totalCount = this.userWorkspaceMapper.count(condition);
         int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
-        List<UserWorkspaceVo> userWorkspaceVos = ConvertUtil.convertListToListClass(results, UserWorkspaceVo.class);
+        List<UserWorkspaceVo> userWorkspaceVos = ConvertUtil.convertListToListClass(results, UserWorkspaceVo.class); //UserWorkspace�쓽 �뜲�씠�꽣瑜� 由ъ뒪�듃 �삎�떇�쑝濡� 蹂듭궗�빐�꽌 UserWorkspaceVo�뿉 �떞湲�
 
         for (UserWorkspaceVo userWorkspaceVo : userWorkspaceVos) {
             userWorkspaceVo.setAccount(CommonUtil.decryptAES128(userWorkspaceVo.getAccount()));
@@ -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