From ebfd37816a332308519b30af5bfb017c5052be69 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 목, 13 1월 2022 17:34:35 +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 |  326 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 249 insertions(+), 77 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 d909d9e..fefabe8 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -11,14 +11,14 @@
 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;
+import kr.wisestone.owl.mapper.IssueRelationMapper;
 import kr.wisestone.owl.mapper.ProjectMapper;
-import kr.wisestone.owl.repository.IssueRelationRepository;
-import kr.wisestone.owl.repository.IssueRepository;
-import kr.wisestone.owl.repository.UserDepartmentRepository;
-import kr.wisestone.owl.repository.WorkflowDepartmentRepository;
+import kr.wisestone.owl.repository.*;
 import kr.wisestone.owl.service.*;
 import kr.wisestone.owl.util.*;
 import kr.wisestone.owl.util.DateUtil;
@@ -33,6 +33,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;
@@ -83,6 +85,9 @@
 
     @Autowired
     private CompanyFieldService companyFieldService;
+
+    @Autowired
+    private CompanyFieldCategoryService companyFieldCategoryService;
 
     @Autowired
     private IspFieldService ispFieldService;
@@ -178,6 +183,15 @@
     private IssueMapper issueMapper;
 
     @Autowired
+    private IssueCompanyRepository issueCompanyRepository;
+
+    @Autowired
+    private IssueIspRepository issueIspRepository;
+
+    @Autowired
+    private IssueHostingRepository issueHostingRepository;
+
+    @Autowired
     private ExcelConditionCheck excelConditionCheck;
 
     @Autowired
@@ -194,6 +208,12 @@
 
     @Autowired
     private WorkflowDepartmentRepository workflowDepartmentRepository;
+
+    @Autowired
+    private IssueRelationMapper issueRelationMapper;
+
+    @Autowired
+    private WorkflowTransitionService workflowTransitionService;
 
     @Override
     protected JpaRepository<Issue, Long> getRepository() {
@@ -223,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();
@@ -244,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());
 
@@ -283,7 +306,7 @@
                     issueApiForm.addUseIssueCustomFieldId(customFieldApiOverlap.getCustomField().getId());
                 }
 
-                // 以묐났�맂 �씠�뒋寃��깋
+                // 醫낅즺�긽�깭媛� �븘�땶 以묐났�맂 �긽�쐞 �씠�뒋寃��깋
                 List<Issue> issues = this.findIssue(issueApiForm, customFieldApiOverlaps, user.getId());
                 int size = issues.size();
                 if (size > 0) {
@@ -309,11 +332,11 @@
             return issueForm;
 
         } else {
-            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_USER_ERROR));
+            throw new ApiAuthException(this.messageAccessor.getMessage(MsgConstants.API_USER_ERROR));
         }
     }
 
-    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);
@@ -322,9 +345,8 @@
             List<Map<String, Object>> issueHostingFields = Lists.newArrayList();
 
             for (Map<String, Object> issueCustomField : issueForm.getIssueCustomFields()) {
-                int customFieldId = (Integer) issueCustomField.get("customFieldId");
-                Long customId = (long) customFieldId;
-                CustomField customField = this.customFieldService.getCustomField(customId);
+                Long customFieldId = MapUtil.getLong(issueCustomField, "customFieldId");
+                CustomField customField = this.customFieldService.getCustomField(customFieldId);
                 if(customField != null && customField.getCustomFieldType().toString().equals("SITE") && customField.getName().equals("�룄硫붿씤")) {
                     String useValue = issueCustomField.get("useValue").toString();
                     if(companyFields != null && companyFields.size() > 0) {
@@ -356,6 +378,8 @@
                 issueForm.setIssueHostingFields(issueHostingFields);
             }
         }
+
+        return issueForm;
     }
 
     private User convertToUser(String token) {
@@ -381,7 +405,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);
             // �븯�쐞 �씠�뒋 異붽�
@@ -414,7 +445,9 @@
             IssueCustomFieldValueFormComparator comp = new IssueCustomFieldValueFormComparator();
             Collections.sort(issueCustomFieldValueForms, comp);
 
+            List<String> userValues = Lists.newArrayList();
             for (IssueCustomFieldValueForm issueCustomFieldValueForm : issueCustomFieldValueForms) {
+                userValues.add(issueCustomFieldValueForm.getUseValue());
                 for(CustomFieldApiOverlap customFieldApiOverlap : customFieldApiOverlaps) {
                     if (customFieldApiOverlap.getCustomField().getId().equals(issueCustomFieldValueForm.getCustomFieldId())) {
                         if (useIdx > 0) {
@@ -428,7 +461,9 @@
 
             IssueCustomFieldValueCondition issueCustomFieldValueCondition = new IssueCustomFieldValueCondition();
             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) {
@@ -498,7 +533,6 @@
         this.issueIspService.modifyIssueIspField(issue, issueForm);
         //  HOSTING �젙蹂� ���옣
         this.issueHostingService.modifyIssueHostingField(issue, issueForm);
-
 
         //  泥⑤� �뙆�씪 ���옣
         //  multipartFile �쓣 file Map List 媛앹껜濡� 蹂�寃쏀븳�떎.
@@ -716,7 +750,7 @@
     }
 
     //  �씠�뒋 �젙蹂대�� �씠硫붿씪 �쟾�넚�뿉 �궗�슜�븯湲� �쐞�빐 Map �삎�깭濡� 蹂��솚�븳�떎.
-    private void makeIssueMapToIssue(Issue issue, Map<String, Object> issueMap) {
+    public void makeIssueMapToIssue(Issue issue, Map<String, Object> issueMap) {
         issueMap.put("title", issue.getTitle());
         issueMap.put("issueNumber", issue.getIssueNumber());
         issueMap.put("issueTypeName", issue.getIssueType().getName());
@@ -908,42 +942,40 @@
             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)) { //理쒓퀬愿�由ъ옄 & �봽濡쒖젥�듃,�씠�뒋 愿�由ъ옄 �씪 寃쎌슦 紐⑤뱺 �씠�뒋 蹂닿린
 //            this.SetMyDepartmentId(issueCondition);
-            //this.SetAllDepartmentId(issueCondition);
+        //this.SetAllDepartmentId(issueCondition);
 //        } /*else{
 //            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;
         //  �씠�뒋 �븘�씠�뵒 珥덇린�솕
@@ -959,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);
@@ -1457,11 +1489,24 @@
     @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();
+
+            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": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦遺��꽌, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� �뀑�똿�븳�떎.
@@ -1478,17 +1523,15 @@
                     this.setIssueCustomFields(issue, issueVo);  //  �궗�슜�옄 �젙�쓽 �븘�뱶 媛� �젙蹂� �뀑�똿
                     this.setRelationIssue(issue, issueVo);        //�뿰愿� �씪媛� �뀑�똿
                     this.setDownIssues(issue, issueVo); //�븯�쐞 �씠�뒋 �꽭�똿
-
                     break;
 
                 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;
             }
         }
-
         //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
         log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_DETAIL));
 
@@ -1496,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) {
@@ -1517,8 +1561,21 @@
 
     // �븯�쐞 �씠�뒋 �젙蹂대�� �뀑�똿�븳�떎
     private void setDownIssues(Issue issue, IssueVo issueVo) {
-        List<Issue> downIssues = this.issueRepository.findByParentIssueId(issue.getId());
-        if(downIssues != null && downIssues.size()>0){
+        Page<Issue> downIssues = null;
+
+        List<Issue> downIssueList = this.issueRepository.findByParentIssueId(issue.getId());
+        if(downIssueList != null && downIssueList.size() > 0) {
+            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);
+        }
+        if(downIssues != null){
+            issueVo.setDownTotalPage(downIssues.getTotalPages());
+            issueVo.setDownTotalCount(downIssues.getTotalElements());
+
             List<IssueVo> resultList = new ArrayList<>();
             for(Issue downIssue : downIssues){
                 IssueVo downIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
@@ -1535,6 +1592,8 @@
                 this.setIssueCustomFields(downIssue, downIssueVo);   // �궗�슜�옄�젙�쓽�븘�뱶 �젙蹂� �꽭�똿
                 this.setIssueHistory(downIssue, downIssueVo);   //  �씠�뒋 湲곕줉 �젙蹂� �뀑�똿
                 this.setIssueComments(downIssue, downIssueVo);  //  �뙎湲� �젙蹂� �뀑�똿
+
+                downIssueVo.setModifyPermissionCheck(issueVo.getModifyPermissionCheck());
 
                 resultList.add(downIssueVo);
             }
@@ -1616,13 +1675,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();
 
-                Issue relationIssue = issueRelation.getRelationIssue();
+        List<Map<String, Object>> results = this.issueRelationMapper.findByIssueId(issueVo);
+        Long totalCount = this.issueRelationMapper.count(issueVo);
 
+        if (issue != null && issueVo != null && results.size() > 0) {
+            int totalPage = (int) Math.ceil((totalCount - 1) / issueVo.getRelPageSize()) + 1;
+            issueVo.setRelTotalPage(totalPage);
+            issueVo.setRelTotalCount(totalCount);
+            for (Map<String, Object> result : results) {
+                IssueRelationVo issueRelationVo = ConvertUtil.convertMapToClass(result, IssueRelationVo.class);
+                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());
@@ -1638,6 +1702,8 @@
                 IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(relationIssue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
                 issueStatusVo.setIssueStatusType(relationIssue.getIssueStatus().getIssueStatusType().toString());
                 issueRelationVo.setIssueStatusVo(issueStatusVo);
+
+                issueRelationVo.setModifyPermissionCheck(issueVo.getModifyPermissionCheck());
 
                 this.setRegister(relationIssue, relIssueVo); // �벑濡앹옄
                 this.setIssueDepartment(relationIssue, relIssueVo);  //  �떞�떦遺��꽌 �젙蹂� �뀑�똿
@@ -1755,6 +1821,7 @@
         List<Issue> resultIssueVos = Lists.newArrayList();
         String comma = ",";
 
+        List<String> userValues = Lists.newArrayList();
         if (issueCustomFieldValueForms.size() > 0) {
             IssueCustomFieldValueFormComparator comp = new IssueCustomFieldValueFormComparator();
             Collections.sort(issueCustomFieldValueForms, comp);
@@ -1762,6 +1829,7 @@
             String concatUseValue = "";
             for (int i = 0; i < issueCustomFieldValueForms.size(); i++) {
                 IssueCustomFieldValueForm issueCustomFieldValueForm = issueCustomFieldValueForms.get(i);
+                userValues.add(issueCustomFieldValueForm.getUseValue());
                 if (i > 0) {
                     concatUseValue = concatUseValue.concat(comma);
                 }
@@ -1770,6 +1838,7 @@
 
             IssueCustomFieldValueCondition issueCustomFieldValueCondition = new IssueCustomFieldValueCondition();
             issueCustomFieldValueCondition.setUseValue(concatUseValue);
+            issueCustomFieldValueCondition.setUseValues(userValues);
             issueCustomFieldValueCondition.setIssueTypeId(issueApiform.getIssueTypeId());
             List<Map<String, Object>> results = this.issueMapper.findByCustomFieldValue(issueCustomFieldValueCondition);
             if (results != null && results.size() > 0) {
@@ -1893,6 +1962,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);
@@ -2729,6 +2805,26 @@
             CompanyField companyField = issueCompany.getCompanyField();
             if (companyField != null) {
                 issueCompanyVo.setCompanyId(issueCompany.getCompanyField().getId());
+                if (issueCompany.getCompanyTypeId() != null) {
+                    CompanyFieldCategory companyType = this.companyFieldCategoryService.find(issueCompany.getCompanyTypeId());
+                    issueCompanyVo.setCompanyTypeName(companyType.getUseValue());
+                }
+                if (issueCompany.getParentSectorId() != null) {
+                    CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(issueCompany.getParentSectorId());
+                    issueCompanyVo.setParentSectorName(parentSector.getUseValue());
+                }
+                if (issueCompany.getChildSectorId() != null) {
+                    CompanyFieldCategory childSector = this.companyFieldCategoryService.find(issueCompany.getChildSectorId());
+                    issueCompanyVo.setChildSectorName(childSector.getUseValue());
+                }
+                if (issueCompany.getRegionId() != null) {
+                    CompanyFieldCategory region = this.companyFieldCategoryService.find(issueCompany.getRegionId());
+                    issueCompanyVo.setRegionName(region.getUseValue());
+                }
+                if (issueCompany.getStatusId() != null) {
+                    CompanyFieldCategory status = this.companyFieldCategoryService.find(issueCompany.getStatusId());
+                    issueCompanyVo.setStatusName(status.getUseValue());
+                }
             }
             issueCompanyVos.add(issueCompanyVo);
         }
@@ -2916,7 +3012,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();
@@ -2997,7 +3093,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);
 
@@ -3008,10 +3106,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());
             }
@@ -3034,8 +3134,6 @@
             //  �씠�뒋 �궗�슜�옄 �젙�쓽 媛� �븘�뱶 踰뚰겕 �벑濡�
             this.bulkInsertIssueCustomFieldValue(issueForms, issueTypeCustomFieldMaps);
             //  3.628 - 3.445
-
-            // �뾽泥�,ISP,�샇�뒪�똿 異붽�
 
             /*serviceStart.stop();
             log.debug("2李� ���옣 �떆媛� : " + serviceStart.getTime());*/
@@ -3148,6 +3246,29 @@
                 issueCustomField.put("registerId", this.webAppUtil.getLoginId());
                 issueCustomFieldValueMaps.add(issueCustomField);
             }
+            IssueForm partners = this.findCompanyField(issueForm); // 媛숈� �룄硫붿씤 �뾽泥� 李얘린
+            Issue issue = this.findOne(issueForm.getId());
+            if (partners.getIssueCompanyFields() != null && partners.getIssueCompanyFields().size() > 0) {
+                for (Map<String, Object> company : partners.getIssueCompanyFields()) {
+                    IssueCompany issueCompany = ConvertUtil.convertMapToClass(company, IssueCompany.class);
+                    issueCompany.setIssue(issue);
+                    this.issueCompanyRepository.saveAndFlush(issueCompany);
+                }
+            }
+            if (partners.getIssueIspFields() != null && partners.getIssueIspFields().size() > 0) {
+                for (Map<String, Object> isp : partners.getIssueIspFields()) {
+                    IssueIsp issueIsp = ConvertUtil.convertMapToClass(isp, IssueIsp.class);
+                    issueIsp.setIssue(issue);
+                    this.issueIspRepository.saveAndFlush(issueIsp);
+                }
+            }
+            if (partners.getIssueHostingFields() != null && partners.getIssueHostingFields().size() > 0) {
+                for (Map<String, Object> hosting : partners.getIssueHostingFields()) {
+                    IssueHosting issueHosting = ConvertUtil.convertMapToClass(hosting, IssueHosting.class);
+                    issueHosting.setIssue(issue);
+                    this.issueHostingRepository.saveAndFlush(issueHosting);
+                }
+            }
         }
 
         if (issueCustomFieldValueMaps.size() > 0) {
@@ -3156,8 +3277,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();
@@ -3220,13 +3349,13 @@
                     break;*/
                 case 4:
                     //  �떆�옉�씪�쓣 IssueForm �뿉 ���옣�븳�떎.
-                    if (cell != null) {
+                    if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
                         this.setIssueFormPeriod(cell, issueForm, true, rowIndex);
                     }
                     break;
                 case 5:
                     //  醫낅즺�씪�쓣 IssueForm �뿉 ���옣�븳�떎.
-                    if (cell != null) {
+                    if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
                         this.setIssueFormPeriod(cell, issueForm, false, rowIndex);
                     }
                     break;
@@ -3342,7 +3471,7 @@
 
             //  媛믪씠 怨듬갚�씠硫� 以묒�
             String cellValue = CommonUtil.convertExcelStringToCell(cell);
-            if (StringUtils.isEmpty(cellValue)) {
+            if (StringUtils.isEmpty(cellValue) || !cell.toString().equals("null")) {
                 return;
             }
 
@@ -3540,6 +3669,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
@@ -3708,44 +3868,56 @@
     @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
     public void findPartner(Map<String, Object> resJsonData, Map<String, Object> params) {
         Long issueTypeId = MapUtil.getLong(params, "issueTypeId");
-        IssueType issueType = this.issueTypeService.getIssueType(issueTypeId); // �씠�뒋�쓽 �씠�뒋�쑀�삎 媛앹껜
-        Integer using = issueType.getUsePartner() != null ? issueType.getUsePartner().intValue() : 0; // �씠�뒋�쑀�삎蹂꾨줈 �궗�슜以묒씤 �뾽泥�/ISP/�샇�뒪�똿 媛�
-
         List<UsePartnerVo> usePartnerVos = Lists.newArrayList();
+        Integer using = 0;
+
+        if (issueTypeId != null) {
+            IssueType issueType = this.issueTypeService.getIssueType(issueTypeId); // �씠�뒋�쓽 �씠�뒋�쑀�삎 媛앹껜
+            using = issueType.getUsePartner() != null ? issueType.getUsePartner().intValue() : 0; // �씠�뒋�쑀�삎蹂꾨줈 �궗�슜以묒씤 �뾽泥�/ISP/�샇�뒪�똿 媛�
+        } else {
+            for (int partner : UsePartner.partners) {
+                using += partner;
+            }
+        }
+
         for (Integer usePartner : UsePartner.partners) { //1(�뾽泥�), 2(ISP), 4(�샇�뒪�똿)
             UsePartnerVo usePartnerVo = UsePartner.checkUsePartner(using, usePartner);
             if (usePartnerVo != null) {
                 usePartnerVos.add(usePartnerVo);
             }
-            resJsonData.put(Constants.RES_KEY_CONTENTS, usePartnerVos);
         }
+
+        resJsonData.put(Constants.RES_KEY_CONTENTS, usePartnerVos);
     }
 
     @Override

--
Gitblit v1.8.0