From 145928e42a8ae18129fcbc720824a9e4f78999bd Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 금, 17 12월 2021 17:23:03 +0900
Subject: [PATCH] 상위이슈의 상세페이지에서 하위이슈에 대한 활동내역 보여주기

---
 src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java |  741 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 573 insertions(+), 168 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..96d90c3 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -1,14 +1,10 @@
 package kr.wisestone.owl.service.impl;
 
 import com.google.common.collect.Lists;
-import com.sun.org.apache.bcel.internal.generic.NEW;
 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;
@@ -16,6 +12,7 @@
 import kr.wisestone.owl.domain.enumType.IssueHistoryType;
 import kr.wisestone.owl.domain.enumType.IssueStatusType;
 import kr.wisestone.owl.exception.OwlRuntimeException;
+import kr.wisestone.owl.mapper.DepartmentMapper;
 import kr.wisestone.owl.mapper.IssueMapper;
 import kr.wisestone.owl.mapper.ProjectMapper;
 import kr.wisestone.owl.repository.IssueRelationRepository;
@@ -83,6 +80,15 @@
 
     @Autowired
     private ApiTokenService apiTokenService;
+
+    @Autowired
+    private CompanyFieldService companyFieldService;
+
+    @Autowired
+    private IspFieldService ispFieldService;
+
+    @Autowired
+    private HostingFieldService hostingFieldService;
 
     @Autowired
     private CommonConfiguration configuration;
@@ -154,6 +160,9 @@
     private UserWorkspaceService userWorkspaceService;
 
     @Autowired
+    private UserLevelService userLevelService;
+
+    @Autowired
     private WorkflowDepartmentService workflowDepartmentService;
 
     @Autowired
@@ -175,7 +184,13 @@
     private SimpMessagingTemplate simpMessagingTemplate;
 
     @Autowired
+    private UserDepartmentService userDepartmentService;
+
+    @Autowired
     private UserDepartmentRepository userDepartmentRepository;
+
+    @Autowired
+    private DepartmentMapper departmentMapper;
 
     @Autowired
     private WorkflowDepartmentRepository workflowDepartmentRepository;
@@ -196,6 +211,15 @@
         this.issueVersionService.addIssueVersion(issue);
     }
 
+    @Override
+    @Transactional
+    public void addIssueVersion(Long id, Long userId) {
+        Issue issue = this.getIssue(id);
+        User user = this.userService.getUser(userId);
+        //  �씠�뒋 踰꾩쟾 �깮�꽦
+        this.issueVersionService.addIssueVersion(issue, user);
+    }
+
 
     private IssueForm convertToIssueForm(IssueApiForm issueApiForm, User user) {
         if (issueApiForm.getIssueTypeId() == null) {
@@ -211,23 +235,16 @@
 
         Workflow workflow = issueType.getWorkflow();
 
-        // �씠�뒋 �긽�깭媛� 吏��젙�릺�뼱 �엳吏� �븡�쓣 寃쎌슦 珥덇린媛믪쑝濡� 吏��젙
-        if (issueApiForm.getIssueStatusId() == null) {
-            List<IssueStatusVo> issueStatusVos = issueStatusService.findByWorkflowId(workflow.getId());
-            IssueStatusVo issueStatusVo = issueStatusVos.get(0);
-            issueApiForm.setIssueStatusId(issueStatusVo.getId());
-        }
-
-        // �썙�겕�뵆濡쒖슦 �긽�깭�뿉 �뵲瑜� �떞�떦遺��꽌 媛��졇�삤湲�
-        if (issueApiForm.getIssueStatusId() != null) {
-            WorkflowDepartmentCondition workflowDepartmentCondition = new WorkflowDepartmentCondition();
-            workflowDepartmentCondition.setIssueStatusId(issueApiForm.getIssueStatusId());
-            workflowDepartmentCondition.setWorkflowId(workflow.getId());
-            List<WorkflowDepartmentVo> workflowDepartmentVos = this.workflowDepartmentService.find(workflowDepartmentCondition);
-
-            for (WorkflowDepartmentVo workflowDepartmentVo : workflowDepartmentVos) {
-                issueForm.addDepartmentId(workflowDepartmentVo.getDepartmentVo().getId());
+        if (issueApiForm.getApiType().equals(IssueApiForm.ApiType.add)) {
+            // �씠�뒋 �긽�깭媛� 吏��젙�릺�뼱 �엳吏� �븡�쓣 寃쎌슦 �썙�겕�뵆濡쒖슦 ��湲� �긽�깭 媛믪쑝濡� 吏��젙
+            List<Long> departmentIds = this.workflowDepartmentService.findFirstDepartmentIds(workflow);
+            if (departmentIds != null && departmentIds.size() > 0) {
+                for (Long departmentId : departmentIds) {
+                    issueForm.addDepartmentId(departmentId);
+                }
             }
+        } else if (issueApiForm.getIssueStatusId() == null){
+            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_ISSUE_STATUS_NOT_EXIST));
         }
 
         // �봽濡쒖젥�듃 �엯�젰
@@ -257,21 +274,34 @@
 
             // �긽�쐞�씪媛먯뿉 �궗�슜�븷 以묐났媛� �꽕�젙
             List<CustomFieldApiOverlap> customFieldApiOverlaps = this.customFieldApiOverlapService.find(user.getId(), issueApiForm.getIssueTypeId());
-            for(int i=0; i < customFieldApiOverlaps.size() ; i++ ){
-                CustomFieldApiOverlap customFieldApiOverlap = customFieldApiOverlaps.get(i);
-                issueApiForm.addUseIssueCustomFieldId(customFieldApiOverlap.getCustomField().getId());
-            }
+//            if (customFieldApiOverlaps == null || customFieldApiOverlaps.size() == 0){
+//                throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_OVERLAP_SETTING_NOT_EXIST));
+//            }
+            if (customFieldApiOverlaps != null && customFieldApiOverlaps.size() > 0) {
+                for (int i = 0; i < customFieldApiOverlaps.size(); i++) {
+                    CustomFieldApiOverlap customFieldApiOverlap = customFieldApiOverlaps.get(i);
+                    issueApiForm.addUseIssueCustomFieldId(customFieldApiOverlap.getCustomField().getId());
+                }
 
-            List<IssueVo> issueVos = this.findIssue(issueApiForm, customFieldApiOverlaps, user.getId());
-            int size = issueVos.size();
-            if (size > 0) {
-                issueForm.setParentIssueId(issueVos.get(0).getId());
+                // 以묐났�맂 �씠�뒋寃��깋
+                List<Issue> issues = this.findIssue(issueApiForm, customFieldApiOverlaps, user.getId());
+                int size = issues.size();
+                if (size > 0) {
+                    Issue targetIssue = issues.get(0);
+                    if (targetIssue.getParentIssue() != null) {
+                        issueForm.setParentIssueId(targetIssue.getParentIssue().getId());
+                    } else {
+                        issueForm.setParentIssueId(targetIssue.getId());
+                    }
+                }
             }
 
             issueForm.setIsApi(Issue.IS_API_YES);
 
             // �궗�슜�옄 �젙�쓽 �븘�뱶 �꽕�젙
             issueForm.setIssueCustomFields(issueApiForm.getCustomFieldValues());
+            //  媛숈� �룄硫붿씤 �뾽泥� 李얘린
+            this.findCompanyField(issueForm);
 
             // api �엯�젰媛� �쟻�슜
             ConvertUtil.copyProperties(issueApiForm, issueForm);
@@ -280,6 +310,51 @@
 
         } else {
             throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_USER_ERROR));
+        }
+    }
+
+    private void findCompanyField(IssueForm issueForm) {
+        if(issueForm.getIssueCustomFields() != null && issueForm.getIssueCustomFields().size() > 0) {
+            CompanyFieldCondition condition = new CompanyFieldCondition();
+            List<Map<String, Object>> companyFields = this.companyFieldService.find(condition);
+            List<Map<String, Object>> issueCompanyFields = Lists.newArrayList();
+            List<Map<String, Object>> issueIspFields = Lists.newArrayList();
+            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);
+                if(customField != null && customField.getCustomFieldType().toString().equals("SITE") && customField.getName().equals("�룄硫붿씤")) {
+                    String useValue = issueCustomField.get("useValue").toString();
+                    if(companyFields != null && companyFields.size() > 0) {
+                        for (Map<String, Object> companyField : companyFields) {
+                            CompanyFieldVo companyFieldVo = ConvertUtil.convertMapToClass(companyField, CompanyFieldVo.class);
+                            if(useValue.equals(companyFieldVo.getUrl())) {
+                                companyField.put("companyId", companyField.get("id"));
+                                issueCompanyFields.add(companyField);
+                                if(companyFieldVo.getIspId() != null) {
+                                    Map<String, Object> ispField = this.ispFieldService.find(companyFieldVo.getIspId());
+                                    if (ispField != null) {
+                                        ispField.put("ispId", ispField.get("id"));
+                                        issueIspFields.add(ispField);
+                                    }
+                                }
+                                if(companyFieldVo.getHostingId() != null) {
+                                    Map<String, Object> hostingField = this.hostingFieldService.find(companyFieldVo.getHostingId());
+                                    if (hostingField != null) {
+                                        hostingField.put("hostingId", hostingField.get("id"));
+                                        issueHostingFields.add(hostingField);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                issueForm.setIssueCompanyFields(issueCompanyFields);
+                issueForm.setIssueIspFields(issueIspFields);
+                issueForm.setIssueHostingFields(issueHostingFields);
+            }
         }
     }
 
@@ -300,10 +375,11 @@
         IssueForm issueForm = this.convertToIssueForm(issueApiForm, user);
 
         List<Issue> issues = Lists.newArrayList();
-        if (issueForm.getParentIssueId() != null) {
+        if (issueForm.getParentIssueId() != null    // 湲곗〈 異붽��맂 �긽�쐞 �씪媛먯씠 �뾾嫄곕굹 �꽕�젙�맂 以묐났 �씠�뒋 id媛� �뾾�쓣�븣
+                || issueApiForm.getUseIssueCustomFieldIds().size() == 0) {
             issues.add(addIssue(user, issueForm, issueApiForm.getMultipartFiles()));
         } else {
-            // �긽�쐞 �씠�뒋 異붽�
+            // 媛��긽 �긽�쐞 �씠�뒋 異붽�
             IssueForm parentIssueForm = issueForm.clone();
             parentIssueForm.setUseIssueCustomFields(issueApiForm.getUseIssueCustomFieldIds());
             Issue issue = addIssue(user, parentIssueForm, null);
@@ -326,9 +402,9 @@
     }
 
     // 以묐났�맂 �긽�쐞 �씠�뒋 寃��깋
-    private List<IssueVo> findIssue(IssueApiForm issueApiform, List<CustomFieldApiOverlap> customFieldApiOverlaps, Long userId) {
+    private List<Issue> findIssue(IssueApiForm issueApiform, List<CustomFieldApiOverlap> customFieldApiOverlaps, Long userId) {
         List<IssueCustomFieldValueForm> issueCustomFieldValueForms = issueApiform.getIssueCustomFieldValues();
-        List<IssueVo> resultIssueVos = Lists.newArrayList();
+        List<Issue> resultIssueVos = Lists.newArrayList();
         String comma = ",";
 
         if (issueCustomFieldValueForms.size() > 0) {
@@ -352,10 +428,11 @@
 
             IssueCustomFieldValueCondition issueCustomFieldValueCondition = new IssueCustomFieldValueCondition();
             issueCustomFieldValueCondition.setUseValue(concatUseValue);
+            issueCustomFieldValueCondition.setIssueTypeId(issueApiform.getIssueTypeId());
             List<Map<String, Object>> results = this.issueMapper.findByCustomFieldValue(issueCustomFieldValueCondition);
             if (results != null && results.size() > 0) {
                 for (Map<String, Object> result : results) {
-                    resultIssueVos.add(ConvertUtil.convertMapToClass(result, IssueVo.class));
+                    resultIssueVos.add(this.getIssue(MapUtil.getLong(result, "id")));
                 }
             }
         }
@@ -454,6 +531,91 @@
     public Issue addRelIssue(IssueForm issueForm, List<MultipartFile> multipartFiles) {
         User user = this.webAppUtil.getLoginUserObject();
         return addRelIssue(user, issueForm, multipartFiles);
+    }
+
+    //  �븯�쐞�씠�뒋瑜� �깮�꽦�븳�떎.
+    @Override
+    @Transactional
+    public Issue addDownIssue(IssueForm issueForm, List<MultipartFile> multipartFiles) {
+        User user = this.webAppUtil.getLoginUserObject();
+        return addDownIssue(user, issueForm, multipartFiles);
+    }
+
+    //  �븯�쐞�씠�뒋瑜� �깮�꽦�븳�떎.
+    @Override
+    @Transactional
+    public Issue addDownIssue(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
+        //  �궗�슜�븯怨� �엳�뒗 �뾽臾� 怨듦컙�씠 �솢�꽦 �긽�깭�씤吏� �솗�씤�븳�떎. �궗�슜 怨듦컙�뿉�꽌 濡쒓렇�씤�븳 �궗�슜�옄媛� 鍮꾪솢�꽦�씤吏� �솗�씤�븳�떎.
+        Workspace workspace = this.workspaceService.checkUseWorkspace(user, user.getLastWorkspaceId());
+        //  �봽濡쒖젥�듃 �쑀�슚�꽦 泥댄겕
+        Project project = this.projectService.getProject(issueForm.getProjectId());
+        //  �씠�뒋 �쑀�삎 �쑀�슚�꽦 泥댄겕
+        IssueType issueType = this.issueTypeService.getIssueType(issueForm.getIssueTypeId());
+        //  �슦�꽑�닚�쐞 �쑀�슚�꽦 泥댄겕
+        Priority priority = this.priorityService.getPriority(issueForm.getPriorityId());
+        //  以묒슂�룄 �쑀�슚�꽦 泥댄겕
+        Severity severity = this.severityService.getSeverity(issueForm.getSeverityId());
+
+        //  �젣紐� �쑀�슚�꽦 泥댄겕
+        this.verifyTitle(issueForm.getTitle());
+        //  �궇吏� �쑀�슚�꽦 泥댄겕
+        this.checkStartCompleteDate(issueForm.getStartDate(), issueForm.getCompleteDate());
+        //  �떞�떦 遺��꽌 �쑀�슚�꽦 泥댄겕
+        //this.verifyIssueDepartment(project, issueForm);
+
+        //  �씠�뒋 �긽�깭 �쑀�삎�씠 '��湲�' �씤 �씠�뒋 �긽�깭 媛��졇�삤湲�
+        IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
+
+        Issue issue = ConvertUtil.copyProperties(issueForm, Issue.class);
+        issue.setProject(project);
+        issue.setIssueStatus(issueStatus);
+        issue.setIssueType(issueType);
+        issue.setPriority(priority);
+        issue.setSeverity(severity);
+        if (issueForm.getParentIssueId() != null){
+            Issue parentIssue = this.getIssue(issueForm.getParentIssueId());
+            issue.setParentIssue(parentIssue);
+        }
+
+        issue.setIssueNumber(this.issueNumberGeneratorService.generateIssueNumber(project));    //  媛� �봽濡쒖젥�듃�쓽 怨좎쑀 �씠�뒋 踰덊샇 �깮�꽦
+
+        issue = this.issueRepository.saveAndFlush(issue);
+
+        issue.setReverseIndex(issue.getId() * -1);  //  荑쇰━ �냽�룄 媛쒖꽑�쓣 �쐞�빐 由щ쾭�뒪 �씤�뜳�뒪 �깮�꽦
+        //  �떞�떦�옄 吏��젙
+        //this.issueUserService.modifyIssueUser(issue, project.getWorkspace(), issueForm.getUserIds());
+        //  �떞�떦遺��꽌 吏��젙
+        this.issueDepartmentService.modifyIssueDepartment(issue, user, project.getWorkspace(), issueForm.getDepartmentIds());
+        //  �뾽泥� �젙蹂� ���옣
+        this.issueCompanyService.modifyIssueCompanyField(issue, issueForm.getIssueCompanyFields());
+        //  ISP �젙蹂� ���옣
+        this.issueIspService.modifyIssueIspField(issue, issueForm.getIssueIspFields());
+        //  HOSTING �젙蹂� ���옣
+        this.issueHostingService.modifyIssueHostingField(issue, issueForm.getIssueHostingFields());
+
+        //  泥⑤� �뙆�씪 ���옣
+        //  multipartFile �쓣 file Map List 媛앹껜濡� 蹂�寃쏀븳�떎.
+        List<Map<String, Object>> convertFileMaps = this.convertMultipartFileToFile(multipartFiles);
+        this.attachedFileService.addAttachedFile(convertFileMaps, issue, user.getAccount());
+
+        //  �뀓�뒪�듃 �뿉�뵒�꽣�뿉 泥⑤��븳 �뙆�씪�쓣 �씠�뒋�� �뿰寃�
+        this.checkNotHaveIssueIdAttachedFile(issue, issueForm);
+        //  �궗�슜�옄 �젙�쓽 �븘�뱶 ���옣
+        this.issueCustomFieldValueService.modifyIssueCustomFieldValue(issue, issueForm.getIssueCustomFields());
+        //  �씠�뒋 �씠�젰 �깮�꽦
+        this.issueHistoryService.addIssueHistory(issue, user, IssueHistoryType.ADD, null);
+        //  �씠�뒋 �쐞�뿕 愿�由� �깮�꽦
+        this.issueRiskService.addIssueRisk(issue, project.getWorkspace());
+        //  �쁺�냽�꽦 而⑦뀓�뒪�듃 鍮꾩슦湲�
+        this.clear();
+        //  �씠�뒋 �깮�꽦, �궘�젣�떆 �삁�빟 �씠硫붿씪�뿉 �벑濡앺빐�넃�뒗�떎.
+        this.reservationIssueEmail(issue, EmailType.ISSUE_ADD);
+        //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
+
+        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
+        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_ADD));
+
+        return issue;
     }
 
     //  �뿰愿��씠�뒋瑜� �깮�꽦�븳�떎.
@@ -690,8 +852,22 @@
             for(UserDepartment myDepartment : myDepartments){
                 myDepartmentIds.add(myDepartment.getDepartmentId());
             }
+        } else {
+            myDepartmentIds.add(-1L);
         }
         issueCondition.setMyDepartmentIds(myDepartmentIds);
+    }
+
+    void SetAllDepartmentId(IssueCondition issueCondition){
+        List<Long> departmentIds = Lists.newArrayList();
+        List<Map<String, Object>> departmentList = this.departmentMapper.find(null);
+
+        if(departmentList != null && departmentList.size() > 0){
+            for(Map<String, Object> department : departmentList){
+                departmentIds.add((Long) department.get("id"));
+            }
+        }
+        issueCondition.setMyDepartmentIds(departmentIds);
     }
 
     void SetWorkflowDepartment(List<IssueVo> issueVos){
@@ -745,17 +921,21 @@
         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)) {
-            results = this.issueMapper.find(issueCondition);
-            totalCount = this.issueMapper.count(issueCondition);
+        if (this.userWorkspaceService.checkWorkspaceManager(user)
+                || MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE)) {
+            this.SetAllDepartmentId(issueCondition);
         } else{
             this.SetMyDepartmentId(issueCondition);
-            results = this.issueMapper.findByDepartment(issueCondition);
-            totalCount = this.issueMapper.countByDepartment(issueCondition);
+            /*results = this.issueMapper.findByDepartment(issueCondition);
+            totalCount = this.issueMapper.countByDepartment(issueCondition);*/
         }
+        results = this.issueMapper.find(issueCondition);
+        totalCount = this.issueMapper.count(issueCondition);
 
 
         //  �뒠�떇 �쟾 - 0.8, 0.9, 0.9, 0.9, 0.9
@@ -768,11 +948,20 @@
 
         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);
 
-        this.setCountDownIssues(results, issueVos);
+        if (issueCondition.getTree()) {
+            this.setParentIssue(issueVos);
+            this.setDownIssues(user, issueVos);
+            this.setRelationIssues(issueVos);
+        }
+        this.setCountDownIssues(issueVos);
+
         this.SetWorkflowDepartment(issueVos); //�썙�겕�뵆濡쒖슦�뿉 �꽕�젙�븳 �떞�떦遺��꽌 媛��졇�삤湲�
 
         resJsonData.put(Constants.RES_KEY_CONTENTS, issueVos);
@@ -784,11 +973,67 @@
         return issueVos;
     }
 
+
+    // �븯�쐞 �씠�뒋 �꽭�똿(�옱洹�)
+    private void setDownIssues(User user, List<IssueVo> issueVos) {
+        for(IssueVo issueVo : issueVos) {
+            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueVo.getId());
+            List<IssueVo> downIssueVos = Lists.newArrayList();
+            IssueCondition issueCondition = new IssueCondition();
+            issueCondition.addIssueIds(String.valueOf(issueVo.getId()));
+
+            for(Issue downIssue : downIssues){
+                IssueVo addIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
+                addIssueVo.setIssueTypeId(downIssue.getIssueType().getId());
+                downIssueVos.add(addIssueVo);
+            }
+            issueVo.setIssueDownVos(downIssueVos);
+
+            if (downIssueVos.size() > 0) {
+                this.setDownIssues(user, downIssueVos);
+            }
+
+            //  �씠�뒋 �궗�슜�옄 �젙蹂� 異붽�
+            //this.setIssueUserList(issueVos, issueCondition);
+            this.setIssueDepartmentList(issueVos, issueCondition, user);
+            //  �벑濡앹옄 �젙蹂� 異붽�
+            this.setRegister(issueVos);  //  �떞�떦�옄 �젙蹂� �뀑�똿
+            //  �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂� 異붽�
+            this.setIssueCustomFieldValue(issueVos, issueCondition);
+            //�썙�겕�뵆濡쒖슦�뿉 �꽕�젙�븳 �떞�떦遺��꽌 媛��졇�삤湲�
+            this.SetWorkflowDepartment(issueVos);
+        }
+    }
+
+    // �뿰愿� �씠�뒋 �꽭�똿
+    private void setRelationIssues(List<IssueVo> issueVos) {
+        for(IssueVo issueVo : issueVos) {
+            List<IssueVo> relationIssues = this.issueRelationService.findRelationIssue(issueVo.getId());
+            for(IssueVo relationIssue : relationIssues){
+                issueVo.addRelationIssueVo(ConvertUtil.copyProperties(relationIssue, IssueVo.class));
+            }
+        }
+    }
+
+    // �긽�쐞 �씠�뒋 泥댄겕
+    private void setParentIssue(List<IssueVo> issueVos) {
+        for(IssueVo issueVo : issueVos) {
+            if(issueVo.getParentIssueId() != null) {
+                Issue parentIssue = this.getIssue(issueVo.getParentIssueId());
+                //issueVo.setParentIssueVo(ConvertUtil.copyProperties(parentIssue, IssueVo.class));
+                if(parentIssue.getIssueCustomFieldValues() == null || parentIssue.getIssueCustomFieldValues().size() == 0){
+                    issueVo.setIssueCustomFieldValueVos(null);
+                }
+                ConvertUtil.copyProperties(parentIssue, issueVo);
+            }
+        }
+    }
+
     @Override
     @Transactional(readOnly = true)
-    public void setCountDownIssues(List<Map<String, Object>> results, List<IssueVo> issueVos) {
-        for (Map<String, Object> result : results){
-            List<Issue> downIssues = this.issueRepository.findByParentIssueId((Long) result.get("id")); //�븯�쐞�씠�뒋 媛��졇�삤湲�
+    public void setCountDownIssues(List<IssueVo> issueVos) {
+        for (IssueVo issueVo : issueVos){
+            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueVo.getId()); //�븯�쐞�씠�뒋 媛��졇�삤湲�
             if(downIssues != null && downIssues.size() > 0){ //�긽�쐞�씠�뒋 媛�吏�怨� �엳�뒗 �븷�뱾�씠 �엳�쑝硫�
                 int downIssueAllCount = 0;// �븯�쐞�씠�뒋 �쟾泥� 移댁슫�듃
                 int downIssueCount = 0;// �븯�쐞�씠�뒋 誘몄셿猷� 移댁슫�듃
@@ -807,12 +1052,8 @@
                         downIssueCount ++;
                     }
 
-                    for(IssueVo issueVo : issueVos){
-                        if(issueVo.getId().equals(parentIssueVo.getId())){
-                            issueVo.setDownIssueCount(downIssueCount);
-                            issueVo.setDownIssueAllCount(parentIssueVo.getDownIssueAllCount());
-                        }
-                    }
+                    issueVo.setDownIssueCount(downIssueCount);
+                    issueVo.setDownIssueAllCount(parentIssueVo.getDownIssueAllCount());
                 }
             }
         }
@@ -825,15 +1066,19 @@
     public void findApiIssue(ApiMonitorCondition apiMonitorCondition, Map<String, Object> resJsonData) {
 
         IssueTypeCondition issueTypeCondition = new IssueTypeCondition();
+        issueTypeCondition.setIsApi(Issue.IS_API_YES);
         List<IssueTypeVo> issueTypes = this.issueTypeService.findIssueType(issueTypeCondition);
 
-        // 媛믪씠 �뾾�쓣 寃쎌슦 珥덇린媛� �엯�젰
-        if (StringUtils.isEmpty(apiMonitorCondition.getSearchPeriod())) {
-            apiMonitorCondition.setSearchPeriod(DateUtil.LAST_SEVEN_DAYS);
-        }
-
         //  寃��깋 �씪�옄瑜� 援ы븳�떎.
-        List<Date> searchDates = CommonUtil.findSearchPeriod(apiMonitorCondition.getSearchPeriod());
+        List<Date> searchDates = Lists.newArrayList();
+        if (apiMonitorCondition.getSearchPeriod().equals(DateUtil.CUSTOM_INPUT)) {
+            Date startDate = DateUtil.convertStrToDate(apiMonitorCondition.getSearchStartDate(), "yyyy-MM-dd");
+            Date endDate = DateUtil.addDays(DateUtil.convertStrToDate(apiMonitorCondition.getSearchEndDate(), "yyyy-MM-dd"), 1);
+
+            searchDates = CommonUtil.findSearchPeriod(startDate, endDate);
+        } else {
+            searchDates = CommonUtil.findSearchPeriod(apiMonitorCondition.getSearchPeriod());
+        }
 
         //  �궇吏쒓� 寃��깋�릺吏� �븡�븯�쑝硫� �삤瑜�
         if (searchDates.size() < 1) {
@@ -1042,7 +1287,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)) {
                 projects = this.projectMapper.findByWorkspaceManagerAll(projectCondition);
             } else  {
                 projects = this.projectService.findByWorkspaceIdAndIncludeProjectAll(projectCondition);
@@ -1151,7 +1398,7 @@
             }
 
             //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
-            if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user)) {
+            if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, null)) {
                 issueVo.setModifyPermissionCheck(Boolean.TRUE);
             }
         }
@@ -1188,7 +1435,7 @@
             }
 
             //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
-            if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user)) {
+            if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, issueVo.getDepartmentVos())) {
                 issueVo.setModifyPermissionCheck(Boolean.TRUE);
             }
         }
@@ -1203,6 +1450,7 @@
         if (issueCondition.getId() != null) {
             Issue issue = this.getIssue(issueCondition.getId());
             issueVo = ConvertUtil.copyProperties(issue, IssueVo.class);
+            User user = this.webAppUtil.getLoginUserObject();
 
             switch (issueCondition.getDeep()) {
                 case "01": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦遺��꽌, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� �뀑�똿�븳�떎.
@@ -1223,7 +1471,7 @@
                     break;
 
                 case "02": //  �봽濡쒖젥�듃, �씠�뒋 �쑀�삎, �씠�뒋 �긽�깭,  �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦�옄, 泥⑤��뙆�씪, �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂�, �뙎湲�, 湲곕줉�쓣 �뀑�똿�븳�떎.
-                    this.setIssueDetail(issueVo, issue);    //  �씠�뒋 �긽�꽭 �젙蹂대�� �뀑�똿�븳�떎.
+                    this.setIssueDetail(issueVo, issue, user);    //  �씠�뒋 �긽�꽭 �젙蹂대�� �뀑�똿�븳�떎.
                     this.setIssueTableConfigs(issue, issueVo);
                     issueVo.setProjectVo(ConvertUtil.copyProperties(issue.getProject(), ProjectVo.class));
                     break;
@@ -1259,32 +1507,34 @@
     // �븯�쐞 �씠�뒋 �젙蹂대�� �뀑�똿�븳�떎
     private void setDownIssues(Issue issue, IssueVo issueVo) {
         List<Issue> downIssues = this.issueRepository.findByParentIssueId(issue.getId());
-            if(downIssues != null && downIssues.size()>0){
-                List<IssueVo> resultList = new ArrayList<>();
-                for(Issue downIssue : downIssues){
-                    IssueVo downIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
-                    downIssueVo.setIssueTypeVo(ConvertUtil.copyProperties(downIssue.getIssueType(), IssueTypeVo.class));
-                    downIssueVo.setPriorityVo(ConvertUtil.copyProperties(downIssue.getPriority(), PriorityVo.class));
-                    downIssueVo.setSeverityVo(ConvertUtil.copyProperties(downIssue.getSeverity(), SeverityVo.class));
-                    //�씠�뒋 �긽�깭 異붽�
-                    IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(downIssue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
-                    issueStatusVo.setIssueStatusType(downIssue.getIssueStatus().getIssueStatusType().toString());
-                    downIssueVo.setIssueStatusVo(issueStatusVo);
+        if(downIssues != null && downIssues.size()>0){
+            List<IssueVo> resultList = new ArrayList<>();
+            for(Issue downIssue : downIssues){
+                IssueVo downIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
+                downIssueVo.setIssueTypeVo(ConvertUtil.copyProperties(downIssue.getIssueType(), IssueTypeVo.class));
+                downIssueVo.setPriorityVo(ConvertUtil.copyProperties(downIssue.getPriority(), PriorityVo.class));
+                downIssueVo.setSeverityVo(ConvertUtil.copyProperties(downIssue.getSeverity(), SeverityVo.class));
+                //�씠�뒋 �긽�깭 異붽�
+                IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(downIssue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
+                issueStatusVo.setIssueStatusType(downIssue.getIssueStatus().getIssueStatusType().toString());
+                downIssueVo.setIssueStatusVo(issueStatusVo);
 
-                    this.setRegister(downIssue, downIssueVo); // �벑濡앹옄
-                    this.setIssueDepartment(downIssue, downIssueVo);  //  �떞�떦遺��꽌 �젙蹂� �뀑�똿
-                    this.setIssueCustomFields(downIssue, downIssueVo);   // �궗�슜�옄�젙�쓽�븘�뱶 �젙蹂� �꽭�똿
+                this.setRegister(downIssue, downIssueVo); // �벑濡앹옄
+                this.setIssueDepartment(downIssue, downIssueVo);  //  �떞�떦遺��꽌 �젙蹂� �뀑�똿
+                this.setIssueCustomFields(downIssue, downIssueVo);   // �궗�슜�옄�젙�쓽�븘�뱶 �젙蹂� �꽭�똿
+                this.setIssueHistory(downIssue, downIssueVo);   //  �씠�뒋 湲곕줉 �젙蹂� �뀑�똿
+                this.setIssueComments(downIssue, downIssueVo);  //  �뙎湲� �젙蹂� �뀑�똿
 
-                    resultList.add(downIssueVo);
-                }
-                issueVo.setIssueDownVos(resultList);
+                resultList.add(downIssueVo);
             }
+            issueVo.setIssueDownVos(resultList);
+        }
     }
 
     //  �씠�뒋 �긽�꽭 �젙蹂대�� �뀑�똿�븳�떎.
     @Override
     @Transactional(readOnly = true)
-    public void setIssueDetail(IssueVo issueVo, Issue issue) {
+    public void setIssueDetail(IssueVo issueVo, Issue issue, User user) {
         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");
@@ -1297,10 +1547,10 @@
         this.setIssueDepartment(issue, issueVo);  //  �떞�떦遺��꽌 �젙蹂� �뀑�똿
         this.setAttachedFiles(issue, issueVo);  //  泥⑤� �뙆�씪 �젙蹂� �뀑�똿
         this.setIssueCustomFields(issue, issueVo);  //  �궗�슜�옄 �젙�쓽 �븘�뱶 媛� �젙蹂� �뀑�똿
-        this.setIssueComments(issue, issueVo);  //  �뙎湲� �젙蹂� �뀑�똿
-        this.setIssueHistory(issue, issueVo);   //  �씠�뒋 湲곕줉 �젙蹂� �뀑�똿
         this.setRelationIssue(issue, issueVo);        //�뿰愿� �씪媛� �뀑�똿
         this.setDownIssues(issue, issueVo); //�븯�쐞 �씪媛� �꽭�똿
+        this.setIssueComments(issue, issueVo);  //  �뙎湲� �젙蹂� �뀑�똿
+        this.setIssueHistory(issue, issueVo);   //  �씠�뒋 湲곕줉 �젙蹂� �뀑�똿
 
         IssueType issueType = this.issueTypeService.getIssueType(issueVo.getIssueTypeVo().getId()); // �씠�뒋�쓽 �씠�뒋�쑀�삎 媛앹껜
         Integer using = issueType.getUsePartner() != null ? issueType.getUsePartner().intValue() : 0; // �씠�뒋�쑀�삎蹂꾨줈 �궗�슜以묒씤 �뾽泥�/ISP/�샇�뒪�똿 媛�
@@ -1319,8 +1569,12 @@
         this.setIssueCompanyField(issue, issueVo);  //�뾽泥� �젙蹂� �꽭�똿
         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);
+        }
     }
 
     //  �긽�쐞�씪媛� �젙蹂� 異붽�
@@ -1428,6 +1682,15 @@
             DepartmentVo departmentVo = ConvertUtil.copyProperties(issueDepartment.getDepartment(), DepartmentVo.class);
             departmentVo.setByName(departmentVo.getDepartmentName());
             departmentVos.add(departmentVo);
+
+            List<UserDepartment> userDepartments = this.userDepartmentRepository.findByDepartmentId(departmentVo.getId());
+            if (userDepartments != null && userDepartments.size() > 0) {
+                for (UserDepartment userDepartment : userDepartments) {
+                    if (userDepartment.getUserId().equals(this.webAppUtil.getLoginId())){
+                        issueVo.setModifyPermissionCheck(Boolean.TRUE);
+                    }
+                }
+            }
         }
         issueVo.setDepartmentVos(departmentVos);
     }
@@ -1469,16 +1732,16 @@
 
     //  �씠�뒋 湲곕줉 �젙蹂대�� �뀑�똿�븳�떎.
     private void setIssueHistory(Issue issue, IssueVo issueVo) {
-        issueVo.setIssueHistoryVos(this.issueHistoryService.findIssueHistory(issue.getId()));
+        issueVo.setIssueHistoryVos(this.issueHistoryService.findIssueHistory(issue));
     }
 
     // �궗�슜�옄 �젙�쓽 �븘�뱶 媛믪씠 媛숈� �씠�뒋 李얘린
     @Override
     @Transactional
-    public List<IssueVo> findIssue(IssueApiForm issueApiform) {
+    public List<Issue> findIssue(IssueApiForm issueApiform) {
 
         List<IssueCustomFieldValueForm> issueCustomFieldValueForms = issueApiform.getIssueCustomFieldValues();
-        List<IssueVo> resultIssueVos = Lists.newArrayList();
+        List<Issue> resultIssueVos = Lists.newArrayList();
         String comma = ",";
 
         if (issueCustomFieldValueForms.size() > 0) {
@@ -1493,10 +1756,11 @@
 
             IssueCustomFieldValueCondition issueCustomFieldValueCondition = new IssueCustomFieldValueCondition();
             issueCustomFieldValueCondition.setUseValue(concatUseValue);
+            issueCustomFieldValueCondition.setIssueTypeId(issueApiform.getIssueTypeId());
             List<Map<String, Object>> results = this.issueMapper.findByCustomFieldValue(issueCustomFieldValueCondition);
             if (results != null && results.size() > 0) {
                 for (Map<String, Object> result : results) {
-                    resultIssueVos.add(ConvertUtil.convertMapToClass(result, IssueVo.class));
+                    resultIssueVos.add(this.getIssue(MapUtil.getLong(result, "id")));
                 }
             }
         }
@@ -1522,11 +1786,10 @@
         User user = this.convertToUser(issueApiForm.getToken());
         IssueForm issueForm = this.convertToIssueForm(issueApiForm, user);
 
-        List<IssueVo> issueVos = this.findIssue(issueApiForm);
-        if (issueVos != null && issueVos.size() > 0) {
-            List<Issue> issue = Lists.newArrayList();
-            for (IssueVo issueVo : issueVos) {
-                IssueVo parentIssueVo = issueVo.getParentIssueVo();
+        List<Issue> issue = this.findIssue(issueApiForm);
+        if (issue != null && issue.size() > 0) {
+            List<Issue> issues = Lists.newArrayList();
+            for (Issue issueVo : issue) {
                 issueForm.setId(issueVo.getId());
 
                 // �옄�룞 醫낅즺 �긽�깭 �꽕�젙�씠 �릺�뼱 �엳吏� �븡�쑝硫� �삤瑜섎컻�깮
@@ -1534,11 +1797,10 @@
                 Issue parentIssue = modifyIssue.getParentIssue();
                 IssueType issueType = modifyIssue.getIssueType();
                 IssueStatus issueStatus = issueType.getIssueStatus();
-                if (issueStatus == null) {
-                    throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_COMPLETE_ISSUE_STATUS_NOT_EXIST));
-                }
-
                 if (parentIssue != null) {
+                    if (issueStatus == null) {
+                        throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_COMPLETE_ISSUE_STATUS_NOT_EXIST));
+                    }
                     IssueCondition issueCondition = new IssueCondition(issueVo.getId(), parentIssue.getId());
                     List<Map<String, Object>> results = this.issueMapper.findNotCompleteByParentIssueId(issueCondition);
                     // �븯�쐞 �씪媛먯씠 紐⑤몢 醫낅즺 �긽�깭�씪�븣 �긽�쐞 �씪媛먮룄 醫낅즺 泥섎━
@@ -1548,9 +1810,9 @@
                     }
                 }
 
-                issue.add(modifyIssue);
+                issues.add(modifyIssue);
             }
-            return issue;
+            return issues;
         } else {
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.API_ISSUE_NOT_EXIST));
@@ -1611,39 +1873,41 @@
     private Issue modifyIssueForApi(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
         CheckIssueData checkIssueData = this.checkIssue(user, issueForm);
 
-        Issue issue = checkIssueData.getIssue();
-        Project project = checkIssueData.getProject();
-        IssueType issueType = checkIssueData.getIssueType();
-        IssueStatus oldIssueStatus = checkIssueData.getOldIssueStatus();
-        IssueStatus issueStatus = checkIssueData.getNewIssueStatus();
+        // �씠�뒋 �씠�젰 �궓湲곌린
+        this.addIssueHistoryModify(user, issueForm, checkIssueData, multipartFiles);
 
+        // db�뿉 ���옣
+        return this.saveIssue(issueForm, checkIssueData);
+    }
+
+    private void addIssueHistoryModify(User user, IssueForm issueForm, CheckIssueData checkIssueData, List<MultipartFile> multipartFiles) {
         //  蹂�寃� �씠�젰 �젙蹂� 異붿텧
         StringBuilder detectIssueChange = this.issueHistoryService.detectIssueChange(issueForm, checkIssueData, multipartFiles);
 
         //  �봽濡쒖젥�듃媛� 蹂�寃쎈릺硫� �씠�뒋 �꽆踰꾨�� �깉濡� �뵲�빞 �븳�떎.
-        this.checkChangeProject(checkIssueData.getProject(), issue);
+        this.checkChangeProject(checkIssueData.getProject(), checkIssueData.getIssue());
 
         //  �씠�뒋 �쑀�삎�씠 蹂�寃쎈릺�뿀�뒗吏� �솗�씤�븯怨� 蹂�寃쎈릺�뿀�떎硫� �씠�뒋 �긽�깭 �냽�꽦�씠 '��湲�' �씤 �씠�뒋 �긽�깭濡� 援먯껜�븳�떎.
-        if (this.checkChangeIssueType(issueType, issueStatus, issue)) {
-            issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
+        if (this.checkChangeIssueType(checkIssueData.getIssueType(), checkIssueData.getNewIssueStatus(), checkIssueData.getIssue())) {
+            checkIssueData.setNewIssueStatus(this.issueStatusService.findByIssueStatusTypeIsReady(checkIssueData.getIssueType().getWorkflow()));
             //  �씠�뒋 �긽�깭 蹂�寃� �씠�젰 �궓湲곌린 - �씠�젰�쓣 �궓湲곌린 �쐞�빐 issueForm �뿉 issueStatus Id 媛믪쓣 ���옣.
-            issueForm.setIssueStatusId(issueStatus.getId());
-            this.issueHistoryService.detectIssueStatus(issue, issueForm, detectIssueChange, oldIssueStatus, issueStatus);
+            issueForm.setIssueStatusId(checkIssueData.getNewIssueStatus().getId());
+            this.issueHistoryService.detectIssueStatus(checkIssueData.getIssue(), issueForm, detectIssueChange, checkIssueData.getOldIssueStatus(), checkIssueData.getNewIssueStatus());
         }
 
         // db�뿉 ���옣
-        issue = this.saveIssue(issueForm, checkIssueData);
+//        checkIssueData.setIssue(this.saveIssue(issueForm, checkIssueData));
 
         //  �씠�뒋 �씠�젰 �벑濡�
         if (!StringUtils.isEmpty(detectIssueChange.toString())) {
-            this.issueHistoryService.addIssueHistory(issue, user, IssueHistoryType.MODIFY, detectIssueChange.toString());
+            this.issueHistoryService.addIssueHistory(checkIssueData.getIssue(), user, IssueHistoryType.MODIFY, detectIssueChange.toString());
         }
         //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
         UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
         log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_MODIFY));
-
-        return issue;
     }
+
+
 
     private Issue saveIssue(IssueForm issueForm, CheckIssueData checkIssueData) {
         Issue issue = checkIssueData.getIssue();
@@ -1833,7 +2097,7 @@
     //  �씠�뒋 �닔�젙 沅뚰븳 泥댄겕
     private void verifyIssueModifyPermission(Issue issue, User user) {
         //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
-        if (!this.checkHasPermission(ConvertUtil.copyProperties(issue, IssueVo.class), this.getIssueUserVos(issue), user)) {
+        if (!this.checkHasPermission(ConvertUtil.copyProperties(issue, IssueVo.class), this.getIssueUserVos(issue), user, this.getIssueDepartmentVos(issue))) {
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_MODIFY_PERMISSION));
         }
@@ -1858,25 +2122,51 @@
         return userVos;
     }
 
+    //  �씠�뒋�뿉�꽌 �떞�떦�옄 �젙蹂대�� 異붿텧�븳�떎.
+    private List<DepartmentVo> getIssueDepartmentVos(Issue issue) {
+        List<DepartmentVo> departmentVos = Lists.newArrayList();
+
+        Set<IssueDepartment> issueDepartments = issue.getIssueDepartments();
+
+        try {
+            for (IssueDepartment issueDepartment : issueDepartments) {
+                Department department = issueDepartment.getDepartment();
+                DepartmentVo departmentVo = ConvertUtil.copyProperties(department, DepartmentVo.class);
+                departmentVos.add(departmentVo);
+            }
+        } catch (Exception ex) {
+
+        }
+
+        return departmentVos;
+    }
+
     //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
-    private boolean checkHasPermission(IssueVo issueVo, List<UserVo> issueUserVos, User user) {
+    private boolean checkHasPermission(IssueVo issueVo, List<UserVo> issueUserVos, User user, List<DepartmentVo> departmentVos) {
         boolean hasPermission = false;
 
         //  �뾽臾� 怨듦컙 愿�由ъ옄�씪 寃쎌슦 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
         hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.WORKSPACE_MANAGER, issueVo, null, null, user);
         //  �봽濡쒖젥�듃 愿�由ъ옄�씪 寃쎌슦 �빐�떦 �봽濡쒖젥�듃�뿉 �벑濡앸맂 �씠�뒋�뒗 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
         hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.PROJECT_MANAGER, issueVo, null, null, user);
+        //  �씠�뒋 愿�由ъ옄�씪 寃쎌슦 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
+        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ISSUE_MANAGER, issueVo, null, null, user);
         //   �씠�뒋 �벑濡앹옄�씪 寃쎌슦 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
         hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.REGISTER, issueVo, null, null, user);
-        //  �씠�뒋 �떞�떦�옄�씪 寃쎌슦 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎. => �떞�떦遺��꽌濡� �닔�젙 - 泥댄겕
+        //  �씠�뒋 �떞�떦�옄�씪 寃쎌슦 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
         //hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ASSIGNEE, issueVo, issueUserVos);
+        //  �씠�뒋 �떞�떦遺��꽌�씪 寃쎌슦 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
+        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.DEPARTMENT, issueVo, null, departmentVos, user);
         //  �떞�떦�옄媛� �뾾�쑝硫� 紐⑤뱺 �궗�슜�옄媛� �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
+
+        //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;
     }
 
     //  �씠�뒋 �닔�젙 沅뚰븳�쓣 �솗�씤�븳�떎.
-    private boolean checkIssueModifyPermission(Boolean hasPermission, String checkType, IssueVo issueVo, List<UserVo> issueUserVos, List<DepartmentVo> issueDepartmentVos, User user) {
+    private boolean checkIssueModifyPermission(Boolean hasPermission, String checkType, IssueVo issueVo, List<UserVo> issueUserVos, List<DepartmentVo> departmentVos, User user) {
         if (!hasPermission) {
             switch (checkType) {
                 case Issue.WORKSPACE_MANAGER:  //  �뾽臾� 怨듦컙 愿�由ъ옄
@@ -1888,6 +2178,11 @@
                     Issue issue = this.getIssue(issueVo.getId());
                     //  �봽濡쒖젥�듃 愿�由ъ옄�씪 寃쎌슦 �빐�떦 �봽濡쒖젥�듃�뿉 �벑濡앸맂 �씠�뒋�뒗 �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
                     hasPermission = this.projectRoleUserService.checkProjectManager(issue.getProject(), user);
+                    break;
+
+                case Issue.ISSUE_MANAGER:    //  �씠�뒋 愿�由ъ옄
+                    UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
+                    hasPermission = MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE);
                     break;
 
                 case Issue.REGISTER:   //  �씠�뒋 �벑濡앹옄
@@ -1911,17 +2206,22 @@
 
                 case Issue.DEPARTMENT:
                     //  �떞�떦遺��꽌媛� �뾾�쑝硫� 紐⑤뱺 �궗�슜�옄媛� �닔�젙 沅뚰븳�쓣 媛뽯뒗�떎.
-                    if (issueDepartmentVos.size() < 1) {
+                    /*if (userDepartmentVos.size() < 1) {
                         hasPermission = true;
                         break;
-                    }
-                    //   �씠�뒋 �떞�떦遺��꽌 �뿬遺� �솗�씤
-                    /*for (DepartmentVo issueDepartmentVo : issueDepartmentVos) {
-                        if (issueDepartmentVo.getId().equals()) {
-                            hasPermission = true;
-                            break;
-                        }
                     }*/
+                    //   �씠�뒋 �떞�떦遺��꽌 �뿬遺� �솗�씤
+                    for (DepartmentVo departmentVo : departmentVos) {
+                        List<UserDepartment> userDepartments = this.userDepartmentService.findByDepartmentId(departmentVo.getId());
+                        if(userDepartments != null && userDepartments.size() > 0) {
+                            for (UserDepartment userDepartment : userDepartments) {
+                                if (userDepartment.getUserId().equals(user.getId())){
+                                    hasPermission = true;
+                                    break;
+                                }
+                            }
+                        }
+                    }
                     break;
             }
         }
@@ -1944,6 +2244,19 @@
         this.verifyIssueModifyPermission(issue, user);
 
         IssueStatus issueStatus = this.issueStatusService.getIssueStatus(issueForm.getIssueStatusId());
+
+        if (issueStatus.getIssueStatusType().toString().equals("CLOSE")) {
+            List<String> downIssuesStatus = issueForm.getDownIssuesStatus();
+            if (downIssuesStatus != null && downIssuesStatus.size() > 0) {
+                for (String downIssueStatus : downIssuesStatus) {
+                    if (!downIssueStatus.equals("CLOSE")) {
+                        throw new OwlRuntimeException(
+                                this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_MODIFY_STATUS));
+                    }
+                }
+            }
+        }
+
         //  �씠�뒋 �긽�깭瑜� 蹂�寃쏀븷 �븣 �꽑�깮�븳 �씠�뒋 �긽�깭濡� 蹂�寃쏀븷 �닔 �엳�뒗吏� �솗�씤�븳�떎.
         this.issueStatusService.checkNextIssueStatus(issue, issueStatus);
         //  蹂�寃� �씠�젰 �젙蹂� 異붿텧
@@ -2068,20 +2381,95 @@
         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);
+        Issue issue = null;
+        if(issueId != null){
+            issue = this.getIssue(issueId);
+        }
         //  �씠�뒋 �닔�젙 沅뚰븳�쓣 媛뽮퀬 �엳�뒗吏� �솗�씤
         this.verifyIssueModifyPermission(issue, user);
 
@@ -2506,7 +2894,7 @@
             Map<String, Priority> priorityMaps = new HashMap<>();   //  �슦�꽑 �닚�쐞 紐⑥쓬
             Map<String, Severity> severityMaps = new HashMap<>();   //  以묒슂�룄 紐⑥쓬
             Map<String, Object> userMaps = new HashMap<>(); //  �궗�슜�옄 紐⑥쓬
-            Map<String, Object> departmentMaps = new HashMap<>(); //  遺��꽌 紐⑥쓬
+            Map<String, DepartmentVo> departmentMaps = new HashMap<>(); //  遺��꽌 紐⑥쓬
             Map<String, CustomField> customFieldMaps = new HashMap<>();
             Map<String, IssueStatus> issueStatusReadyMaps = new HashMap<>();   //  �긽�깭 �냽�꽦 '��湲�'�씤 �씠�뒋 �긽�깭
             Map<Long, Long> issueNumberMaps = new HashMap<>();  //  �씠�뒋 踰덊샇 紐⑥쓬
@@ -2556,7 +2944,7 @@
                 //  1踰� �뿤�뜑遺��꽣 �뜲�씠�꽣 �쁺�뿭
                 if (rowIndex > 1) {
                     //  �씠�뒋濡� �벑濡앺븯湲� �쐞�빐 IssueForm �뿉 �뜲�씠�꽣瑜� �뀑�똿�븳�떎.
-                    issueForms.add(this.setIssueFormToExcelField(row, (rowIndex + 1), issueStatusReadyMaps, projectMaps, issueTypeMaps, priorityMaps, severityMaps, userMaps, customFieldMaps, issueNumberMaps, headers));
+                    issueForms.add(this.setIssueFormToExcelField(row, (rowIndex + 1), issueStatusReadyMaps, projectMaps, issueTypeMaps, priorityMaps, severityMaps, userMaps, departmentMaps, customFieldMaps, issueNumberMaps, headers));
                 }
             }
 
@@ -2707,7 +3095,7 @@
 
     //  �씠�뒋�쓽 二쇱슂 �냽�꽦�쓣 map �뿉 ���옣�븯�뿬 �뿊�� import �뿉�꽌 吏��젙�븳 ���긽(�씠�뒋 �냽�꽦)�쓣 鍮좊Ⅴ寃� 李얠쓣 �닔 �엳寃� �븳�떎.
     private void IssueAttributeMapToList(Map<String, Project> projectMaps, Map<String, IssueType> issueTypeMaps, Map<String, Priority> priorityMaps, Map<String, Severity> severityMaps,
-                                         Map<String, Object> userMaps, Map<String, Object> departmentMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, Map<String, Long> issueTypeCustomFieldMaps, Map<String, IssueStatus> issueStatusReadyMaps) {
+                                         Map<String, Object> userMaps, Map<String, DepartmentVo> departmentMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, Map<String, Long> issueTypeCustomFieldMaps, Map<String, IssueStatus> issueStatusReadyMaps) {
         //  �봽濡쒖젥�듃 �궎濡� 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
         List<Project> projects = this.projectService.findByWorkspaceId();
         List<Long> projectIds = Lists.newArrayList();
@@ -2731,16 +3119,7 @@
             for (Map<String, Object> user : users) {
                 userMap.put(CommonUtil.decryptAES128(MapUtil.getString(user, "account")), MapUtil.getLong(user, "userId"));
             }
-
             userMaps.put(project.getProjectKey(), userMap);
-
-            //  �봽濡쒖젥�듃�뿉 李몄뿬�븯�뒗 遺��꽌 �젙蹂�
-            List<Map<String, Object>> departments = this.departmentService.findProjectDepartment(project);
-            List<Long> departmentList = Lists.newArrayList();
-            //  遺��꽌 �젙蹂대�� ���옣
-            for (Map<String, Object> department : departments) {
-                departmentList.add(MapUtil.getLong(department, "departmentId"));
-            }
         }
 
         //  �씠�뒋 �쑀�삎�쓣 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
@@ -2750,6 +3129,13 @@
 
             IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
             issueStatusReadyMaps.put(issueType.getId().toString(), issueStatus);
+
+            //  �썙�겕�뵆濡쒖슦�뿉 �냽�빐�엳�뒗 遺��꽌 �젙蹂�
+            List<DepartmentVo> departments = this.departmentService.findWorkflowDepartment(issueType.getId());
+            //  遺��꽌 �젙蹂대�� ���옣
+            for (DepartmentVo department : departments) {
+                departmentMaps.put(department.getDepartmentName(), department);
+            }
         }
 
         //  �슦�꽑�닚�쐞瑜� 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
@@ -2773,7 +3159,7 @@
 
     //  �뿊�� �븘�뱶�뿉 �엳�뒗 �젙蹂대�� �씠�뒋 form �쑝濡� �삷湲대떎.
     private IssueForm setIssueFormToExcelField(Row row, int rowIndex, Map<String, IssueStatus> issueStatusReadyMaps, Map<String, Project> projectMaps, Map<String, IssueType> issueTypeMaps, Map<String,
-            Priority> priorityMaps, Map<String, Severity> severityMaps, Map<String, Object> userMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, List<String> headers) {
+            Priority> priorityMaps, Map<String, Severity> severityMaps, Map<String, Object> userMaps, Map<String, DepartmentVo> departmentMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, List<String> headers) {
         IssueForm issueForm = new IssueForm();
         issueForm.setRegisterId(this.webAppUtil.getLoginId());
         Project project = null;
@@ -2817,9 +3203,13 @@
                     //  以묒슂�룄瑜� IssueForm �뿉 ���옣�븳�떎.
                     this.setIssueFormSeverity(cell, severityMaps, issueForm, rowIndex);
                     break;
+                /*case 6:
+                    //  �떞�떦�옄瑜� IssueForm �뿉 ���옣�븳�떎.
+                    this.setIssueFormAssignee(cell, userMaps, issueForm, project);
+                    break;*/
                 case 6:
                     //  �떞�떦遺��꽌瑜� IssueForm �뿉 ���옣�븳�떎.
-                    this.setIssueFormAssignee(cell, userMaps, issueForm, project);
+                    this.setIssueFormDepartment(cell, departmentMaps, issueForm, project);
                     break;
                 case 7:
                     //  �떆�옉�씪�쓣 IssueForm �뿉 ���옣�븳�떎.
@@ -2830,7 +3220,7 @@
                     this.setIssueFormPeriod(cell, issueForm, false, rowIndex);
                     break;
                 default:
-                    //  8踰� �씠�긽遺��꽣�뒗 �궗�슜�옄 �젙�쓽 �븘�뱶. �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� IssueForm �뿉 ���옣�븳�떎.
+                    //  9踰� 遺��꽣�뒗 �궗�슜�옄 �젙�쓽 �븘�뱶. �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� IssueForm �뿉 ���옣�븳�떎.
                     this.setIssueFormCustomFieldValue(cell, customFieldMaps, issueForm, headers.get(cellIndex), rowIndex);
             }
         }
@@ -2959,20 +3349,39 @@
         issueForm.setSeverityId(severity.getId());
     }
 
-    //  �떞�떦遺��꽌瑜� IssueForm �뿉 ���옣�븳�떎.
     private void setIssueFormAssignee(Cell cell, Map<String, Object> userMaps, IssueForm issueForm, Project project) {
         if (cell != null) {
             String[] splitAssignee = CommonUtil.convertExcelStringToCell(cell).split("#");
             Map<String, Object> userMap = (Map<String, Object>) MapUtil.getObject(userMaps, project.getProjectKey());
 
-            List<Long> departmentIds = Lists.newArrayList();
+            List<Long> userIds = Lists.newArrayList();
 
             for (String account : splitAssignee) {
                 if (MapUtil.getLong(userMap, account) != null) {
-                    departmentIds.add(MapUtil.getLong(userMap, account));
+                    userIds.add(MapUtil.getLong(userMap, account));
                 }
             }
+            issueForm.setUserIds(userIds);
+        }
+    }
 
+    //  �떞�떦遺��꽌瑜� IssueForm �뿉 ���옣�븳�떎.
+    private void setIssueFormDepartment(Cell cell, Map<String, DepartmentVo> departmentMaps, IssueForm issueForm, Project project) {
+        if (cell != null) {
+            String[] splitDepartment = CommonUtil.convertExcelStringToCell(cell).split("#");
+
+            //  媛믪씠 怨듬갚�씠硫� 以묒�
+            String cellValue = CommonUtil.convertExcelStringToCell(cell);
+            if (StringUtils.isEmpty(cellValue)) {
+                return;
+            }
+
+            List<Long> departmentIds = Lists.newArrayList();
+
+            for (String department : splitDepartment) {
+                DepartmentVo departmentVo = departmentMaps.get(department);
+                departmentIds.add(departmentVo.getId());
+            }
             issueForm.setDepartmentIds(departmentIds);
         }
     }
@@ -2980,6 +3389,12 @@
     //  �떆�옉�씪, 醫낅즺�씪�쓣 IssueForm �뿉 ���옣�븳�떎.
     private void setIssueFormPeriod(Cell cell, IssueForm issueForm, Boolean checkStartDate, int rowIndex) {
         if (cell != null && !cell.toString().equals("")) {
+
+            //  媛믪씠 怨듬갚�씠硫� 以묒�
+            String cellValue = CommonUtil.convertExcelStringToCell(cell);
+            if (StringUtils.isEmpty(cellValue)) {
+                return;
+            }
 
             Date startDate;
 
@@ -3142,45 +3557,36 @@
     //  �씠�뒋瑜� �뀥�뵆由우뿉 �뵲�씪 �뙆�듃�꼫 �떞�떦�옄�뿉寃� 硫붿씪濡� 諛쒖넚�븳�떎.
     @Override
     @Transactional(readOnly = true)
-    public void sendIssueEmailPartners(IssueForm issueForm) {
-        if (issueForm.getSendEmails().size() < 1) {
+    public void sendIssueEmailPartners(EmailTemplateForm emailTemplateForm) {
+        if (emailTemplateForm.getSendEmails().size() < 1) {
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SEND_USER));
-        }else if (issueForm.getTemplate() == null){
+        }else if (emailTemplateForm.getTemplate() == null){
             throw new OwlRuntimeException(
                     this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SELECT_TEMPLATE));
+        } else if (emailTemplateForm.getIssueId() == null) {
+            throw new OwlRuntimeException(
+                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_EXIST));
         }
 
-        Issue issue = this.getIssue(issueForm.getId());
+        Issue issue = this.getIssue(emailTemplateForm.getIssueId());
 
-        Map<String, Object> issueMap = new HashMap<>();
-        //  �씠�뒋 �젙蹂대�� �씠硫붿씪 �쟾�넚�뿉 �궗�슜�븯湲� �쐞�빐 Map �삎�깭濡� 蹂��솚�븳�떎.
-        this.makeIssueMapToIssue(issue, issueMap);
         //  諛쒖떊�옄 �몴�떆
+        User user = this.webAppUtil.getLoginUserObject();
         UserVo toUser = this.webAppUtil.getLoginUser();
-        issueMap.put("toUser", toUser.getName() + "(" + CommonUtil.decryptAES128(toUser.getAccount()) + ")");
-
-        // �씠�뒋 留곹겕
-        String projectKey = issue.getProject().getProjectKey();
-        Long IssueNumber = issue.getIssueNumber();
-        String link = this.configuration.getEmailSendUrl() + "/#/issues/issueList?projectKey=" + projectKey + "&issueNumber=" + IssueNumber.toString();
-
-        issueMap.put("issueLink", link);
-        issueMap.put("projectLink", link);
 
         //  �궗�슜�옄 �떆�뒪�뀥 湲곕뒫 �궗�슜 �젙蹂� �닔吏�
         log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_ANOTHER_USER_SEND_EMAIL));
         StringBuilder sb = new StringBuilder();
 
-        if(issueForm.getTemplate().equals(EmailType.ISSUE_SEND_1.toString())){
-            this.systemEmailService.directEmail(ConvertUtil.ToArray(issueForm.getSendEmails()), EmailType.ISSUE_SEND_1, issueMap, null);
-        }else if(issueForm.getTemplate().equals(EmailType.ISSUE_SEND_2.toString())){
-            this.systemEmailService.directEmail(ConvertUtil.ToArray(issueForm.getSendEmails()), EmailType.ISSUE_SEND_2, issueMap, null);
-        }else if(issueForm.getTemplate().equals(EmailType.ISSUE_SEND_3.toString())){
-            this.systemEmailService.directEmail(ConvertUtil.ToArray(issueForm.getSendEmails()), EmailType.ISSUE_SEND_3, issueMap, null);
+        Locale locale = CommonUtil.getUserLanguage(user.getLanguage());
+        String[] sendMails = ConvertUtil.ToArray(emailTemplateForm.getSendEmails());
+        for(int i=0; i < sendMails.length; i++) {
+            sendMails[i] = CommonUtil.decryptAES128(sendMails[i]);
         }
-        //硫붿씪 �쟾�넚 �씠�젰 �궓湲곌린
-        this.issueHistoryService.detectSendIssueMail(IssueHistoryType.SEND, issueForm, sb);
+        this.systemEmailService.sendEmail(emailTemplateForm.getTitle(), emailTemplateForm.getTemplate(), sendMails, null);
+
+        this.issueHistoryService.detectSendIssueMail(IssueHistoryType.SEND, emailTemplateForm.getSendEmails(), sb);
         this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.SEND, sb.toString());
     }
 
@@ -3374,7 +3780,6 @@
         }
         this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString()); //parentIssue = myIssue(湲곕줉�� �쁽�옱 �긽�꽭�럹�씠吏��뿉 �빐�빞�븯�땲源�)
         this.issueRepository.saveAndFlush(issue);
-
     }
 
     @Override

--
Gitblit v1.8.0