Commit f7479712 f7479712987580f79ab811540c7db93e96cae53a by xianghan

1.修改app绑定大屏的业务逻辑

1 parent f1e0e3b6
......@@ -61,4 +61,7 @@ public interface UserAppRepository extends JpaRepository<UserApp, Long>, JpaSpec
" :#{#resources.gender}, NULL, now(), NULL, :#{#resources.tags}, " +
" :#{#resources.description}, :#{#resources.createTime}, now());", nativeQuery = true)
void saveByIdManual(@Param("resources") UserAppIdManual userAppIdManual);
Optional<UserApp> findByMemberId(Long memberId);
}
......
......@@ -92,4 +92,6 @@ public interface UserAppService {
ResultInfo saveAppAndBindWeixin4Vis(VisUserWeixin resources);
ResultInfo saveAppAndBindQq4Vis(VisUserQq resources);
UserAppDTO findByMemberId(Long memberId);
}
......
......@@ -549,6 +549,12 @@ public class UserAppServiceImpl implements UserAppService {
return ResultInfo.failure(null);
}
@Override
@Transactional(readOnly = true)
public UserAppDTO findByMemberId(Long memberId) {
UserApp userApp = this.userAppRepository.findByMemberId(memberId).orElseGet(UserApp::new);
return this.userAppMapper.toDto(userApp);
}
@Override
......
......@@ -242,20 +242,14 @@ public class UserOperationController {
@ApiOperation("app绑定大屏")
@AnonymousAccess
public ResultInfo appBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources);
log.info("app绑定大屏, 参数 appBind# resources ==> {}",resources);
Long memberId = resources.getMemberId();
if (Objects.isNull(memberId)) {
return ResultInfo.failure("参数错误,memberId 不存在");
}
String platformAccount = resources.getPlatformAccount();
if (StringUtils.isBlank(platformAccount)) {
return ResultInfo.failure("参数错误,大屏账号不存在");
return ResultInfo.failure("参数错误, memberId不得为空");
}
boolean result = this.userOperationService.appBind(resources);
return ResultInfo.success(result);
return this.userOperationService.appBind(resources);
}
@PostMapping("/appUnbind")
......
......@@ -124,7 +124,7 @@ public interface UserOperationService {
* @param resources
* @return
*/
boolean appBind(BindBean resources);
ResultInfo appBind(BindBean resources);
/**
*
......
......@@ -204,7 +204,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
BeanUtils.copyProperties(pointsAvailableDTO, _tempPoints);
BeanUtils.copyProperties(tempPoints, _tempPoints);
_tempPoints.setPoints(-(Math.abs(points)));
Long totalPoints = currentPoints + tempPoints.getPoints();
Long totalPoints = currentPoints - points;
this.doInsertTrPointsDetail(memberId, memberCode, _tempPoints, currentPoints, totalPoints);
}
......
......@@ -1272,7 +1272,6 @@ public class UserOperationServiceImpl implements UserOperationService {
// 更新大屏账户
this.userTvService.doUpdatePriorityMemberCode(userTv);
userTvDTO.setPriorityMemberCode(memberDTO.getCode());
}
......@@ -1318,8 +1317,98 @@ public class UserOperationServiceImpl implements UserOperationService {
}
@Override
public boolean appBind(BindBean resources) {
return this.minaBind(resources);
public ResultInfo appBind(BindBean resources) {
Long memberId = resources.getMemberId();
String platformAccount = resources.getPlatformAccount();
// 大屏账户
UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
log.info("查询大屏账号信息, appBind# userTvDTO ==>> {}", userTvDTO);
// 账户是否存在
if (Objects.isNull(userTvDTO.getId())) {
log.error("大屏账号信息不存在, appBind# platformAccount ==> {}",platformAccount);
return ResultInfo.failure("大屏账号信息不存在, 请检查数据");
}
// app账户
if (Objects.nonNull(memberId)) {
UserAppDTO userAppDTO = this.userAppService.findByMemberId(memberId);
log.info("检查app账号是否存在, appBind# userAppDTO ==>> {}", userAppDTO);
// 账户是否存在
if (Objects.isNull(userAppDTO.getId())) {
log.error("通过会员id无法找到对应的app账号, appBind# memberId ==> {}", memberId);
return ResultInfo.failure("app账号不存在,请检查数据");
}
}
MemberDTO memberDTO = this.memberService.findById(memberId);
log.info("检查会员是否存在, appBind# memberDTO ==>> {}", memberDTO);
if (Objects.nonNull(memberDTO.getId())) {
Long userIptvId = memberDTO.getUserIptvId();
if (Objects.nonNull(userIptvId)) {
log.error("该会员已绑定,appBind# 会员id ==> {} | 绑定的大屏账号id ==>> ", memberDTO.getId(), userIptvId);
return ResultInfo.failure(GlobeExceptionMsg.ALREADY_BIND);
}
} else {
log.error("会员信息不存在,请检查数据, appBind# memberId ==>> {}", memberId);
return ResultInfo.failure("会员信息不存在,请检查数据");
}
// 主账户
String priorityMemberCode = userTvDTO.getPriorityMemberCode();
if (StringUtils.isBlank(priorityMemberCode)) {
priorityMemberCode = memberDTO.getCode();
log.info("大屏账号为绑定主账号,开始设置主会员 priorityMemberCode ==>> {}", priorityMemberCode);
UserTv userTv = new UserTv();
userTv.setId(userTvDTO.getId());
userTv.setPriorityMemberCode(priorityMemberCode);
// 更新大屏账户
this.userTvService.doUpdatePriorityMemberCode(userTv);
userTvDTO.setPriorityMemberCode(memberDTO.getCode());
}
Member member = new Member();
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
String platform = userTvDTO.getPlatform();
// 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
Integer bindIptvPlatformType = 0;
// 联通
if (UserConstant.platform_lt.contains(platform)) {
bindIptvPlatformType = PLATFORM_LIST[3];
}
// 移动
if (UserConstant.platform_yd.contains(platform)) {
bindIptvPlatformType = PLATFORM_LIST[2];
}
// 电信
if (UserConstant.platform_dx.contains(platform)) {
bindIptvPlatformType = PLATFORM_LIST[1];
}
member.setUserIptvId(userTvDTO.getId());
member.setBindIptvTime(TimestampUtil.now());
member.setBindIptvPlatformType(bindIptvPlatformType);
log.info("修改小屏会员对应的绑定关系,member ==>> {}", member);
// 修改会员信息
this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member);
memberDTO.setPlatformAccount(platformAccount);
log.info("发送绑定消息至大屏,memberDTO ==>> {} || userTvDTO ==>> {}", memberDTO, userTvDTO);
// 同步至iptv
((UserOperationServiceImpl)AopContext.currentProxy())
.asyncMinaBind(new MemberAndUserTvDTO(memberDTO, userTvDTO));
UserTvSimpleDTO userTvSimpleDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount);
if (Objects.nonNull(userTvSimpleDTO.getPlatformAccount()) && StringUtils.isBlank(userTvSimpleDTO.getPriorityMemberCode())) {
userTvSimpleDTO.setPriorityMemberCode(priorityMemberCode);
JSONObject hashMap = JSONObject.parseObject(JSON.toJSONString(userTvSimpleDTO), JSONObject.class);
this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap);
}
return ResultInfo.success(true);
}
/**
......@@ -1397,17 +1486,6 @@ public class UserOperationServiceImpl implements UserOperationService {
return userTvDTO;
}
private void updateUserTvSimplePriorityMemberCodeRedis(String platformAccount, String priorityMemberCode){
// 修改缓存中MemberSimple的大屏主账号信息,因为执行任务之前会去检查主会员d
UserTvSimpleDTO userTvSimpleDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount);
if (Objects.nonNull(userTvSimpleDTO.getPlatformAccount()) && StringUtils.isBlank(userTvSimpleDTO.getPriorityMemberCode())) {
userTvSimpleDTO.setPriorityMemberCode(priorityMemberCode);
JSONObject hashMap = JSONObject.parseObject(JSON.toJSONString(userTvSimpleDTO), JSONObject.class);
this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap);
}
}
/**
*
* @param unionId 身份唯一标识
......