From 64e60497047f9bf85e0fcff2e6c0718b8eb16af2 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 목, 06 1월 2022 18:04:09 +0900
Subject: [PATCH] - 엑셀 임포트시 워크플로우에 담당부서가 없을경우도 등록 가능하게 수정 - 엑셀 임포트시 상위이슈 선택 안해도 등록 가능

---
 src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java |   69 ++++++++++++++++++++++++++--------
 1 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
index 05f35c1..557f603 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -14,6 +14,7 @@
 import kr.wisestone.owl.exception.OwlRuntimeException;
 import kr.wisestone.owl.mapper.DepartmentMapper;
 import kr.wisestone.owl.mapper.IssueMapper;
+import kr.wisestone.owl.mapper.IssueRelationMapper;
 import kr.wisestone.owl.mapper.ProjectMapper;
 import kr.wisestone.owl.repository.IssueRelationRepository;
 import kr.wisestone.owl.repository.IssueRepository;
@@ -33,6 +34,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.messaging.simp.SimpMessagingTemplate;
@@ -194,6 +197,9 @@
 
     @Autowired
     private WorkflowDepartmentRepository workflowDepartmentRepository;
+
+    @Autowired
+    private IssueRelationMapper issueRelationMapper;
 
     @Override
     protected JpaRepository<Issue, Long> getRepository() {
@@ -1468,11 +1474,22 @@
     @Transactional(readOnly = true)
     public void detailIssue(Map<String, Object> resJsonData, IssueCondition issueCondition) {
         IssueVo issueVo = new IssueVo();
+        Pageable relPageable = issueCondition.getRelPageable();
+        Pageable downPageable = issueCondition.getDownPageable();
 
         if (issueCondition.getId() != null) {
             Issue issue = this.getIssue(issueCondition.getId());
             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());
 
             switch (issueCondition.getDeep()) {
                 case "01": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦遺��꽌, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� �뀑�똿�븳�떎.
@@ -1489,7 +1506,6 @@
                     this.setIssueCustomFields(issue, issueVo);  //  �궗�슜�옄 �젙�쓽 �븘�뱶 媛� �젙蹂� �뀑�똿
                     this.setRelationIssue(issue, issueVo);        //�뿰愿� �씪媛� �뀑�똿
                     this.setDownIssues(issue, issueVo); //�븯�쐞 �씠�뒋 �꽭�똿
-
                     break;
 
                 case "02": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦�옄, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂�, �뙎湲�, 湲곕줉�쓣 �뀑�똿�븳�떎.
@@ -1499,7 +1515,6 @@
                     break;
             }
         }
-
         //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
         log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_DETAIL));
 
@@ -1528,8 +1543,13 @@
 
     // �븯�쐞 �씠�뒋 �젙蹂대�� �뀑�똿�븳�떎
     private void setDownIssues(Issue issue, IssueVo issueVo) {
-        List<Issue> downIssues = this.issueRepository.findByParentIssueId(issue.getId());
-        if(downIssues != null && downIssues.size()>0){
+        //List<Issue> downIssues = this.issueRepository.findByParentIssueId(issue.getId());
+        int startPage = (int) Math.floor(issueVo.getDownPage()/issueVo.getDownPageSize());
+        Pageable pageable = PageRequest.of(startPage, issueVo.getDownPageSize());
+        Page<Issue> downIssues = this.issueRepository.findByParentIssueId(issue.getId(), pageable);
+        issueVo.setDownTotalPage(downIssues.getTotalPages());
+        issueVo.setDownTotalCount(downIssues.getTotalElements());
+        if(downIssues != null){
             List<IssueVo> resultList = new ArrayList<>();
             for(Issue downIssue : downIssues){
                 IssueVo downIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
@@ -1629,13 +1649,18 @@
 
     // �뿰愿� �씠�뒋 �젙蹂대�� �뀑�똿�븳�떎
     private void setRelationIssue(Issue issue, IssueVo issueVo) {
-        Set<IssueRelation> issueRelations = issue.getIssueRelations();
-        if (issue != null && issueVo != null && issueRelations.size() > 0) {
-            for (IssueRelation issueRelation : issueRelations) {
-                IssueRelationVo issueRelationVo = ConvertUtil.copyProperties(issueRelation, IssueRelationVo.class);
+        //Set<IssueRelation> issueRelations = issue.getIssueRelations();
+        List<Map<String, Object>> results = this.issueRelationMapper.findByIssueId(issueVo);
+        Long totalCount = this.issueRelationMapper.count(issueVo);
 
-                Issue relationIssue = issueRelation.getRelationIssue();
+        int totalPage = (int) Math.ceil((totalCount - 1) / issueVo.getRelPageSize()) + 1;
+        issueVo.setRelTotalPage(totalPage);
+        issueVo.setRelTotalCount(totalCount);
 
+        if (issue != null && issueVo != null && results.size() > 0) {
+            for (Map<String, Object> result : results) {
+                IssueRelationVo issueRelationVo = ConvertUtil.convertMapToClass(result, IssueRelationVo.class);
+                Issue relationIssue = this.findOne(issueRelationVo.getId());
                 IssueVo relIssueVo = ConvertUtil.copyProperties(relationIssue, IssueVo.class);
                 Project project = this.projectService.getProject(relationIssue.getProject().getId());
                 relIssueVo.setProjectId(project.getId());
@@ -2941,7 +2966,7 @@
 
             Workspace workspace = this.workspaceService.getWorkspace(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());  //  �씠�뒋瑜� �꽔�쑝�젮�뒗 �뾽臾� 怨듦컙
             //  �씠�뒋�쓽 二쇱슂 �냽�꽦�쓣 map �뿉 ���옣�븯�뿬 �뿊�� import �뿉�꽌 吏��젙�븳 ���긽(�씠�뒋 �냽�꽦)�쓣 鍮좊Ⅴ寃� 李얠쓣 �닔 �엳寃� �븳�떎.
-            this.IssueAttributeMapToList(priorityMaps, severityMaps, departmentMaps, customFieldMaps, issueTypeCustomFieldMaps);
+            this.IssueAttributeMapToList(issueForm, priorityMaps, severityMaps, departmentMaps, customFieldMaps, issueTypeCustomFieldMaps);
             //  0.237 - 0.230
 
             List<IssueForm> issueForms = Lists.newArrayList();
@@ -3022,7 +3047,9 @@
                 issue.setIssueType(issueType);
                 issue.setProject(project);
                 issue.setIssueNumber(issueNumber);
-                issue.setParentIssue(this.getIssue(saveIssueForm.getParentIssueId()));
+                if (saveIssueForm.getParentIssueId() != null && saveIssueForm.getParentIssueId() > -1) {
+                    issue.setParentIssue(this.getIssue(saveIssueForm.getParentIssueId()));
+                }
 
                 issue = this.issueRepository.saveAndFlush(issue);
 
@@ -3033,10 +3060,12 @@
                 issueDepartment.setWorkspace(workspace);
 
                 List<Long> departmentsIds = this.workflowDepartmentService.findFirstDepartmentIds(workflow);
-                for (Long departmentId : departmentsIds) {
-                    issueDepartment.setDepartment(this.departmentService.getDepartment(departmentId));
+                if (departmentsIds != null && departmentsIds.size() > 0) {
+                    for (Long departmentId : departmentsIds) {
+                        issueDepartment.setDepartment(this.departmentService.getDepartment(departmentId));
+                    }
+                    issue.addIssueDepartment(issueDepartment);
                 }
-                issue.addIssueDepartment(issueDepartment);
 
                 saveIssueForm.setIssueStatusId(issueStatus.getId());
             }
@@ -3181,8 +3210,16 @@
     }
 
     //  �씠�뒋�쓽 二쇱슂 �냽�꽦�쓣 map �뿉 ���옣�븯�뿬 �뿊�� import �뿉�꽌 吏��젙�븳 ���긽(�씠�뒋 �냽�꽦)�쓣 鍮좊Ⅴ寃� 李얠쓣 �닔 �엳寃� �븳�떎.
-    private void IssueAttributeMapToList(Map<String, Priority> priorityMaps, Map<String, Severity> severityMaps,
+    private void IssueAttributeMapToList(IssueForm issueForm, Map<String, Priority> priorityMaps, Map<String, Severity> severityMaps,
                                          Map<String, DepartmentVo> departmentMaps, Map<String, CustomField> customFieldMaps,Map<String, Long> issueTypeCustomFieldMaps) {
+
+        Project project = this.projectService.getProject(issueForm.getProjectId());
+
+        for (IssueTypeCustomField issueTypeCustomField : project.getIssueTypeCustomFields()) {
+            //  鍮좊Ⅴ寃� 李얘린 �쐞�빐 �씠�뒋 ���엯 �븘�씠�뵒 + �궗�슜�옄 �젙�쓽 �븘�뱶 �븘�씠�뵒瑜� �궎濡� �븳�떎.
+            String makeKey = issueTypeCustomField.getIssueType().getId().toString() + issueTypeCustomField.getCustomField().getId().toString();
+            issueTypeCustomFieldMaps.put(makeKey, issueTypeCustomField.getId());
+        }
 
         //  �슦�꽑�닚�쐞瑜� 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
         List<Priority> priorities = this.priorityService.findByWorkspaceId();
@@ -3367,7 +3404,7 @@
 
             //  媛믪씠 怨듬갚�씠硫� 以묒�
             String cellValue = CommonUtil.convertExcelStringToCell(cell);
-            if (StringUtils.isEmpty(cellValue)) {
+            if (StringUtils.isEmpty(cellValue) || !cell.toString().equals("null")) {
                 return;
             }
 

--
Gitblit v1.8.0