1.添加checkBind接口
Showing
4 changed files
with
133 additions
and
50 deletions
| 1 | package com.topdraw.business.process.rest; | 1 | package com.topdraw.business.process.rest; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 4 | import cn.hutool.core.util.StrUtil; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.topdraw.annotation.AnonymousAccess; | 6 | import com.topdraw.annotation.AnonymousAccess; |
| 6 | import com.topdraw.annotation.Log; | 7 | import com.topdraw.annotation.Log; |
| ... | @@ -10,10 +11,12 @@ import com.topdraw.business.module.user.iptv.domain.UserTv; | ... | @@ -10,10 +11,12 @@ import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 10 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 11 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 11 | import com.topdraw.business.process.domian.TempIptvUser; | 12 | import com.topdraw.business.process.domian.TempIptvUser; |
| 12 | import com.topdraw.business.process.domian.UnbindGroup; | 13 | import com.topdraw.business.process.domian.UnbindGroup; |
| 14 | import com.topdraw.business.process.domian.weixin.BindBean; | ||
| 13 | import com.topdraw.business.process.domian.weixin.SubscribeBean; | 15 | import com.topdraw.business.process.domian.weixin.SubscribeBean; |
| 14 | import com.topdraw.business.process.domian.weixin.SubscribeBeanEvent; | 16 | import com.topdraw.business.process.domian.weixin.SubscribeBeanEvent; |
| 15 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | 17 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; |
| 16 | import com.topdraw.business.process.service.UserOperationService; | 18 | import com.topdraw.business.process.service.UserOperationService; |
| 19 | import com.topdraw.common.IResultInfo; | ||
| 17 | import com.topdraw.common.ResultInfo; | 20 | import com.topdraw.common.ResultInfo; |
| 18 | import com.topdraw.config.RedisKeyUtil; | 21 | import com.topdraw.config.RedisKeyUtil; |
| 19 | import com.topdraw.exception.BadRequestException; | 22 | import com.topdraw.exception.BadRequestException; |
| ... | @@ -28,6 +31,7 @@ import io.swagger.annotations.ApiOperation; | ... | @@ -28,6 +31,7 @@ import io.swagger.annotations.ApiOperation; |
| 28 | import lombok.extern.slf4j.Slf4j; | 31 | import lombok.extern.slf4j.Slf4j; |
| 29 | import org.springframework.beans.BeanUtils; | 32 | import org.springframework.beans.BeanUtils; |
| 30 | import org.springframework.beans.factory.annotation.Autowired; | 33 | import org.springframework.beans.factory.annotation.Autowired; |
| 34 | import org.springframework.util.Assert; | ||
| 31 | import org.springframework.validation.annotation.Validated; | 35 | import org.springframework.validation.annotation.Validated; |
| 32 | import org.springframework.web.bind.annotation.*; | 36 | import org.springframework.web.bind.annotation.*; |
| 33 | 37 | ||
| ... | @@ -151,8 +155,16 @@ public class UserOperationController { | ... | @@ -151,8 +155,16 @@ public class UserOperationController { |
| 151 | @PostMapping("/appletBind") | 155 | @PostMapping("/appletBind") |
| 152 | @ApiOperation("微信小程序绑定大屏") | 156 | @ApiOperation("微信小程序绑定大屏") |
| 153 | @AnonymousAccess | 157 | @AnonymousAccess |
| 154 | public ResultInfo appletBind(@Validated @RequestBody WeiXinUserBean resources) { | 158 | public ResultInfo appletBind(@Validated @RequestBody BindBean resources) { |
| 155 | UserWeixinDTO result = this.userTvOperationService.appletBind(resources); | 159 | String unionId = resources.getUnionId(); |
| 160 | if (StringUtils.isBlank(unionId)) | ||
| 161 | Assert.state(StrUtil.isNotBlank(unionId), "跨屏绑定,请先进行授权"); | ||
| 162 | |||
| 163 | Long platformUserId = resources.getPlatformUserId(); | ||
| 164 | if (Objects.isNull(platformUserId)) | ||
| 165 | Assert.state(StrUtil.isNotBlank(unionId), "大屏id不得为空"); | ||
| 166 | |||
| 167 | boolean result = this.userTvOperationService.appletBind(resources); | ||
| 156 | return ResultInfo.success(result); | 168 | return ResultInfo.success(result); |
| 157 | } | 169 | } |
| 158 | 170 | ||
| ... | @@ -254,6 +266,14 @@ public class UserOperationController { | ... | @@ -254,6 +266,14 @@ public class UserOperationController { |
| 254 | return ResultInfo.success(result); | 266 | return ResultInfo.success(result); |
| 255 | } | 267 | } |
| 256 | 268 | ||
| 269 | @GetMapping(value = "/checkBind") | ||
| 270 | @ApiOperation("校验是否绑定") | ||
| 271 | public IResultInfo checkBind(BindBean bindBean) { | ||
| 272 | Assert.notNull(bindBean.getId(), "id can not be null"); | ||
| 273 | Map<String, Object> map = this.userTvOperationService.checkBind(bindBean); | ||
| 274 | return ResultInfo.success(); | ||
| 275 | } | ||
| 276 | |||
| 257 | /** | 277 | /** |
| 258 | * @param data | 278 | * @param data |
| 259 | * @description 通过大屏关注的订阅号,因为订阅号不支持带参二维码, | 279 | * @description 通过大屏关注的订阅号,因为订阅号不支持带参二维码, | ... | ... |
| ... | @@ -4,11 +4,13 @@ import com.topdraw.business.module.member.profile.domain.MemberProfile; | ... | @@ -4,11 +4,13 @@ import com.topdraw.business.module.member.profile.domain.MemberProfile; |
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 5 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 5 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 6 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 6 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 7 | import com.topdraw.business.process.domian.weixin.BindBean; | ||
| 7 | import com.topdraw.business.process.domian.weixin.BuyVipBean; | 8 | import com.topdraw.business.process.domian.weixin.BuyVipBean; |
| 8 | import com.topdraw.business.process.domian.weixin.SubscribeBean; | 9 | import com.topdraw.business.process.domian.weixin.SubscribeBean; |
| 9 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | 10 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; |
| 10 | 11 | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 13 | import java.util.Map; | ||
| 12 | 14 | ||
| 13 | public interface UserOperationService { | 15 | public interface UserOperationService { |
| 14 | 16 | ||
| ... | @@ -113,5 +115,12 @@ public interface UserOperationService { | ... | @@ -113,5 +115,12 @@ public interface UserOperationService { |
| 113 | * @param resources | 115 | * @param resources |
| 114 | * @return | 116 | * @return |
| 115 | */ | 117 | */ |
| 116 | UserWeixinDTO appletBind(WeiXinUserBean resources); | 118 | boolean appletBind(BindBean resources); |
| 119 | |||
| 120 | /** | ||
| 121 | * | ||
| 122 | * @param bindBean | ||
| 123 | * @return | ||
| 124 | */ | ||
| 125 | Map<String, Object> checkBind(BindBean bindBean); | ||
| 117 | } | 126 | } | ... | ... |
| ... | @@ -31,10 +31,7 @@ import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; | ... | @@ -31,10 +31,7 @@ import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; |
| 31 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 31 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
| 32 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 32 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 33 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | 33 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; |
| 34 | import com.topdraw.business.process.domian.weixin.BuyVipBean; | 34 | import com.topdraw.business.process.domian.weixin.*; |
| 35 | import com.topdraw.business.process.domian.weixin.SubscribeBean; | ||
| 36 | import com.topdraw.business.process.domian.weixin.UserCollectionMq; | ||
| 37 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | ||
| 38 | import com.topdraw.business.process.service.UserOperationService; | 35 | import com.topdraw.business.process.service.UserOperationService; |
| 39 | import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; | 36 | import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; |
| 40 | import com.topdraw.config.LocalConstants; | 37 | import com.topdraw.config.LocalConstants; |
| ... | @@ -625,6 +622,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -625,6 +622,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 625 | // 链接微信服务器 | 622 | // 链接微信服务器 |
| 626 | String url = WeChatConstants.CODE2SESSION.replace("APPID", appId_) | 623 | String url = WeChatConstants.CODE2SESSION.replace("APPID", appId_) |
| 627 | .replace("SECRET", secret).replace("JSCODE", code); | 624 | .replace("SECRET", secret).replace("JSCODE", code); |
| 625 | |||
| 628 | String entityBody = HttpUtil.get(url); | 626 | String entityBody = HttpUtil.get(url); |
| 629 | log.info("entityBody [{}]",entityBody); | 627 | log.info("entityBody [{}]",entityBody); |
| 630 | 628 | ||
| ... | @@ -906,7 +904,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -906,7 +904,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 906 | */ | 904 | */ |
| 907 | private MemberDTO bindIptvId(MemberDTO memberDTO,Long userIptvId,Integer bindIptvPlatformType) { | 905 | private MemberDTO bindIptvId(MemberDTO memberDTO,Long userIptvId,Integer bindIptvPlatformType) { |
| 908 | 906 | ||
| 909 | //MemberDTO memberDTO = this.memberService.getByCode(resources.getCode()); | ||
| 910 | if (memberDTO != null) { | 907 | if (memberDTO != null) { |
| 911 | memberDTO.setUserIptvId(userIptvId); | 908 | memberDTO.setUserIptvId(userIptvId); |
| 912 | memberDTO.setBindIptvTime(TimestampUtil.now()); | 909 | memberDTO.setBindIptvTime(TimestampUtil.now()); |
| ... | @@ -1191,48 +1188,93 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1191,48 +1188,93 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1191 | } | 1188 | } |
| 1192 | 1189 | ||
| 1193 | @Override | 1190 | @Override |
| 1194 | public UserWeixinDTO appletBind(WeiXinUserBean resources) { | 1191 | public boolean appletBind(BindBean resources) { |
| 1195 | /*Optional<UserWeixin> userWeixinOptional = userWeixinRepository.findById(criteria.getId()); | 1192 | Long id = resources.getId(); |
| 1196 | if (!userWeixinOptional.isPresent()) { | 1193 | Long platformUserId = resources.getPlatformUserId(); |
| 1197 | throw new EntityNotFoundException(UserWeixin.class, "id", criteria.getId().toString()); | 1194 | |
| 1198 | } | 1195 | // 微信账户 |
| 1199 | UserWeixin userWeixin = userWeixinOptional.get(); | 1196 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findById(id); |
| 1200 | Member weixinMember = userWeixin.getMember(); | 1197 | |
| 1201 | String unionid = criteria.getUnionid(); | 1198 | if (Objects.isNull(userWeixinDTO.getId())) { |
| 1202 | 1199 | log.error("param ==> id ==> [{}]",id); | |
| 1203 | Long personId = null; | 1200 | throw new EntityNotFoundException(UserWeixinDTO.class, "id", userWeixinDTO.getId().toString()); |
| 1204 | 1201 | } | |
| 1205 | // 前端先校验绑定状态,若已绑定会予以提示,进一步操作,可能会产生换绑 | 1202 | |
| 1206 | // 小屏账号关联person,且已进行了授权 | 1203 | // 会员 |
| 1207 | if (ObjectUtil.isNull(weixinMember) && StrUtil.isNotBlank(unionid)) { | 1204 | Long memberId = userWeixinDTO.getMemberId(); |
| 1208 | //第一次绑定 | 1205 | MemberDTO memberDTO = this.findMemberById(memberId); |
| 1209 | // 微信用户unionid为空,或者与传到unionid一致,否则报错 | 1206 | if (Objects.isNull(memberDTO.getId())) { |
| 1210 | Assert.state(StrUtil.isBlank(userWeixin.getUnionid()) || ObjectUtil.equals(userWeixin.getUnionid(), unionid), "用户信息有误,请重新授权"); | 1207 | log.error("param ==> memberId ==> [{}]",id); |
| 1211 | 1208 | throw new EntityNotFoundException(MemberDTO.class, "id", memberId.toString()); | |
| 1212 | userWeixin.setUnionid(unionid); | 1209 | } |
| 1213 | Member member = getOrGenerateMobileMember(userWeixin, null); | 1210 | |
| 1214 | personId = member.getId(); | 1211 | // 已绑定大屏 |
| 1215 | } else if (ObjectUtil.isNotNull(weixinMember)) { | 1212 | Long userIptvId = memberDTO.getUserIptvId(); |
| 1216 | personId = weixinMember.getId(); | 1213 | if (Objects.nonNull(userIptvId) && userIptvId == platformUserId) { |
| 1217 | personCode = weixinMember.getCode(); | 1214 | throw new BadRequestException("不能重复绑定同一个账户"); |
| 1218 | } | 1215 | } |
| 1219 | 1216 | ||
| 1220 | TvUserQueryCriteria tvUserQueryCriteria = new TvUserQueryCriteria(); | 1217 | // 大屏账户 |
| 1221 | tvUserQueryCriteria.setPlatformAccount(criteria.getPlatformUserId()); | 1218 | UserTvDTO userTvDTO = this.findUserIptvById(platformUserId); |
| 1222 | List<TvUserDTO> tvUsers = tvUserService.queryAll(tvUserQueryCriteria); | 1219 | if (Objects.nonNull(userTvDTO.getId())) { |
| 1223 | // 理论上,大屏账号在创建/修改时,会同步到此侧,查不到可能是传值有误,或还未同步过来 | 1220 | // 主账户 |
| 1224 | Assert.notEmpty(tvUsers, "大屏账号不存在,请检查或稍后重试"); | 1221 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
| 1225 | TvUser tvUser = tvUserMapper.toEntity(tvUsers.get(0)); | 1222 | |
| 1226 | 1223 | if (StringUtils.isEmpty(priorityMemberCode)) { | |
| 1227 | // 更新关联的大屏账号 | 1224 | |
| 1228 | // personService.updateBindTvUser(personCode, tvUser.getId()); | 1225 | String code = memberDTO.getCode(); |
| 1229 | weixinMember.setUserIptvId(tvUser.getId()); | 1226 | userTvDTO.setPriorityMemberCode(code); |
| 1230 | weixinMember.setBindIptvTime(new Timestamp(System.currentTimeMillis())); | 1227 | |
| 1231 | weixinMember.setBindIptvPlatformType(1); | 1228 | // 更新大屏信息 |
| 1232 | memberService.update(weixinMember); | 1229 | this.doUpdateUserTv(userTvDTO); |
| 1233 | userWeixin.setMemberId(personId); | 1230 | } |
| 1234 | update(userWeixin);*/ | 1231 | |
| 1235 | return null; | 1232 | // 会员绑定大屏 |
| 1233 | this.bindIptvId(memberDTO,userTvDTO); | ||
| 1234 | |||
| 1235 | } | ||
| 1236 | |||
| 1237 | return true; | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | @Override | ||
| 1241 | public Map<String, Object> checkBind(BindBean bindBean) { | ||
| 1242 | Map<String, Object> map = new HashMap<>(); | ||
| 1243 | Long id = bindBean.getId(); | ||
| 1244 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findById(id); | ||
| 1245 | if (Objects.nonNull(userWeixinDTO.getId())) { | ||
| 1246 | Long memberId = userWeixinDTO.getMemberId(); | ||
| 1247 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 1248 | Long userIptvId = memberDTO.getUserIptvId(); | ||
| 1249 | if (Objects.nonNull(userIptvId)) { | ||
| 1250 | map.put("isBind", 1); | ||
| 1251 | map.put("platformUserId", userIptvId); | ||
| 1252 | return map; | ||
| 1253 | } else { | ||
| 1254 | map.put("isBind", 0); | ||
| 1255 | } | ||
| 1256 | } | ||
| 1257 | return map; | ||
| 1258 | } | ||
| 1259 | |||
| 1260 | /** | ||
| 1261 | * 通过id检索大屏信息 | ||
| 1262 | * @param userIptvId | ||
| 1263 | * @return | ||
| 1264 | */ | ||
| 1265 | private UserTvDTO findUserIptvById(Long userIptvId) { | ||
| 1266 | UserTvDTO userTvDTO = this.userTvService.findById(userIptvId); | ||
| 1267 | return userTvDTO; | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | /** | ||
| 1271 | * 更新大屏 | ||
| 1272 | * @param userTvDTO | ||
| 1273 | */ | ||
| 1274 | private void doUpdateUserTv(UserTvDTO userTvDTO) { | ||
| 1275 | UserTv userTv = new UserTv(); | ||
| 1276 | BeanUtils.copyProperties(userTvDTO,userTv); | ||
| 1277 | this.userTvService.update(userTv); | ||
| 1236 | } | 1278 | } |
| 1237 | 1279 | ||
| 1238 | /** | 1280 | /** | ... | ... |
-
Please register or sign in to post a comment