1.优化
Showing
1 changed file
with
121 additions
and
34 deletions
... | @@ -170,61 +170,138 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -170,61 +170,138 @@ public class UserOperationServiceImpl implements UserOperationService { |
170 | String headimgurl = resources.getHeadimgurl(); | 170 | String headimgurl = resources.getHeadimgurl(); |
171 | Integer sex = resources.getSex(); | 171 | Integer sex = resources.getSex(); |
172 | 172 | ||
173 | // 检查小屏账户是否存在 | 173 | // 账户和会员都存在 |
174 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId, appId, openId); | 174 | UserWeixinDTO userWeixinDTO = this.findFirstByAppIdAndOpenId(appId, openId); |
175 | if (Objects.nonNull(userWeixinDTO.getId())) { | 175 | if (Objects.nonNull(userWeixinDTO.getId()) && Objects.nonNull(userWeixinDTO.getMemberId())) { |
176 | log.error("createWeixinUserAndMember ==>> result ==>> [{}]", userWeixinDTO); | 176 | log.error("createWeixinUserAndMember ==>> result ==>> [{}]", userWeixinDTO); |
177 | throw new BadRequestException(GlobeExceptionMsg.OPERATION_FORBID + "==>> " + GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); | 177 | throw new BadRequestException(GlobeExceptionMsg.OPERATION_FORBID + "==>> " + GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); |
178 | } | 178 | } |
179 | 179 | ||
180 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 | 180 | // 账号存在但无会员 |
181 | UserWeixinDTO _userWeixinDTO = this.findFirstByUnionId(unionId); | 181 | if (Objects.nonNull(userWeixinDTO.getId()) && Objects.isNull(userWeixinDTO.getMemberId())) { |
182 | if (Objects.nonNull(_userWeixinDTO.getId())) { | ||
183 | 182 | ||
184 | Assert.notNull(_userWeixinDTO.getMemberId(), GlobeExceptionMsg.MEMBER_ID_IS_NULL); | 183 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 |
184 | UserWeixinDTO _userWeixinDTO = this.findFirstByUnionId(unionId); | ||
185 | if (Objects.nonNull(_userWeixinDTO.getId())) { | ||
185 | 186 | ||
186 | // 小屏会员 | 187 | if (Objects.nonNull(_userWeixinDTO.getMemberId())) { |
187 | MemberDTO memberDTO = this.findMemberById(_userWeixinDTO.getMemberId()); | ||
188 | if (Objects.nonNull(memberDTO)) { | ||
189 | 188 | ||
190 | resources.setMemberId(_userWeixinDTO.getMemberId()); | 189 | // 有其他账号的话,将此账号与对应的会员进行绑定 |
191 | UserWeixin userWeixin = UserWeixinBuilder.build(resources); | 190 | MemberDTO memberDTO = this.findMemberById(_userWeixinDTO.getMemberId()); |
192 | UserWeixinDTO weixinDTO = this.createWeixinUser(userWeixin, memberDTO.getId(), memberDTO.getCode()); | 191 | userWeixinDTO.setMemberId(memberDTO.getId()); |
193 | weixinDTO.setMemberCode(memberDTO.getCode()); | 192 | userWeixinDTO.setMemberCode(memberDTO.getCode()); |
193 | if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { | ||
194 | userWeixinDTO.setUnionid(unionId); | ||
195 | } | ||
196 | UserWeixin userWeixin = new UserWeixin(); | ||
197 | BeanUtils.copyProperties(userWeixinDTO, userWeixin); | ||
198 | UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); | ||
199 | return _userWeixinDTO1; | ||
194 | 200 | ||
195 | // 同步至iptv | 201 | } else { |
196 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncWeixin(weixinDTO); | ||
197 | 202 | ||
198 | return weixinDTO; | 203 | // 有其他账号但都无会员,新建会员并将此账号绑定新建的这个会员 |
204 | Member _member = | ||
205 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
206 | headimgurl, nickname, 0, sex); | ||
199 | 207 | ||
200 | } | 208 | MemberDTO memberDTO = this.createMember(_member); |
201 | 209 | ||
202 | throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_CODE_IS_NULL); | 210 | if (Objects.nonNull(memberDTO)) { |
211 | userWeixinDTO.setMemberId(memberDTO.getId()); | ||
212 | userWeixinDTO.setMemberCode(memberDTO.getCode()); | ||
213 | if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { | ||
214 | userWeixinDTO.setUnionid(unionId); | ||
215 | } | ||
216 | UserWeixin userWeixin = new UserWeixin(); | ||
217 | BeanUtils.copyProperties(userWeixinDTO, userWeixin); | ||
218 | UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); | ||
219 | return _userWeixinDTO1; | ||
203 | 220 | ||
204 | } else { | 221 | } |
205 | 222 | ||
206 | // 新建会员 | 223 | } |
207 | Member _member = | ||
208 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
209 | headimgurl, nickname, 0, sex); | ||
210 | 224 | ||
211 | MemberDTO memberDTO = this.createMember(_member); | 225 | } else { |
212 | 226 | ||
213 | if (Objects.nonNull(memberDTO)) { | 227 | // 该账号存在但无其他账号,新建会员 |
214 | UserWeixin userWeixin = UserWeixinBuilder.build(memberDTO.getId(), resources); | 228 | Member _member = |
215 | UserWeixinDTO _userWeixinDTO1 = this.createWeixinUser(userWeixin, memberDTO.getId(), memberDTO.getCode()); | 229 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, |
230 | headimgurl, nickname, 0, sex); | ||
216 | 231 | ||
217 | // 同步至iptv | 232 | MemberDTO memberDTO = this.createMember(_member); |
218 | ((UserOperationServiceImpl)AopContext.currentProxy()). | 233 | |
219 | asyncMemberAndUserWeixin4Iptv(new MemberAndWeixinUserDTO(memberDTO, _userWeixinDTO1)); | 234 | if (Objects.nonNull(memberDTO)) { |
235 | userWeixinDTO.setMemberId(memberDTO.getId()); | ||
236 | userWeixinDTO.setMemberCode(memberDTO.getCode()); | ||
237 | if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { | ||
238 | userWeixinDTO.setUnionid(unionId); | ||
239 | } | ||
240 | UserWeixin userWeixin = new UserWeixin(); | ||
241 | BeanUtils.copyProperties(userWeixinDTO, userWeixin); | ||
242 | UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); | ||
243 | return _userWeixinDTO1; | ||
244 | |||
245 | } | ||
220 | 246 | ||
221 | return _userWeixinDTO1; | ||
222 | } | 247 | } |
223 | 248 | ||
224 | throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_CODE_IS_NULL); | 249 | } |
250 | |||
251 | // 无账号 | ||
252 | if (Objects.isNull(userWeixinDTO.getId())) { | ||
253 | |||
254 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 | ||
255 | UserWeixinDTO _userWeixinDTO = this.findFirstByUnionId(unionId); | ||
256 | if (Objects.nonNull(_userWeixinDTO.getId())) { | ||
257 | |||
258 | Assert.notNull(_userWeixinDTO.getMemberId(), GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
259 | |||
260 | // 小屏会员 | ||
261 | MemberDTO memberDTO = this.findMemberById(_userWeixinDTO.getMemberId()); | ||
262 | if (Objects.nonNull(memberDTO)) { | ||
263 | |||
264 | resources.setMemberId(_userWeixinDTO.getMemberId()); | ||
265 | UserWeixin userWeixin = UserWeixinBuilder.build(resources); | ||
266 | UserWeixinDTO weixinDTO = this.createWeixinUser(userWeixin, memberDTO.getId(), memberDTO.getCode()); | ||
267 | weixinDTO.setMemberCode(memberDTO.getCode()); | ||
268 | |||
269 | // 同步至iptv | ||
270 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncWeixin(weixinDTO); | ||
271 | |||
272 | return weixinDTO; | ||
273 | |||
274 | } | ||
275 | |||
276 | throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_CODE_IS_NULL); | ||
277 | |||
278 | } else { | ||
279 | |||
280 | // 新建会员 | ||
281 | Member _member = | ||
282 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
283 | headimgurl, nickname, 0, sex); | ||
284 | |||
285 | MemberDTO memberDTO = this.createMember(_member); | ||
286 | |||
287 | if (Objects.nonNull(memberDTO)) { | ||
288 | UserWeixin userWeixin = UserWeixinBuilder.build(memberDTO.getId(), resources); | ||
289 | UserWeixinDTO _userWeixinDTO1 = this.createWeixinUser(userWeixin, memberDTO.getId(), memberDTO.getCode()); | ||
290 | |||
291 | // 同步至iptv | ||
292 | ((UserOperationServiceImpl)AopContext.currentProxy()). | ||
293 | asyncMemberAndUserWeixin4Iptv(new MemberAndWeixinUserDTO(memberDTO, _userWeixinDTO1)); | ||
294 | |||
295 | return _userWeixinDTO1; | ||
296 | } | ||
297 | |||
298 | throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_CODE_IS_NULL); | ||
299 | |||
300 | } | ||
225 | 301 | ||
226 | } | 302 | } |
227 | 303 | ||
304 | return userWeixinDTO; | ||
228 | } | 305 | } |
229 | 306 | ||
230 | 307 | ||
... | @@ -1114,11 +1191,21 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1114,11 +1191,21 @@ public class UserOperationServiceImpl implements UserOperationService { |
1114 | * @param openId | 1191 | * @param openId |
1115 | * @return | 1192 | * @return |
1116 | */ | 1193 | */ |
1117 | private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId( String unionId,String appId, String openId) { | 1194 | private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId(String unionId, String appId, String openId) { |
1118 | return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId); | 1195 | return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId); |
1119 | } | 1196 | } |
1120 | 1197 | ||
1121 | /** | 1198 | /** |
1199 | * 获取小屏账户 | ||
1200 | * @param appId | ||
1201 | * @param openId | ||
1202 | * @return | ||
1203 | */ | ||
1204 | private UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId) { | ||
1205 | return this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId); | ||
1206 | } | ||
1207 | |||
1208 | /** | ||
1122 | * | 1209 | * |
1123 | * @param member | 1210 | * @param member |
1124 | * @return | 1211 | * @return | ... | ... |
-
Please register or sign in to post a comment