DracChannelCodeFollowStaffService.java
5.54 KB
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
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.entity.DracChannelCodeFollowStaff;
import cn.com.glsx.entmicro.mapper.DracChannelCodeFollowStaffMapper;
import cn.com.glsx.entmicro.mapper.EntmicroStaffDepartRelationMapper;
import cn.com.glsx.entmicro.model.request.DracChannelCodeFollowStaffRequest;
import cn.com.glsx.entmicro.model.response.ChannelCodeStaffInfoResponse;
import cn.com.glsx.entmicro.model.response.DracChannelCodeFollowStaffResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author Lichongyuan
* @Description: 活码员工关联服务
* @date 2021/11/12 11:32
*/
@Service
@Slf4j
public class DracChannelCodeFollowStaffService {
@Resource
private DracChannelCodeFollowStaffMapper dracChannelCodeFollowStaffMapper;
@Resource
private EntmicroStaffDepartRelationMapper entmicroStaffDepartRelationMapper;
/**
* 批量插入
*
* @param dracChannelCodeFollowStaffs
*/
public void insertList(List<DracChannelCodeFollowStaff> dracChannelCodeFollowStaffs) {
//TODO 校验重复
dracChannelCodeFollowStaffMapper.insertList(dracChannelCodeFollowStaffs);
}
/**
* 新增关联
*
* @param dracChannelCodeFollowStaff
*/
public void insert(DracChannelCodeFollowStaff dracChannelCodeFollowStaff) {
dracChannelCodeFollowStaffMapper.insert(dracChannelCodeFollowStaff);
}
/**
* codeId和staffId查关联数据
*
* @param codeId
* @param staffId
* @return
*/
public List<DracChannelCodeFollowStaff> findByCodeId(Integer codeId, List<Integer> staffId) {
return dracChannelCodeFollowStaffMapper.findByCodeId(codeId, staffId);
}
/**
* 更新关联
*/
public void update(DracChannelCodeFollowStaffRequest dracChannelCodeFollowStaffRequest) {
//查出本地活码和员工关联
List<DracChannelCodeFollowStaff> oldList =findByCodeId(dracChannelCodeFollowStaffRequest.getCodeId());
//根据入参的staffId查询本地员工信息
List<ChannelCodeStaffInfoResponse> newStaffByIdList = entmicroStaffDepartRelationMapper.getStaffByIdList(dracChannelCodeFollowStaffRequest.getStaffIds(), dracChannelCodeFollowStaffRequest.getMerchantId());
//入参参数转化
List<DracChannelCodeFollowStaff> tranNewParam = newStaffByIdList.stream().map(index -> {
DracChannelCodeFollowStaff dracChannelCodeFollowStaff = new DracChannelCodeFollowStaff();
dracChannelCodeFollowStaff.setStaffId(index.getRelationId());
dracChannelCodeFollowStaff.setStaffName(index.getStaffName());
dracChannelCodeFollowStaff.setCodeId(dracChannelCodeFollowStaffRequest.getCodeId());
dracChannelCodeFollowStaff.setUpdatedTime(new Date());
dracChannelCodeFollowStaff.setDelFlag((int) Constants.NORMAL_FLAG);
return dracChannelCodeFollowStaff;
}).collect(Collectors.toList());
//对比入参员工
List<DracChannelCodeFollowStaff> addList = tranNewParam.stream().filter(index -> !oldList.contains(index)).collect(Collectors.toList());
List<DracChannelCodeFollowStaff> deleteList = oldList.stream().filter(index -> !tranNewParam.contains(index)).collect(Collectors.toList());
List<DracChannelCodeFollowStaff> updateList = oldList.stream().filter(index -> tranNewParam.contains(index)).collect(Collectors.toList());
//新增活码员工关系
if (!CollectionUtils.isEmpty(addList)) {
addList.forEach(index -> {
index.setDelFlag((int) Constants.NORMAL_FLAG);
insert(index);
});
}
//更新员工活码关系
if (!CollectionUtils.isEmpty(updateList)) {
updateList.forEach(index -> {
index.setUpdatedTime(new Date());
index.setUpdatedBy(dracChannelCodeFollowStaffRequest.getCreatedBy());
dracChannelCodeFollowStaffMapper.updateByPrimaryKeySelective(index);
});
}
//删除活码员工关系
if (!CollectionUtils.isEmpty(deleteList)) {
deleteList.forEach(index -> {
deleteDracChannelCodeFollowStaff(index);
});
}
}
/**
* codeId查询关联数据
*
* @param codeId
* @return
*/
public List<DracChannelCodeFollowStaff> findByCodeId(Integer codeId) {
return dracChannelCodeFollowStaffMapper.findByCodeId(codeId, null);
}
/**
* codeId查关联员工
*
* @param codeId
* @return
*/
public List<DracChannelCodeFollowStaffResponse> findStaffByCodeId(Set<Integer> codeId) {
List<DracChannelCodeFollowStaffResponse> staffByCodeId = dracChannelCodeFollowStaffMapper.findStaffByCodeId(codeId);
return staffByCodeId;
}
/**
* 删除单条关联
*
* @param dracChannelCodeFollowStaff
*/
public void deleteDracChannelCodeFollowStaff(DracChannelCodeFollowStaff dracChannelCodeFollowStaff) {
dracChannelCodeFollowStaffMapper.deleteDracChannelCodeFollowStaff(dracChannelCodeFollowStaff.getId());
}
/**
* 删除本地活码关联员工信息
*
* @param codeId
*/
public void deleteByCodeId(Integer codeId) {
dracChannelCodeFollowStaffMapper.deleteByCodeId(codeId);
}
}