OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2021-11-05 8e538d93ca3f8da8d082ad2ee497625349d9a4dd
src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java
@@ -1,5 +1,8 @@
package kr.wisestone.owl.service.impl;
import kr.wisestone.owl.domain.UserLevel;
import kr.wisestone.owl.web.form.UserLevelForm;
import org.springframework.ui.Model;
import com.google.common.collect.Lists;
import kr.wisestone.owl.common.ExcelConditionCheck;
import kr.wisestone.owl.constant.Constants;
@@ -19,7 +22,6 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@@ -50,6 +52,7 @@
        return this.departmentManageRepository;
    }
    // 부서 추가
    @Override
    public DepartmentManage addDepartmentManage(DepartmentManageForm departmentManageForm) {
        DepartmentManage departmentManage = ConvertUtil.copyProperties(departmentManageForm, DepartmentManage.class);
@@ -57,6 +60,20 @@
        return departmentManage;
    }
    // 부서 목록을 가져온다.
    @Override
    public List<DepartmentManageVo> findDepartment(Map<String, Object> resJsonData,
                                                   DepartmentManageCondition condition, Pageable pageable) {
        condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
        condition.setPageSize(pageable.getPageSize());
        List<Map<String, Object>> results = this.departmentManageMapper.find(condition);
        Long totalDepartmentCount = this.departmentManageMapper.count(condition);
        return this.convertDepartmentManageVoToMap(results, totalDepartmentCount, pageable, resJsonData);
    }
    // 사용자 부서 ID로 조회한다.
    @Override
    public DepartmentManage getDepartment(Long id) {
        if (id == null) {
@@ -74,40 +91,58 @@
        return departmentManage;
    }
    // 부서를 삭제한다.
    @Override
    public List<DepartmentManageVo> findDepartment(Map<String, Object> resJsonData,
                                                   DepartmentManageCondition condition, Pageable pageable) {
        condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
        condition.setPageSize(pageable.getPageSize());
        List<Map<String, Object>> results = this.departmentManageMapper.find(condition);
        Long totalDepartmentCount = this.departmentManageMapper.count(condition);
        return this.convertDepartmentManageVoToMap(results, totalDepartmentCount, pageable, resJsonData);
    public void removeDepartment(DepartmentManageForm departmentManageForm) {
        if (departmentManageForm.getRemoveIds().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.PROJECT_REMOVE_NOT_SELECT));
        }
        this.departmentManageRepository.flush();
    }
    // 부서 상세 조회한다.
    @Override
    public void detailDepartment(Map<String, Object> resJsonData, DepartmentManageCondition departmentManageCondition) {
        DepartmentManageVo departmentManageVo = new DepartmentManageVo();
        if (departmentManageVo.getId() != null) {
            DepartmentManage departmentManage = this.getDepartment(departmentManageCondition.getId());
            departmentManageVo = ConvertUtil.copyProperties(departmentManage, DepartmentManageVo.class);
        }
        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVo);
    }
    // 부서 정보를 수정한다.
    @Override
    public void modifyDepartment(DepartmentManageForm departmentManageForm) {
        DepartmentManage departmentManage = ConvertUtil.copyProperties(departmentManageForm, DepartmentManage.class);
        departmentManageRepository.saveAndFlush(departmentManage);
    }
    //  검색 결과를 DepartmentManageVo 로 변환한다.
    private List<DepartmentManageVo> convertDepartmentManageVoToMap(List<Map<String, Object>> results, Long totalDepartmentCount, Pageable pageable, Map<String, Object> resJsonData) {
    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((totalDepartmentCount - 1) / pageable.getPageSize()) + 1;
        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, totalDepartmentCount));
                totalPage, totalDepartmentsCount));
        return departmentManageVos;
    }
    //  부서 목록을 엑셀로 다운로드 한다.
    // 부서 목록을 엑셀로 다운로드 한다.
    @Override
    public ModelAndView downloadExcel(HttpServletRequest request, Model model) {
        ModelAndView modelAndView = this.workspaceService.checkUseExcelDownload(model);
        if (modelAndView != null) {
            return modelAndView;
@@ -131,6 +166,7 @@
        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);