1.修改部分保存逻辑
Showing
3 changed files
with
86 additions
and
15 deletions
| ... | @@ -8,6 +8,7 @@ import com.topdraw.annotation.Log; | ... | @@ -8,6 +8,7 @@ import com.topdraw.annotation.Log; |
| 8 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | 8 | import com.topdraw.business.module.member.profile.domain.MemberProfile; |
| 9 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 9 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 10 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 10 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 11 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | ||
| 11 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 12 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 12 | import com.topdraw.business.process.domian.TempIptvUser; | 13 | import com.topdraw.business.process.domian.TempIptvUser; |
| 13 | import com.topdraw.business.process.domian.UnbindGroup; | 14 | import com.topdraw.business.process.domian.UnbindGroup; |
| ... | @@ -49,6 +50,10 @@ public class UserOperationController { | ... | @@ -49,6 +50,10 @@ public class UserOperationController { |
| 49 | @Autowired | 50 | @Autowired |
| 50 | private UserOperationService userTvOperationService; | 51 | private UserOperationService userTvOperationService; |
| 51 | @Autowired | 52 | @Autowired |
| 53 | private UserWeixinService userWeixinService; | ||
| 54 | @Autowired | ||
| 55 | private WeiXinRequestUtil weixinRequestUtil; | ||
| 56 | @Autowired | ||
| 52 | private RedisUtils redisUtils; | 57 | private RedisUtils redisUtils; |
| 53 | 58 | ||
| 54 | @Log("新增大屏账户同时创建会员信息") | 59 | @Log("新增大屏账户同时创建会员信息") |
| ... | @@ -175,6 +180,7 @@ public class UserOperationController { | ... | @@ -175,6 +180,7 @@ public class UserOperationController { |
| 175 | @ApiOperation("微信公众号关注") | 180 | @ApiOperation("微信公众号关注") |
| 176 | @AnonymousAccess | 181 | @AnonymousAccess |
| 177 | public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException { | 182 | public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException { |
| 183 | |||
| 178 | String content = data.getContent(); | 184 | String content = data.getContent(); |
| 179 | SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(content, SubscribeBean.class); | 185 | SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(content, SubscribeBean.class); |
| 180 | 186 | ||
| ... | @@ -185,6 +191,11 @@ public class UserOperationController { | ... | @@ -185,6 +191,11 @@ public class UserOperationController { |
| 185 | } | 191 | } |
| 186 | 192 | ||
| 187 | 193 | ||
| 194 | /** | ||
| 195 | * | ||
| 196 | * @param subscribeBean | ||
| 197 | * @throws IOException | ||
| 198 | */ | ||
| 188 | private void parseSubscribe(SubscribeBean subscribeBean) throws IOException { | 199 | private void parseSubscribe(SubscribeBean subscribeBean) throws IOException { |
| 189 | if (Objects.nonNull(subscribeBean)) { | 200 | if (Objects.nonNull(subscribeBean)) { |
| 190 | 201 | ||
| ... | @@ -211,15 +222,14 @@ public class UserOperationController { | ... | @@ -211,15 +222,14 @@ public class UserOperationController { |
| 211 | if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION)) | 222 | if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION)) |
| 212 | throw new BadRequestException("非订阅号"); | 223 | throw new BadRequestException("非订阅号"); |
| 213 | 224 | ||
| 214 | // 用户类型 | 225 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId); |
| 215 | // JSONObject userInfo = weixinRequestUtil.getUserInfo(wxInfoMap, openId); | 226 | if (Objects.nonNull(userWeixinDTO.getId())) { |
| 216 | JSONObject userInfo = new JSONObject(); | 227 | unionId = userWeixinDTO.getUnionid(); |
| 217 | userInfo.put("unionid","oqDha5idQxR0WGPW2qHi-meHRtyg"); | 228 | } else { |
| 218 | log.info("userInfo is : {}", userInfo.toJSONString()); | 229 | JSONObject userInfo = this.weixinRequestUtil.getUserInfo(wxInfoMap, openId); |
| 219 | unionId = userInfo.get("unionid").toString(); | 230 | unionId = userInfo.getString("unionid"); |
| 231 | } | ||
| 220 | 232 | ||
| 221 | if (StringUtils.isBlank(unionId)) | ||
| 222 | throw new BadRequestException("unionid 不存在!"); | ||
| 223 | } | 233 | } |
| 224 | 234 | ||
| 225 | // unionId不得为空 | 235 | // unionId不得为空 | ... | ... |
| 1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | 4 | import com.topdraw.business.module.member.profile.domain.MemberProfile; |
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 5 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 5 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 6 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| ... | @@ -42,6 +43,9 @@ public interface UserOperationService { | ... | @@ -42,6 +43,9 @@ public interface UserOperationService { |
| 42 | 43 | ||
| 43 | /** | 44 | /** |
| 44 | * 微信公众号关注 | 45 | * 微信公众号关注 |
| 46 | * 1.团粉,会员vip=0,则修改为vip=1 | ||
| 47 | * 2.判断是否通过扫描大屏的二维码进行关注的,如果是需要绑定大屏账户,将对应会员中iptvUserId绑定大屏对应的id | ||
| 48 | * 3.修改微信账户的status字段为1(已关注) | ||
| 45 | * @param resources | 49 | * @param resources |
| 46 | * @return | 50 | * @return |
| 47 | */ | 51 | */ |
| ... | @@ -123,4 +127,7 @@ public interface UserOperationService { | ... | @@ -123,4 +127,7 @@ public interface UserOperationService { |
| 123 | * @return | 127 | * @return |
| 124 | */ | 128 | */ |
| 125 | Map<String, Object> checkBind(BindBean bindBean); | 129 | Map<String, Object> checkBind(BindBean bindBean); |
| 130 | |||
| 131 | |||
| 132 | JSONObject getUnionIdByAppIdAndOpenId(String appId,String secret,String code); | ||
| 126 | } | 133 | } | ... | ... |
| ... | @@ -196,7 +196,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -196,7 +196,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 196 | throw new BadRequestException("大屏信息不存在!"); | 196 | throw new BadRequestException("大屏信息不存在!"); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | // 大屏账户绑定小屏会员的code | 199 | // 大屏是否绑定主账号 |
| 200 | this.bondPriorityMember(userTvDTO,memberDTO_0,"auto"); | 200 | this.bondPriorityMember(userTvDTO,memberDTO_0,"auto"); |
| 201 | 201 | ||
| 202 | // 小屏会员绑定大屏账户id | 202 | // 小屏会员绑定大屏账户id |
| ... | @@ -980,6 +980,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -980,6 +980,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 980 | 980 | ||
| 981 | // 保存、修改会员加密信息 | 981 | // 保存、修改会员加密信息 |
| 982 | return this.doSaveOrUpdateMemberProfile(weiXinBeanDefinition,resources); | 982 | return this.doSaveOrUpdateMemberProfile(weiXinBeanDefinition,resources); |
| 983 | |||
| 983 | } | 984 | } |
| 984 | 985 | ||
| 985 | @Override | 986 | @Override |
| ... | @@ -1033,6 +1034,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1033,6 +1034,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1033 | @Override | 1034 | @Override |
| 1034 | public boolean deleteAllCollection(String content) { | 1035 | public boolean deleteAllCollection(String content) { |
| 1035 | try { | 1036 | try { |
| 1037 | |||
| 1036 | log.info("receive UserCollection delete all message, content {}", content); | 1038 | log.info("receive UserCollection delete all message, content {}", content); |
| 1037 | JSONObject jsonObject = JSONObject.parseObject(content); | 1039 | JSONObject jsonObject = JSONObject.parseObject(content); |
| 1038 | String platformAccount = jsonObject.getString("platformAccount"); | 1040 | String platformAccount = jsonObject.getString("platformAccount"); |
| ... | @@ -1041,12 +1043,15 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1041,12 +1043,15 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1041 | 1043 | ||
| 1042 | Long id = userTvDTO.getId(); | 1044 | Long id = userTvDTO.getId(); |
| 1043 | List<UserCollection> userCollections = this.userCollectionService.findByUserIdAndType(id, type); | 1045 | List<UserCollection> userCollections = this.userCollectionService.findByUserIdAndType(id, type); |
| 1046 | |||
| 1044 | if (userCollections == null || userCollections.isEmpty()) { | 1047 | if (userCollections == null || userCollections.isEmpty()) { |
| 1045 | return false; | 1048 | return false; |
| 1046 | } | 1049 | } |
| 1050 | |||
| 1047 | for (UserCollection userCollection : userCollections) { | 1051 | for (UserCollection userCollection : userCollections) { |
| 1048 | this.userCollectionDetailService.deleteAllByUserCollectionId(userCollection.getId()); | 1052 | this.userCollectionDetailService.deleteAllByUserCollectionId(userCollection.getId()); |
| 1049 | } | 1053 | } |
| 1054 | |||
| 1050 | } catch (Exception e) { | 1055 | } catch (Exception e) { |
| 1051 | log.error("CollectionDeleteConsumer || UserCollection delete all error || {}", e.toString(), e); | 1056 | log.error("CollectionDeleteConsumer || UserCollection delete all error || {}", e.toString(), e); |
| 1052 | } | 1057 | } |
| ... | @@ -1122,46 +1127,63 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1122,46 +1127,63 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1122 | JSONObject jsonObject = JSONObject.parseObject(content); | 1127 | JSONObject jsonObject = JSONObject.parseObject(content); |
| 1123 | String platformAccount = jsonObject.getString("platformAccount"); | 1128 | String platformAccount = jsonObject.getString("platformAccount"); |
| 1124 | String data = jsonObject.getString("data"); | 1129 | String data = jsonObject.getString("data"); |
| 1125 | if (StringUtils.isBlank(data) || !data.startsWith("[")) { | 1130 | |
| 1131 | if (StringUtils.isBlank(data) || !data.startsWith("[")) | ||
| 1126 | return false; | 1132 | return false; |
| 1127 | } | 1133 | |
| 1134 | |||
| 1128 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 1135 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
| 1129 | 1136 | ||
| 1130 | Long tvUserId = userTvDTO.getId(); | 1137 | Long tvUserId = userTvDTO.getId(); |
| 1131 | List<UserCollectionMq> userCollectionMqList = JSONObject.parseArray(data, UserCollectionMq.class); | 1138 | List<UserCollectionMq> userCollectionMqList = JSONObject.parseArray(data, UserCollectionMq.class); |
| 1132 | if (userCollectionMqList == null || userCollectionMqList.isEmpty()) { | 1139 | |
| 1140 | if (userCollectionMqList == null || userCollectionMqList.isEmpty()) | ||
| 1133 | return false; | 1141 | return false; |
| 1134 | } | 1142 | |
| 1143 | |||
| 1135 | Map<Long, List<UserCollectionMq>> collect = userCollectionMqList.stream().collect(Collectors.groupingBy(UserCollectionMq::getUserCollectionId)); | 1144 | Map<Long, List<UserCollectionMq>> collect = userCollectionMqList.stream().collect(Collectors.groupingBy(UserCollectionMq::getUserCollectionId)); |
| 1145 | |||
| 1136 | for (Map.Entry<Long, List<UserCollectionMq>> entry : collect.entrySet()) { | 1146 | for (Map.Entry<Long, List<UserCollectionMq>> entry : collect.entrySet()) { |
| 1147 | |||
| 1137 | List<UserCollectionMq> value = entry.getValue(); | 1148 | List<UserCollectionMq> value = entry.getValue(); |
| 1138 | UserCollectionMq userCollectionMq = value.get(0); | 1149 | UserCollectionMq userCollectionMq = value.get(0); |
| 1139 | if (StringUtils.isBlank(userCollectionMq.getName())) { | 1150 | if (StringUtils.isBlank(userCollectionMq.getName())) |
| 1140 | userCollectionMq.setName("DEFAULT"); | 1151 | userCollectionMq.setName("DEFAULT"); |
| 1141 | } | 1152 | |
| 1153 | |||
| 1142 | UserCollection userCollection = this.userCollectionService | 1154 | UserCollection userCollection = this.userCollectionService |
| 1143 | .findFirstByUserIdAndTypeAndName(tvUserId, userCollectionMq.getType(), userCollectionMq.getName()).orElseGet(UserCollection::new); | 1155 | .findFirstByUserIdAndTypeAndName(tvUserId, userCollectionMq.getType(), userCollectionMq.getName()).orElseGet(UserCollection::new); |
| 1156 | |||
| 1144 | userCollection.setAppId(userCollectionMq.getAppId()) | 1157 | userCollection.setAppId(userCollectionMq.getAppId()) |
| 1145 | .setUserId(tvUserId) | 1158 | .setUserId(tvUserId) |
| 1146 | .setName(userCollectionMq.getName()) | 1159 | .setName(userCollectionMq.getName()) |
| 1147 | .setType(userCollectionMq.getType()) | 1160 | .setType(userCollectionMq.getType()) |
| 1148 | .setCount(userCollection.getCount() == null ? value.size() : userCollection.getCount() + value.size()); | 1161 | .setCount(userCollection.getCount() == null ? value.size() : userCollection.getCount() + value.size()); |
| 1149 | UserCollection userCollectionSave = this.userCollectionService.save(userCollection); | 1162 | UserCollection userCollectionSave = this.userCollectionService.save(userCollection); |
| 1163 | |||
| 1150 | for (UserCollectionMq collectionMq : value) { | 1164 | for (UserCollectionMq collectionMq : value) { |
| 1165 | |||
| 1151 | UserCollectionDetail userCollectionDetail = collectionMq2DetailMapper.toEntity(collectionMq); | 1166 | UserCollectionDetail userCollectionDetail = collectionMq2DetailMapper.toEntity(collectionMq); |
| 1152 | Optional<UserCollectionDetail> userCollectionDetailOptional = userCollectionDetailRepository | 1167 | Optional<UserCollectionDetail> userCollectionDetailOptional = userCollectionDetailRepository |
| 1153 | .findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(), userCollectionDetail.getDetailType(), userCollectionSave.getId()); | 1168 | .findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(), userCollectionDetail.getDetailType(), userCollectionSave.getId()); |
| 1154 | //观影记录同一天只存一条记录 | 1169 | //观影记录同一天只存一条记录 |
| 1155 | if (userCollectionDetailOptional.isPresent() && | 1170 | if (userCollectionDetailOptional.isPresent() && |
| 1156 | DateUtil.isSameDay(new Date(userCollectionDetailOptional.get().getCreateTime().getTime()), new Date())) { | 1171 | DateUtil.isSameDay(new Date(userCollectionDetailOptional.get().getCreateTime().getTime()), new Date())) { |
| 1172 | |||
| 1157 | userCollectionDetail.setId(userCollectionDetailOptional.get().getId()); | 1173 | userCollectionDetail.setId(userCollectionDetailOptional.get().getId()); |
| 1174 | |||
| 1158 | } else { | 1175 | } else { |
| 1176 | |||
| 1159 | userCollectionDetail.setId(null) | 1177 | userCollectionDetail.setId(null) |
| 1160 | .setUserCollectionId(userCollectionSave.getId()); | 1178 | .setUserCollectionId(userCollectionSave.getId()); |
| 1179 | |||
| 1161 | } | 1180 | } |
| 1181 | |||
| 1162 | userCollectionDetailRepository.save(userCollectionDetail); | 1182 | userCollectionDetailRepository.save(userCollectionDetail); |
| 1183 | |||
| 1163 | } | 1184 | } |
| 1164 | } | 1185 | } |
| 1186 | |||
| 1165 | } catch (Exception e) { | 1187 | } catch (Exception e) { |
| 1166 | log.error("CollectionAddConsumer || UserCollection add error || {}", e.toString(), e); | 1188 | log.error("CollectionAddConsumer || UserCollection add error || {}", e.toString(), e); |
| 1167 | } | 1189 | } |
| ... | @@ -1170,23 +1192,34 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1170,23 +1192,34 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1170 | 1192 | ||
| 1171 | @Override | 1193 | @Override |
| 1172 | public List<MemberDTO> findBindByPlatformAccount(String platformAccount) { | 1194 | public List<MemberDTO> findBindByPlatformAccount(String platformAccount) { |
| 1195 | |||
| 1173 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 1196 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
| 1197 | |||
| 1174 | if (Objects.nonNull(userTvDTO.getId())) { | 1198 | if (Objects.nonNull(userTvDTO.getId())) { |
| 1199 | |||
| 1175 | Long id = userTvDTO.getId(); | 1200 | Long id = userTvDTO.getId(); |
| 1176 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | 1201 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
| 1177 | List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id); | 1202 | List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id); |
| 1203 | |||
| 1178 | if (!CollectionUtils.isEmpty(memberDTOList)) { | 1204 | if (!CollectionUtils.isEmpty(memberDTOList)) { |
| 1205 | |||
| 1179 | for (MemberDTO memberDTO : memberDTOList) { | 1206 | for (MemberDTO memberDTO : memberDTOList) { |
| 1207 | |||
| 1180 | String code = memberDTO.getCode(); | 1208 | String code = memberDTO.getCode(); |
| 1181 | if (code.equalsIgnoreCase(priorityMemberCode)) { | 1209 | if (code.equalsIgnoreCase(priorityMemberCode)) { |
| 1182 | memberDTO.setIptvMajor(IPTV_MAJOR[1]); | 1210 | memberDTO.setIptvMajor(IPTV_MAJOR[1]); |
| 1183 | } else { | 1211 | } else { |
| 1184 | memberDTO.setIptvMajor(IPTV_MAJOR[0]); | 1212 | memberDTO.setIptvMajor(IPTV_MAJOR[0]); |
| 1185 | } | 1213 | } |
| 1214 | |||
| 1186 | } | 1215 | } |
| 1216 | |||
| 1187 | } | 1217 | } |
| 1218 | |||
| 1188 | return memberDTOList; | 1219 | return memberDTOList; |
| 1220 | |||
| 1189 | } | 1221 | } |
| 1222 | |||
| 1190 | return null; | 1223 | return null; |
| 1191 | } | 1224 | } |
| 1192 | 1225 | ||
| ... | @@ -1306,6 +1339,27 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1306,6 +1339,27 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1306 | return map; | 1339 | return map; |
| 1307 | } | 1340 | } |
| 1308 | 1341 | ||
| 1342 | @Override | ||
| 1343 | public JSONObject getUnionIdByAppIdAndOpenId(String appId,String secret,String code) { | ||
| 1344 | // 链接微信服务器 | ||
| 1345 | String url = WeChatConstants.CODE2SESSION.replace("APPID", appId) | ||
| 1346 | .replace("SECRET", secret).replace("JSCODE", code); | ||
| 1347 | |||
| 1348 | String entityBody = HttpUtil.get(url); | ||
| 1349 | log.info("entityBody [{}]",entityBody); | ||
| 1350 | |||
| 1351 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
| 1352 | |||
| 1353 | String errCode = jsonObject.getString("errcode"); | ||
| 1354 | |||
| 1355 | if (StringUtils.isNotEmpty(errCode)) { | ||
| 1356 | String nameStr = jsonObject.getString("errmsg"); | ||
| 1357 | throw new BadRequestException(nameStr); | ||
| 1358 | } | ||
| 1359 | |||
| 1360 | return jsonObject; | ||
| 1361 | } | ||
| 1362 | |||
| 1309 | /** | 1363 | /** |
| 1310 | * 通过id检索大屏信息 | 1364 | * 通过id检索大屏信息 |
| 1311 | * @param userIptvId | 1365 | * @param userIptvId | ... | ... |
-
Please register or sign in to post a comment