1.修改绑定、解绑实现
Showing
2 changed files
with
51 additions
and
112 deletions
... | @@ -23,7 +23,6 @@ import lombok.extern.slf4j.Slf4j; | ... | @@ -23,7 +23,6 @@ import lombok.extern.slf4j.Slf4j; |
23 | import org.apache.commons.lang3.StringUtils; | 23 | import org.apache.commons.lang3.StringUtils; |
24 | import org.springframework.beans.BeanUtils; | 24 | import org.springframework.beans.BeanUtils; |
25 | import org.springframework.beans.factory.annotation.Autowired; | 25 | import org.springframework.beans.factory.annotation.Autowired; |
26 | import org.springframework.cache.annotation.CachePut; | ||
27 | import org.springframework.cache.annotation.Cacheable; | 26 | import org.springframework.cache.annotation.Cacheable; |
28 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
29 | import org.springframework.transaction.annotation.Propagation; | 28 | import org.springframework.transaction.annotation.Propagation; |
... | @@ -63,7 +62,6 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -63,7 +62,6 @@ public class MemberServiceImpl implements MemberService { |
63 | 62 | ||
64 | @Override | 63 | @Override |
65 | @Transactional(readOnly = true) | 64 | @Transactional(readOnly = true) |
66 | // @Cacheable(cacheNames = RedisKeyConstants.cacheMemberById, key = "#id") | ||
67 | public MemberDTO findById(Long id) { | 65 | public MemberDTO findById(Long id) { |
68 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); | 66 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); |
69 | return this.memberMapper.toDto(member); | 67 | return this.memberMapper.toDto(member); |
... | @@ -140,7 +138,6 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -140,7 +138,6 @@ public class MemberServiceImpl implements MemberService { |
140 | 138 | ||
141 | @Override | 139 | @Override |
142 | @Transactional(rollbackFor = Exception.class) | 140 | @Transactional(rollbackFor = Exception.class) |
143 | // @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") | ||
144 | public Integer doUpdateMemberCoupon(Member resource) { | 141 | public Integer doUpdateMemberCoupon(Member resource) { |
145 | return this.memberRepository.doUpdateMemberCoupon(resource); | 142 | return this.memberRepository.doUpdateMemberCoupon(resource); |
146 | } | 143 | } |
... | @@ -155,7 +152,6 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -155,7 +152,6 @@ public class MemberServiceImpl implements MemberService { |
155 | 152 | ||
156 | @Override | 153 | @Override |
157 | @Transactional(rollbackFor = Exception.class) | 154 | @Transactional(rollbackFor = Exception.class) |
158 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") | ||
159 | public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) { | 155 | public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) { |
160 | log.info("修改会员vip和vip过期时间 ==>> {}", resource); | 156 | log.info("修改会员vip和vip过期时间 ==>> {}", resource); |
161 | try { | 157 | try { |
... | @@ -178,30 +174,20 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -178,30 +174,20 @@ public class MemberServiceImpl implements MemberService { |
178 | 174 | ||
179 | @Override | 175 | @Override |
180 | @Transactional(rollbackFor = Exception.class) | 176 | @Transactional(rollbackFor = Exception.class) |
181 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") | ||
182 | public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) { | 177 | public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) { |
183 | log.info("修改会员绑定大屏信息 ==>> {}", resource); | ||
184 | try { | ||
185 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
186 | |||
187 | Integer count = this.memberRepository.updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(resource); | 178 | Integer count = this.memberRepository.updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(resource); |
188 | if (Objects.nonNull(count) && count > 0) { | 179 | log.info("修改会员绑定关系的结果, count ==>> {}", count); |
180 | if (count > 0) { | ||
189 | Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new); | 181 | Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new); |
182 | log.info("修改会员绑定关系成功,==>> {}", member); | ||
190 | return this.memberMapper.toDto(member); | 183 | return this.memberMapper.toDto(member); |
191 | } | 184 | } |
192 | 185 | ||
193 | } catch (Exception e) { | ||
194 | log.info("修改会员绑定大屏信息,"+e.getMessage()); | ||
195 | } finally { | ||
196 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
197 | } | ||
198 | |||
199 | return this.memberMapper.toDto(resource); | 186 | return this.memberMapper.toDto(resource); |
200 | } | 187 | } |
201 | 188 | ||
202 | @Override | 189 | @Override |
203 | @Transactional(rollbackFor = Exception.class) | 190 | @Transactional(rollbackFor = Exception.class) |
204 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") | ||
205 | public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) { | 191 | public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) { |
206 | log.info("修改会员头像、昵称、性别 ==>> {}", resource); | 192 | log.info("修改会员头像、昵称、性别 ==>> {}", resource); |
207 | try { | 193 | try { |
... | @@ -248,7 +234,6 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -248,7 +234,6 @@ public class MemberServiceImpl implements MemberService { |
248 | 234 | ||
249 | @Override | 235 | @Override |
250 | @Transactional(rollbackFor = Exception.class) | 236 | @Transactional(rollbackFor = Exception.class) |
251 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resources.code") | ||
252 | public MemberDTO update(Member resources) { | 237 | public MemberDTO update(Member resources) { |
253 | log.info("修改会员信息 ==>> {}", resources); | 238 | log.info("修改会员信息 ==>> {}", resources); |
254 | try { | 239 | try { | ... | ... |
... | @@ -720,16 +720,39 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -720,16 +720,39 @@ public class UserOperationServiceImpl implements UserOperationService { |
720 | log.info("会员信息置空大屏的结果,memberDTO ==>> {}", memberDTO); | 720 | log.info("会员信息置空大屏的结果,memberDTO ==>> {}", memberDTO); |
721 | memberDTO.setPlatformAccount(platformAccount); | 721 | memberDTO.setPlatformAccount(platformAccount); |
722 | 722 | ||
723 | // 置空主账号 | ||
724 | userTvDTO = this.resetMainAccount(memberDTO, userTvDTO, bindMemberCode); | ||
725 | userTvDTO.setMemberCode(memberCode); | ||
726 | 723 | ||
727 | log.info("大屏账号置空主会员的结果,userTvDTO ==>> {}", userTvDTO); | 724 | log.info("大屏解绑,重置大屏账号的主会员,查看当前会员是否是主账号 ==>>memberCode ==>> {} || 大屏账号 ==>> userTvDTO ==>> {}", userTvDTO); |
728 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, userTvDTO)); | 725 | if (StringUtils.isBlank(bindMemberCode)) { |
729 | 726 | ||
727 | UserTv userTv = new UserTv(); | ||
728 | userTv.setId(userTvDTO.getId()); | ||
729 | userTv.setPriorityMemberCode(null); | ||
730 | this.userTvService.doUpdatePriorityMemberCode(userTv); | ||
731 | |||
732 | UserTvDTO _userTvDTO = new UserTvDTO(); | ||
733 | _userTvDTO.setPlatformAccount(platformAccount); | ||
734 | _userTvDTO.setPriorityMemberCode(null); | ||
735 | log.info("大屏账号置空主会员的结果,userTvDTO ==>> {}", _userTvDTO); | ||
736 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO)); | ||
730 | 737 | ||
731 | this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, ""); | 738 | this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, ""); |
732 | 739 | ||
740 | } else { | ||
741 | |||
742 | UserTv userTv = new UserTv(); | ||
743 | userTv.setId(userTvDTO.getId()); | ||
744 | userTv.setPriorityMemberCode(bindMemberCode); | ||
745 | // 绑定新的主账号 | ||
746 | this.userTvService.doUpdatePriorityMemberCode(userTv); | ||
747 | |||
748 | UserTvDTO _userTvDTO = new UserTvDTO(); | ||
749 | _userTvDTO.setPlatformAccount(platformAccount); | ||
750 | _userTvDTO.setPriorityMemberCode(bindMemberCode); | ||
751 | log.info("大屏账号置空主会员的结果,userTvDTO ==>> {}", userTvDTO); | ||
752 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO)); | ||
753 | this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, bindMemberCode); | ||
754 | } | ||
755 | |||
733 | return true; | 756 | return true; |
734 | } | 757 | } |
735 | 758 | ||
... | @@ -1111,79 +1134,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1111,79 +1134,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
1111 | return this.memberService.findById(memberId); | 1134 | return this.memberService.findById(memberId); |
1112 | } | 1135 | } |
1113 | 1136 | ||
1114 | /** | ||
1115 | * 重置主账号 | ||
1116 | * @param memberDTO 会员code | ||
1117 | * @param userTvDTO 大屏id | ||
1118 | * @param bindMemberCode true:自动设置主账号 false: 手动设置 | ||
1119 | */ | ||
1120 | private UserTvDTO resetMainAccount(MemberDTO memberDTO, UserTvDTO userTvDTO, String bindMemberCode) { | ||
1121 | |||
1122 | log.info("大屏解绑,重置大屏账号的主会员,查看当前会员是否是主账号 ==>>memberCode ==>> {} || 大屏账号 ==>> userTvDTO ==>> {}", userTvDTO); | ||
1123 | if (StringUtils.isBlank(bindMemberCode)) { | ||
1124 | // 有其他绑定的小程序会员,排除自己 | ||
1125 | /*List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id); | ||
1126 | log.info("后台指定一个默认主会员,通过大屏id查询到的绑定的小屏会员memberDTOList ==>> {}", memberDTOList); | ||
1127 | if (!CollectionUtils.isEmpty(memberDTOList)) { | ||
1128 | |||
1129 | Long memberId = userTvDTO.getMemberId(); | ||
1130 | MemberDTO memberDTO1 = this.memberService.findById(memberId); | ||
1131 | |||
1132 | List<MemberDTO> collect = | ||
1133 | memberDTOList.stream().filter(memberDTO -> | ||
1134 | !memberDTO.getCode().equalsIgnoreCase(memberCode) && | ||
1135 | !memberDTO.getCode().equalsIgnoreCase(memberDTO1.getCode())).collect(Collectors.toList()); | ||
1136 | log.info("过滤掉当前需要解绑的会员以及绑定的大屏会员之后剩余的会员列表 ==>> {}", memberDTOList); | ||
1137 | |||
1138 | if (!CollectionUtils.isEmpty(collect)) { | ||
1139 | |||
1140 | // 按绑定时间倒排 | ||
1141 | collect.sort(new Comparator<MemberDTO>() { | ||
1142 | @Override | ||
1143 | public int compare(MemberDTO memberDTO, MemberDTO t1) { | ||
1144 | return t1.getBindIptvTime().compareTo(memberDTO.getBindIptvTime()); | ||
1145 | } | ||
1146 | }); | ||
1147 | |||
1148 | // 绑定新的主账号 | ||
1149 | UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, memberDTOList.get(0).getCode(), "manual"); | ||
1150 | log.info("绑定新的主账号 ==>> _userTvDTO ==>> {}", _userTvDTO); | ||
1151 | |||
1152 | return _userTvDTO; | ||
1153 | |||
1154 | } | ||
1155 | |||
1156 | } else { | ||
1157 | |||
1158 | log.info("无其他绑定的小屏会员信息 "); | ||
1159 | // 绑定新的主账号 | ||
1160 | UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, null, "manual"); | ||
1161 | log.info("绑定新的主账号 ==>> _userTvDTO ==>> {}", _userTvDTO); | ||
1162 | return _userTvDTO; | ||
1163 | |||
1164 | }*/ | ||
1165 | |||
1166 | // 绑定新的主账号 | ||
1167 | // UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, null, "manual"); | ||
1168 | UserTv userTv = new UserTv(); | ||
1169 | userTv.setId(userTvDTO.getId()); | ||
1170 | userTv.setPlatform(userTvDTO.getPlatformAccount()); | ||
1171 | userTv.setPriorityMemberCode(null); | ||
1172 | UserTvDTO _userTvDTO = this.userTvService.doUpdatePriorityMemberCode(userTv); | ||
1173 | log.info("绑定新的主账号 ==>> _userTvDTO ==>> {}", _userTvDTO); | ||
1174 | return _userTvDTO; | ||
1175 | |||
1176 | } else { | ||
1177 | |||
1178 | UserTv userTv = new UserTv(); | ||
1179 | userTv.setId(userTvDTO.getId()); | ||
1180 | userTv.setPlatform(userTvDTO.getPlatformAccount()); | ||
1181 | userTv.setPriorityMemberCode(bindMemberCode); | ||
1182 | // 绑定新的主账号 | ||
1183 | return this.userTvService.doUpdatePriorityMemberCode(userTv); | ||
1184 | |||
1185 | } | ||
1186 | } | ||
1187 | 1137 | ||
1188 | /** | 1138 | /** |
1189 | * | 1139 | * |
... | @@ -1339,11 +1289,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1339,11 +1289,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
1339 | return false; | 1289 | return false; |
1340 | } | 1290 | } |
1341 | 1291 | ||
1342 | return this.tvUnbindAndSetNewPriorityMemberCode(memberDTO, userTvDTO); | ||
1343 | } | ||
1344 | |||
1345 | private boolean tvUnbindAndSetNewPriorityMemberCode(MemberDTO memberDTO, UserTvDTO userTvDTO) { | ||
1346 | |||
1347 | // 解绑(置空大屏信息) | 1292 | // 解绑(置空大屏信息) |
1348 | Member member = new Member(); | 1293 | Member member = new Member(); |
1349 | member.setId(memberDTO.getId()); | 1294 | member.setId(memberDTO.getId()); |
... | @@ -1352,9 +1297,8 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1352,9 +1297,8 @@ public class UserOperationServiceImpl implements UserOperationService { |
1352 | member.setUserIptvId(null); | 1297 | member.setUserIptvId(null); |
1353 | member.setBindIptvPlatformType(null); | 1298 | member.setBindIptvPlatformType(null); |
1354 | log.info("置空会员绑定的大屏信息, member ==>> {}", member); | 1299 | log.info("置空会员绑定的大屏信息, member ==>> {}", member); |
1355 | memberDTO = this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member); | 1300 | this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member); |
1356 | log.info("会员信息置空大屏的结果,memberDTO ==>> {}", memberDTO); | 1301 | log.info("会员信息置空大屏的结果,memberDTO ==>> {}", memberDTO); |
1357 | memberDTO.setPlatformAccount(userTvDTO.getPlatformAccount()); | ||
1358 | 1302 | ||
1359 | // 有其他绑定的小程序会员,排除自己 | 1303 | // 有其他绑定的小程序会员,排除自己 |
1360 | List<MemberDTO> memberDTOS = this.memberService.findByUserIptvId(userTvDTO.getId()); | 1304 | List<MemberDTO> memberDTOS = this.memberService.findByUserIptvId(userTvDTO.getId()); |
... | @@ -1380,8 +1324,15 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1380,8 +1324,15 @@ public class UserOperationServiceImpl implements UserOperationService { |
1380 | userTv.setId(userTvDTO.getId()); | 1324 | userTv.setId(userTvDTO.getId()); |
1381 | userTv.setPlatform(userTvDTO.getPlatformAccount()); | 1325 | userTv.setPlatform(userTvDTO.getPlatformAccount()); |
1382 | userTv.setPriorityMemberCode(collect.get(0).getCode()); | 1326 | userTv.setPriorityMemberCode(collect.get(0).getCode()); |
1383 | userTvDTO = this.userTvService.doUpdatePriorityMemberCode(userTv); | 1327 | this.userTvService.doUpdatePriorityMemberCode(userTv); |
1384 | log.info("大屏账号绑定新的主账号 ==>> userTvDTO ==>> {}", userTvDTO); | 1328 | |
1329 | UserTvDTO _userTvDTO = new UserTvDTO(); | ||
1330 | _userTvDTO.setPlatformAccount(userTvDTO.getPlatformAccount()); | ||
1331 | _userTvDTO.setPriorityMemberCode(userTv.getPriorityMemberCode()); | ||
1332 | log.info("同步绑定信息至大屏侧, 参数 ==>> {}", new MemberAndUserTvDTO(memberDTO, _userTvDTO)); | ||
1333 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO)); | ||
1334 | |||
1335 | this.updateUserTvSimplePriorityMemberCodeRedis(userTvDTO.getPlatformAccount(), userTv.getPriorityMemberCode()); | ||
1385 | } | 1336 | } |
1386 | 1337 | ||
1387 | } else { | 1338 | } else { |
... | @@ -1389,19 +1340,22 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1389,19 +1340,22 @@ public class UserOperationServiceImpl implements UserOperationService { |
1389 | // 绑定新的主账号 | 1340 | // 绑定新的主账号 |
1390 | UserTv userTv = new UserTv(); | 1341 | UserTv userTv = new UserTv(); |
1391 | userTv.setId(userTvDTO.getId()); | 1342 | userTv.setId(userTvDTO.getId()); |
1392 | userTv.setPlatform(userTvDTO.getPlatformAccount()); | ||
1393 | userTv.setPriorityMemberCode(null); | 1343 | userTv.setPriorityMemberCode(null); |
1394 | userTvDTO = this.userTvService.doUpdatePriorityMemberCode(userTv); | 1344 | this.userTvService.doUpdatePriorityMemberCode(userTv); |
1395 | log.info("大屏账号置空主会员的结果,userTvDTO ==>> {}", userTvDTO); | ||
1396 | } | ||
1397 | |||
1398 | log.info("同步绑定信息至大屏侧, 参数 ==>> {}", new MemberAndUserTvDTO(memberDTO, userTvDTO)); | ||
1399 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, userTvDTO)); | ||
1400 | 1345 | ||
1346 | UserTvDTO _userTvDTO = new UserTvDTO(); | ||
1347 | _userTvDTO.setPlatformAccount(userTvDTO.getPlatformAccount()); | ||
1348 | _userTvDTO.setPriorityMemberCode(null); | ||
1349 | log.info("同步绑定信息至大屏侧, 参数 ==>> {}", new MemberAndUserTvDTO(memberDTO, _userTvDTO)); | ||
1350 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO)); | ||
1401 | this.updateUserTvSimplePriorityMemberCodeRedis(userTvDTO.getPlatformAccount(), ""); | 1351 | this.updateUserTvSimplePriorityMemberCodeRedis(userTvDTO.getPlatformAccount(), ""); |
1352 | } | ||
1353 | |||
1402 | return true; | 1354 | return true; |
1403 | } | 1355 | } |
1404 | 1356 | ||
1357 | |||
1358 | |||
1405 | @Override | 1359 | @Override |
1406 | public UserWeixinDTO findById(Long userId) { | 1360 | public UserWeixinDTO findById(Long userId) { |
1407 | return this.userWeixinService.findById(userId); | 1361 | return this.userWeixinService.findById(userId); | ... | ... |
-
Please register or sign in to post a comment