Commit 1b6b6ac4 1b6b6ac4f19b1a6ce8aea0afa59013b02e6fd06f by xianghan

1.优化

1 parent df8b22d5
......@@ -2,6 +2,7 @@ package com.topdraw.business.module.user.iptv.domain;
import com.topdraw.business.module.common.domain.AsyncMqModule;
import com.topdraw.business.module.common.validated.CreateGroup;
import com.topdraw.business.module.common.validated.UpdateGroup;
import lombok.Data;
import lombok.experimental.Accessors;
import cn.hutool.core.bean.BeanUtil;
......@@ -51,7 +52,7 @@ public class UserTv extends AsyncMqModule implements Serializable {
/** 运营商平台账号 */
@Column(name = "platform_account")
@NotNull(message = "platformAccount can't be null !",groups = {CreateGroup.class})
@NotNull(message = "platformAccount can't be null !",groups = {CreateGroup.class, UpdateGroup.class})
private String platformAccount;
/** 手机号 */
......
......@@ -101,8 +101,8 @@ public class UserOperationController {
SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class);
// 解析参数
this.parseSubscribe(subscribeBean);
boolean result = this.userOperationService.subscribe(subscribeBean);
return ResultInfo.success(result);
this.userOperationService.subscribe(subscribeBean);
return ResultInfo.success();
}
/**
......@@ -112,19 +112,15 @@ public class UserOperationController {
*/
private void parseSubscribe(SubscribeBean subscribeBean) throws IOException {
String appId = subscribeBean.getAppId();
String appId = subscribeBean.getAppid();
Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL);
// openId
String openId = subscribeBean.getOpenId();
String openId = subscribeBean.getOpenid();
Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL);
// unionId
String unionId = subscribeBean.getUnionid();
Assert.notNull(openId, GlobeExceptionMsg.UNION_ID_IS_NULL);
subscribeBean.setAppid(appId);
subscribeBean.setOpenid(openId);
subscribeBean.setUnionid(unionId);
// 匹配配置文件中的微信列表信息
Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId);
......@@ -206,7 +202,7 @@ public class UserOperationController {
@AnonymousAccess
public ResultInfo saveUserInfo(@RequestBody String data) {
log.info("saveUserInfo ==> input ==> [{}]",data);
log.info("UserOperationController ==> saveUserInfo ==>> param ==>> [{}]",data);
Assert.notNull(data, "用户数据不可为空");
JSONObject json = JSONObject.parseObject(data);
......@@ -327,7 +323,7 @@ public class UserOperationController {
@RequestMapping(value = "/changeMainAccount")
@ApiOperation("大屏更换主账号")
@AnonymousAccess
public ResultInfo changeMainAccount(@Validated @RequestBody UserTv resources) {
public ResultInfo changeMainAccount(@Validated(value = {UpdateGroup.class}) @RequestBody UserTv resources) {
log.info("UserOperationController ==> changeMainAccount ==>> param ==> [{}]",resources);
this.userOperationService.changeMainAccount(resources);
......
......@@ -131,4 +131,11 @@ public interface UserOperationService {
* @return
*/
UserTvDTO checkBind(MemberDTO memberDTO);
/**
*
* @param platformAccount
* @return
*/
UserTvDTO findByPlatformAccount(String platformAccount);
}
......
......@@ -37,8 +37,9 @@ import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.QueryHelp;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -359,15 +360,21 @@ public class UserOperationServiceImpl implements UserOperationService {
// 会员编码
String memberCode = resources.getMemberCode();
this.findMemberByCode(memberCode);
UserTvDTO userTvDTO = this.findByPriorityMemberCode(memberCode);
String platformAccount = resources.getPlatformAccount();
this.findByPlatformAccount(platformAccount);
UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
if (Objects.nonNull(userTvDTO)) {
if (userTvDTO.getPriorityMemberCode().equalsIgnoreCase(memberCode))
throw new BadRequestException("会员已是主账户");
throw new BadRequestException("该会员已绑定其他账户");
} else {
throw new EntityNotFoundException(UserTvDTO.class , "platformAccount" , GlobeExceptionMsg.IPTV_IS_NULL);
}
......@@ -383,16 +390,18 @@ public class UserOperationServiceImpl implements UserOperationService {
@Override
public void unbind(UserTv resources) {
String platformAccount = resources.getPlatformAccount();
String memberCode = resources.getMemberCode();
// 大屏会员
MemberDTO memberDTOS = this.findMemberByCode(memberCode);
UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
if (Objects.isNull(userTvDTO))
throw new EntityNotFoundException(UserTvDTO.class, "PlatformAccount", GlobeExceptionMsg.IPTV_IS_NULL);
// 解绑(置空大屏信息)
this.resetIptvColumn(memberDTOS);
this.resetIptvColumn(this.findMemberByCode(memberCode));
// 置空主账号
this.resetMainAccount(memberCode);
this.resetMainAccount(memberCode, userTvDTO.getId());
}
@Override
......@@ -865,19 +874,49 @@ public class UserOperationServiceImpl implements UserOperationService {
}
/**
* 置空主账号
* 重置主账号
* @param memberCode
*/
private void resetMainAccount(String memberCode) {
private void resetMainAccount(String memberCode, Long id) {
UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode);
if (Objects.nonNull(userTvDTO)) {
userTvDTO.setPriorityMemberCode(null);
List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id);
if (CollectionUtils.isNotEmpty(memberDTOList)) {
// 过滤解绑的会员
List<MemberDTO> memberDTOS = memberDTOList.stream().filter(memberDTO -> !memberDTO.getCode().equalsIgnoreCase(memberCode))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(memberDTOS)) {
// 按绑定时间倒排
memberDTOS.sort(new Comparator<MemberDTO>() {
@Override
public int compare(MemberDTO memberDTO, MemberDTO t1) {
return t1.getBindIptvTime().compareTo(memberDTO.getBindIptvTime());
}
});
// 绑定新的主账号
this.bondPriorityMember(userTvDTO, memberDTOS.get(0).getCode() , "manual");
}
} else {
// 没有绑定其他会员,直接解绑,不换绑
userTvDTO.setPriorityMemberCode(null);
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO,userTv);
this.userTvService.unbindPriorityMemberCode(userTv);
}
}
}
/**
......@@ -885,8 +924,9 @@ public class UserOperationServiceImpl implements UserOperationService {
* @param memberDTOS
*/
private void resetIptvColumn(MemberDTO memberDTOS) {
// 若无关系,不做处理
if (Objects.nonNull(memberDTOS))
if (Objects.nonNull(memberDTOS) && Objects.isNull(memberDTOS.getUserIptvId()))
return;
Member member = new Member();
......@@ -903,8 +943,7 @@ public class UserOperationServiceImpl implements UserOperationService {
* @return
*/
private MemberDTO findMemberByCode(String memberCode) {
MemberDTO memberDTO = memberService.findByCode(memberCode);
return memberDTO;
return memberService.findByCode(memberCode);
}
/**
......@@ -1083,4 +1122,9 @@ public class UserOperationServiceImpl implements UserOperationService {
}
return null;
}
@Override
public UserTvDTO findByPlatformAccount(String platformAccount) {
return this.userTvService.findByPlatformAccount(platformAccount);
}
}
......