| | |
| | | package kr.wisestone.owl.service.impl; |
| | | |
| | | import kr.wisestone.owl.web.form.UserLevelForm; |
| | | import kr.wisestone.owl.service.UserService; |
| | | import org.springframework.ui.Model; |
| | | import com.google.common.collect.Lists; |
| | | import kr.wisestone.owl.common.ExcelConditionCheck; |
| | |
| | | private DepartmentManageMapper departmentManageMapper; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private WorkspaceService workspaceService; |
| | | |
| | | @Autowired |
| | |
| | | |
| | | // 부서 목록을 가져온다. |
| | | @Override |
| | | public List<DepartmentManageVo> findDepartment(Map<String, Object> resJsonData, |
| | | public List<DepartmentManageVo>findDepartment(Map<String, Object> resJsonData, |
| | | DepartmentManageCondition condition, Pageable pageable) { |
| | | condition.setPage(pageable.getPageNumber() * pageable.getPageSize()); |
| | | condition.setPageSize(pageable.getPageSize()); |
| | |
| | | return this.convertDepartmentManageVoToMap(results, totalDepartmentCount, pageable, resJsonData); |
| | | } |
| | | |
| | | |
| | | |
| | | // 사용자 부서 ID로 조회한다. |
| | | // 부서 상세 조회한다. |
| | | @Override |
| | | public DepartmentManage getDepartment(Long id) { |
| | | if (id == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.USER_LEVEL_NOT_EXIST)); |
| | | public void detailDepartment(Map<String, Object> resJsonData, DepartmentManageCondition departmentManageCondition) { |
| | | DepartmentManageVo departmentManageVo = new DepartmentManageVo(); |
| | | |
| | | Long departmentId = departmentManageCondition.getId(); |
| | | if (departmentId != null) { |
| | | DepartmentManage departmentManage = this.getDepartment(departmentId); |
| | | departmentManageVo = ConvertUtil.copyProperties(departmentManage, DepartmentManageVo.class); |
| | | } |
| | | resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVo); |
| | | } |
| | | |
| | | DepartmentManage departmentManage = this.findOne(id); |
| | | |
| | | if (departmentManage == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.USER_LEVEL_NOT_EXIST)); |
| | | } |
| | | |
| | | return departmentManage; |
| | | // 부서 정보를 수정한다. |
| | | @Override |
| | | public void modifyDepartment(DepartmentManageForm departmentManageForm) { |
| | | DepartmentManage departmentManage = ConvertUtil.copyProperties(departmentManageForm, DepartmentManage.class); |
| | | departmentManageRepository.saveAndFlush(departmentManage); |
| | | } |
| | | |
| | | // 부서를 삭제한다. |
| | | @Override |
| | | public void removeUserLevel(DepartmentManageForm departmentManageForm) { |
| | | public void removeDepartment(DepartmentManageForm departmentManageForm) { |
| | | if (departmentManageForm.getRemoveIds().size() < 1) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.PROJECT_REMOVE_NOT_SELECT)); |
| | | this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_REMOVE_NOT_SELECT)); |
| | | } |
| | | |
| | | for (Long id : departmentManageForm.getRemoveIds()) { |
| | | if (!this.userService.useUserLevel(id)) { |
| | | this.departmentManageRepository.deleteById(id); |
| | | } else { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE)); |
| | | } |
| | | |
| | | } |
| | | this.departmentManageRepository.flush(); |
| | | } |
| | | |
| | | |
| | | // 검색 결과를 DepartmentManageVo 로 변환한다. |
| | | private List<DepartmentManageVo> convertDepartmentManageVoToMap(List<Map<String, Object>> results, Long totalDepartmentsCount, Pageable pageable, Map<String, Object> resJsonData) { |
| | | List<DepartmentManageVo> departmentManageVos = Lists.newArrayList(); |
| | | |
| | | for (Map<String, Object> result : results) { |
| | | DepartmentManageVo departmentManageVo = ConvertUtil.convertMapToClass(result, DepartmentManageVo.class); |
| | | departmentManageVos.add(departmentManageVo); |
| | | } |
| | | |
| | | int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1; |
| | | |
| | | resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVos); |
| | | resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(), |
| | | totalPage, totalDepartmentsCount)); |
| | | |
| | | return departmentManageVos; |
| | | } |
| | | |
| | | // 부서 목록을 엑셀로 다운로드 한다. |
| | | @Override |
| | | public ModelAndView downloadExcel(HttpServletRequest request, Model model) { |
| | | |
| | |
| | | |
| | | List<Map<String, Object>> results = this.departmentManageMapper.find(departmentManageCondition); |
| | | List<DepartmentManageVo> departmentManageVos = ConvertUtil.convertListToListClass(results, DepartmentManageVo.class); |
| | | |
| | | // code_ko_KR 에 code명 설정 |
| | | ExportExcelVo excelInfo = new ExportExcelVo(); |
| | | excelInfo.setFileName(this.messageAccessor.message("부서 목록")); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentName", this.messageAccessor.message("departmentManage.departmentName"), 6, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentDescription", this.messageAccessor.message("departmentManage.departmentDescription"), 20, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentCount", this.messageAccessor.message("departmentManage.departmentCount"), 3, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | |
| | | excelInfo.setDatas(departmentManageVos); |
| | | |
| | | model.addAttribute(Constants.EXCEL, excelInfo); |
| | | return new ModelAndView(this.excelView); |
| | | |
| | | } |
| | | |
| | | // 사용자 부서 ID로 조회한다. |
| | | @Override |
| | | public DepartmentManage getDepartment(Long id) { |
| | | if (id == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_NOT_EXIST)); |
| | | } |
| | | |
| | | DepartmentManage departmentManage = this.findOne(id); |
| | | |
| | | if (departmentManage == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_NOT_EXIST)); |
| | | } |
| | | |
| | | return departmentManage; |
| | | } |
| | | |
| | | |
| | | // 삭제 할 부서 유저가 사용하고 있는지 확인 |
| | | @Override |
| | | public boolean department(Long Id) { |
| | | return this.departmentManageMapper.findBydepartmentId(Id) > 0; |
| | | } |
| | | |
| | | |
| | | // 검색 결과를 DepartmentManageVo 로 변환한다. |
| | | private List<DepartmentManageVo> convertDepartmentManageVoToMap(List<Map<String, Object>> results, Long totalDepartmentsCount, Pageable pageable, Map<String, Object> resJsonData) { |
| | | List<DepartmentManageVo> departmentManageVos = Lists.newArrayList(); |
| | | |
| | | for (Map<String, Object> result : results) { |
| | | DepartmentManageVo departmentManageVo = ConvertUtil.convertMapToClass(result, DepartmentManageVo.class); |
| | | departmentManageVos.add(departmentManageVo); |
| | | } |
| | | |
| | | int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1; |
| | | |
| | | resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVos); |
| | | resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(), |
| | | totalPage, totalDepartmentsCount)); |
| | | |
| | | return departmentManageVos; |
| | | } |
| | | } |