From 30ddd2cf095d2857ba1134fb3deaf51392ef1030 Mon Sep 17 00:00:00 2001
From: jhjang <jhjang@maprex.co.kr>
Date: 화, 07 12월 2021 21:31:45 +0900
Subject: [PATCH] Merge branch 'master' of http://192.168.0.25:9001/r/owl-kisa

---
 src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java |  131 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 116 insertions(+), 15 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
index 763d552..344147e 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
@@ -1,12 +1,18 @@
 package kr.wisestone.owl.service.impl;
 
-import kr.wisestone.owl.domain.Department;
+import kr.wisestone.owl.domain.*;
 import kr.wisestone.owl.mapper.DepartmentMapper;
-import kr.wisestone.owl.service.UserService;
+import kr.wisestone.owl.repository.WorkflowDepartmentRepository;
+import kr.wisestone.owl.service.*;
+import kr.wisestone.owl.util.CommonUtil;
 import kr.wisestone.owl.web.condition.DepartmentCondition;
 import kr.wisestone.owl.web.condition.UserCondition;
 import kr.wisestone.owl.web.form.DepartmentForm;
 import kr.wisestone.owl.web.form.UserDepartmentForm;
+import org.jsoup.Jsoup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.Model;
 import com.google.common.collect.Lists;
 import kr.wisestone.owl.common.ExcelConditionCheck;
@@ -14,8 +20,6 @@
 import kr.wisestone.owl.constant.MsgConstants;
 import kr.wisestone.owl.exception.OwlRuntimeException;
 import kr.wisestone.owl.repository.DepartmentRepository;
-import kr.wisestone.owl.service.DepartmentService;
-import kr.wisestone.owl.service.WorkspaceService;
 import kr.wisestone.owl.util.ConvertUtil;
 import kr.wisestone.owl.vo.*;
 import kr.wisestone.owl.web.view.ExcelView;
@@ -33,6 +37,8 @@
 @Service
 public class DepartmentServiceImpl extends AbstractServiceImpl<Department, Long, JpaRepository<Department, Long>> implements DepartmentService {
 
+    private static final Logger log = LoggerFactory.getLogger(IssueServiceImpl.class);
+
     @Autowired
     private DepartmentRepository departmentRepository;
 
@@ -40,7 +46,22 @@
     private DepartmentMapper departmentMapper;
 
     @Autowired
-    private UserService userService;
+    private DepartmentService departmentService;
+
+    @Autowired
+    private UserDepartmentService userDepartmentService;
+
+    @Autowired
+    private ProjectRoleDepartmentService projectRoleDepartmentService;
+
+    @Autowired
+    private ProjectRoleService projectRoleService;
+
+    @Autowired
+    private WorkflowDepartmentRepository workflowDepartmentRepository;
+
+    @Autowired
+    private IssueTypeService issueTypeService;
 
     @Autowired
     private WorkspaceService workspaceService;
@@ -106,8 +127,61 @@
         }
 
         for (Long id : departmentForm.getRemoveIds()) {
-            this.departmentRepository.deleteById(id);
-            this.departmentRepository.flush();
+            if (!this.departmentService.countInDepartment(id)) {
+                this.departmentRepository.deleteById(id);
+            } else {
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE));
+            }
+        }
+        this.departmentRepository.flush();
+    }
+
+    //  �봽濡쒖젥�듃�뿉 李몄뿬�븯�뒗 遺��꽌 �젙蹂대�� 議고쉶�븳�떎.
+    @Override
+    @Transactional(readOnly = true)
+    public List<Map<String, Object>> findProjectDepartment(Project project) {
+        DepartmentCondition departmentCondition = new DepartmentCondition();
+        departmentCondition.setProjectId(project.getId());
+        return this.departmentMapper.findProjectDepartment(departmentCondition);
+    }
+
+    //  �봽濡쒖젥�듃�뿉 李몄뿬�븯�뒗 遺��꽌 紐⑸줉�쓣 媛��졇�삩�떎.
+    @Override
+    @Transactional(readOnly = true)
+    public void findProjectDepartment(Map<String, Object> resJsonData, DepartmentCondition departmentCondition) {
+        ProjectRole projectRole = this.projectRoleService.findByProjectIdAndRoleType(departmentCondition.getProjectId(), ProjectRole.TYPE_DEFAULT);
+        List<ProjectRoleDepartment> projectRoleDepartments = this.projectRoleDepartmentService.findByProjectRoleId(projectRole.getId());
+        List<DepartmentVo> departmentVos = Lists.newArrayList();
+
+        for (ProjectRoleDepartment projectRoleDepartment : projectRoleDepartments) {
+            DepartmentVo departmentVo = ConvertUtil.copyProperties(projectRoleDepartment.getDepartment(), DepartmentVo.class);
+            departmentVo.setByName(departmentVo.getDepartmentName());
+            departmentVos.add(departmentVo);
+        }
+
+        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);
+    }
+
+    //  �썙�겕�뵆濡쒖슦�뿉 �냽�빐�엳�뒗 遺��꽌 紐⑸줉 議고쉶
+    @Override
+    @Transactional(readOnly = true)
+    public void findWorkflowDepartment(Map<String, Object> resJsonData, DepartmentCondition departmentCondition) {
+
+        IssueType issueType = this.issueTypeService.getIssueType(departmentCondition.getIssueTypeId());
+        Long workflowId = issueType.getWorkflow().getId();
+        List<WorkflowDepartment> workflowDepartmentList = this.workflowDepartmentRepository.findByWorkflowId(workflowId);
+        List<DepartmentVo> departmentVos = Lists.newArrayList();
+
+        //List<Long> workflowDepartmentIds = Lists.newArrayList();
+        if(workflowDepartmentList != null && workflowDepartmentList.size()>0){
+            for(WorkflowDepartment workflowDepartment : workflowDepartmentList){
+                DepartmentVo departmentVo = ConvertUtil.copyProperties(workflowDepartment.getDepartment(), DepartmentVo.class);
+                departmentVo.setByName(departmentVo.getDepartmentName());
+                //workflowDepartmentIds.add(workflowDepartment.getDepartment().getId());
+                departmentVos.add(departmentVo);
+            }
+            resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);
         }
     }
 
@@ -140,11 +214,44 @@
         excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentDescription", this.messageAccessor.message("department.departmentDescription"), 20, ExportExcelAttrVo.ALIGN_CENTER));
         excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentCount", this.messageAccessor.message("department.departmentCount"), 3, ExportExcelAttrVo.ALIGN_CENTER));
 
-        excelInfo.setDatas(departmentVos);
+        //  DepartmentVos �뜲�씠�꽣瑜� �뿊���뿉�꽌 �몴�떆�븷 �닔 �엳�뒗 �뜲�씠�꽣濡� 蹂�寃쏀븳�떎.
+        List<Map<String, Object>> convertExcelViewToDepartmentMaps = this.convertExcelViewToDepartmentVos(departmentVos);
+
+        excelInfo.setDatas(convertExcelViewToDepartmentMaps);
 
         model.addAttribute(Constants.EXCEL, excelInfo);
         return new ModelAndView(this.excelView);
 
+    }
+
+    @Override
+    public boolean countInDepartment(Long id) {
+        return this.departmentMapper.countInDepartment(id) > 0;
+    }
+
+    //  DepartmentVos �뜲�씠�꽣瑜� �뿊���뿉�꽌 �몴�떆�븷 �닔 �엳�뒗 �뜲�씠�꽣濡� 蹂�寃쏀븳�떎.
+    private List<Map<String, Object>> convertExcelViewToDepartmentVos(List<DepartmentVo> departmentVos) {
+        List<Map<String, Object>> results = Lists.newArrayList();
+
+        for (DepartmentVo departmentVo : departmentVos){
+            try {
+                Map<String, Object> result = new HashMap<>();
+                result.put("departmentName", departmentVo.getDepartmentName());
+                result.put("departmentCount", departmentVo.getDepartmentCount());
+
+                String description= "";
+
+                if(departmentVo.getDepartmentDescription() != null){
+                    description = Jsoup.parse(departmentVo.getDepartmentDescription()).text(); //HTML �깭洹� �젣嫄�
+                    description = description.replaceAll("\\<.*?>", ""); //怨듬갚 �젣嫄�
+                }
+                result.put("departmentDescription", description);
+                results.add(result);
+            } catch (Exception e) {
+                log.error("�뿊�� �떎�슫濡쒕뱶 �삤瑜� 諛쒖깮");
+            }
+        }
+        return results;
     }
 
     // �궗�슜�옄 遺��꽌 ID濡� 議고쉶�븳�떎.
@@ -165,12 +272,6 @@
         return department;
     }
 
-    //  �궘�젣 �븷 遺��꽌 �쑀��媛� �궗�슜�븯怨� �엳�뒗吏� �솗�씤
-    @Override
-    public boolean department(Long Id) {
-        return this.departmentMapper.findBydepartmentId(Id) > 0;
-    }
-
     @Override
     public List<Map<String, Object>> findByDepartmentIds(UserCondition condition) {
         return this.departmentMapper.findByDepartmentIds(condition);
@@ -185,7 +286,7 @@
             departmentVo.setByName(departmentVo.getDepartmentName());
             departmentVos.add(departmentVo);
         }
-
+        
         int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1;
 
         resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);

--
Gitblit v1.8.0