OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-12-11 8c444812f7b9f0ad92e6e5a76f159778232eac65
src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
@@ -1,15 +1,15 @@
package kr.wisestone.owl.service.impl;
import kr.wisestone.owl.domain.Department;
import kr.wisestone.owl.domain.UserDepartment;
import kr.wisestone.owl.domain.UserLevel;
import kr.wisestone.owl.domain.*;
import kr.wisestone.owl.mapper.DepartmentMapper;
import kr.wisestone.owl.service.UserDepartmentService;
import kr.wisestone.owl.service.UserService;
import kr.wisestone.owl.service.*;
import kr.wisestone.owl.web.condition.DepartmentCondition;
import kr.wisestone.owl.web.condition.UserCondition;
import kr.wisestone.owl.web.form.DepartmentForm;
import kr.wisestone.owl.web.form.UserDepartmentForm;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import com.google.common.collect.Lists;
import kr.wisestone.owl.common.ExcelConditionCheck;
@@ -17,8 +17,6 @@
import kr.wisestone.owl.constant.MsgConstants;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.repository.DepartmentRepository;
import kr.wisestone.owl.service.DepartmentService;
import kr.wisestone.owl.service.WorkspaceService;
import kr.wisestone.owl.util.ConvertUtil;
import kr.wisestone.owl.vo.*;
import kr.wisestone.owl.web.view.ExcelView;
@@ -36,6 +34,8 @@
@Service
public class DepartmentServiceImpl extends AbstractServiceImpl<Department, Long, JpaRepository<Department, Long>> implements DepartmentService {
    private static final Logger log = LoggerFactory.getLogger(IssueServiceImpl.class);
    @Autowired
    private DepartmentRepository departmentRepository;
@@ -46,7 +46,16 @@
    private DepartmentService departmentService;
    @Autowired
    private UserDepartmentService userDepartmentService;
    private WorkflowDepartmentService workflowDepartmentService;
    @Autowired
    private ProjectRoleDepartmentService projectRoleDepartmentService;
    @Autowired
    private ProjectRoleService projectRoleService;
    @Autowired
    private IssueTypeService issueTypeService;
    @Autowired
    private WorkspaceService workspaceService;
@@ -122,6 +131,67 @@
        this.departmentRepository.flush();
    }
    //  프로젝트에 참여하는 부서 정보를 조회한다.
    @Override
    @Transactional(readOnly = true)
    public List<Map<String, Object>> findProjectDepartment(Project project) {
        DepartmentCondition departmentCondition = new DepartmentCondition();
        departmentCondition.setProjectId(project.getId());
        return this.departmentMapper.findProjectDepartment(departmentCondition);
    }
    //  프로젝트에 참여하는 부서 목록을 가져온다.
    @Override
    @Transactional(readOnly = true)
    public void findProjectDepartment(Map<String, Object> resJsonData, DepartmentCondition departmentCondition) {
        ProjectRole projectRole = this.projectRoleService.findByProjectIdAndRoleType(departmentCondition.getProjectId(), ProjectRole.TYPE_DEFAULT);
        List<ProjectRoleDepartment> projectRoleDepartments = this.projectRoleDepartmentService.findByProjectRoleId(projectRole.getId());
        List<DepartmentVo> departmentVos = Lists.newArrayList();
        for (ProjectRoleDepartment projectRoleDepartment : projectRoleDepartments) {
            DepartmentVo departmentVo = ConvertUtil.copyProperties(projectRoleDepartment.getDepartment(), DepartmentVo.class);
            departmentVo.setByName(departmentVo.getDepartmentName());
            departmentVos.add(departmentVo);
        }
        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);
    }
    //  워크플로우에 속해있는 부서 목록 조회
    @Override
    @Transactional(readOnly = true)
    public void findWorkflowDepartment(Map<String, Object> resJsonData, DepartmentCondition departmentCondition) {
        List<DepartmentVo> departmentVos = findWorkflowDepartment(departmentCondition.getIssueTypeId());
        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);
    }
    //  워크플로우에 속해있는 부서 목록 조회
    @Override
    @Transactional(readOnly = true)
    public List<DepartmentVo> findWorkflowDepartment(Long issueTypeId) {
        List<WorkflowDepartment> workflowDepartmentList = this.findWorkflowDepartmentByIssueTypeId(issueTypeId);
        List<DepartmentVo> departmentVos = Lists.newArrayList();
        if(workflowDepartmentList != null && workflowDepartmentList.size()>0){
            for(WorkflowDepartment workflowDepartment : workflowDepartmentList){
                DepartmentVo departmentVo = ConvertUtil.copyProperties(workflowDepartment.getDepartment(), DepartmentVo.class);
                departmentVo.setByName(departmentVo.getDepartmentName());
                departmentVos.add(departmentVo);
            }
        }
        return departmentVos;
    }
    // 이슈 유형(워크플로우)에 있는 담당부서 조회
    private List<WorkflowDepartment> findWorkflowDepartmentByIssueTypeId(Long issueTypeId) {
        Long workflowId = this.getWorkflowId(issueTypeId);
        return this.workflowDepartmentService.find(workflowId);
    }
    private Long getWorkflowId(Long issueTypeId) {
        IssueType issueType = this.issueTypeService.getIssueType(issueTypeId);
        return issueType.getWorkflow().getId();
    }
    // 부서 목록을 엑셀로 다운로드 한다.
    @Override
@@ -151,7 +221,10 @@
        excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentDescription", this.messageAccessor.message("department.departmentDescription"), 20, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentCount", this.messageAccessor.message("department.departmentCount"), 3, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.setDatas(departmentVos);
        //  DepartmentVos 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
        List<Map<String, Object>> convertExcelViewToDepartmentMaps = this.convertExcelViewToDepartmentVos(departmentVos);
        excelInfo.setDatas(convertExcelViewToDepartmentMaps);
        model.addAttribute(Constants.EXCEL, excelInfo);
        return new ModelAndView(this.excelView);
@@ -163,6 +236,30 @@
        return this.departmentMapper.countInDepartment(id) > 0;
    }
    //  DepartmentVos 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
    private List<Map<String, Object>> convertExcelViewToDepartmentVos(List<DepartmentVo> departmentVos) {
        List<Map<String, Object>> results = Lists.newArrayList();
        for (DepartmentVo departmentVo : departmentVos){
            try {
                Map<String, Object> result = new HashMap<>();
                result.put("departmentName", departmentVo.getDepartmentName());
                result.put("departmentCount", departmentVo.getDepartmentCount());
                String description= "";
                if(departmentVo.getDepartmentDescription() != null){
                    description = Jsoup.parse(departmentVo.getDepartmentDescription()).text(); //HTML 태그 제거
                    description = description.replaceAll("\\<.*?>", ""); //공백 제거
                }
                result.put("departmentDescription", description);
                results.add(result);
            } catch (Exception e) {
                log.error("엑셀 다운로드 오류 발생");
            }
        }
        return results;
    }
    // 사용자 부서 ID로 조회한다.
    @Override
@@ -196,7 +293,7 @@
            departmentVo.setByName(departmentVo.getDepartmentName());
            departmentVos.add(departmentVo);
        }
        int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1;
        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);