UserOperationServiceImpl.java
11.1 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package com.topdraw.business.process.service.impl;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.UserTvService;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
import com.topdraw.business.module.user.weixin.service.UserWeixinService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.service.UserOperationService;
import com.topdraw.business.process.service.dto.MemberAndUserTvDTO;
import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO;
import com.topdraw.exception.EntityNotFoundException;
import com.topdraw.exception.GlobeExceptionMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Objects;
@Service
@Slf4j
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserOperationServiceImpl implements UserOperationService {
@Autowired
private MemberService memberService;
@Autowired
private UserTvService userTvService;
@Autowired
private UserWeixinService userWeixinService;
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {
UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO();
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid);
if (Objects.isNull(_userWeixinDTO.getId())) {
// 检查会员是否存在
UserWeixinDTO _userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid);
if (Objects.nonNull(_userWeixinDTO1.getId())) {
// 会员已存在
Long memberId = _userWeixinDTO1.getMemberId();
userWeixinDTO.setMemberId(memberId);
this.createWeixin(userWeixinDTO);
} else {
// 会员不存在
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
MemberDTO _memberDTO = this.createMember(memberDTO);
userWeixinDTO.setMemberId(_memberDTO.getId());
this.createWeixin(userWeixinDTO);
}
} else {
// 账号存在,修改账号和会员
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId());
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
this.updateMember(_memberDTO, memberDTO);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTvDTO) {
UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO();
MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO();
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.isNull(_userTvDTO)) {
// 创建大屏会员
MemberDTO _memberDTO = this.createMember(memberAndUserTvDTO.getMemberDTO());
userTvDTO.setMemberId(_memberDTO.getId());
// 创建大屏账号
this.createUserTv(userTvDTO);
} else {
this.updateUserTv(_userTvDTO, userTvDTO);
String code = memberDTO.getCode();
MemberDTO _memberDTO = this.memberService.findByCode(code);
this.updateMember(_memberDTO, memberDTO);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncAppletBind(MemberAndUserTvDTO memberAndUserTvDTO) {
UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO();
MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO();
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.nonNull(_userTvDTO)) {
//
this.updateUserTv(_userTvDTO, userTvDTO);
String code = memberDTO.getCode();
MemberDTO _memberDTO = this.memberService.findByCode(code);
memberDTO.setUserIptvId(_userTvDTO.getId());
this.updateMember(_memberDTO, memberDTO);
} else {
throw new EntityNotFoundException(UserTvDTO.class, "id", GlobeExceptionMsg.IPTV_IS_NULL);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) {
UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO();
MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO();
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.nonNull(_userTvDTO)) {
//
this.updateUserTv(_userTvDTO, userTvDTO);
String code = memberDTO.getCode();
MemberDTO _memberDTO = this.memberService.findByCode(code);
this.updateMember(_memberDTO, memberDTO);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncWeixin(UserWeixinDTO userWeixinDTO) {
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid);
if (Objects.nonNull(_userWeixinDTO.getId())) {
userWeixinDTO.setId(_userWeixinDTO.getId());
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
} else {
userWeixinDTO.setId(null);
String memberCode = userWeixinDTO.getMemberCode();
MemberDTO memberDTO = this.memberService.findByCode(memberCode);
userWeixinDTO.setMemberId(memberDTO.getId());
this.createWeixin(userWeixinDTO);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUserTv(UserTvDTO userTvDTO) {
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.nonNull(_userTvDTO)) {
Long id = _userTvDTO.getId();
userTvDTO.setId(id);
this.updateUserTv(_userTvDTO, userTvDTO);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMember(MemberDTO memberDTO) {
String code = memberDTO.getCode();
if (StringUtils.isNotBlank(code)) {
MemberDTO _memberDTO = this.memberService.findByCode(code);
if (Objects.nonNull(_memberDTO)) {
Long id = _memberDTO.getId();
memberDTO.setId(id);
this.updateMember(_memberDTO, memberDTO);
}
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {
UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO();
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid);
if (Objects.nonNull(_userWeixinDTO)) {
// 账号存在,修改账号和会员
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId());
if (Objects.nonNull(_memberDTO)) {
memberDTO.setUserIptvId(_memberDTO.getUserIptvId());
this.updateMember(_memberDTO, memberDTO);
} else {
throw new EntityNotFoundException(MemberDTO.class, "id", GlobeExceptionMsg.MEMBER_ID_IS_NULL);
}
} else {
throw new EntityNotFoundException(UserWeixinDTO.class, "id", GlobeExceptionMsg.WEIXIN_IS_NULL);
}
}
private MemberDTO createMember(MemberDTO memberDTO){
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
return this.memberService.create(member);
}
private MemberDTO updateMember(MemberDTO _memberDTO, MemberDTO memberDTO){
memberDTO.setId(_memberDTO.getId());
memberDTO.setCode(_memberDTO.getCode());
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
return this.memberService.update(member);
}
private void createWeixin(UserWeixinDTO weixinDTO){
UserWeixin userWeixin = new UserWeixin();
BeanUtils.copyProperties(weixinDTO, userWeixin);
this.userWeixinService.create(userWeixin);
}
private void updateWeixin(UserWeixinDTO _userWeixinDTO, UserWeixinDTO weixinDTO){
weixinDTO.setId(_userWeixinDTO.getId());
weixinDTO.setMemberId(_userWeixinDTO.getMemberId());
weixinDTO.setUnionid(_userWeixinDTO.getUnionid());
weixinDTO.setAppid(_userWeixinDTO.getAppid());
weixinDTO.setOpenid(_userWeixinDTO.getOpenid());
UserWeixin userWeixin = new UserWeixin();
BeanUtils.copyProperties(weixinDTO, userWeixin);
this.userWeixinService.update(userWeixin);
}
private void createUserTv(UserTvDTO userTvDTO){
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO, userTv);
this.userTvService.create(userTv);
}
private void updateUserTv(UserTvDTO _userTvDTO, UserTvDTO userTvDTO){
userTvDTO.setId(_userTvDTO.getId());
userTvDTO.setVisUserId(_userTvDTO.getVisUserId());
userTvDTO.setMemberId(_userTvDTO.getMemberId());
userTvDTO.setPlatformAccount(_userTvDTO.getPlatformAccount());
userTvDTO.setCreateTime(_userTvDTO.getCreateTime());
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO, userTv);
this.userTvService.update(userTv);
}
}