Commit 1b6b6ac4 1b6b6ac4f19b1a6ce8aea0afa59013b02e6fd06f by xianghan

1.优化

1 parent df8b22d5
...@@ -2,6 +2,7 @@ package com.topdraw.business.module.user.iptv.domain; ...@@ -2,6 +2,7 @@ package com.topdraw.business.module.user.iptv.domain;
2 2
3 import com.topdraw.business.module.common.domain.AsyncMqModule; 3 import com.topdraw.business.module.common.domain.AsyncMqModule;
4 import com.topdraw.business.module.common.validated.CreateGroup; 4 import com.topdraw.business.module.common.validated.CreateGroup;
5 import com.topdraw.business.module.common.validated.UpdateGroup;
5 import lombok.Data; 6 import lombok.Data;
6 import lombok.experimental.Accessors; 7 import lombok.experimental.Accessors;
7 import cn.hutool.core.bean.BeanUtil; 8 import cn.hutool.core.bean.BeanUtil;
...@@ -51,7 +52,7 @@ public class UserTv extends AsyncMqModule implements Serializable { ...@@ -51,7 +52,7 @@ public class UserTv extends AsyncMqModule implements Serializable {
51 52
52 /** 运营商平台账号 */ 53 /** 运营商平台账号 */
53 @Column(name = "platform_account") 54 @Column(name = "platform_account")
54 @NotNull(message = "platformAccount can't be null !",groups = {CreateGroup.class}) 55 @NotNull(message = "platformAccount can't be null !",groups = {CreateGroup.class, UpdateGroup.class})
55 private String platformAccount; 56 private String platformAccount;
56 57
57 /** 手机号 */ 58 /** 手机号 */
......
...@@ -101,8 +101,8 @@ public class UserOperationController { ...@@ -101,8 +101,8 @@ public class UserOperationController {
101 SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class); 101 SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class);
102 // 解析参数 102 // 解析参数
103 this.parseSubscribe(subscribeBean); 103 this.parseSubscribe(subscribeBean);
104 boolean result = this.userOperationService.subscribe(subscribeBean); 104 this.userOperationService.subscribe(subscribeBean);
105 return ResultInfo.success(result); 105 return ResultInfo.success();
106 } 106 }
107 107
108 /** 108 /**
...@@ -112,19 +112,15 @@ public class UserOperationController { ...@@ -112,19 +112,15 @@ public class UserOperationController {
112 */ 112 */
113 private void parseSubscribe(SubscribeBean subscribeBean) throws IOException { 113 private void parseSubscribe(SubscribeBean subscribeBean) throws IOException {
114 114
115 String appId = subscribeBean.getAppId(); 115 String appId = subscribeBean.getAppid();
116 Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL); 116 Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL);
117 // openId 117 // openId
118 String openId = subscribeBean.getOpenId(); 118 String openId = subscribeBean.getOpenid();
119 Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL); 119 Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL);
120 // unionId 120 // unionId
121 String unionId = subscribeBean.getUnionid(); 121 String unionId = subscribeBean.getUnionid();
122 Assert.notNull(openId, GlobeExceptionMsg.UNION_ID_IS_NULL); 122 Assert.notNull(openId, GlobeExceptionMsg.UNION_ID_IS_NULL);
123 123
124 subscribeBean.setAppid(appId);
125 subscribeBean.setOpenid(openId);
126 subscribeBean.setUnionid(unionId);
127
128 // 匹配配置文件中的微信列表信息 124 // 匹配配置文件中的微信列表信息
129 Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId); 125 Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId);
130 126
...@@ -206,7 +202,7 @@ public class UserOperationController { ...@@ -206,7 +202,7 @@ public class UserOperationController {
206 @AnonymousAccess 202 @AnonymousAccess
207 public ResultInfo saveUserInfo(@RequestBody String data) { 203 public ResultInfo saveUserInfo(@RequestBody String data) {
208 204
209 log.info("saveUserInfo ==> input ==> [{}]",data); 205 log.info("UserOperationController ==> saveUserInfo ==>> param ==>> [{}]",data);
210 Assert.notNull(data, "用户数据不可为空"); 206 Assert.notNull(data, "用户数据不可为空");
211 207
212 JSONObject json = JSONObject.parseObject(data); 208 JSONObject json = JSONObject.parseObject(data);
...@@ -327,7 +323,7 @@ public class UserOperationController { ...@@ -327,7 +323,7 @@ public class UserOperationController {
327 @RequestMapping(value = "/changeMainAccount") 323 @RequestMapping(value = "/changeMainAccount")
328 @ApiOperation("大屏更换主账号") 324 @ApiOperation("大屏更换主账号")
329 @AnonymousAccess 325 @AnonymousAccess
330 public ResultInfo changeMainAccount(@Validated @RequestBody UserTv resources) { 326 public ResultInfo changeMainAccount(@Validated(value = {UpdateGroup.class}) @RequestBody UserTv resources) {
331 log.info("UserOperationController ==> changeMainAccount ==>> param ==> [{}]",resources); 327 log.info("UserOperationController ==> changeMainAccount ==>> param ==> [{}]",resources);
332 328
333 this.userOperationService.changeMainAccount(resources); 329 this.userOperationService.changeMainAccount(resources);
......
...@@ -131,4 +131,11 @@ public interface UserOperationService { ...@@ -131,4 +131,11 @@ public interface UserOperationService {
131 * @return 131 * @return
132 */ 132 */
133 UserTvDTO checkBind(MemberDTO memberDTO); 133 UserTvDTO checkBind(MemberDTO memberDTO);
134
135 /**
136 *
137 * @param platformAccount
138 * @return
139 */
140 UserTvDTO findByPlatformAccount(String platformAccount);
134 } 141 }
......
...@@ -37,8 +37,9 @@ import com.topdraw.exception.GlobeExceptionMsg; ...@@ -37,8 +37,9 @@ import com.topdraw.exception.GlobeExceptionMsg;
37 import com.topdraw.util.TimestampUtil; 37 import com.topdraw.util.TimestampUtil;
38 import com.topdraw.utils.QueryHelp; 38 import com.topdraw.utils.QueryHelp;
39 import com.topdraw.utils.RedisUtils; 39 import com.topdraw.utils.RedisUtils;
40 import com.topdraw.utils.StringUtils;
41 import lombok.extern.slf4j.Slf4j; 40 import lombok.extern.slf4j.Slf4j;
41 import org.apache.commons.collections4.CollectionUtils;
42 import org.apache.commons.lang3.StringUtils;
42 import org.springframework.beans.BeanUtils; 43 import org.springframework.beans.BeanUtils;
43 import org.springframework.beans.factory.annotation.Autowired; 44 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.beans.factory.annotation.Value; 45 import org.springframework.beans.factory.annotation.Value;
...@@ -359,15 +360,21 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -359,15 +360,21 @@ public class UserOperationServiceImpl implements UserOperationService {
359 360
360 // 会员编码 361 // 会员编码
361 String memberCode = resources.getMemberCode(); 362 String memberCode = resources.getMemberCode();
363 this.findMemberByCode(memberCode);
362 364
363 UserTvDTO userTvDTO = this.findByPriorityMemberCode(memberCode); 365 String platformAccount = resources.getPlatformAccount();
366 this.findByPlatformAccount(platformAccount);
367
368 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
364 369
365 if (Objects.nonNull(userTvDTO)) { 370 if (Objects.nonNull(userTvDTO)) {
366 371
367 if (userTvDTO.getPriorityMemberCode().equalsIgnoreCase(memberCode)) 372 if (userTvDTO.getPriorityMemberCode().equalsIgnoreCase(memberCode))
368 throw new BadRequestException("会员已是主账户"); 373 throw new BadRequestException("会员已是主账户");
369 374
370 throw new BadRequestException("该会员已绑定其他账户"); 375 } else {
376
377 throw new EntityNotFoundException(UserTvDTO.class , "platformAccount" , GlobeExceptionMsg.IPTV_IS_NULL);
371 378
372 } 379 }
373 380
...@@ -383,16 +390,18 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -383,16 +390,18 @@ public class UserOperationServiceImpl implements UserOperationService {
383 @Override 390 @Override
384 public void unbind(UserTv resources) { 391 public void unbind(UserTv resources) {
385 392
393 String platformAccount = resources.getPlatformAccount();
386 String memberCode = resources.getMemberCode(); 394 String memberCode = resources.getMemberCode();
387 395
388 // 大屏会员 396 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
389 MemberDTO memberDTOS = this.findMemberByCode(memberCode); 397 if (Objects.isNull(userTvDTO))
398 throw new EntityNotFoundException(UserTvDTO.class, "PlatformAccount", GlobeExceptionMsg.IPTV_IS_NULL);
390 399
391 // 解绑(置空大屏信息) 400 // 解绑(置空大屏信息)
392 this.resetIptvColumn(memberDTOS); 401 this.resetIptvColumn(this.findMemberByCode(memberCode));
393 402
394 // 置空主账号 403 // 置空主账号
395 this.resetMainAccount(memberCode); 404 this.resetMainAccount(memberCode, userTvDTO.getId());
396 } 405 }
397 406
398 @Override 407 @Override
...@@ -865,19 +874,49 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -865,19 +874,49 @@ public class UserOperationServiceImpl implements UserOperationService {
865 } 874 }
866 875
867 /** 876 /**
868 * 置空主账号 877 * 重置主账号
869 * @param memberCode 878 * @param memberCode
870 */ 879 */
871 private void resetMainAccount(String memberCode) { 880 private void resetMainAccount(String memberCode, Long id) {
881
872 UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode); 882 UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode);
873 if (Objects.nonNull(userTvDTO)) { 883 if (Objects.nonNull(userTvDTO)) {
874 userTvDTO.setPriorityMemberCode(null);
875 884
885 List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id);
886 if (CollectionUtils.isNotEmpty(memberDTOList)) {
887
888 // 过滤解绑的会员
889 List<MemberDTO> memberDTOS = memberDTOList.stream().filter(memberDTO -> !memberDTO.getCode().equalsIgnoreCase(memberCode))
890 .collect(Collectors.toList());
891
892 if (CollectionUtils.isNotEmpty(memberDTOS)) {
893
894 // 按绑定时间倒排
895 memberDTOS.sort(new Comparator<MemberDTO>() {
896 @Override
897 public int compare(MemberDTO memberDTO, MemberDTO t1) {
898 return t1.getBindIptvTime().compareTo(memberDTO.getBindIptvTime());
899 }
900 });
901
902 // 绑定新的主账号
903 this.bondPriorityMember(userTvDTO, memberDTOS.get(0).getCode() , "manual");
904
905 }
906
907 } else {
908
909 // 没有绑定其他会员,直接解绑,不换绑
910 userTvDTO.setPriorityMemberCode(null);
876 UserTv userTv = new UserTv(); 911 UserTv userTv = new UserTv();
877 BeanUtils.copyProperties(userTvDTO,userTv); 912 BeanUtils.copyProperties(userTvDTO,userTv);
878 913
879 this.userTvService.unbindPriorityMemberCode(userTv); 914 this.userTvService.unbindPriorityMemberCode(userTv);
915
916 }
917
880 } 918 }
919
881 } 920 }
882 921
883 /** 922 /**
...@@ -885,8 +924,9 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -885,8 +924,9 @@ public class UserOperationServiceImpl implements UserOperationService {
885 * @param memberDTOS 924 * @param memberDTOS
886 */ 925 */
887 private void resetIptvColumn(MemberDTO memberDTOS) { 926 private void resetIptvColumn(MemberDTO memberDTOS) {
927
888 // 若无关系,不做处理 928 // 若无关系,不做处理
889 if (Objects.nonNull(memberDTOS)) 929 if (Objects.nonNull(memberDTOS) && Objects.isNull(memberDTOS.getUserIptvId()))
890 return; 930 return;
891 931
892 Member member = new Member(); 932 Member member = new Member();
...@@ -903,8 +943,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -903,8 +943,7 @@ public class UserOperationServiceImpl implements UserOperationService {
903 * @return 943 * @return
904 */ 944 */
905 private MemberDTO findMemberByCode(String memberCode) { 945 private MemberDTO findMemberByCode(String memberCode) {
906 MemberDTO memberDTO = memberService.findByCode(memberCode); 946 return memberService.findByCode(memberCode);
907 return memberDTO;
908 } 947 }
909 948
910 /** 949 /**
...@@ -1083,4 +1122,9 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1083,4 +1122,9 @@ public class UserOperationServiceImpl implements UserOperationService {
1083 } 1122 }
1084 return null; 1123 return null;
1085 } 1124 }
1125
1126 @Override
1127 public UserTvDTO findByPlatformAccount(String platformAccount) {
1128 return this.userTvService.findByPlatformAccount(platformAccount);
1129 }
1086 } 1130 }
......