From 3bdf2a1f2757de8ab6570508385d89124243943c Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 금, 10 12월 2021 15:34:13 +0900
Subject: [PATCH] 일반회원 대시보드 오류 해결

---
 src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java |  154 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 119 insertions(+), 35 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 f0022e5..5f53d71 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -5,10 +5,7 @@
 import kr.wisestone.owl.common.ExcelConditionCheck;
 import kr.wisestone.owl.common.IssueCustomFieldValueFormComparator;
 import kr.wisestone.owl.config.CommonConfiguration;
-import kr.wisestone.owl.constant.Constants;
-import kr.wisestone.owl.constant.ElasticSearchConstants;
-import kr.wisestone.owl.constant.MsgConstants;
-import kr.wisestone.owl.constant.UsePartner;
+import kr.wisestone.owl.constant.*;
 import kr.wisestone.owl.data.CheckIssueData;
 import kr.wisestone.owl.domain.*;
 import kr.wisestone.owl.domain.enumType.CustomFieldType;
@@ -152,6 +149,9 @@
 
     @Autowired
     private UserWorkspaceService userWorkspaceService;
+
+    @Autowired
+    private UserLevelService userLevelService;
 
     @Autowired
     private WorkflowDepartmentService workflowDepartmentService;
@@ -718,11 +718,11 @@
     public List<IssueVo> findIssue(Map<String, Object> resJsonData, IssueCondition issueCondition, Pageable pageable) {
 
         //  寃��깋 議곌굔�쓣 留뚮뱺�떎
-        if (!this.makeIssueSearchCondition(issueCondition, Lists.newArrayList("01", "02", "03"), pageable)) {
+        /*if (!this.makeIssueSearchCondition(issueCondition, Lists.newArrayList("01", "02", "03"), pageable)) {
             //  �씠�뒋 紐⑸줉�쓣 李얠� 紐삵븷 寃쎌슦 湲곕낯 �젙蹂대줈 由ы꽩�븳�떎.
             this.notFoundIssueList(resJsonData, pageable);
             return Lists.newArrayList();
-        }
+        }*/
 
         Set<String> issueIds = new HashSet<>(); //  �궗�슜�옄 �젙�쓽 �븘�뱶 寃��깋�떆 �굹�삤�뒗 �씠�뒋 �븘�씠�뵒 ���옣 而щ젆�뀡
 
@@ -745,10 +745,13 @@
         issueCondition.setWorkspaceId(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());
         User user = this.webAppUtil.getLoginUserObject();
 
+
         List<Map<String, Object>> results = Lists.newArrayList();
         Long totalCount = 0L;
+        UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
 
-        if (this.userWorkspaceService.checkWorkspaceManager(user)) {
+        if (this.userWorkspaceService.checkWorkspaceManager(user)
+                || MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE_PROJECT_ALL)) {
             results = this.issueMapper.find(issueCondition);
             totalCount = this.issueMapper.count(issueCondition);
         } else{
@@ -768,6 +771,7 @@
 
         int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
         //  �씠�뒋 �븘�씠�뵒 珥덇린�솕
+        issueCondition.setIsApi(issueCondition.getIsApi());
         issueCondition.setIssueIds(Lists.newArrayList());
         //  Map �뿉 �엳�뒗 �뜲�씠�꽣瑜� IssueVo �뜲�씠�꽣濡� 蹂��솚�븳�떎.
         this.setMapToIssueVo(results, issueVos, issueCondition, user);
@@ -1034,6 +1038,7 @@
         condition.setWorkspaceId(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());
         projectCondition.setWorkspaceId(condition.getWorkspaceId());
 
+
         //  �봽濡쒖젥�듃 �궎媛� 議댁옱�븷 寃쎌슦 �봽濡쒖젥�듃 �궎�뿉 �빐�떦�븯�뒗 �봽濡쒖젥�듃瑜� 議고쉶�븯怨� 寃��깋 議곌굔�뿉 �뀑�똿�븳�떎.
         if (!this.getProjectByProjectKey(condition.getProjectKey(), condition)) {
             return false;
@@ -1042,7 +1047,9 @@
         //  �봽濡쒖젥�듃瑜� �꽑�깮�븯吏� �븡�븯�쑝硫� �빐�떦 �뾽臾� 怨듦컙�뿉�꽌 李몄뿬�븯怨� �엳�뒗 �봽濡쒖젥�듃瑜� 李얜뒗�떎.
         if (condition.getProjectIds().size() < 1) {
             List<Map<String, Object>> projects = null;
-            if (this.userWorkspaceService.checkWorkspaceManager(user)) {
+            UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
+            if (this.userWorkspaceService.checkWorkspaceManager(user)
+                    || MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE_PROJECT_ALL)) {
                 projects = this.projectMapper.findByWorkspaceManagerAll(projectCondition);
             } else  {
                 projects = this.projectService.findByWorkspaceIdAndIncludeProjectAll(projectCondition);
@@ -1872,6 +1879,9 @@
         //hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ASSIGNEE, issueVo, issueUserVos);
         //  �떞�떦�옄媛� �뾾�쑝硫� 紐⑤뱺 �궗�슜�옄媛� �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
 
+        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ALL_ISSUE_MANAGER, issueVo, null, null, user);
+        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ALL_PROJECT_MANAGER, issueVo, null, null, user);
+
         return hasPermission;
     }
 
@@ -2068,49 +2078,123 @@
         List<Issue> removeIssues = Lists.newArrayList();
 
         for (Long issueId : issueForm.getRemoveIds()) {
+            //�븯�쐞�씠�뒋 泥댄겕
+            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueId);
+            if(downIssues != null && downIssues.size() > 0){
+                for(Issue downIssue : downIssues){
+                    if(downIssue.getParentIssue() != null){
+                        downIssue.setParentIssue(null);
+                    }
+                }
+            }
+
             Issue issue = this.issueRemoves(issueId, user);
             removeIssues.add(issue);
         }
 
-        if (removeIssues.size() > 0) {
-            //this.issueRepository.deleteAll(removeIssues);
-        }
+        /*if (removeIssues.size() > 0) {
+            this.issueRepository.deleteAll(removeIssues);
+        }*/
 
         //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
         log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_REMOVE));
     }
 
+    //  �씠�뒋瑜� �궘�젣�븳�떎.
+    @Override
+    @Transactional
+    public void removeAllIssues(IssueForm issueForm) {
+        //  �궗�슜�븯怨� �엳�뒗 �뾽臾� 怨듦컙�씠 �솢�꽦 �긽�깭�씤吏� �솗�씤�븳�떎. �궗�슜 怨듦컙�뿉�꽌 濡쒓렇�씤�븳 �궗�슜�옄媛� 鍮꾪솢�꽦�씤吏� �솗�씤�븳�떎.
+        User user = this.webAppUtil.getLoginUserObject();
+        this.workspaceService.checkUseWorkspace();
+
+        if (issueForm.getRemoveIds().size() < 1) {
+            throw new OwlRuntimeException(
+                    this.messageAccessor.getMessage(MsgConstants.ISSUE_REMOVE_NOT_SELECT));
+        }
+
+        List<Issue> removeIssues = Lists.newArrayList();
+
+        for (Long issueId : issueForm.getRemoveIds()) {
+            //�븯�쐞�씠�뒋 泥댄겕
+            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueId);
+            if(downIssues != null && downIssues.size() > 0){
+                for(Issue downIssue : downIssues){
+                    Long downIssueId = downIssue.getId();
+                    downIssue = this.issueRemoves(downIssueId, user);
+                    removeIssues.add(downIssue);
+                }
+            }
+            Issue issue = this.issueRemoves(issueId, user);
+            removeIssues.add(issue);
+        }
+        //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
+        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_REMOVE));
+    }
+
+    //  �븯�쐞�씠�뒋瑜� �궘�젣�븳�떎.
+    @Override
+    @Transactional
+    public void removeDownIssues(IssueForm issueForm) {
+        //  �궗�슜�븯怨� �엳�뒗 �뾽臾� 怨듦컙�씠 �솢�꽦 �긽�깭�씤吏� �솗�씤�븳�떎. �궗�슜 怨듦컙�뿉�꽌 濡쒓렇�씤�븳 �궗�슜�옄媛� 鍮꾪솢�꽦�씤吏� �솗�씤�븳�떎.
+        User user = this.webAppUtil.getLoginUserObject();
+        this.workspaceService.checkUseWorkspace();
+
+        if (issueForm.getRemoveIds().size() < 1) {
+            throw new OwlRuntimeException(
+                    this.messageAccessor.getMessage(MsgConstants.ISSUE_REMOVE_NOT_SELECT));
+        }
+
+        List<Issue> removeIssues = Lists.newArrayList();
+        Long downIssueId = 0L;
+        for (Long issueId : issueForm.getRemoveIds()) {
+            //�궘�젣 �븷 �씠�뒋�쓽 �븯�쐞�씠�뒋 泥댄겕
+            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueId);
+            if(downIssues != null && downIssues.size() > 0){
+                for(Issue downIssue : downIssues){
+                    downIssueId = downIssue.getId();
+                }
+            }
+            Issue issue = this.issueRemoves(downIssueId, user);
+            removeIssues.add(issue);
+        }
+        //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
+        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_REMOVE));
+    }
+
     private Issue issueRemoves(Long issueId, User user) {
-        Issue issue = this.getIssue(issueId);
-        //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
-        this.verifyIssueModifyPermission(issue, user);
+        Issue issue = this.findOne(issueId);
+        if(issue != null){
+            //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
+            this.verifyIssueModifyPermission(issue, user);
 
-        //  �씠�뒋 泥⑤� �뙆�씪�쓣 �궘�젣�븳�떎.
-        if (issue.getAttachedFiles().size() > 0) {
-            List<Long> attachedFileIds = Lists.newArrayList();
+            //  �씠�뒋 泥⑤� �뙆�씪�쓣 �궘�젣�븳�떎.
+            if (issue.getAttachedFiles().size() > 0) {
+                List<Long> attachedFileIds = Lists.newArrayList();
 
-            for (AttachedFile attachedFile : issue.getAttachedFiles()) {
-                attachedFileIds.add(attachedFile.getId());
+                for (AttachedFile attachedFile : issue.getAttachedFiles()) {
+                    attachedFileIds.add(attachedFile.getId());
+                }
+                //  泥⑤��뙆�씪 �궘�젣
+                this.attachedFileService.removeAttachedFiles(attachedFileIds);
             }
-            //  泥⑤��뙆�씪 �궘�젣
-            this.attachedFileService.removeAttachedFiles(attachedFileIds);
-        }
 
-        // 吏��슱 �씠�뒋媛� �뿰愿��씠�뒋�씤吏� 泥댄겕 �썑 �뿰愿��씠�뒋 �뀒�씠釉붿뿉�꽌�룄 �궘�젣�븳�떎.
-        List<IssueRelation> issueRelationList = this.issueRelationRepository.findByRelationIssueId(issueId);
-        if (issueRelationList != null && issueRelationList.size() > 0) {
-            for(IssueRelation issueRelation : issueRelationList){
-                StringBuilder sb = new StringBuilder();
-                issueHistoryService.detectRelationIssue(IssueHistoryType.DELETE, issueRelation, sb);
-                issueHistoryService.addIssueHistory(issueRelation.getIssue(), IssueHistoryType.MODIFY, sb.toString());
-                this.issueRelationRepository.delete(issueRelation);
+            // 吏��슱 �씠�뒋媛� �뿰愿��씠�뒋�씤吏� 泥댄겕 �썑 �뿰愿��씠�뒋 �뀒�씠釉붿뿉�꽌�룄 �궘�젣�븳�떎.
+            List<IssueRelation> issueRelationList = this.issueRelationRepository.findByRelationIssueId(issueId);
+            if (issueRelationList != null && issueRelationList.size() > 0) {
+                for(IssueRelation issueRelation : issueRelationList){
+                    StringBuilder sb = new StringBuilder();
+                    issueHistoryService.detectRelationIssue(IssueHistoryType.DELETE, issueRelation, sb);
+                    issueHistoryService.addIssueHistory(issueRelation.getIssue(), IssueHistoryType.MODIFY, sb.toString());
+                    this.issueRelationRepository.delete(issueRelation);
+                }
             }
-        }
 
-        //  �씠�뒋 �깮�꽦, �궘�젣�떆 �삁�빟 �씠硫붿씪�뿉 �벑濡앺빐�넃�뒗�떎.
-        this.reservationIssueEmail(issue, EmailType.ISSUE_REMOVE);
-        //  �씠�뒋 �궘�젣
-        this.issueRepository.delete(issue);
+            //  �씠�뒋 �깮�꽦, �궘�젣�떆 �삁�빟 �씠硫붿씪�뿉 �벑濡앺빐�넃�뒗�떎.
+            this.reservationIssueEmail(issue, EmailType.ISSUE_REMOVE);
+            //  �씠�뒋 �궘�젣
+            this.issueRepository.delete(issue);
+        }
 
         return issue;
     }

--
Gitblit v1.8.0