Commit aa35f24e aa35f24ea4033a6bc4293a0af5c36268a17a949d by xianghan

1.优化

1 parent 7c111ab7
...@@ -243,6 +243,13 @@ public class UserOperationController { ...@@ -243,6 +243,13 @@ public class UserOperationController {
243 return ResultInfo.success(); 243 return ResultInfo.success();
244 } 244 }
245 245
246 /**
247 * 1.未关注、未绑定
248 * 2.已绑定、未关注
249 * 3.已关注、未绑定
250 * @param data
251 * @return
252 */
246 @PostMapping(value = "/memberPreprocess") 253 @PostMapping(value = "/memberPreprocess")
247 @ApiOperation("暂存大小屏信息并检查关注与绑定状态") 254 @ApiOperation("暂存大小屏信息并检查关注与绑定状态")
248 @AnonymousAccess 255 @AnonymousAccess
...@@ -293,6 +300,8 @@ public class UserOperationController { ...@@ -293,6 +300,8 @@ public class UserOperationController {
293 platformAccount1 = userTvDTO.getPlatformAccount(); 300 platformAccount1 = userTvDTO.getPlatformAccount();
294 } 301 }
295 302
303
304
296 } else { 305 } else {
297 306
298 // 数据异常,没有会员 307 // 数据异常,没有会员
...@@ -301,7 +310,7 @@ public class UserOperationController { ...@@ -301,7 +310,7 @@ public class UserOperationController {
301 310
302 } 311 }
303 312
304 // 关注 313 // 关注
305 if (result.equalsIgnoreCase(SUBSCRIBE)) { 314 if (result.equalsIgnoreCase(SUBSCRIBE)) {
306 315
307 // 未绑定 316 // 未绑定
......
...@@ -36,10 +36,14 @@ import com.topdraw.config.RedisKeyUtil; ...@@ -36,10 +36,14 @@ import com.topdraw.config.RedisKeyUtil;
36 import com.topdraw.exception.BadRequestException; 36 import com.topdraw.exception.BadRequestException;
37 import com.topdraw.exception.EntityNotFoundException; 37 import com.topdraw.exception.EntityNotFoundException;
38 import com.topdraw.exception.GlobeExceptionMsg; 38 import com.topdraw.exception.GlobeExceptionMsg;
39 import com.topdraw.resttemplate.RestTemplateClient;
39 import com.topdraw.util.Base64Util; 40 import com.topdraw.util.Base64Util;
41 import com.topdraw.util.IdWorker;
40 import com.topdraw.util.TimestampUtil; 42 import com.topdraw.util.TimestampUtil;
41 import com.topdraw.utils.QueryHelp; 43 import com.topdraw.utils.QueryHelp;
42 import com.topdraw.utils.RedisUtils; 44 import com.topdraw.utils.RedisUtils;
45 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
46 import com.topdraw.weixin.subscribe.service.WechatSubscribeRecordService;
43 import lombok.extern.slf4j.Slf4j; 47 import lombok.extern.slf4j.Slf4j;
44 import org.apache.commons.lang3.StringUtils; 48 import org.apache.commons.lang3.StringUtils;
45 import org.springframework.aop.framework.AopContext; 49 import org.springframework.aop.framework.AopContext;
...@@ -55,6 +59,7 @@ import org.springframework.util.Assert; ...@@ -55,6 +59,7 @@ import org.springframework.util.Assert;
55 import org.springframework.util.Base64Utils; 59 import org.springframework.util.Base64Utils;
56 import org.springframework.util.CollectionUtils; 60 import org.springframework.util.CollectionUtils;
57 61
62 import java.net.URLDecoder;
58 import java.util.*; 63 import java.util.*;
59 import java.util.stream.Collectors; 64 import java.util.stream.Collectors;
60 65
...@@ -64,23 +69,25 @@ import java.util.stream.Collectors; ...@@ -64,23 +69,25 @@ import java.util.stream.Collectors;
64 public class UserOperationServiceImpl implements UserOperationService { 69 public class UserOperationServiceImpl implements UserOperationService {
65 70
66 @Autowired 71 @Autowired
67 private MemberService memberService;
68 @Autowired
69 private UserTvService userTvService; 72 private UserTvService userTvService;
70 @Autowired 73 @Autowired
74 private MemberService memberService;
75 @Autowired
71 private UserWeixinService userWeixinService; 76 private UserWeixinService userWeixinService;
72 @Autowired 77 @Autowired
73 private UserWeixinRepository userWeixinRepository; 78 private UserWeixinRepository userWeixinRepository;
74
75 @Autowired 79 @Autowired
76 private UserCollectionService userCollectionService; 80 private UserCollectionService userCollectionService;
77 @Autowired 81 @Autowired
82 private CollectionMq2DetailMapper collectionMq2DetailMapper;
83 @Autowired
78 private UserCollectionDetailService userCollectionDetailService; 84 private UserCollectionDetailService userCollectionDetailService;
79 @Autowired 85 @Autowired
80 private CollectionMq2DetailMapper collectionMq2DetailMapper; 86 private WechatSubscribeRecordService wechatSubscribeRecordService;
81 @Autowired 87 @Autowired
82 private UserCollectionDetailRepository userCollectionDetailRepository; 88 private UserCollectionDetailRepository userCollectionDetailRepository;
83 89
90
84 @Autowired 91 @Autowired
85 private RedisUtils redisUtils; 92 private RedisUtils redisUtils;
86 93
...@@ -112,6 +119,8 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -112,6 +119,8 @@ public class UserOperationServiceImpl implements UserOperationService {
112 public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) {} 119 public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) {}
113 @AsyncMqSend 120 @AsyncMqSend
114 public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {} 121 public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {}
122 @AsyncMqSend
123 public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {}
115 124
116 /** 125 /**
117 * 创建大屏账户同时创建会员 126 * 创建大屏账户同时创建会员
...@@ -413,8 +422,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -413,8 +422,7 @@ public class UserOperationServiceImpl implements UserOperationService {
413 UserWeixinDTO _userWeixinDTO = this.doUpdateUserWeiXinStatus(userWeixinDTO, SUBSCRIBE_STATUS); 422 UserWeixinDTO _userWeixinDTO = this.doUpdateUserWeiXinStatus(userWeixinDTO, SUBSCRIBE_STATUS);
414 423
415 // 同步至iptv 424 // 同步至iptv
416 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncWeixin(_userWeixinDTO); 425 // ((UserOperationServiceImpl)AopContext.currentProxy()).asyncWeixin(_userWeixinDTO);
417 }
418 426
419 // 大屏信息 427 // 大屏信息
420 JSONObject iptvUserInfo = resources.getIptvUserInfo(); 428 JSONObject iptvUserInfo = resources.getIptvUserInfo();
...@@ -437,17 +445,42 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -437,17 +445,42 @@ public class UserOperationServiceImpl implements UserOperationService {
437 } 445 }
438 } 446 }
439 447
448 // 修改会员信息
449 MemberDTO _memberDTO1 = this.doUpdateMemberByMemberDTO(memberDTO);
450 // 同步至iptv
451 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncSubscribe(new MemberAndWeixinUserDTO(_memberDTO1, _userWeixinDTO));
452
440 // 大屏账户 453 // 大屏账户
441 String platformAccount = iptvUserInfo.getString("platformAccount"); 454 String platformAccount = iptvUserInfo.getString("platformAccount");
455 // 绑定
456 this.bind(memberDTO, platformAccount);
442 457
443 this.bind(memberDTO,platformAccount); 458 // 保存关注记录
459 this.saveWechatSubscribeRecord(memberDTO, 1);
460
461 }
444 462
445 } 463 }
446 464
447 return true; 465 return true;
466 }
467
468 /**
469 *
470 * @param memberDTO
471 * @param subscribe
472 */
473 private void saveWechatSubscribeRecord(MemberDTO memberDTO, int subscribe) {
448 474
475 WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord();
476 wechatSubscribeRecord.setCode(IdWorker.generatorString());
477 wechatSubscribeRecord.setMemberId(memberDTO.getId());
478 wechatSubscribeRecord.setOperationFlag(subscribe);
479
480 this.wechatSubscribeRecordService.create(wechatSubscribeRecord);
449 } 481 }
450 482
483
451 /** 484 /**
452 * 微信公众号取消关注 485 * 微信公众号取消关注
453 * @param resources 486 * @param resources
...@@ -471,6 +504,9 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -471,6 +504,9 @@ public class UserOperationServiceImpl implements UserOperationService {
471 // 同步至iptv 504 // 同步至iptv
472 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnsubscribe(new MemberAndWeixinUserDTO(_memberDTO, userWeixinDTO)); 505 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnsubscribe(new MemberAndWeixinUserDTO(_memberDTO, userWeixinDTO));
473 506
507 // 关注记录
508 this.saveWechatSubscribeRecord(_memberDTO, 2);
509
474 return true; 510 return true;
475 } 511 }
476 512
...@@ -494,6 +530,20 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -494,6 +530,20 @@ public class UserOperationServiceImpl implements UserOperationService {
494 530
495 try { 531 try {
496 532
533 try {
534 String headimgurl = json.get("headimgurl").toString();
535 if (StringUtils.isNotBlank(headimgurl)) {
536 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
537 String image = RestTemplateClient.netImage(headimgurlDecode);
538 if (StringUtils.isNotBlank(image))
539 json.put("headimgurl",image);
540 }
541 data = json.toJSONString();
542 } catch (Exception e) {
543 log.info("头像解析失败!!!");
544 e.printStackTrace();
545 }
546
497 // 过期时间300S 547 // 过期时间300S
498 this.redisUtils.set(RedisKeyUtil.genSeSuSubscribeKey(unionId), data, 300); 548 this.redisUtils.set(RedisKeyUtil.genSeSuSubscribeKey(unionId), data, 300);
499 Object o = this.redisUtils.get(RedisKeyUtil.genSeSuSubscribeKey(unionId)); 549 Object o = this.redisUtils.get(RedisKeyUtil.genSeSuSubscribeKey(unionId));
......
...@@ -150,6 +150,12 @@ public class IdWorker { ...@@ -150,6 +150,12 @@ public class IdWorker {
150 return idWorker.nextId(); 150 return idWorker.nextId();
151 } 151 }
152 152
153 public static String generatorString(){
154 IdWorker idWorker = new IdWorker();
155 return String.valueOf(idWorker.nextId());
156 }
157
158
153 public static String generatorCode(String prefix){ 159 public static String generatorCode(String prefix){
154 IdWorker idWorker = new IdWorker(); 160 IdWorker idWorker = new IdWorker();
155 if (StringUtils.isNotBlank(prefix)) { 161 if (StringUtils.isNotBlank(prefix)) {
......
1 package com.topdraw.weixin.subscribe.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12 import java.util.UUID;
13
14 import java.io.Serializable;
15
16 /**
17 * @author XiangHan
18 * @date 2022-05-21
19 */
20 @Entity
21 @Data
22 @EntityListeners(AuditingEntityListener.class)
23 @Accessors(chain = true)
24 @Table(name="uc_wechat_subscribe_record")
25 public class WechatSubscribeRecord implements Serializable {
26
27 // ID
28 @Id
29 @GeneratedValue(strategy = GenerationType.IDENTITY)
30 @Column(name = "id")
31 private Long id;
32
33 // 标识
34 @Column(name = "code", nullable = false)
35 private String code;
36
37 // 会员id
38 @Column(name = "member_id", nullable = false)
39 private Long memberId;
40
41 // 操作类型 1:关注;2:取关
42 @Column(name = "operation_flag")
43 private Integer operationFlag;
44
45 // 实例id
46 @Column(name = "entity_id")
47 private Long entityId;
48
49 // 实例code
50 @Column(name = "entity_code")
51 private Long entityCode;
52
53 // 实例类型 1:大屏扫码;2:营销活动;
54 @Column(name = "entity_type")
55 private Long entityType;
56
57 // 来源类型 1:大屏;2:营销活动;3:其他;
58 @Column(name = "source_type")
59 private Integer sourceType;
60
61 // 来源描述
62 @Column(name = "source_info")
63 private String sourceInfo;
64
65 // 创建时间
66 @CreatedDate
67 @Column(name = "create_time")
68 private Timestamp createTime;
69
70 // 更新时间
71 @LastModifiedDate
72 @Column(name = "update_time")
73 private Timestamp updateTime;
74
75 public void copy(WechatSubscribeRecord source){
76 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
77 }
78 }
1 package com.topdraw.weixin.subscribe.repository;
2
3 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2022-05-21
12 */
13 public interface WechatSubscribeRecordRepository extends JpaRepository<WechatSubscribeRecord, Long>, JpaSpecificationExecutor<WechatSubscribeRecord> {
14
15 Optional<WechatSubscribeRecord> findFirstByCode(String code);
16 }
1 package com.topdraw.weixin.subscribe.service;
2
3 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
4
5 /**
6 * @author XiangHan
7 * @date 2022-05-21
8 */
9 public interface WechatSubscribeRecordService {
10
11 void create(WechatSubscribeRecord resources);
12 }
1 package com.topdraw.weixin.subscribe.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-05-21
11 */
12 @Data
13 public class WechatSubscribeRecordDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 会员id
22 private Long memberId;
23
24 // 操作类型 1:关注;2:取关
25 private Integer operationFlag;
26
27 // 实例id
28 private Long entityId;
29
30 // 实例code
31 private Long entityCode;
32
33 // 实例类型 1:大屏扫码;2:营销活动;
34 private Long entityType;
35
36 // 来源类型 1:大屏;2:营销活动;3:其他;
37 private Integer sourceType;
38
39 // 来源描述
40 private String sourceInfo;
41
42 // 创建时间
43 private Timestamp createTime;
44
45 // 更新时间
46 private Timestamp updateTime;
47 }
1 package com.topdraw.weixin.subscribe.service.impl;
2
3 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
4 import com.topdraw.weixin.subscribe.repository.WechatSubscribeRecordRepository;
5 import com.topdraw.weixin.subscribe.service.WechatSubscribeRecordService;
6 import com.topdraw.weixin.subscribe.service.mapper.WechatSubscribeRecordMapper;
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Service;
9 import org.springframework.transaction.annotation.Propagation;
10 import org.springframework.transaction.annotation.Transactional;
11
12 /**
13 * @author XiangHan
14 * @date 2022-05-21
15 */
16 @Service
17 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
18 public class WechatSubscribeRecordServiceImpl implements WechatSubscribeRecordService {
19
20 @Autowired
21 private WechatSubscribeRecordRepository wechatSubscribeRecordRepository;
22
23 @Autowired
24 private WechatSubscribeRecordMapper wechatSubscribeRecordMapper;
25
26 @Override
27 @Transactional(rollbackFor = Exception.class)
28 public void create(WechatSubscribeRecord resources) {
29 this.wechatSubscribeRecordRepository.save(resources);
30 }
31 }
1 package com.topdraw.weixin.subscribe.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
5 import com.topdraw.weixin.subscribe.service.dto.WechatSubscribeRecordDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-05-21
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface WechatSubscribeRecordMapper extends BaseMapper<WechatSubscribeRecordDTO, WechatSubscribeRecord> {
15
16 }
...@@ -107,8 +107,8 @@ file: ...@@ -107,8 +107,8 @@ file:
107 107
108 service: 108 service:
109 mq: 109 mq:
110 exchange: uce.exchange # 管理侧 110 exchange: uce.exchange
111 queue: uce.queue # 管理侧 111 queue: uce.queue
112 112
113 weixin: 113 weixin:
114 list: 114 list:
...@@ -141,4 +141,4 @@ weixin: ...@@ -141,4 +141,4 @@ weixin:
141 env: dev 141 env: dev
142 142
143 api: 143 api:
144 uc-service: http://127.0.0.1:8210
...\ No newline at end of file ...\ No newline at end of file
144 uc-service: http://127.0.0.1:8446
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -39,16 +39,16 @@ public class GeneratorCode extends BaseTest { ...@@ -39,16 +39,16 @@ public class GeneratorCode extends BaseTest {
39 @Rollback(value = false) 39 @Rollback(value = false)
40 @Transactional(rollbackFor = Exception.class) 40 @Transactional(rollbackFor = Exception.class)
41 public void generator() { 41 public void generator() {
42 var dbName = "x_activity_address"; 42 var dbName = "uc_wechat_subscribe_record";
43 // 表名称,支持多表 43 // 表名称,支持多表
44 var tableNames = Arrays.asList(dbName); 44 var tableNames = Arrays.asList(dbName);
45 String[] s = dbName.split("_"); 45 String[] s = dbName.split("_");
46 46
47 var pre = s[0]; 47 var pre = s[0];
48 var target1 = s[s.length-1]; 48 var target1 = s[s.length-1];
49 var preRoute = "com.topdraw.business.module.contact."; 49 var preRoute = "com.topdraw.weixin.";
50 StringBuilder builder = new StringBuilder(preRoute); 50 StringBuilder builder = new StringBuilder(preRoute);
51 builder.append("vis"); 51 builder.append("subscribe");
52 // builder.append(target); 52 // builder.append(target);
53 53
54 tableNames.forEach(tableName -> { 54 tableNames.forEach(tableName -> {
......