OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-10-14 d680ff9fa4298ad3c0cd12f5f9d87f6c51110480
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
package kr.wisestone.owl.service.impl;
 
import com.google.common.collect.Lists;
import kr.wisestone.owl.domain.*;
import kr.wisestone.owl.mapper.IssueUserMapper;
import kr.wisestone.owl.repository.IssueUserRepository;
import kr.wisestone.owl.service.IssueUserService;
import kr.wisestone.owl.service.ProjectService;
import kr.wisestone.owl.util.CommonUtil;
import kr.wisestone.owl.util.MapUtil;
import kr.wisestone.owl.web.form.IssueForm;
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.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class IssueUserServiceImpl extends AbstractServiceImpl<IssueUser, Long, JpaRepository<IssueUser, Long>> implements IssueUserService {
 
    private static final Logger log = LoggerFactory.getLogger(IssueUserServiceImpl.class);
 
    @Autowired
    private IssueUserRepository issueUserRepository;
 
    @Autowired
    private IssueUserMapper issueUserMapper;
 
    @Override
    protected JpaRepository<IssueUser, Long> getRepository() {
        return this.issueUserRepository;
    }
 
    //  이슈 담당자를 변경한다.
    @Override
    @Transactional
    public void modifyIssueUser(Issue issue, Workspace workspace, List<Long> userIds) {
        List<Long> oldUserIds = Lists.newArrayList();
 
        //  이전 담당자
        for (IssueUser issueUser : issue.getIssueUsers()) {
            oldUserIds.add(issueUser.getUser().getId());
        }
 
        List<Long> newUserIds = CommonUtil.searchChangeList(oldUserIds, userIds); //  추가해야할 사용자를 찾는다.
        List<Long> removeUserIds = CommonUtil.searchChangeList(userIds, oldUserIds); //  삭제해야할 사용자를 찾는다.
 
        if (removeUserIds.size() > 0) {
            Map<String, Object> removeIssueAssigneeMap = new HashMap<>();
            removeIssueAssigneeMap.put("issueId", issue.getId());
            removeIssueAssigneeMap.put("userIds", removeUserIds);
 
            //  담당자 삭제
            this.issueUserMapper.deleteIssueUserByIssueIdAndMultiUserId(removeIssueAssigneeMap);
        }
 
        if (newUserIds.size() > 0) {
            List<Map<String, Long>> addIssueAssigneeMaps = Lists.newArrayList();
 
            for (Long userId : newUserIds) {
                Map<String, Long> issueAssigneeMap = new HashMap<>();
                issueAssigneeMap.put("userId", userId);
                issueAssigneeMap.put("issueId", issue.getId());
                issueAssigneeMap.put("workspaceId", workspace.getId());
                issueAssigneeMap.put("registerId", this.webAppUtil.getLoginId());
                addIssueAssigneeMaps.add(issueAssigneeMap);
            }
 
            //  담당자 추가
            this.issueUserMapper.insertIssueUser(addIssueAssigneeMaps);
        }
    }
 
 
 
    //  이슈 담당자 찾기
    @Override
    @Transactional
    public List<IssueUser> find(Issue issue) {
        return this.issueUserRepository.findByIssueId(issue.getId());
    }
 
    //  이슈 담당자 벌크 등록
    @Override
    @Transactional
    public void insertIssueUser(List<Map<String, Long>> issueAssigneeMaps) {
        //  이슈 담당자 벌크 등록
        this.issueUserMapper.insertIssueUser(issueAssigneeMaps);
    }
 
    //  이슈 담당자에서 제외한다.
    @Override
    @Transactional
    public void removeIssueUser(Long projectId, List<Long> excludeUserIds) {
 
        for (Long userId : excludeUserIds) {
            Map<String, Object> issueUserMap = new HashMap<>();
            issueUserMap.put("userId", userId);
            issueUserMap.put("projectId", projectId);
 
            List<Map<String, Object>> results = this.issueUserMapper.findByUserIdAndProjectId(issueUserMap);
 
            if (results.size() > 0) {
                List<Long> issueIds = Lists.newArrayList();
 
                for (Map<String, Object> result : results) {
                    Long id = MapUtil.getLong(result, "id");
 
                    if (id != null) {
                        issueIds.add(id);
                    }
                }
 
                if (issueIds.size() > 0) {
                    Map<String, Object> removeIssueAssigneeMap = new HashMap<>();
                    removeIssueAssigneeMap.put("userId", userId);
                    removeIssueAssigneeMap.put("issueIds", issueIds);
                    this.issueUserMapper.deleteIssueUserByUserIdAndMultiIssueId(removeIssueAssigneeMap);
                }
            }
        }
 
    }
}