package kr.wisestone.owl.service.impl;
|
|
|
import com.google.common.collect.Lists;
|
import kr.wisestone.owl.constant.MsgConstants;
|
import kr.wisestone.owl.domain.*;
|
import kr.wisestone.owl.domain.enumType.IssueStatusType;
|
import kr.wisestone.owl.domain.enumType.ProjectType;
|
import kr.wisestone.owl.exception.OwlRuntimeException;
|
import kr.wisestone.owl.mapper.WorkflowDepartmentMapper;
|
import kr.wisestone.owl.repository.WorkflowDepartmentRepository;
|
import kr.wisestone.owl.repository.WorkflowTransitionRepository;
|
import kr.wisestone.owl.service.*;
|
import kr.wisestone.owl.util.ConvertUtil;
|
import kr.wisestone.owl.util.MapUtil;
|
import kr.wisestone.owl.vo.*;
|
import kr.wisestone.owl.web.condition.WorkflowCondition;
|
import kr.wisestone.owl.web.condition.WorkflowDepartmentCondition;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.*;
|
|
|
@Service
|
public class WorkflowDepartmentServiceImpl extends AbstractServiceImpl<WorkflowDepartment, Long, JpaRepository<WorkflowDepartment, Long>> implements WorkflowDepartmentService {
|
|
private static final Logger log = LoggerFactory.getLogger(WorkflowDepartmentServiceImpl.class);
|
|
@Autowired
|
private WorkflowDepartmentMapper workflowDepartmentMapper;
|
|
@Autowired
|
private WorkflowDepartmentRepository workflowDepartmentRepository;
|
|
@Autowired
|
private IssueStatusService issueStatusService;
|
|
@Autowired
|
private DepartmentService departmentService;
|
|
@Override
|
protected JpaRepository<WorkflowDepartment, Long> getRepository() {
|
return workflowDepartmentRepository;
|
}
|
|
@Override
|
public WorkflowDepartment getWorkflowDepartment(Long id) {
|
if (id == null) {
|
throw new OwlRuntimeException(
|
this.messageAccessor.getMessage(MsgConstants.WORKFLOW_DEPARTMENT_NOT_EXIST));
|
}
|
|
WorkflowDepartment workflowDepartment = this.findOne(id);
|
|
if (workflowDepartment == null) {
|
throw new OwlRuntimeException(
|
this.messageAccessor.getMessage(MsgConstants.WORKFLOW_DEPARTMENT_NOT_EXIST));
|
}
|
|
return workflowDepartment;
|
}
|
|
// 담당 부서정보를 조회한다.
|
public List<WorkflowDepartmentVo> find(Long workflowId, Long issueStatusId) {
|
WorkflowDepartmentCondition condition = new WorkflowDepartmentCondition();
|
condition.setWorkflowId(workflowId);
|
condition.setIssueStatusId(issueStatusId);
|
|
return find(condition);
|
}
|
|
// 담당 부서정보를 조회한다.
|
@Transactional(readOnly = true)
|
@Override
|
public List<WorkflowDepartmentVo> find(WorkflowDepartmentCondition condition) {
|
|
List<WorkflowDepartment> workflowDepartmentList = null;
|
List<WorkflowDepartmentVo> workflowDepartmentVos = Lists.newArrayList();
|
//워크플로우, 이슈 상태별 담당부서 조회
|
if (condition.getWorkflowId() != null && condition.getIssueStatusId() != null) {
|
workflowDepartmentList = this.workflowDepartmentRepository.findByWorkflowIdAndIssueStatusId(condition.getWorkflowId(), condition.getIssueStatusId());
|
|
for(int i = 0; i < workflowDepartmentList.size(); i++){
|
WorkflowDepartment workflowDepartment = workflowDepartmentList.get(i);
|
WorkflowDepartmentVo workflowDepartmentVo = ConvertUtil.copyProperties(workflowDepartment, WorkflowDepartmentVo.class);
|
DepartmentVo departmentVo = ConvertUtil.copyProperties(workflowDepartment.getDepartment(), DepartmentVo.class);
|
departmentVo.setByName(departmentVo.getDepartmentName());
|
workflowDepartmentVo.setDepartmentVo(departmentVo);
|
|
workflowDepartmentVos.add(workflowDepartmentVo);
|
}
|
} else {
|
// 워크플로우 모든 담당 부서 조회
|
List<Map<String, Object>> results = this.workflowDepartmentMapper.find(condition);
|
List<WorkflowDepartmentCondition> conditions = ConvertUtil.convertListToListClass(results, WorkflowDepartmentCondition.class);
|
|
for (WorkflowDepartmentCondition cond : conditions) {
|
WorkflowDepartmentVo workflowDepartmentVo = new WorkflowDepartmentVo();
|
Department department = this.departmentService.getDepartment(cond.getDepartmentId());
|
DepartmentVo departmentVo = ConvertUtil.copyProperties(department, DepartmentVo.class);
|
departmentVo.setByName(department.getDepartmentName());
|
workflowDepartmentVo.setDepartmentVo(departmentVo);
|
workflowDepartmentVos.add(workflowDepartmentVo);
|
}
|
}
|
|
return workflowDepartmentVos;
|
}
|
|
// 워크플로우의 상태에 지정된 담당부서를 변경한다
|
@Override
|
@Transactional
|
public void modify(Workflow workflow, List<IssueStatusVo> issueStatusVos) {
|
this.remove(workflow.getId());
|
List<WorkflowDepartment> workflowDepartmentList = Lists.newArrayList();
|
for (IssueStatusVo issueStatusVo : issueStatusVos) {
|
for (WorkflowDepartmentVo workflowDepartmentVo : issueStatusVo.getWorkflowDepartmentVos()) {
|
WorkflowDepartment workflowDepartment = ConvertUtil.copyProperties(workflowDepartmentVo, WorkflowDepartment.class);
|
workflowDepartment.setIssueStatus(this.issueStatusService.getIssueStatus(issueStatusVo.getId()));
|
workflowDepartment.setWorkflow(workflow);
|
Department department = this.departmentService.getDepartment(workflowDepartmentVo.getDepartmentVo().getId());
|
workflowDepartment.setDepartment(department);
|
|
workflowDepartmentList.add(workflowDepartment);
|
}
|
}
|
this.workflowDepartmentRepository.saveAll(workflowDepartmentList);
|
}
|
|
@Override
|
@Transactional
|
public void remove(Long workflowId) {
|
WorkflowDepartmentCondition condition = new WorkflowDepartmentCondition();
|
condition.setWorkflowId(workflowId);
|
|
this.workflowDepartmentMapper.deleteAll(condition);
|
}
|
}
|