| | |
| | | |
| | | 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.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; |
| | |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private UserLevelService userLevelService; |
| | | |
| | | @Autowired |
| | | private DepartmentService departmentService; |
| | | |
| | | @Autowired |
| | | private UserWorkspaceMapper userWorkspaceMapper; |
| | |
| | | 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()); |
| | | 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())); |
| | | |
| | | // 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(), |
| | |
| | | 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); |
| | | |
| | | // 등급 변경 된 유저 로그아웃 시키기 |
| | | 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.departmentService.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); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | 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); |
| | |
| | | return this.userWorkspaceRepository.findByUserIdAndManagerYn(userId, true); |
| | | } |
| | | |
| | | // 워크스페이스 관리자 조회 |
| | | @Override |
| | | @Transactional(readOnly = true) |
| | | public UserWorkspace findWorkspaceManager(Long userId) { |
| | | return this.userWorkspaceRepository.findByUserId(userId); |
| | | } |
| | | |
| | | // 업무 공간 사용자 연결 아이디로 업무 공간 사용자 연결 정보를 조회한다. |
| | | @Override |
| | | @Transactional(readOnly = true) |
| | |
| | | // 업무 공간 담당자 여부를 확인한다. |
| | | @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()); |
| | | } |
| | |
| | | this.userWorkspaceRepository.saveAll(userWorkspaces); |
| | | } |
| | | } |
| | | |
| | | } |