From b8ab6de032d3a6ee029331dbb58d764a5409189b Mon Sep 17 00:00:00 2001 From: 이민희 <mhlee@maprex.co.kr> Date: 월, 28 2월 2022 15:51:13 +0900 Subject: [PATCH] - api로 하위이슈 추가 시 상위이슈의 파트너 정보 적용 --- src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 153 insertions(+), 16 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..67d7586 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,16 @@ 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.UserDepartmentRepository; +import kr.wisestone.owl.service.*; 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 +18,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,14 +35,34 @@ @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; + + @Autowired + private UserDepartmentService userDepartmentService; @Autowired private DepartmentMapper departmentMapper; @Autowired - private UserService userService; + private DepartmentService departmentService; + + @Autowired + private WorkflowDepartmentService workflowDepartmentService; + + @Autowired + private ProjectRoleDepartmentService projectRoleDepartmentService; + + @Autowired + private IssueDepartmentService issueDepartmentService; + + @Autowired + private ProjectRoleService projectRoleService; + + @Autowired + private IssueTypeService issueTypeService; @Autowired private WorkspaceService workspaceService; @@ -106,11 +128,94 @@ } for (Long id : departmentForm.getRemoveIds()) { - this.departmentRepository.deleteById(id); - this.departmentRepository.flush(); + if (this.departmentService.countInDepartment(id)) { + // �궗�슜�옄媛� 遺��꽌�뿉 �냽�빐 �엳�뒗吏� 泥댄겕 + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE)); + + } else if (this.workflowDepartmentService.usingDepartment(id)) { + // �썙�겕�뵆濡쒖슦�뿉�꽌 �빐�떦 遺��꽌瑜� �궗�슜�븯怨� �엳�뒗吏� 泥댄겕 + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE_IN_WORKFLOW)); + + } else if (this.projectRoleDepartmentService.usingDepartment(id)) { + // �봽濡쒖젥�듃�쓽 �떞�떦遺��꽌�씤吏� 泥댄겕 + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE_IN_PROJECT)); + + } else if (this.issueDepartmentService.usingDepartment(id)) { + // �씠�뒋�쓽 �떞�떦遺��꽌濡� �릺�뼱�엳�뒗吏� 泥댄겕 + throw new OwlRuntimeException( + this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE_IN_ISSUE)); + + } else { + this.departmentRepository.deleteById(id); + } } + 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) { + List<DepartmentVo> departmentVos = findWorkflowDepartment(departmentCondition.getIssueTypeId()); + resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos); + } + + // �썙�겕�뵆濡쒖슦�뿉 �냽�빐�엳�뒗 遺��꽌 紐⑸줉 議고쉶 + @Override + @Transactional(readOnly = true) + public List<DepartmentVo> findWorkflowDepartment(Long issueTypeId) { + List<WorkflowDepartment> workflowDepartmentList = this.findWorkflowDepartmentByIssueTypeId(issueTypeId); + List<DepartmentVo> departmentVos = Lists.newArrayList(); + + if(workflowDepartmentList != null && workflowDepartmentList.size()>0){ + for(WorkflowDepartment workflowDepartment : workflowDepartmentList){ + DepartmentVo departmentVo = ConvertUtil.copyProperties(workflowDepartment.getDepartment(), DepartmentVo.class); + departmentVo.setByName(departmentVo.getDepartmentName()); + departmentVos.add(departmentVo); + } + } + return departmentVos; + } + + // �씠�뒋 �쑀�삎(�썙�겕�뵆濡쒖슦)�뿉 �엳�뒗 �떞�떦遺��꽌 議고쉶 + private List<WorkflowDepartment> findWorkflowDepartmentByIssueTypeId(Long issueTypeId) { + Long workflowId = this.getWorkflowId(issueTypeId); + return this.workflowDepartmentService.find(workflowId); + } + + private Long getWorkflowId(Long issueTypeId) { + IssueType issueType = this.issueTypeService.getIssueType(issueTypeId); + return issueType.getWorkflow().getId(); + } // 遺��꽌 紐⑸줉�쓣 �뿊��濡� �떎�슫濡쒕뱶 �븳�떎. @Override @@ -140,11 +245,49 @@ 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) { + boolean result = false; + List<UserDepartment> usingDepartments = this.userDepartmentService.findByDepartmentId(id); + if(usingDepartments != null && usingDepartments.size() > 0){ + result = true; + } + return result; + } + + // 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 +308,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 +322,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