From 0dca48e62f053d2fa725649ee2842412a9b4f476 Mon Sep 17 00:00:00 2001
From: wyu <kknd09321@nate.com>
Date: 목, 06 1월 2022 11:42:18 +0900
Subject: [PATCH] Merge branch 'master' of http://192.168.0.25:9001/r/owl-kisa

---
 src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java |  138 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 108 insertions(+), 30 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 3049801..7be00d2 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;
@@ -195,6 +198,9 @@
     @Autowired
     private WorkflowDepartmentRepository workflowDepartmentRepository;
 
+    @Autowired
+    private IssueRelationMapper issueRelationMapper;
+
     @Override
     protected JpaRepository<Issue, Long> getRepository() {
         return this.issueRepository;
@@ -283,7 +289,7 @@
                     issueApiForm.addUseIssueCustomFieldId(customFieldApiOverlap.getCustomField().getId());
                 }
 
-                // 以묐났�맂 �씠�뒋寃��깋
+                // 醫낅즺�긽�깭媛� �븘�땶 以묐났�맂 �긽�쐞 �씠�뒋寃��깋
                 List<Issue> issues = this.findIssue(issueApiForm, customFieldApiOverlaps, user.getId());
                 int size = issues.size();
                 if (size > 0) {
@@ -313,7 +319,7 @@
         }
     }
 
-    private void findCompanyField(IssueForm issueForm) {
+    private IssueForm findCompanyField(IssueForm issueForm) {
         if(issueForm.getIssueCustomFields() != null && issueForm.getIssueCustomFields().size() > 0) {
             CompanyFieldCondition condition = new CompanyFieldCondition();
             List<Map<String, Object>> companyFields = this.companyFieldService.find(condition);
@@ -356,6 +362,7 @@
                 issueForm.setIssueHostingFields(issueHostingFields);
             }
         }
+        return issueForm;
     }
 
     private User convertToUser(String token) {
@@ -381,7 +388,14 @@
         } else {
             // 媛��긽 �긽�쐞 �씠�뒋 異붽�
             IssueForm parentIssueForm = issueForm.clone();
+            // 媛��긽 �긽�쐞 �씠�뒋 異붽�
             parentIssueForm.setUseIssueCustomFields(issueApiForm.getUseIssueCustomFieldIds());
+            //  媛숈� �룄硫붿씤 �뾽泥� 李얘린
+            IssueForm partners = this.findCompanyField(parentIssueForm);
+            parentIssueForm.setIssueCompanyFields(partners.getIssueCompanyFields());
+            parentIssueForm.setIssueIspFields(partners.getIssueIspFields());
+            parentIssueForm.setIssueHostingFields(partners.getIssueHostingFields());
+
             Issue issue = addIssue(user, parentIssueForm, null);
             issues.add(issue);
             // �븯�쐞 �씠�뒋 異붽�
@@ -432,6 +446,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) {
@@ -501,7 +516,6 @@
         this.issueIspService.modifyIssueIspField(issue, issueForm);
         //  HOSTING �젙蹂� ���옣
         this.issueHostingService.modifyIssueHostingField(issue, issueForm);
-
 
         //  泥⑤� �뙆�씪 ���옣
         //  multipartFile �쓣 file Map List 媛앹껜濡� 蹂�寃쏀븳�떎.
@@ -931,7 +945,7 @@
 //        if (!this.userWorkspaceService.checkWorkspaceManager(user)
 //                && !MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE)) { //理쒓퀬愿�由ъ옄 & �봽濡쒖젥�듃,�씠�뒋 愿�由ъ옄 �씪 寃쎌슦 紐⑤뱺 �씠�뒋 蹂닿린
 //            this.SetMyDepartmentId(issueCondition);
-            //this.SetAllDepartmentId(issueCondition);
+        //this.SetAllDepartmentId(issueCondition);
 //        } /*else{
 //            results = this.issueMapper.findByDepartment(issueCondition);
 //            totalCount = this.issueMapper.countByDepartment(issueCondition);
@@ -1458,13 +1472,19 @@
     //  �씠�뒋 �긽�꽭 �젙蹂대�� 議고쉶�븳�떎.
     @Override
     @Transactional(readOnly = true)
-    public void detailIssue(Map<String, Object> resJsonData, IssueCondition issueCondition) {
+    public void detailIssue(Map<String, Object> resJsonData, IssueCondition issueCondition, Pageable relPageable, Pageable downPageable) {
         IssueVo issueVo = new IssueVo();
 
         if (issueCondition.getId() != null) {
             Issue issue = this.getIssue(issueCondition.getId());
             issueVo = ConvertUtil.copyProperties(issue, IssueVo.class);
             User user = this.webAppUtil.getLoginUserObject();
+
+            issueVo.setRelPage(relPageable.getPageNumber() * relPageable.getPageSize());
+            issueVo.setRelPageSize(relPageable.getPageSize());
+
+            issueVo.setDownPage(downPageable.getPageNumber() * downPageable.getPageSize());
+            issueVo.setDownPageSize(downPageable.getPageSize());
 
             switch (issueCondition.getDeep()) {
                 case "01": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦遺��꽌, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� �뀑�똿�븳�떎.
@@ -1481,7 +1501,6 @@
                     this.setIssueCustomFields(issue, issueVo);  //  �궗�슜�옄 �젙�쓽 �븘�뱶 媛� �젙蹂� �뀑�똿
                     this.setRelationIssue(issue, issueVo);        //�뿰愿� �씪媛� �뀑�똿
                     this.setDownIssues(issue, issueVo); //�븯�쐞 �씠�뒋 �꽭�똿
-
                     break;
 
                 case "02": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦�옄, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂�, �뙎湲�, 湲곕줉�쓣 �뀑�똿�븳�떎.
@@ -1491,11 +1510,19 @@
                     break;
             }
         }
+        Long relTotalCount = issueVo.getRelTotalCount();
+        int relTotalPage = issueVo.getRelTotalPage();
 
+        Long downTotalCount = issueVo.getDownTotalCount();
+        int downTotalPage = issueVo.getDownTotalPage();
         //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
         log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_DETAIL));
 
         resJsonData.put(Constants.RES_KEY_CONTENTS, issueVo);
+        resJsonData.put(Constants.REQ_KEY_RELATION_ISSUE_PAGE_VO, new ResPage(relPageable.getPageNumber(), relPageable.getPageSize(),
+                relTotalPage, relTotalCount));
+        resJsonData.put(Constants.REQ_KEY_DOWN_ISSUE_PAGE_VO, new ResPage(downPageable.getPageNumber(), downPageable.getPageSize(),
+                downTotalPage, downTotalCount));
     }
 
     // �뀒�씠釉� �꽕�젙 �뀑�똿
@@ -1520,8 +1547,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);
@@ -1621,13 +1653,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());
@@ -1903,6 +1940,13 @@
     // �씠�뒋 �닔�젙(API�슜)
     private Issue modifyIssueForApi(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
         CheckIssueData checkIssueData = this.checkIssue(user, issueForm);
+
+        if (issueForm.getComment() != null && !issueForm.getComment().equals("")) { //�뙎湲� 異붽�
+            IssueCommentForm issueCommentForm = new IssueCommentForm();
+            issueCommentForm.setDescription(issueForm.getComment());
+            issueCommentForm.setIssueId(issueForm.getId());
+            this.issueCommentService.addIssueComment(issueCommentForm, user);
+        }
 
         // �씠�뒋 �씠�젰 �궓湲곌린
         this.addIssueHistoryModify(user, issueForm, checkIssueData, multipartFiles);
@@ -3550,6 +3594,37 @@
         this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.SEND, sb.toString());
     }
 
+    @Override
+    public void sendCommonEmail(EmailCommonForm emailCommonForm) {
+        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());
+
+        //  諛쒖떊�옄 �몴�떆
+        User user = this.webAppUtil.getLoginUserObject();
+        UserVo toUser = this.webAppUtil.getLoginUser();
+
+        //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
+        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_ANOTHER_USER_SEND_EMAIL));
+        StringBuilder sb = new StringBuilder();
+
+        Locale locale = CommonUtil.getUserLanguage(user.getLanguage());
+        String[] sendMails = ConvertUtil.ToArray(emailCommonForm.getSendEmails());
+        for(int i=0; i < sendMails.length; i++) {
+            sendMails[i] = CommonUtil.decryptAES128(sendMails[i]);
+        }
+        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());
+    }
+
     //  �삁�빟 諛쒖깮 �씠�뒋瑜� �떎�뻾�븳�떎
     @Override
     @Transactional
@@ -3718,28 +3793,31 @@
     @Transactional
     @Override
     public void modifyParentIssue(IssueForm issueDownForm) {
-        Issue issue = this.getIssue(issueDownForm.getId()); //�븯�쐞 �씠�뒋
+        //Issue issue = this.getIssue(issueDownForm.getId()); //�븯�쐞 �씠�뒋
         Long newParentIssueId = issueDownForm.getParentIssueId(); //蹂�寃쏀븷 �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋
-
         StringBuilder sb = new StringBuilder();
 
-        Issue parentIssue = issue.getParentIssue(); //蹂�寃� �쟾 �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋
-        if(parentIssue != null && parentIssue.getId().equals(newParentIssueId)){ //蹂�寃� �쟾 �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋媛� 議댁옱 �븷 寃쎌슦
-            this.issueHistoryService.detectDownIssues(IssueHistoryType.DELETE, issue, sb);
-            this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString());
-        }
+        for (Long downId : issueDownForm.getIds()) {
+            Issue issue = this.getIssue(downId);
 
-        if (newParentIssueId != null) { // 異붽� �븷 寃쎌슦
-            parentIssue = this.getIssue(newParentIssueId); //�긽�쐞�씠�뒋(myIssue)
-            issue.setParentIssue(parentIssue); //myIssue瑜� �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋濡� set
-            this.issueHistoryService.detectDownIssues(IssueHistoryType.ADD, issue, sb); //issue = �븯�쐞�씠�뒋
-        } else{
-            // �궘�젣 �븷 寃쎌슦
-            this.issueHistoryService.detectDownIssues(IssueHistoryType.DELETE, issue, sb);
-            issue.setParentIssue(null);
+            Issue parentIssue = issue.getParentIssue(); //蹂�寃� �쟾 �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋
+            if(parentIssue != null && parentIssue.getId().equals(newParentIssueId)){ //蹂�寃� �쟾 �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋媛� 議댁옱 �븷 寃쎌슦
+                this.issueHistoryService.detectDownIssues(IssueHistoryType.DELETE, issue, sb);
+                this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString());
+            }
+
+            if (newParentIssueId != null) { // 異붽� �븷 寃쎌슦
+                parentIssue = this.getIssue(newParentIssueId); //�긽�쐞�씠�뒋(myIssue)
+                issue.setParentIssue(parentIssue); //myIssue瑜� �븯�쐞�씠�뒋�쓽 �긽�쐞�씠�뒋濡� set
+                this.issueHistoryService.detectDownIssues(IssueHistoryType.ADD, issue, sb); //issue = �븯�쐞�씠�뒋
+            } else{
+                // �궘�젣 �븷 寃쎌슦
+                this.issueHistoryService.detectDownIssues(IssueHistoryType.DELETE, issue, sb);
+                issue.setParentIssue(null);
+            }
+            this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString()); //parentIssue = myIssue(湲곕줉�� �쁽�옱 �긽�꽭�럹�씠吏��뿉 �빐�빞�븯�땲源�)
+            this.issueRepository.saveAndFlush(issue);
         }
-        this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString()); //parentIssue = myIssue(湲곕줉�� �쁽�옱 �긽�꽭�럹�씠吏��뿉 �빐�빞�븯�땲源�)
-        this.issueRepository.saveAndFlush(issue);
     }
 
     @Override

--
Gitblit v1.8.0