OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2021-12-11 385f0d9070b90d2253ddaeaf1b2e2491ebaeda95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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);
    }
 
    public List<WorkflowDepartment> find(Long workflowId) {
        return this.workflowDepartmentRepository.findByWorkflowId(workflowId);
    }
 
 
    @Override
    // 워크플로우의 해당 이슈상태를 가진 워크플로우 부서 가져오기(Ready)
    public List<Long> findFirstDepartmentIds(Workflow workflow) {
        List<Long> departmentIds = Lists.newArrayList();
        IssueStatus issueStatus = issueStatusService.findByIssueStatusTypeIsReady(workflow);
 
        // 워크플로우 상태에 따른 담당부서 가져오기
        if (issueStatus != null) {
            WorkflowDepartmentCondition workflowDepartmentCondition = new WorkflowDepartmentCondition();
            workflowDepartmentCondition.setIssueStatusId(issueStatus.getId());
            workflowDepartmentCondition.setWorkflowId(workflow.getId());
            List<WorkflowDepartmentVo> workflowDepartmentVos = this.find(workflowDepartmentCondition);
 
            for (WorkflowDepartmentVo workflowDepartmentVo : workflowDepartmentVos) {
                departmentIds.add(workflowDepartmentVo.getDepartmentVo().getId());
            }
        }
        return departmentIds;
    }
 
    // 담당 부서정보를 조회한다.
    @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);
    }
}