| | |
| | | |
| | | import com.google.common.collect.Lists; |
| | | import kr.wisestone.owl.constant.Constants; |
| | | import kr.wisestone.owl.constant.MngPermission; |
| | | import kr.wisestone.owl.constant.MsgConstants; |
| | | import kr.wisestone.owl.domain.User; |
| | | import kr.wisestone.owl.domain.UserLevel; |
| | | import kr.wisestone.owl.exception.OwlRuntimeException; |
| | | import kr.wisestone.owl.mapper.UserLevelMapper; |
| | | import kr.wisestone.owl.mapper.UserMapper; |
| | | import kr.wisestone.owl.repository.UserLevelRepository; |
| | | import kr.wisestone.owl.service.UserLevelService; |
| | | import kr.wisestone.owl.service.UserService; |
| | | import kr.wisestone.owl.util.CommonUtil; |
| | | import kr.wisestone.owl.util.ConvertUtil; |
| | | import kr.wisestone.owl.vo.ResPage; |
| | |
| | | import kr.wisestone.owl.vo.UserVo; |
| | | import kr.wisestone.owl.web.condition.UserCondition; |
| | | import kr.wisestone.owl.web.condition.UserLevelCondition; |
| | | import kr.wisestone.owl.web.form.ManageUserForm; |
| | | import kr.wisestone.owl.web.form.UserLevelForm; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.jpa.repository.JpaRepository; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @Autowired |
| | | private UserLevelMapper userLevelMapper; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Override |
| | | protected JpaRepository<UserLevel, Long> getRepository() { |
| | | return this.userLevelRepository; |
| | | } |
| | | |
| | | // 사용자 가입 후 UserLevel 값 저장 |
| | | @Override |
| | | public UserLevel addUserLevel(UserLevelForm userLevelForm) { |
| | | userLevelForm.makePermission(); |
| | | UserLevel userLevel = ConvertUtil.copyProperties(userLevelForm, UserLevel.class); |
| | | userLevelRepository.saveAndFlush(userLevel); |
| | | return userLevel; |
| | | } |
| | | |
| | | // 최고관리자 등급 추가 |
| | | @Override |
| | | public List<UserLevelVo> findUser(Map<String, Object> resJsonData, UserLevelCondition condition, |
| | | Pageable pageable) { |
| | | public UserLevel addSuperUserLevel() { |
| | | UserLevel userLevel = new UserLevel(); |
| | | userLevel.setLevelName("최고관리자"); |
| | | userLevel.setPermission(MngPermission.makeAllPermission()); |
| | | |
| | | userLevel = userLevelRepository.saveAndFlush(userLevel); |
| | | return userLevel; |
| | | } |
| | | |
| | | // 사용자 등급 목록을 가져온다. |
| | | @Override |
| | | public List<UserLevelVo> findUser(Map<String, Object> resJsonData, |
| | | UserLevelCondition condition, Pageable pageable) { |
| | | |
| | | condition.setPage(pageable.getPageNumber() * pageable.getPageSize()); |
| | | condition.setPageSize(pageable.getPageSize()); |
| | |
| | | |
| | | return this.convertUserLevelVoToMap(results, totalUsersCount, pageable, resJsonData); |
| | | } |
| | | // 사용자 등급 정보를 수정한다. |
| | | @Override |
| | | public void modifyUserLevel(UserLevelForm userLevelForm) { |
| | | userLevelForm.makePermission(); |
| | | UserLevel userLevel = ConvertUtil.copyProperties(userLevelForm, UserLevel.class); |
| | | userLevelRepository.saveAndFlush(userLevel); |
| | | } |
| | | |
| | | @Override |
| | | public void removeUserLevel(UserLevelForm userLevelForm) { |
| | | if (userLevelForm.getRemoveIds().size() < 1) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.PROJECT_REMOVE_NOT_SELECT)); |
| | | } |
| | | |
| | | for (Long id : userLevelForm.getRemoveIds()) { |
| | | if (!this.userService.useUserLevel(id)) { |
| | | this.userLevelRepository.deleteById(id); |
| | | } else { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.USER_LEVEL_ALREADY)); |
| | | } |
| | | } |
| | | |
| | | this.userLevelRepository.flush(); |
| | | } |
| | | |
| | | // 검색 결과를 UserLevelVo 로 변환한다. |
| | | private List<UserLevelVo> convertUserLevelVoToMap(List<Map<String, Object>> results, Long totalUsersCount, Pageable pageable, Map<String, Object> resJsonData) { |
| | |
| | | |
| | | for (Map<String, Object> result : results) { |
| | | UserLevelVo userLevelVo = ConvertUtil.convertMapToClass(result, UserLevelVo.class); |
| | | userLevelVo.toPermissionValues(); |
| | | userLevelVos.add(userLevelVo); |
| | | } |
| | | |