WeGroupCodeServiceImpl.java
6.13 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.linkwechat.wecom.service.impl;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.wecom.domain.WeCommunityNewGroup;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import com.linkwechat.wecom.mapper.WeCommunityNewGroupMapper;
import com.linkwechat.wecom.mapper.WeGroupCodeActualMapper;
import com.linkwechat.wecom.service.IWeGroupCodeActualService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.linkwechat.wecom.mapper.WeGroupCodeMapper;
import com.linkwechat.wecom.domain.WeGroupCode;
import com.linkwechat.wecom.service.IWeGroupCodeService;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
/**
* 客户群活码Service业务层处理
*
* @author ruoyi
* @date 2020-10-07
*/
@Service
public class WeGroupCodeServiceImpl extends ServiceImpl<WeGroupCodeMapper, WeGroupCode> implements IWeGroupCodeService {
private final IWeGroupCodeActualService iWeGroupCodeActualService;
private final WeGroupCodeActualMapper actualCodeMapper;
private final WeCommunityNewGroupMapper communityNewGroupMapper;
public WeGroupCodeServiceImpl(IWeGroupCodeActualService iWeGroupCodeActualService, WeGroupCodeActualMapper actualCodeMapper, WeCommunityNewGroupMapper communityNewGroupMapper) {
this.iWeGroupCodeActualService = iWeGroupCodeActualService;
this.actualCodeMapper = actualCodeMapper;
this.communityNewGroupMapper = communityNewGroupMapper;
}
/**
* 根据群活码id查询实际码列表
*
* @param groupCodeId 群活码id
* @return 结果
*/
@Override
public List<WeGroupCodeActual> selectActualList(Long groupCodeId) {
return actualCodeMapper.selectActualList(groupCodeId);
}
/**
* 查询客户群活码列表
*
* @param weGroupCode 客户群活码
* @return 客户群活码
*/
@Override
public List<WeGroupCode> selectWeGroupCodeList(WeGroupCode weGroupCode) {
List<WeGroupCode> weGroupCodeList = baseMapper.selectWeGroupCodeList(weGroupCode);
for (WeGroupCode item : weGroupCodeList) {
List<WeGroupCodeActual> actualList = actualCodeMapper.selectActualList(item.getId());
item.setActualList(actualList);
}
return weGroupCodeList;
}
/**
* 新增客户群活码
*
* @param weGroupCode 客户群活码
*/
@Override
public void insertWeGroupCode(WeGroupCode weGroupCode) {
try {
baseMapper.insertWeGroupCode(weGroupCode);
} catch (Exception e) {
throw new WeComException(e.getMessage());
}
}
/**
* 修改客户群活码
*
* @param weGroupCode 客户群活码
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
public int updateWeGroupCode(WeGroupCode weGroupCode) {
// 更新实际码
List<WeGroupCodeActual> actualList = weGroupCode.getActualList();
if (CollectionUtil.isNotEmpty(actualList)) {
iWeGroupCodeActualService.updateBatchById(actualList);
}
return baseMapper.updateById(weGroupCode);
}
/**
* 批量删除客户群活码
*
* @param ids 需要删除的客户群活码ID
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteWeGroupCodeByIds(Long[] ids) {
// 删除新客拉群信息,防止出现新科拉群没有群活码可用
LambdaUpdateWrapper<WeGroupCodeActual> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.in(WeGroupCodeActual::getGroupCodeId, Arrays.asList(ids)).set(WeGroupCodeActual::getDelFlag, 1);
actualCodeMapper.update(null, updateWrapper);
return removeByIds(Arrays.asList(ids)) ? 1 : 0;
}
/**
* 删除客户群活码信息
*
* @param id 客户群活码ID
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
public int deleteWeGroupCodeById(Long id) {
// 需要删除新客拉群信息
LambdaUpdateWrapper<WeCommunityNewGroup> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(WeCommunityNewGroup::getGroupCodeId, id).set(WeCommunityNewGroup::getDelFlag, 1);
communityNewGroupMapper.update(null, updateWrapper);
// 删除群活码
return baseMapper.deleteById(id);
}
/**
* 检测活码名称是否被占用
*
* @param weGroupCode 活码对象
* @return 结果
*/
@Override
public boolean isNameOccupied(WeGroupCode weGroupCode) {
Long currentId = Optional.ofNullable(weGroupCode.getId()).orElse(-1L);
LambdaQueryWrapper<WeGroupCode> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WeGroupCode::getActivityName, weGroupCode.getActivityName()).eq(WeGroupCode::getDelFlag, 0);
List<WeGroupCode> res = baseMapper.selectList(queryWrapper);
return !res.isEmpty() && !currentId.equals(res.get(0).getId());
}
/**
* 通过员工活码获取群活码,用于新客自动拉群。
*
* @param state 员工活码state
* @return 群活码URL
*/
@Override
public String selectGroupCodeUrlByEmplCodeState(String state) {
return baseMapper.selectGroupCodeUrlByEmplCodeState(state);
}
/**
* 统计扫码次数
* @param groupCode
*/
@Override
@Async
public void countScanTimes(WeGroupCode groupCode) {
if(groupCode !=null){
groupCode.setTotalScanTimes(
groupCode.getTotalScanTimes()+1
);
this.updateById(groupCode);
}
}
}