1.添加修改会员相关人员验证条件
2.转移h5登录接口 3.微信相关事件实现逻辑
Showing
8 changed files
with
252 additions
and
61 deletions
... | @@ -5,6 +5,8 @@ import lombok.experimental.Accessors; | ... | @@ -5,6 +5,8 @@ import lombok.experimental.Accessors; |
5 | import cn.hutool.core.bean.BeanUtil; | 5 | import cn.hutool.core.bean.BeanUtil; |
6 | import cn.hutool.core.bean.copier.CopyOptions; | 6 | import cn.hutool.core.bean.copier.CopyOptions; |
7 | import javax.persistence.*; | 7 | import javax.persistence.*; |
8 | import javax.validation.constraints.NotNull; | ||
9 | |||
8 | import org.springframework.data.annotation.CreatedDate; | 10 | import org.springframework.data.annotation.CreatedDate; |
9 | import org.springframework.data.annotation.LastModifiedDate; | 11 | import org.springframework.data.annotation.LastModifiedDate; |
10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 12 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
... | @@ -28,6 +30,7 @@ public class MemberRelatedInfo implements Serializable { | ... | @@ -28,6 +30,7 @@ public class MemberRelatedInfo implements Serializable { |
28 | @Id | 30 | @Id |
29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
30 | @Column(name = "id") | 32 | @Column(name = "id") |
33 | @NotNull(groups = {UpdateGroup.class}) | ||
31 | private Long id; | 34 | private Long id; |
32 | 35 | ||
33 | // 会员id | 36 | // 会员id | ... | ... |
1 | package com.topdraw.business.module.member.relatedinfo.rest; | 1 | package com.topdraw.business.module.member.relatedinfo.rest; |
2 | 2 | ||
3 | import com.topdraw.annotation.AnonymousAccess; | ||
4 | import com.topdraw.business.module.member.relatedinfo.domain.UpdateGroup; | ||
5 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
3 | import com.topdraw.business.module.member.service.MemberService; | 6 | import com.topdraw.business.module.member.service.MemberService; |
4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 7 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
5 | import com.topdraw.common.ResultInfo; | 8 | import com.topdraw.common.ResultInfo; |
... | @@ -7,6 +10,8 @@ import com.topdraw.annotation.Log; | ... | @@ -7,6 +10,8 @@ import com.topdraw.annotation.Log; |
7 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 10 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
8 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; | 11 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; |
9 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | 12 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; |
13 | import com.topdraw.exception.BadRequestException; | ||
14 | import lombok.extern.slf4j.Slf4j; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.data.domain.Pageable; | 16 | import org.springframework.data.domain.Pageable; |
12 | import org.springframework.util.Assert; | 17 | import org.springframework.util.Assert; |
... | @@ -20,9 +25,10 @@ import java.util.Objects; | ... | @@ -20,9 +25,10 @@ import java.util.Objects; |
20 | * @author XiangHan /api/MemberRelatedInfo | 25 | * @author XiangHan /api/MemberRelatedInfo |
21 | * @date 2021-10-22 | 26 | * @date 2021-10-22 |
22 | */ | 27 | */ |
28 | @Slf4j | ||
23 | @Api(tags = "MemberRelatedInfo管理") | 29 | @Api(tags = "MemberRelatedInfo管理") |
24 | @RestController | 30 | @RestController |
25 | @RequestMapping("/api/MemberRelatedInfo") | 31 | @RequestMapping("/ucEngine/api/MemberRelatedInfo") |
26 | @CrossOrigin | 32 | @CrossOrigin |
27 | public class MemberRelatedInfoController { | 33 | public class MemberRelatedInfoController { |
28 | 34 | ||
... | @@ -45,21 +51,29 @@ public class MemberRelatedInfoController { | ... | @@ -45,21 +51,29 @@ public class MemberRelatedInfoController { |
45 | return ResultInfo.success(); | 51 | return ResultInfo.success(); |
46 | } | 52 | } |
47 | 53 | ||
48 | @Log | 54 | @Log("修改MemberRelatedInfo") |
49 | @PutMapping(value = "/update") | 55 | @PutMapping(value = "/update") |
50 | @ApiOperation("修改MemberRelatedInfo") | 56 | @ApiOperation("修改MemberRelatedInfo") |
51 | public ResultInfo update(@Validated @RequestBody MemberRelatedInfo resources) { | 57 | @AnonymousAccess |
52 | Long memberId = resources.getMemberId(); | 58 | public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody MemberRelatedInfo resources) { |
53 | String idCard = resources.getIdCard(); | 59 | Long id = resources.getId(); |
54 | Assert.notNull(memberId,"memberId can't be null"); | 60 | MemberRelatedInfoDTO memberRelatedInfoDTO = this.MemberRelatedInfoService.findById(id); |
55 | Assert.notNull(idCard,"idCard can't be null"); | 61 | if (memberRelatedInfoDTO.getId() != null) { |
56 | MemberDTO memberDTO = this.memberService.findById(memberId); | 62 | Long memberId = memberRelatedInfoDTO.getMemberId(); |
57 | if (Objects.nonNull(memberDTO)) { | 63 | if (Objects.isNull(memberId)) { |
58 | String code = memberDTO.getCode(); | 64 | log.info("id ==>> [{}]",id); |
59 | Assert.notNull(code,"code can't be null"); | 65 | throw new BadRequestException("memberId is null! please check member info"); |
60 | resources.setMemberCode(code); | 66 | } |
61 | MemberRelatedInfoService.update(resources); | 67 | |
68 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
69 | if (Objects.nonNull(memberDTO)) { | ||
70 | String code = memberDTO.getCode(); | ||
71 | Assert.notNull(code,"code can't be null"); | ||
72 | resources.setMemberCode(code); | ||
73 | MemberRelatedInfoService.update(resources); | ||
74 | } | ||
62 | } | 75 | } |
76 | |||
63 | return ResultInfo.success(); | 77 | return ResultInfo.success(); |
64 | } | 78 | } |
65 | 79 | ... | ... |
... | @@ -14,6 +14,9 @@ import java.time.LocalDateTime; | ... | @@ -14,6 +14,9 @@ import java.time.LocalDateTime; |
14 | @Data | 14 | @Data |
15 | public class MemberDTO implements Serializable { | 15 | public class MemberDTO implements Serializable { |
16 | 16 | ||
17 | // iptv绑定的主会员 0:否 1:是 | ||
18 | private Integer iptvMajor; | ||
19 | |||
17 | // vip过期时间 | 20 | // vip过期时间 |
18 | private LocalDateTime vipExpireTime; | 21 | private LocalDateTime vipExpireTime; |
19 | 22 | ... | ... |
1 | package com.topdraw.business.module.user.weixin.service.dto; | 1 | package com.topdraw.business.module.user.weixin.service.dto; |
2 | 2 | ||
3 | import com.topdraw.annotation.Query; | ||
3 | import lombok.Data; | 4 | import lombok.Data; |
4 | 5 | ||
5 | /** | 6 | /** |
... | @@ -9,6 +10,7 @@ import lombok.Data; | ... | @@ -9,6 +10,7 @@ import lombok.Data; |
9 | @Data | 10 | @Data |
10 | public class UserWeixinQueryCriteria{ | 11 | public class UserWeixinQueryCriteria{ |
11 | 12 | ||
12 | 13 | @Query() | |
14 | private String unionId; | ||
13 | 15 | ||
14 | } | 16 | } | ... | ... |
... | @@ -38,7 +38,6 @@ import org.springframework.validation.annotation.Validated; | ... | @@ -38,7 +38,6 @@ import org.springframework.validation.annotation.Validated; |
38 | import org.springframework.web.bind.annotation.*; | 38 | import org.springframework.web.bind.annotation.*; |
39 | 39 | ||
40 | import java.io.IOException; | 40 | import java.io.IOException; |
41 | import java.util.HashMap; | ||
42 | import java.util.List; | 41 | import java.util.List; |
43 | import java.util.Map; | 42 | import java.util.Map; |
44 | import java.util.Objects; | 43 | import java.util.Objects; |
... | @@ -119,6 +118,7 @@ public class UserOperationController { | ... | @@ -119,6 +118,7 @@ public class UserOperationController { |
119 | @Log("大屏用户解绑") | 118 | @Log("大屏用户解绑") |
120 | @PutMapping(value = "/unbind") | 119 | @PutMapping(value = "/unbind") |
121 | @ApiOperation("大屏用户解绑") | 120 | @ApiOperation("大屏用户解绑") |
121 | @AnonymousAccess | ||
122 | public ResultInfo unbind(@Validated(value = {UnbindGroup.class}) @RequestBody TempIptvUser resources) { | 122 | public ResultInfo unbind(@Validated(value = {UnbindGroup.class}) @RequestBody TempIptvUser resources) { |
123 | UserTv userTv = new UserTv(); | 123 | UserTv userTv = new UserTv(); |
124 | BeanUtils.copyProperties(resources,userTv); | 124 | BeanUtils.copyProperties(resources,userTv); |
... | @@ -129,6 +129,7 @@ public class UserOperationController { | ... | @@ -129,6 +129,7 @@ public class UserOperationController { |
129 | @Log("大屏更换主账号") | 129 | @Log("大屏更换主账号") |
130 | @PutMapping(value = "/changeMainAccount") | 130 | @PutMapping(value = "/changeMainAccount") |
131 | @ApiOperation("大屏更换主账号") | 131 | @ApiOperation("大屏更换主账号") |
132 | @AnonymousAccess | ||
132 | public ResultInfo changeMainAccount(@Validated(value = {UnbindGroup.class}) @RequestBody TempIptvUser resources) { | 133 | public ResultInfo changeMainAccount(@Validated(value = {UnbindGroup.class}) @RequestBody TempIptvUser resources) { |
133 | UserTv userTv = new UserTv(); | 134 | UserTv userTv = new UserTv(); |
134 | BeanUtils.copyProperties(resources,userTv); | 135 | BeanUtils.copyProperties(resources,userTv); |
... | @@ -136,6 +137,15 @@ public class UserOperationController { | ... | @@ -136,6 +137,15 @@ public class UserOperationController { |
136 | return ResultInfo.success("update success"); | 137 | return ResultInfo.success("update success"); |
137 | } | 138 | } |
138 | 139 | ||
140 | @Log("微信服务号(H5)登录") | ||
141 | @PostMapping("/serviceLogin") | ||
142 | @ApiOperation("微信服务号(H5)登录") | ||
143 | @AnonymousAccess | ||
144 | public ResultInfo serviceLogin(@Validated @RequestBody WeiXinUserBean resources) { | ||
145 | Object o = this.userTvOperationService.serviceLogin(resources); | ||
146 | return ResultInfo.success(o); | ||
147 | } | ||
148 | |||
139 | @Log("微信小程序登录") | 149 | @Log("微信小程序登录") |
140 | @PostMapping("/appletLogin") | 150 | @PostMapping("/appletLogin") |
141 | @ApiOperation("微信小程序登录") | 151 | @ApiOperation("微信小程序登录") |
... | @@ -187,7 +197,9 @@ public class UserOperationController { | ... | @@ -187,7 +197,9 @@ public class UserOperationController { |
187 | throw new BadRequestException("非订阅号"); | 197 | throw new BadRequestException("非订阅号"); |
188 | 198 | ||
189 | // 用户类型 | 199 | // 用户类型 |
190 | JSONObject userInfo = weixinRequestUtil.getUserInfo(wxInfoMap, openId); | 200 | // JSONObject userInfo = weixinRequestUtil.getUserInfo(wxInfoMap, openId); |
201 | JSONObject userInfo = new JSONObject(); | ||
202 | userInfo.put("unionid","oqDha5idQxR0WGPW2qHi-meHRtyg"); | ||
191 | log.info("userInfo is : {}", userInfo.toJSONString()); | 203 | log.info("userInfo is : {}", userInfo.toJSONString()); |
192 | unionId = userInfo.get("unionid").toString(); | 204 | unionId = userInfo.get("unionid").toString(); |
193 | 205 | ||
... | @@ -212,10 +224,13 @@ public class UserOperationController { | ... | @@ -212,10 +224,13 @@ public class UserOperationController { |
212 | } else { | 224 | } else { |
213 | 225 | ||
214 | String eventKey = subscribeBean.getEventKey(); | 226 | String eventKey = subscribeBean.getEventKey(); |
215 | // 用户扫描带参二维码关注。发消息 | 227 | |
216 | // 去除固定前缀,获取二维码参数 | 228 | if (StringUtils.isNotBlank(eventKey)) { |
217 | eventKey = eventKey.substring(8); | 229 | // 用户扫描带参二维码关注。发消息 |
218 | iptvUserInfo = com.alibaba.fastjson.JSONObject.parseObject(eventKey); | 230 | // 去除固定前缀,获取二维码参数 |
231 | eventKey = eventKey.substring(8); | ||
232 | iptvUserInfo = JSONObject.parseObject(eventKey); | ||
233 | } | ||
219 | 234 | ||
220 | } | 235 | } |
221 | 236 | ||
... | @@ -224,10 +239,6 @@ public class UserOperationController { | ... | @@ -224,10 +239,6 @@ public class UserOperationController { |
224 | subscribeBean.setIptvUserInfo(iptvUserInfo); | 239 | subscribeBean.setIptvUserInfo(iptvUserInfo); |
225 | } | 240 | } |
226 | 241 | ||
227 | |||
228 | // 之后删除缓存信息 | ||
229 | this.redisUtils.del(RedisKeyUtil.genSeSuSubscribeKey(unionId)); | ||
230 | |||
231 | } | 242 | } |
232 | } | 243 | } |
233 | 244 | ... | ... |
... | @@ -12,29 +12,99 @@ import java.util.List; | ... | @@ -12,29 +12,99 @@ import java.util.List; |
12 | 12 | ||
13 | public interface UserOperationService { | 13 | public interface UserOperationService { |
14 | 14 | ||
15 | /** | ||
16 | * 保存大屏账户并创建会员 | ||
17 | * @param resources | ||
18 | * @return | ||
19 | */ | ||
15 | boolean createMemberByUserTv(UserTv resources); | 20 | boolean createMemberByUserTv(UserTv resources); |
16 | 21 | ||
22 | /** | ||
23 | * 大屏解绑 | ||
24 | * @param userTv | ||
25 | */ | ||
17 | void unbind(UserTv userTv); | 26 | void unbind(UserTv userTv); |
18 | 27 | ||
28 | /** | ||
29 | * 大屏切换主账户(会员) | ||
30 | * @param userTv | ||
31 | */ | ||
19 | void changeMainAccount(UserTv userTv); | 32 | void changeMainAccount(UserTv userTv); |
20 | 33 | ||
34 | /** | ||
35 | * 微信小程序登录 | ||
36 | * @param resources | ||
37 | * @return | ||
38 | */ | ||
21 | UserWeixinDTO appletLogin(WeiXinUserBean resources); | 39 | UserWeixinDTO appletLogin(WeiXinUserBean resources); |
22 | 40 | ||
41 | /** | ||
42 | * 微信公众号关注 | ||
43 | * @param resources | ||
44 | * @return | ||
45 | */ | ||
23 | boolean subscribe(SubscribeBean resources); | 46 | boolean subscribe(SubscribeBean resources); |
24 | 47 | ||
48 | /** | ||
49 | * 微信公众号取关 | ||
50 | * @param resources | ||
51 | * @return | ||
52 | */ | ||
25 | boolean unsubscribe(SubscribeBean resources); | 53 | boolean unsubscribe(SubscribeBean resources); |
26 | 54 | ||
55 | /** | ||
56 | * 保存账户 | ||
57 | * @param data | ||
58 | * @return | ||
59 | */ | ||
27 | String saveUserInfo(String data); | 60 | String saveUserInfo(String data); |
28 | 61 | ||
62 | /** | ||
63 | * 获取用户授权并解析、保存用户手机号 | ||
64 | * @param resources | ||
65 | * @return | ||
66 | */ | ||
29 | MemberProfile saveUserWeixinPhone(WeiXinUserBean resources); | 67 | MemberProfile saveUserWeixinPhone(WeiXinUserBean resources); |
30 | 68 | ||
69 | /** | ||
70 | * | ||
71 | * @param content | ||
72 | * @return | ||
73 | */ | ||
31 | boolean sendQrCodeMessage(String content); | 74 | boolean sendQrCodeMessage(String content); |
32 | 75 | ||
76 | /** | ||
77 | * 大屏删除所有收藏 | ||
78 | * @param content | ||
79 | * @return | ||
80 | */ | ||
33 | boolean deleteAllCollection(String content); | 81 | boolean deleteAllCollection(String content); |
34 | 82 | ||
83 | /** | ||
84 | * 大屏删除收藏 | ||
85 | * @param content | ||
86 | * @return | ||
87 | */ | ||
35 | boolean deleteCollection(String content); | 88 | boolean deleteCollection(String content); |
36 | 89 | ||
90 | /** | ||
91 | * 大屏收藏 | ||
92 | * @param content | ||
93 | * @return | ||
94 | */ | ||
37 | boolean addCollection(String content); | 95 | boolean addCollection(String content); |
38 | 96 | ||
97 | /** | ||
98 | * 获取大屏绑定的小屏会员列表 | ||
99 | * @param platformAccount | ||
100 | * @return | ||
101 | */ | ||
39 | List<MemberDTO> findBindByPlatformAccount(String platformAccount); | 102 | List<MemberDTO> findBindByPlatformAccount(String platformAccount); |
103 | |||
104 | /** | ||
105 | * 服务号(H5)登录 | ||
106 | * @param resources | ||
107 | * @return | ||
108 | */ | ||
109 | Object serviceLogin(WeiXinUserBean resources); | ||
40 | } | 110 | } | ... | ... |
... | @@ -27,6 +27,7 @@ import com.topdraw.business.module.user.weixin.collection.repository.UserCollect | ... | @@ -27,6 +27,7 @@ import com.topdraw.business.module.user.weixin.collection.repository.UserCollect |
27 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionDetailService; | 27 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionDetailService; |
28 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionService; | 28 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionService; |
29 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 29 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
30 | import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; | ||
30 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 31 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
31 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 32 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
32 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | 33 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; |
... | @@ -38,8 +39,11 @@ import com.topdraw.business.process.service.UserOperationService; | ... | @@ -38,8 +39,11 @@ import com.topdraw.business.process.service.UserOperationService; |
38 | import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; | 39 | import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; |
39 | import com.topdraw.config.LocalConstants; | 40 | import com.topdraw.config.LocalConstants; |
40 | import com.topdraw.config.RedisKeyUtil; | 41 | import com.topdraw.config.RedisKeyUtil; |
42 | import com.topdraw.config.ServiceEnvConfig; | ||
41 | import com.topdraw.exception.BadRequestException; | 43 | import com.topdraw.exception.BadRequestException; |
42 | import com.topdraw.exception.EntityNotFoundException; | 44 | import com.topdraw.exception.EntityNotFoundException; |
45 | import com.topdraw.module.mq.DataSyncMsg; | ||
46 | import com.topdraw.module.mq.EntityType; | ||
43 | import com.topdraw.security.AESUtil; | 47 | import com.topdraw.security.AESUtil; |
44 | import com.topdraw.util.IdWorker; | 48 | import com.topdraw.util.IdWorker; |
45 | import com.topdraw.util.TimestampUtil; | 49 | import com.topdraw.util.TimestampUtil; |
... | @@ -57,16 +61,20 @@ import org.redisson.api.RedissonClient; | ... | @@ -57,16 +61,20 @@ import org.redisson.api.RedissonClient; |
57 | import org.springframework.beans.BeanUtils; | 61 | import org.springframework.beans.BeanUtils; |
58 | import org.springframework.beans.factory.annotation.Autowired; | 62 | import org.springframework.beans.factory.annotation.Autowired; |
59 | import org.springframework.beans.factory.annotation.Value; | 63 | import org.springframework.beans.factory.annotation.Value; |
64 | import org.springframework.data.domain.PageRequest; | ||
65 | import org.springframework.data.domain.Sort; | ||
60 | import org.springframework.http.HttpMethod; | 66 | import org.springframework.http.HttpMethod; |
61 | import org.springframework.http.ResponseEntity; | 67 | import org.springframework.http.ResponseEntity; |
62 | import org.springframework.stereotype.Service; | 68 | import org.springframework.stereotype.Service; |
63 | import org.springframework.transaction.annotation.Propagation; | 69 | import org.springframework.transaction.annotation.Propagation; |
64 | import org.springframework.transaction.annotation.Transactional; | 70 | import org.springframework.transaction.annotation.Transactional; |
65 | import org.springframework.util.Assert; | 71 | import org.springframework.util.Assert; |
72 | import org.springframework.util.CollectionUtils; | ||
66 | import org.springframework.web.client.RestTemplate; | 73 | import org.springframework.web.client.RestTemplate; |
67 | 74 | ||
68 | import javax.annotation.Resource; | 75 | import javax.annotation.Resource; |
69 | import java.io.IOException; | 76 | import java.io.IOException; |
77 | import java.sql.Timestamp; | ||
70 | import java.time.LocalDateTime; | 78 | import java.time.LocalDateTime; |
71 | import java.util.*; | 79 | import java.util.*; |
72 | import java.util.concurrent.TimeUnit; | 80 | import java.util.concurrent.TimeUnit; |
... | @@ -77,6 +85,7 @@ import java.util.stream.Collectors; | ... | @@ -77,6 +85,7 @@ import java.util.stream.Collectors; |
77 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 85 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
78 | public class UserOperationServiceImpl implements UserOperationService { | 86 | public class UserOperationServiceImpl implements UserOperationService { |
79 | 87 | ||
88 | |||
80 | @Autowired | 89 | @Autowired |
81 | private RedissonClient redissonClient; | 90 | private RedissonClient redissonClient; |
82 | @Autowired | 91 | @Autowired |
... | @@ -101,6 +110,8 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -101,6 +110,8 @@ public class UserOperationServiceImpl implements UserOperationService { |
101 | private UserCollectionDetailRepository userCollectionDetailRepository; | 110 | private UserCollectionDetailRepository userCollectionDetailRepository; |
102 | @Autowired | 111 | @Autowired |
103 | private CollectionMq2DetailMapper collectionMq2DetailMapper; | 112 | private CollectionMq2DetailMapper collectionMq2DetailMapper; |
113 | @Autowired | ||
114 | private UserWeixinRepository userWeixinRepository; | ||
104 | 115 | ||
105 | 116 | ||
106 | 117 | ||
... | @@ -110,6 +121,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -110,6 +121,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
110 | private static final String SUBSCRIBE = "subscribe"; | 121 | private static final String SUBSCRIBE = "subscribe"; |
111 | private static final String UNSUBSCRIBE = "unsubscribe"; | 122 | private static final String UNSUBSCRIBE = "unsubscribe"; |
112 | private static final Integer[] PLATFORM_LIST = new Integer[]{0,1,2,3}; | 123 | private static final Integer[] PLATFORM_LIST = new Integer[]{0,1,2,3}; |
124 | private static final Integer[] IPTV_MAJOR = new Integer[]{0,1}; | ||
113 | 125 | ||
114 | private static final String QR_CODE_URL = "QR_CODE_URL_"; | 126 | private static final String QR_CODE_URL = "QR_CODE_URL_"; |
115 | 127 | ||
... | @@ -151,17 +163,16 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -151,17 +163,16 @@ public class UserOperationServiceImpl implements UserOperationService { |
151 | String appId = resources.getAppId(); | 163 | String appId = resources.getAppId(); |
152 | String openId = resources.getOpenId(); | 164 | String openId = resources.getOpenId(); |
153 | 165 | ||
154 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = this.parseAppletInfo(resources); | ||
155 | |||
156 | if (Objects.nonNull(weiXinBeanDefinition.getOpenId())) { | ||
157 | throw new RuntimeException("微信信息解析失败!"); | ||
158 | } | ||
159 | |||
160 | // 小屏账户 | 166 | // 小屏账户 |
161 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); | 167 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); |
162 | 168 | ||
163 | if (Objects.isNull(userWeixinDTO.getId())) { | 169 | if (Objects.isNull(userWeixinDTO.getId())) { |
164 | 170 | ||
171 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = new DefaultWeiXinBeanDefinition(); | ||
172 | weiXinBeanDefinition.setUnionId(unionId); | ||
173 | weiXinBeanDefinition.setAppid(appId); | ||
174 | weiXinBeanDefinition.setOpenId(openId); | ||
175 | |||
165 | // 创建会员和账户 | 176 | // 创建会员和账户 |
166 | this.doCreateUserWeiXinAndMember(weiXinBeanDefinition); | 177 | this.doCreateUserWeiXinAndMember(weiXinBeanDefinition); |
167 | 178 | ||
... | @@ -189,7 +200,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -189,7 +200,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
189 | } | 200 | } |
190 | 201 | ||
191 | // 大屏账户绑定小屏会员的code | 202 | // 大屏账户绑定小屏会员的code |
192 | this.bondPriorityMember(userTvDTO,memberDTO_0); | 203 | this.bondPriorityMember(userTvDTO,memberDTO_0,"auto"); |
193 | 204 | ||
194 | // 小屏会员绑定大屏账户id | 205 | // 小屏会员绑定大屏账户id |
195 | MemberDTO memberDTO_1 = this.bindIptvId(memberDTO_0,userTvDTO); | 206 | MemberDTO memberDTO_1 = this.bindIptvId(memberDTO_0,userTvDTO); |
... | @@ -238,9 +249,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -238,9 +249,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
238 | 249 | ||
239 | // 小屏账户 | 250 | // 小屏账户 |
240 | UserWeixin userWeixin = this.generateUserWeiXin(weiXinBeanDefinition,SUBSCRIBE_STATUS); | 251 | UserWeixin userWeixin = this.generateUserWeiXin(weiXinBeanDefinition,SUBSCRIBE_STATUS); |
241 | if (Objects.isNull(userWeixin.getId())) { | ||
242 | throw new BadRequestException("创建小屏账户失败"); | ||
243 | } | ||
244 | 252 | ||
245 | // 保存会员 | 253 | // 保存会员 |
246 | Long memberId = this.doCreateMember(userWeixin,1); | 254 | Long memberId = this.doCreateMember(userWeixin,1); |
... | @@ -270,22 +278,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -270,22 +278,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
270 | } | 278 | } |
271 | 279 | ||
272 | /** | 280 | /** |
273 | * 绑定iptvId字段并修改会员vip字段 | ||
274 | * @param memberDTO | ||
275 | * @param userTvDTO | ||
276 | */ | ||
277 | private MemberDTO bindIptvIdAndUpdateVip(MemberDTO memberDTO, UserTvDTO userTvDTO) { | ||
278 | Integer vip = memberDTO.getVip(); | ||
279 | |||
280 | if (Objects.nonNull(vip) && vip == 0) { | ||
281 | memberDTO.setVip(1); | ||
282 | return this.bindIptvId(memberDTO,userTvDTO); | ||
283 | |||
284 | } | ||
285 | return memberDTO; | ||
286 | } | ||
287 | |||
288 | /** | ||
289 | * 微信公众号取消关注 | 281 | * 微信公众号取消关注 |
290 | * @param resources | 282 | * @param resources |
291 | * @return | 283 | * @return |
... | @@ -508,7 +500,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -508,7 +500,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
508 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionId(unionid); | 500 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionId(unionid); |
509 | 501 | ||
510 | // 无账号,没有绑定会员 | 502 | // 无账号,没有绑定会员 |
511 | if (Objects.isNull(userWeixinDTO.getId()) || Objects.isNull(userWeixinDTO.getMemberId())) { | 503 | if (Objects.isNull(userWeixinDTO.getMemberId())) { |
512 | // 默认会员 | 504 | // 默认会员 |
513 | Member member = MemberBuilder.build(LocalConstants.DEVICE_MOBILE,userWeixin.getHeadimgurl(), | 505 | Member member = MemberBuilder.build(LocalConstants.DEVICE_MOBILE,userWeixin.getHeadimgurl(), |
514 | userWeixin.getNickname(),vip); | 506 | userWeixin.getNickname(),vip); |
... | @@ -711,7 +703,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -711,7 +703,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
711 | MemberDTO memberDTO = this.findMemberByMemberCode(memberCode); | 703 | MemberDTO memberDTO = this.findMemberByMemberCode(memberCode); |
712 | 704 | ||
713 | // 设置主会员 | 705 | // 设置主会员 |
714 | this.bondPriorityMember(userTvDTO, memberDTO); | 706 | this.bondPriorityMember(userTvDTO, memberDTO,"manual"); |
715 | 707 | ||
716 | } | 708 | } |
717 | 709 | ||
... | @@ -720,20 +712,22 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -720,20 +712,22 @@ public class UserOperationServiceImpl implements UserOperationService { |
720 | * @description 检查大屏账户有没有绑定小屏会员,如果没有绑定就将当前会员的code保存到大屏账户中 | 712 | * @description 检查大屏账户有没有绑定小屏会员,如果没有绑定就将当前会员的code保存到大屏账户中 |
721 | * @param userTvDTO | 713 | * @param userTvDTO |
722 | * @param memberDTO | 714 | * @param memberDTO |
715 | * @param auto manual:手动 auto:自动 | ||
723 | */ | 716 | */ |
724 | private void bondPriorityMember(UserTvDTO userTvDTO, MemberDTO memberDTO) { | 717 | private void bondPriorityMember(UserTvDTO userTvDTO, MemberDTO memberDTO,String auto) { |
725 | 718 | ||
726 | // 绑定的小屏编码 | 719 | if (auto.equalsIgnoreCase("auto")) { |
727 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | 720 | // 绑定的小屏编码 |
728 | 721 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | |
729 | if (StringUtils.isNotEmpty(priorityMemberCode)) { | 722 | if (StringUtils.isNotEmpty(priorityMemberCode)) { |
730 | return; | 723 | return; |
724 | } | ||
731 | } | 725 | } |
732 | 726 | ||
733 | String memberCode = memberDTO.getCode(); | 727 | String memberCode = memberDTO.getCode(); |
734 | 728 | ||
735 | // 绑定了小屏,结束 | 729 | // 绑定了小屏,结束 |
736 | if (StringUtils.isEmpty(priorityMemberCode) && StringUtils.isNotEmpty(memberCode)) { | 730 | if (StringUtils.isNotEmpty(memberCode)) { |
737 | userTvDTO.setPriorityMemberCode(memberCode); | 731 | userTvDTO.setPriorityMemberCode(memberCode); |
738 | } | 732 | } |
739 | 733 | ||
... | @@ -1146,12 +1140,102 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1146,12 +1140,102 @@ public class UserOperationServiceImpl implements UserOperationService { |
1146 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 1140 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
1147 | if (Objects.nonNull(userTvDTO.getId())) { | 1141 | if (Objects.nonNull(userTvDTO.getId())) { |
1148 | Long id = userTvDTO.getId(); | 1142 | Long id = userTvDTO.getId(); |
1149 | 1143 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | |
1150 | return this.memberService.findByUserIptvId(id); | 1144 | List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id); |
1145 | if (!CollectionUtils.isEmpty(memberDTOList)) { | ||
1146 | for (MemberDTO memberDTO : memberDTOList) { | ||
1147 | String code = memberDTO.getCode(); | ||
1148 | if (code.equalsIgnoreCase(priorityMemberCode)) { | ||
1149 | memberDTO.setIptvMajor(IPTV_MAJOR[1]); | ||
1150 | } else { | ||
1151 | memberDTO.setIptvMajor(IPTV_MAJOR[0]); | ||
1152 | } | ||
1153 | } | ||
1154 | } | ||
1155 | return memberDTOList; | ||
1151 | } | 1156 | } |
1152 | return null; | 1157 | return null; |
1153 | } | 1158 | } |
1154 | 1159 | ||
1160 | @Override | ||
1161 | public Object serviceLogin(WeiXinUserBean resources) { | ||
1162 | String unionId = resources.getUnionId(); | ||
1163 | String appId = resources.getAppId(); | ||
1164 | String openId = resources.getOpenId(); | ||
1165 | |||
1166 | // 小屏账户 | ||
1167 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); | ||
1168 | |||
1169 | if (Objects.isNull(userWeixinDTO.getId())) { | ||
1170 | |||
1171 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = new DefaultWeiXinBeanDefinition(); | ||
1172 | weiXinBeanDefinition.setUnionId(unionId); | ||
1173 | weiXinBeanDefinition.setAppid(appId); | ||
1174 | weiXinBeanDefinition.setOpenId(openId); | ||
1175 | |||
1176 | // 创建会员和账户 | ||
1177 | this.doCreateUserWeiXinAndMember(weiXinBeanDefinition); | ||
1178 | |||
1179 | } else { | ||
1180 | |||
1181 | // 修改账户和会员信息 | ||
1182 | this.doUpdateUserWeiXinAndMember(userWeixinDTO,appId,openId); | ||
1183 | |||
1184 | } | ||
1185 | |||
1186 | // 为了保证返回的同一用户 | ||
1187 | UserWeixinDTO userWeixinDTO_0 = this.getFirstId(userWeixinDTO); | ||
1188 | return userWeixinDTO_0; | ||
1189 | } | ||
1190 | |||
1191 | /** | ||
1192 | * 同一用户有多个微信APP的情况下展示同一个账户信息 | ||
1193 | * 原则:那个先创建就用那个id | ||
1194 | * @param userWeixinDTO | ||
1195 | */ | ||
1196 | private UserWeixinDTO getFirstId(UserWeixinDTO userWeixinDTO) { | ||
1197 | String unionid = userWeixinDTO.getUnionid(); | ||
1198 | |||
1199 | if (StringUtils.isNotBlank(unionid)) { | ||
1200 | |||
1201 | UserWeixinQueryCriteria criteria = new UserWeixinQueryCriteria(); | ||
1202 | PageRequest pageable = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "createTime")); | ||
1203 | criteria.setUnionId(unionid); | ||
1204 | |||
1205 | List<UserWeixin> userWeixinList = this.userWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) | ||
1206 | -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable).getContent(); | ||
1207 | |||
1208 | List<UserWeixin> h5AppIdList = userWeixinList.stream().filter(e -> ObjectUtil.equal(e.getAppid(), h5AppId)).collect(Collectors.toList()); | ||
1209 | List<UserWeixin> appletAppIdList = userWeixinList.stream().filter(e -> ObjectUtil.equal(e.getAppid(), appletAppid)).collect(Collectors.toList()); | ||
1210 | |||
1211 | //没创建h5账号 返回小程序id | ||
1212 | if (h5AppIdList.isEmpty()) { | ||
1213 | userWeixinDTO.setId(appletAppIdList.get(0).getId()); | ||
1214 | userWeixinDTO.setAuthTime(appletAppIdList.get(0).getAuthTime()); | ||
1215 | } | ||
1216 | |||
1217 | //没创建小程序账号 返回h5id | ||
1218 | if (appletAppIdList.isEmpty()) { | ||
1219 | userWeixinDTO.setId(h5AppIdList.get(0).getId()); | ||
1220 | userWeixinDTO.setAuthTime(h5AppIdList.get(0).getAuthTime()); | ||
1221 | } | ||
1222 | |||
1223 | //都创建 那个先创建 用那个 | ||
1224 | if (!appletAppIdList.isEmpty() && !h5AppIdList.isEmpty()) { | ||
1225 | if (appletAppIdList.get(0).getCreateTime().before(h5AppIdList.get(0).getCreateTime())) { | ||
1226 | userWeixinDTO.setId(appletAppIdList.get(0).getId()); | ||
1227 | userWeixinDTO.setAuthTime(appletAppIdList.get(0).getAuthTime()); | ||
1228 | } else { | ||
1229 | userWeixinDTO.setId(h5AppIdList.get(0).getId()); | ||
1230 | userWeixinDTO.setAuthTime(h5AppIdList.get(0).getAuthTime()); | ||
1231 | } | ||
1232 | } | ||
1233 | |||
1234 | } | ||
1235 | |||
1236 | return userWeixinDTO; | ||
1237 | } | ||
1238 | |||
1155 | /** | 1239 | /** |
1156 | * 保存、修改会员加密信息 | 1240 | * 保存、修改会员加密信息 |
1157 | * @param resources | 1241 | * @param resources | ... | ... |
-
Please register or sign in to post a comment