OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-01-17 8783774ccda8050a0711eab992cb4f8c65937ce1
src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -11,6 +11,8 @@
import kr.wisestone.owl.domain.enumType.EmailType;
import kr.wisestone.owl.domain.enumType.IssueHistoryType;
import kr.wisestone.owl.domain.enumType.IssueStatusType;
import kr.wisestone.owl.exception.ApiAuthException;
import kr.wisestone.owl.exception.ApiParameterException;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.mapper.DepartmentMapper;
import kr.wisestone.owl.mapper.IssueMapper;
@@ -83,6 +85,9 @@
    @Autowired
    private CompanyFieldService companyFieldService;
    @Autowired
    private CompanyFieldCategoryService companyFieldCategoryService;
    @Autowired
    private IspFieldService ispFieldService;
@@ -207,6 +212,9 @@
    @Autowired
    private IssueRelationMapper issueRelationMapper;
    @Autowired
    private WorkflowTransitionService workflowTransitionService;
    @Override
    protected JpaRepository<Issue, Long> getRepository() {
        return this.issueRepository;
@@ -235,14 +243,14 @@
    private IssueForm convertToIssueForm(IssueApiForm issueApiForm, User user) {
        if (issueApiForm.getIssueTypeId() == null) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ISSUE_TYPE_ERROR));
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ISSUE_TYPE_ERROR));
        }
        IssueForm issueForm = ConvertUtil.copyProperties(issueApiForm, IssueForm.class);
//        issueForm.setFiles(issueApiForm.getFiles());
        IssueType issueType = this.issueTypeService.getIssueType(issueApiForm.getIssueTypeId());
        if (issueType == null){
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ISSUE_TYPE_ERROR));
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ISSUE_TYPE_ERROR));
        }
        Workflow workflow = issueType.getWorkflow();
@@ -256,13 +264,16 @@
                }
            }
        } else if (issueApiForm.getIssueStatusId() == null){
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_ISSUE_STATUS_NOT_EXIST));
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_ISSUE_STATUS_NOT_EXIST));
        } else if (!this.workflowTransitionService.contains(issueApiForm.getIssueStatusId(), workflow.getId())) {
            //이슈 상태 유효성 확인
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_ISSUE_STATUS_NOT_EXIST_IN_WORKFLOW));
        }
        // 프로젝트 입력
        Project project = issueType.getProject();
        if (project == null){
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_PROJECT_ERROR));
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_PROJECT_ERROR));
        }
        issueForm.setProjectId(project.getId());
@@ -321,7 +332,7 @@
            return issueForm;
        } else {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_USER_ERROR));
            throw new ApiAuthException(this.messageAccessor.getMessage(MsgConstants.API_USER_ERROR));
        }
    }
@@ -367,6 +378,7 @@
                issueForm.setIssueHostingFields(issueHostingFields);
            }
        }
        return issueForm;
    }
@@ -930,22 +942,19 @@
            return Lists.newArrayList();
        }
        //  튜닝 전 - 1.3 / 1.2 / 1.1
        //  튜닝 후 (단일/다중 검색 조건 3개 기준) - 0.49 / 0.41 / 0.47 / 0.41
        List<IssueVo> issueVos = Lists.newArrayList();  //  이슈 목록 데이터 저장 컬렉션
        //  사용자 정의 필드로 검색한 이슈 아이디 값
        List<String> issueKeys = Lists.newArrayList(issueIds);
        issueCondition.setIssueIds(issueKeys);
        issueCondition.setLoginUserId(this.webAppUtil.getLoginId());
        issueCondition.setWorkspaceId(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());
        User user = this.webAppUtil.getLoginUserObject();
        issueCondition.setLoginUserId(user.getId());
        issueCondition.setWorkspaceId(user.getLastWorkspaceId());
        List<Map<String, Object>> results = Lists.newArrayList();
        Long totalCount = 0L;
        UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
//        UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
//        if (!this.userWorkspaceService.checkWorkspaceManager(user)
//                && !MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE)) { //최고관리자 & 프로젝트,이슈 관리자 일 경우 모든 이슈 보기
@@ -955,17 +964,18 @@
//            results = this.issueMapper.findByDepartment(issueCondition);
//            totalCount = this.issueMapper.countByDepartment(issueCondition);
//        }*/
//        StopWatch serviceStart = new StopWatch();
//        serviceStart.start();
        results = this.issueMapper.find(issueCondition);
//         serviceStart.stop();
//        log.error("result : " + serviceStart.toString());
//        serviceStart = new StopWatch();
//        serviceStart.start();
        totalCount = this.issueMapper.count(issueCondition);
        //  튜닝 전 - 0.8, 0.9, 0.9, 0.9, 0.9
        /*StopWatch serviceStart = new StopWatch();
        serviceStart.start();*/
        //  튜닝 전 - 1.1, 1.1, 1.3, 1.2
        /*serviceStart.stop();
        log.debug("serviceENd1 : " + serviceStart.getTime());*/
//        serviceStart.stop();
//        log.error("totalCount : " + serviceStart.toString());
        int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
        //  이슈 아이디 초기화
@@ -981,8 +991,8 @@
            this.setDownIssues(user, issueVos);
            this.setRelationIssues(issueVos);
        }
        this.setCountDownIssues(issueVos);
        this.setCountDownIssues(issueVos);
        this.SetWorkflowDepartment(issueVos); //워크플로우에 설정한 담당부서 가져오기
        resJsonData.put(Constants.RES_KEY_CONTENTS, issueVos);
@@ -1487,14 +1497,16 @@
            issueVo = ConvertUtil.copyProperties(issue, IssueVo.class);
            User user = this.webAppUtil.getLoginUserObject();
            issueVo.setRelPageNumber(relPageable.getPageNumber());
            issueVo.setRelPageSize(relPageable.getPageSize());
            issueVo.setRelPage(relPageable.getPageNumber() * relPageable.getPageSize());
            issueVo.setDownPageNumber(downPageable.getPageNumber());
            issueVo.setDownPage(downPageable.getPageNumber() * downPageable.getPageSize());
            issueVo.setDownPageSize(downPageable.getPageSize());
            if (relPageable != null) {
                issueVo.setRelPageNumber(relPageable.getPageNumber());
                issueVo.setRelPageSize(relPageable.getPageSize());
                issueVo.setRelPage(relPageable.getPageNumber() * relPageable.getPageSize());
            }
            if (downPageable != null) {
                issueVo.setDownPageNumber(downPageable.getPageNumber());
                issueVo.setDownPage(downPageable.getPageNumber() * downPageable.getPageSize());
                issueVo.setDownPageSize(downPageable.getPageSize());
            }
            switch (issueCondition.getDeep()) {
                case "01": //  프로젝트, 이슈 유형, 이슈 상태,  우선순위, 중요도, 담당부서, 첨부파일, 사용자 정의 필드 정보를 셋팅한다.
@@ -1515,7 +1527,7 @@
                case "02": //  프로젝트, 이슈 유형, 이슈 상태,  우선순위, 중요도, 담당자, 첨부파일, 사용자 정의 필드 정보, 댓글, 기록을 셋팅한다.
                    this.setIssueDetail(issueVo, issue, user);    //  이슈 상세 정보를 셋팅한다.
                    this.setIssueTableConfigs(issue, issueVo);
                    this.setIssueTableConfigs(issue, issueVo, issueCondition);
                    issueVo.setProjectVo(ConvertUtil.copyProperties(issue.getProject(), ProjectVo.class));
                    break;
            }
@@ -1527,8 +1539,9 @@
    }
    // 테이블 설정 셋팅
    private void setIssueTableConfigs(Issue issue, IssueVo issueVo) {
        Long IssueTypeId = issue.getIssueType().getId();
    private void setIssueTableConfigs(Issue issue, IssueVo issueVo, IssueCondition issueCondition) {
        //Long IssueTypeId = issue.getIssueType().getId();
        Long IssueTypeId = issueCondition.getIssueTypeId();
        for (int tableConfigType : IssueTableConfig.IssueTableTypes) {
            if (tableConfigType != IssueTableConfig.ISSUE_TABLE_TYPE_MAIN) {
@@ -1552,7 +1565,10 @@
        List<Issue> downIssueList = this.issueRepository.findByParentIssueId(issue.getId());
        if(downIssueList != null && downIssueList.size() > 0) {
            int startPage = (int) Math.floor(issueVo.getDownPage()/issueVo.getDownPageSize());
            int startPage = 0;
            if (issueVo.getDownPage() != 0) {
                startPage = (int) Math.floor(issueVo.getDownPage()/issueVo.getDownPageSize());
            }
            Pageable pageable = PageRequest.of(startPage, issueVo.getDownPageSize());
            downIssues = this.issueRepository.findByParentIssueId(issue.getId(), pageable);
        }
@@ -1576,6 +1592,9 @@
                this.setIssueCustomFields(downIssue, downIssueVo);   // 사용자정의필드 정보 세팅
                this.setIssueHistory(downIssue, downIssueVo);   //  이슈 기록 정보 셋팅
                this.setIssueComments(downIssue, downIssueVo);  //  댓글 정보 셋팅
                this.setIssueCompanyField(downIssue, downIssueVo);  //업체 정보 세팅
                this.setIssueIspField(downIssue, downIssueVo);  //ISP 정보 세팅
                this.setIssueHostingField(downIssue, downIssueVo);  //HOSTING 정보 세팅
                downIssueVo.setModifyPermissionCheck(issueVo.getModifyPermissionCheck());
@@ -1589,6 +1608,11 @@
    @Override
    @Transactional(readOnly = true)
    public void setIssueDetail(IssueVo issueVo, Issue issue, User user) {
        //  이슈 수정 권한을 갖고 있는지 확인
        if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, issueVo.getDepartmentVos())) {
            issueVo.setModifyPermissionCheck(Boolean.TRUE);
        }
        issueVo.setProjectVo(ConvertUtil.copyProperties(issue.getProject(), ProjectVo.class));
        issueVo.setIssueTypeVo(ConvertUtil.copyProperties(issue.getIssueType(), IssueTypeVo.class));
        IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(issue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
@@ -1624,11 +1648,6 @@
        this.setIssueIspField(issue, issueVo);  //ISP 정보 세팅
        this.setIssueHostingField(issue, issueVo);  //HOSTING 정보 세팅
        this.setParentIssue(issue,issueVo); //상위 이슈 정보 세팅
        //  이슈 수정 권한을 갖고 있는지 확인
        if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, issueVo.getDepartmentVos())) {
            issueVo.setModifyPermissionCheck(Boolean.TRUE);
        }
    }
    //  상위일감 정보 추가
@@ -1670,7 +1689,7 @@
            issueVo.setRelTotalCount(totalCount);
            for (Map<String, Object> result : results) {
                IssueRelationVo issueRelationVo = ConvertUtil.convertMapToClass(result, IssueRelationVo.class);
                Issue relationIssue = this.findOne(issueRelationVo.getId());
                Issue relationIssue = this.findOne(MapUtil.getLong(result, "relationIssueId"));
                IssueVo relIssueVo = ConvertUtil.copyProperties(relationIssue, IssueVo.class);
                Project project = this.projectService.getProject(relationIssue.getProject().getId());
                relIssueVo.setProjectId(project.getId());
@@ -1692,6 +1711,25 @@
                this.setRegister(relationIssue, relIssueVo); // 등록자
                this.setIssueDepartment(relationIssue, relIssueVo);  //  담당부서 정보 셋팅
                this.setIssueCustomFields(relationIssue, relIssueVo);   // 사용자정의필드 정보 세팅
                Set<IssueCompany> issueCompanies = relationIssue.getIssueCompanies();
                Iterator<IssueCompany> itrCompany = issueCompanies.iterator();
                while (itrCompany.hasNext()) {
                    issueRelationVo.addIssueCompanyVo(ConvertUtil.copyProperties(itrCompany.next(), IssueCompanyVo.class));
                }
                Set<IssueIsp> issueIsps = relationIssue.getIssueIspFields();
                Iterator<IssueIsp> itrIsp = issueIsps.iterator();
                while (itrIsp.hasNext()) {
                    issueRelationVo.addIssueIspVo(ConvertUtil.copyProperties(itrIsp.next(), IssueIspVo.class));
                }
                Set<IssueHosting> issueHostings = relationIssue.getIssueHostingFields();
                Iterator<IssueHosting> itrHosting = issueHostings.iterator();
                while (itrHosting.hasNext()) {
                    issueRelationVo.addIssueHostingVo(ConvertUtil.copyProperties(itrHosting.next(), IssueHostingVo.class));
                }
                issueVo.addIssueRelationVo(issueRelationVo);
            }
        } else {
@@ -1824,6 +1862,7 @@
            issueCustomFieldValueCondition.setUseValue(concatUseValue);
            issueCustomFieldValueCondition.setUseValues(userValues);
            issueCustomFieldValueCondition.setIssueTypeId(issueApiform.getIssueTypeId());
            issueCustomFieldValueCondition.setIssueStatusType("CLOSE");
            List<Map<String, Object>> results = this.issueMapper.findByCustomFieldValue(issueCustomFieldValueCondition);
            if (results != null && results.size() > 0) {
                for (Map<String, Object> result : results) {
@@ -2789,6 +2828,26 @@
            CompanyField companyField = issueCompany.getCompanyField();
            if (companyField != null) {
                issueCompanyVo.setCompanyId(issueCompany.getCompanyField().getId());
                if (issueCompany.getCompanyTypeId() != null && issueCompany.getCompanyTypeId() != -1) {
                    CompanyFieldCategory companyType = this.companyFieldCategoryService.find(issueCompany.getCompanyTypeId());
                    issueCompanyVo.setCompanyTypeName(companyType.getUseValue());
                }
                if (issueCompany.getParentSectorId() != null && issueCompany.getParentSectorId() != -1) {
                    CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(issueCompany.getParentSectorId());
                    issueCompanyVo.setParentSectorName(parentSector.getUseValue());
                }
                if (issueCompany.getChildSectorId() != null && issueCompany.getChildSectorId() != -1) {
                    CompanyFieldCategory childSector = this.companyFieldCategoryService.find(issueCompany.getChildSectorId());
                    issueCompanyVo.setChildSectorName(childSector.getUseValue());
                }
                if (issueCompany.getRegionId() != null && issueCompany.getRegionId() != -1) {
                    CompanyFieldCategory region = this.companyFieldCategoryService.find(issueCompany.getRegionId());
                    issueCompanyVo.setRegionName(region.getUseValue());
                }
                if (issueCompany.getStatusId() != null && issueCompany.getStatusId() != -1) {
                    CompanyFieldCategory status = this.companyFieldCategoryService.find(issueCompany.getStatusId());
                    issueCompanyVo.setStatusName(status.getUseValue());
                }
            }
            issueCompanyVos.add(issueCompanyVo);
        }
@@ -3638,12 +3697,12 @@
        if (emailCommonForm.getSendEmails().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SEND_USER));
        } else if (emailCommonForm.getIssueId() == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_EXIST));
        }
        Issue issue = this.getIssue(emailCommonForm.getIssueId());
        Issue issue = null;
        if(emailCommonForm.getIssueId() != null) {
            issue = this.getIssue(emailCommonForm.getIssueId());
        }
        //  발신자 표시
        User user = this.webAppUtil.getLoginUserObject();
@@ -3660,8 +3719,10 @@
        }
        this.systemEmailService.sendEmail(emailCommonForm.getTitle(), emailCommonForm.getDescription(), sendMails, null);
        this.issueHistoryService.detectSendIssueMail(IssueHistoryType.SEND, emailCommonForm.getSendEmails(), sb);
        this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.SEND, sb.toString());
        if (issue != null) {
            this.issueHistoryService.detectSendIssueMail(IssueHistoryType.SEND, emailCommonForm.getSendEmails(), sb);
            this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.SEND, sb.toString());
        }
    }
    //  예약 발생 이슈를 실행한다