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/UserWorkspaceServiceImpl.java |   55 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 40 insertions(+), 15 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 6f6306d..b192044 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java
@@ -9,8 +9,10 @@
 import kr.wisestone.owl.service.*;
 import kr.wisestone.owl.util.CommonUtil;
 import kr.wisestone.owl.util.ConvertUtil;
+import kr.wisestone.owl.vo.DepartmentVo;
 import kr.wisestone.owl.vo.ResPage;
 import kr.wisestone.owl.vo.UserWorkspaceVo;
+import kr.wisestone.owl.web.condition.UserCondition;
 import kr.wisestone.owl.web.condition.UserWorkspaceCondition;
 import kr.wisestone.owl.web.form.UserWorkspaceForm;
 import org.slf4j.Logger;
@@ -40,7 +42,7 @@
     private UserLevelService userLevelService;
 
     @Autowired
-    private DepartmentManageService departmentManageService;
+    private DepartmentService departmentService;
 
     @Autowired
     private UserWorkspaceMapper userWorkspaceMapper;
@@ -77,7 +79,7 @@
     public List<UserWorkspaceVo> findUserWorkspace(Map<String, Object> resJsonData,
                                                    UserWorkspaceCondition condition, Pageable pageable) {
 
-        UserWorkspace userWorkspace = this.findMyWorkspace(this.webAppUtil.getLoginId());
+        UserWorkspace userWorkspace = this.findWorkspaceManager(this.webAppUtil.getLoginId());
         Workspace myWorkspace = userWorkspace.getWorkspace();
         condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
         condition.setPageSize(pageable.getPageSize());
@@ -91,6 +93,16 @@
 
         for (UserWorkspaceVo userWorkspaceVo : userWorkspaceVos) {
             userWorkspaceVo.setAccount(CommonUtil.decryptAES128(userWorkspaceVo.getAccount()));
+
+            // UserCondition �뒗 �썝�옒 userId 媛� �뾾�뿀�떎.
+            UserCondition con = new UserCondition();
+            // 洹몃옒�꽌 Condition�뿉 異붽� �빐二쇨퀬 set �븯�뒗�뜲 洹멸굔 userWorkspaceVo �뿉�꽌 Id 瑜� 媛��졇�삩�떎
+            con.setId(userWorkspaceVo.getUserId());
+            // findByDepartmentIds �씪�뒗嫄� mapper濡� 留뚮뱾�뼱�꽌 荑쇰━ for臾몄쓣 �룎由ш퀬 us
+            List<Map<String, Object>> re = this.departmentService.findByDepartmentIds(con);
+            List<DepartmentVo> vos = ConvertUtil.convertListToListClass(re, DepartmentVo.class);
+
+            userWorkspaceVo.setDepartmentVos(vos);
         }
 
         resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
@@ -114,16 +126,22 @@
             UserLevel userLevel = this.userLevelService.getUserLevel(userWorkspaceForm.getLevelId());
             user.setUserLevel(userLevel);
             userWorkspace.setUser(user);
+
+            //  �벑湲� 蹂�寃� �맂 �쑀�� 濡쒓렇�븘�썐 �떆�궎湲�
+            this.simpMessagingTemplate.convertAndSendToUser(user.getAccount(), "/notification/changeUserLevel", this.messageAccessor.getMessage(MsgConstants.USER_LEVEL_CHANGE));
+
+            //  �꽭�뀡 �뾽�뜲�씠�듃
+            //SecurityUtils.setUserToSession(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);
-        }
+//        DepartmentManage currentDepartment = user.getDepartmentManage();
+//        if (currentDepartment == null || (userWorkspaceForm.getDepartmentId() != null && currentDepartment.getId() != userWorkspaceForm.getDepartmentId())) {
+//            // 遺��꽌紐� 蹂�寃쎌떆
+//            DepartmentManage departmentManage = this.departmentService.getDepartment(userWorkspaceForm.getDepartmentId());
+//            user.setDepartmentManage(departmentManage);
+//            userWorkspace.setUser(user);
+//        }
 
         //  李몄뿬濡� �긽�깭瑜� 蹂�寃쏀븯�젮怨� �븷�븣
         if (userWorkspace.getUseYn() != userWorkspaceForm.getUseYn()) {
@@ -160,10 +178,10 @@
     public void disabledUserWorkspace(User user, Workspace workspace) {
         UserWorkspace userWorkspace = this.userWorkspaceRepository.findByUserIdAndWorkspaceId(user.getId(), workspace.getId());
 
-        if (userWorkspace.getManagerYn()) {
+        /*if (userWorkspace.getManagerYn()) {
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.WORKSPACE_MANAGER_NOT_CHANGE_USE_YN));
-        }
+        }*/
 
         userWorkspace.setUseYn(false);
         this.userWorkspaceRepository.saveAndFlush(userWorkspace);
@@ -204,6 +222,13 @@
         return this.userWorkspaceRepository.findByUserIdAndManagerYn(userId, true);
     }
 
+    //  �썙�겕�뒪�럹�씠�뒪 愿�由ъ옄 議고쉶
+    @Override
+    @Transactional(readOnly = true)
+    public UserWorkspace findWorkspaceManager(Long userId) {
+        return this.userWorkspaceRepository.findByUserId(userId);
+    }
+
     //  �뾽臾� 怨듦컙 �궗�슜�옄 �뿰寃� �븘�씠�뵒濡� �뾽臾� 怨듦컙 �궗�슜�옄 �뿰寃� �젙蹂대�� 議고쉶�븳�떎.
     @Override
     @Transactional(readOnly = true)
@@ -226,15 +251,14 @@
     //  �뾽臾� 怨듦컙 �떞�떦�옄 �뿬遺�瑜� �솗�씤�븳�떎.
     @Override
     @Transactional(readOnly = true)
-    public boolean checkWorkspaceManager() {
+    public boolean checkWorkspaceManager(User user) {
         boolean bIsManager = false;
-        User loginUser = this.userService.getUser(this.webAppUtil.getLoginId());
 
         try
         {
-            Workspace workspace = this.workspaceService.getWorkspace(loginUser.getLastWorkspaceId());   //  �쁽�옱 �젒�냽�븳 �뾽臾� 怨듦컙
+            Workspace workspace = this.workspaceService.getWorkspace(user.getLastWorkspaceId());   //  �쁽�옱 �젒�냽�븳 �뾽臾� 怨듦컙
             //  濡쒓렇�씤�븳 �궗�슜�옄媛� 愿�由ы븯�뒗 �뾽臾� 怨듦컙�쓣 李얜뒗�떎.
-            UserWorkspace userWorkspace = this.findMyWorkspace(this.webAppUtil.getLoginId());
+            UserWorkspace userWorkspace = this.findMyWorkspace(user.getId());
 
             bIsManager = workspace.getId().equals(userWorkspace.getWorkspace().getId());
         }
@@ -271,4 +295,5 @@
             this.userWorkspaceRepository.saveAll(userWorkspaces);
         }
     }
+
 }

--
Gitblit v1.8.0