Commit 9baa0628 9baa06280b8ae4879adbb567f1f67ec078ea70ca by xianghan

1.优化

1 parent 602f936d
Showing 16 changed files with 249 additions and 103 deletions
......@@ -52,7 +52,7 @@ public class DataSyncMsg implements Serializable {
private Long mediaId;
private Long itemId;
private String param;
private String description;
}
@Data
......
......@@ -12,6 +12,13 @@ import java.util.List;
public interface MemberService {
/**
* 获取会员code
* @param id
* @return
*/
String findCodeById(Long id);
/**
* 根据ID查询
* @param id ID
* @return MemberDTO
......
......@@ -47,6 +47,12 @@ public class MemberServiceImpl implements MemberService {
@Override
public String findCodeById(Long id) {
MemberDTO memberDTO = this.findById(id);
return memberDTO.getCode();
}
@Override
public MemberDTO findById(Long id) {
Member member = this.memberRepository.findById(id).orElseGet(Member::new);
ValidationUtil.isNull(member.getId(),"Member","id",id);
......
......@@ -26,8 +26,12 @@ public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, J
Optional<UserWeixin> findFirstByUnionidAndAppid(String unionid, String appId);
Optional<UserWeixin> findFirstByMemberId(Long memberId);
@Modifying
@Transactional
@Query(value = "update `uc_user_weixin` set update_time = :#{#resources.updateTime} where appid = :#{#resources.appid} and openid = :#{#resources.openid}" , nativeQuery = true)
@Query(value = "update `uc_user_weixin` set update_time = :#{#resources.updateTime} " +
"where appid = :#{#resources.appid} and openid = :#{#resources.openid}", nativeQuery = true)
void updateTime(@Param("resources") UserWeixin resources);
}
......
......@@ -13,9 +13,9 @@ import io.swagger.annotations.*;
* @author XiangHan
* @date 2021-12-16
*/
@Api(tags = "UserWeixin管理")
@Api(tags = "微信管理")
@RestController
@RequestMapping("/ucEngine/api/userWeixin")
@RequestMapping("/uce/userWeixin")
public class UserWeixinController {
@Autowired
......@@ -45,11 +45,4 @@ public class UserWeixinController {
return ResultInfo.success();
}
@DeleteMapping(value = "/{id}")
@ApiOperation("删除UserWeixin")
public ResultInfo delete(@PathVariable Long id) {
UserWeixinService.delete(id);
return ResultInfo.success();
}
}
......
......@@ -80,4 +80,11 @@ public interface UserWeixinService {
* @return
*/
UserWeixinDTO findFirstByUnionidAndAppid(String unionid, String appId);
/**
*
* @param memberId
* @return
*/
UserWeixinDTO findFirstByMemberId(Long memberId);
}
......
......@@ -98,4 +98,10 @@ public class UserWeixinServiceImpl implements UserWeixinService {
return this.userWeixinMapper.toDto(userWeixin);
}
@Override
public UserWeixinDTO findFirstByMemberId(Long memberId) {
UserWeixin userWeixin = this.userWeixinRepository.findFirstByMemberId(memberId).orElseGet(UserWeixin::new);
return this.userWeixinMapper.toDto(userWeixin);
}
}
......
......@@ -11,4 +11,6 @@ public class BindBean extends WeiXinUserBean {
@NotNull(message = "platformAccount can't be null" , groups = {BindGroup.class})
private String platformAccount;
}
......
package com.topdraw.business.process.domian.weixin;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class TvUnBindBean extends BindBean {
/** 是否自动设置主账号 true:是;false(默认):否 */
private Boolean autoModel;
}
......@@ -57,7 +57,15 @@ public class WeiXinUserBean {
/** 推荐者id */
private Long sourceUser;
/** 昵称 */
private String nikename;
/** 头像 */
private String headimgurl;
/** 授权码 */
private String authCode;
/** 来源信息 */
private String resourceInfo;
}
......
......@@ -186,21 +186,32 @@ public class UserOperationController {
}
@Log("微信小程序绑定大屏")
@PostMapping("/appletBind")
@PostMapping("/minaBind")
@ApiOperation("微信小程序绑定大屏")
@AnonymousAccess
public ResultInfo appletBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
public ResultInfo minaBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources);
boolean result = this.userOperationService.appletBind(resources);
boolean result = this.userOperationService.minaBind(resources);
return ResultInfo.success(result);
}
@Log("小屏解绑")
@PostMapping("/minaUnbind")
@ApiOperation("小屏解绑")
@AnonymousAccess
public ResultInfo minaUnbind(@Validated(value = {BindGroup.class}) @RequestBody TvUnBindBean tvUnBindBean) {
log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",tvUnBindBean);
this.userOperationService.minaUnbind(tvUnBindBean);
return ResultInfo.success();
}
@Log("暂存大小屏信息并检查关注与绑定状态")
@PostMapping(value = "/saveUserInfo")
@PostMapping(value = "/memberPreprocess")
@ApiOperation("暂存大小屏信息并检查关注与绑定状态")
@AnonymousAccess
public ResultInfo saveUserInfo(@RequestBody String data) {
public ResultInfo memberPreprocess(@RequestBody String data) {
log.info("UserOperationController ==> saveUserInfo ==>> param ==>> [{}]",data);
Assert.notNull(data, "用户数据不可为空");
......@@ -325,14 +336,14 @@ public class UserOperationController {
return ResultInfo.success(result);
}
@Log("大屏用户解绑")
@RequestMapping(value = "/unbind")
@ApiOperation("大屏用户解绑")
@Log("大屏解绑")
@RequestMapping(value = "/tvUnbind")
@ApiOperation("大屏解绑")
@AnonymousAccess
public ResultInfo unbind(@Validated(value = {UpdateGroup.class}) @RequestBody UserTv resources) {
public ResultInfo tvUnbind(@Validated(value = {UpdateGroup.class}) @RequestBody TvUnBindBean resources) {
log.info("UserOperationController ==> unbind ==>> param ==> [{}]",resources);
this.userOperationService.unbind(resources);
this.userOperationService.tvUnbind(resources);
return ResultInfo.success();
}
......@@ -340,10 +351,18 @@ public class UserOperationController {
@RequestMapping(value = "/changeMainAccount")
@ApiOperation("大屏更换主账号")
@AnonymousAccess
public ResultInfo changeMainAccount(@Validated(value = {UpdateGroup.class}) @RequestBody UserTv resources) {
public ResultInfo changeMainAccount(@Validated(value = {UpdateGroup.class}) @RequestBody BindBean resources) {
log.info("UserOperationController ==> changeMainAccount ==>> param ==> [{}]",resources);
this.userOperationService.changeMainAccount(resources);
Long memberId = resources.getMemberId();
String platformAccount = resources.getPlatformAccount();
String code = this.memberService.findCodeById(memberId);
UserTv userTv = new UserTv();
userTv.setMemberCode(code);
userTv.setPlatformAccount(platformAccount);
this.userOperationService.changeMainAccount(userTv);
return ResultInfo.success();
}
......
......@@ -7,6 +7,7 @@ import com.topdraw.business.module.user.weixin.domain.UserWeixin;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.domian.weixin.BindBean;
import com.topdraw.business.process.domian.weixin.SubscribeBean;
import com.topdraw.business.process.domian.weixin.TvUnBindBean;
public interface UserOperationService {
......@@ -43,7 +44,7 @@ public interface UserOperationService {
* 大屏解绑
* @param userTv
*/
void unbind(UserTv userTv);
void tvUnbind(TvUnBindBean userTv);
/**
* 大屏切换主账户(会员)
......@@ -101,7 +102,7 @@ public interface UserOperationService {
* @param resources
* @return
*/
boolean appletBind(BindBean resources);
boolean minaBind(BindBean resources);
/**
*
......@@ -138,4 +139,10 @@ public interface UserOperationService {
* @return
*/
UserTvDTO findByPlatformAccount(String platformAccount);
/**
* 小屏解绑
* @param tvUnBindBean
*/
void minaUnbind(TvUnBindBean tvUnBindBean);
}
......
......@@ -4,7 +4,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.aspect.AsyncMqSend;
import com.topdraw.business.module.member.domain.Member;
......@@ -55,7 +54,6 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
......@@ -372,7 +370,8 @@ public class UserOperationServiceImpl implements UserOperationService {
JSONObject json = JSONObject.parseObject(data);
String unionId = json.getString("unionid");
// 订阅号appid
String appId = json.getString("dyAppid");
// String appId = json.getString("dyAppid");
String appId = json.getString("appid");
try {
......@@ -433,20 +432,23 @@ public class UserOperationServiceImpl implements UserOperationService {
* @param resources
*/
@Override
public void unbind(UserTv resources) {
public void tvUnbind(TvUnBindBean resources) {
Boolean autoModel = resources.getAutoModel();
String platformAccount = resources.getPlatformAccount();
String memberCode = resources.getMemberCode();
Long memberId = resources.getMemberId();
MemberDTO memberDTO = this.memberService.findById(memberId);
String memberCode = memberDTO.getCode();
UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
if (Objects.isNull(userTvDTO))
throw new EntityNotFoundException(UserTvDTO.class, "PlatformAccount", GlobeExceptionMsg.IPTV_IS_NULL);
// 解绑(置空大屏信息)
MemberDTO _memberDTO = this.resetIptvColumn(this.findMemberByCode(memberCode));
MemberDTO _memberDTO = this.minaUnbind_(this.findMemberByCode(memberCode));
// 置空主账号
UserTvDTO _userTvDTO = this.resetMainAccount(memberCode, userTvDTO.getId());
UserTvDTO _userTvDTO = this.resetMainAccount(memberCode, userTvDTO.getId(), autoModel);
// 同步至iptv
((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(_memberDTO, _userTvDTO));
......@@ -615,34 +617,31 @@ public class UserOperationServiceImpl implements UserOperationService {
}
@Override
public boolean appletBind(BindBean resources) {
public boolean minaBind(BindBean resources) {
Long id = resources.getId();
String unionid = resources.getUnionid();
Long _memberId = resources.getMemberId();
String platformAccount = resources.getPlatformAccount();
// 大屏账户
UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
// 账户是否存在
if (Objects.isNull(userTvDTO.getId())){
if (Objects.isNull(userTvDTO.getId())) {
log.error("appletBind ==> platformAccount ==> [{}]",platformAccount);
throw new EntityNotFoundException(UserTvDTO.class,"id",GlobeExceptionMsg.IPTV_IS_NULL);
}
resources.setPlatformUserId(userTvDTO.getId());
UserWeixinDTO userWeixinDTO = null;
// 微信账户
if (Objects.nonNull(id)) {
userWeixinDTO = this.userWeixinService.findById(id);
} else {
userWeixinDTO = this.findFirstByUnionId(unionid);
if (Objects.nonNull(_memberId)) {
userWeixinDTO = this.userWeixinService.findFirstByMemberId(_memberId);
}
// 账户是否存在
if (Objects.isNull(userWeixinDTO.getId())) {
log.error("appletBind ==> weixinId ==> [{}]",id);
throw new EntityNotFoundException(UserWeixinDTO.class, "id", id.toString());
log.error("appletBind ==> weixinId ==> [{}]",userWeixinDTO.getId());
throw new EntityNotFoundException(UserWeixinDTO.class, "id", userWeixinDTO.getId().toString());
}
// 会员
......@@ -697,7 +696,8 @@ public class UserOperationServiceImpl implements UserOperationService {
MemberDTO _memberDTO = this.doUpdateMemberByMemberDTO(memberDTO);
// 同步至iptv
((UserOperationServiceImpl)AopContext.currentProxy()).asyncAppletBind(new MemberAndUserTvDTO(_memberDTO, _userTvDTO));
((UserOperationServiceImpl)AopContext.currentProxy())
.asyncAppletBind(new MemberAndUserTvDTO(_memberDTO, _userTvDTO));
return true;
}
......@@ -932,55 +932,42 @@ public class UserOperationServiceImpl implements UserOperationService {
/**
* 重置主账号
* @param memberCode
* @param memberCode 会员code
* @param id 大屏id
* @param autoModel true:自动设置主账号 false: 手动设置
*/
private UserTvDTO resetMainAccount(String memberCode, Long id) {
private UserTvDTO resetMainAccount(String memberCode, Long id, Boolean autoModel) {
UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode);
if (Objects.nonNull(userTvDTO)) {
userTvDTO.setPriorityMemberCode(null);
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO,userTv);
UserTvDTO _userTvDTO = this.userTvService.update(userTv);
return _userTvDTO;
if (autoModel == true) {
/*List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id);
if (CollectionUtils.isNotEmpty(memberDTOList)) {
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());
// 过滤预解绑的会员
/*List<MemberDTO> memberDTOS = memberDTOList.stream().filter(memberDTO ->
!memberDTO.getCode().equalsIgnoreCase(memberCode)).collect(Collectors.toList());*/
if (CollectionUtils.isNotEmpty(memberDTOS)) {
// if (CollectionUtils.isNotEmpty(memberDTOS)) {
// 按绑定时间倒排
memberDTOS.sort(new Comparator<MemberDTO>() {
@Override
public int compare(MemberDTO memberDTO, MemberDTO t1) {
return t1.getBindIptvTime().compareTo(memberDTO.getBindIptvTime());
}
});
// 绑定新的主账号
UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, memberDTOS.get(0).getCode(), "manual");
return _userTvDTO;
}
// 按绑定时间倒排
memberDTOList.sort(new Comparator<MemberDTO>() {
@Override
public int compare(MemberDTO memberDTO, MemberDTO t1) {
return t1.getBindIptvTime().compareTo(memberDTO.getBindIptvTime());
}
});
} else {
// 绑定新的主账号
UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, memberDTOList.get(0).getCode(), "manual");
// 没有绑定其他会员,直接解绑,不换绑
userTvDTO.setPriorityMemberCode(null);
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO,userTv);
UserTvDTO _userTvDTO = this.userTvService.unbindPriorityMemberCode(userTv);
return _userTvDTO;
}
return _userTvDTO;
}*/
// }
}
}
......@@ -992,7 +979,7 @@ public class UserOperationServiceImpl implements UserOperationService {
* 解绑(置空大屏信息)
* @param memberDTOS
*/
private MemberDTO resetIptvColumn(MemberDTO memberDTOS) {
private MemberDTO minaUnbind_(MemberDTO memberDTOS) {
// 若无关系,不做处理
if (Objects.nonNull(memberDTOS) && Objects.isNull(memberDTOS.getUserIptvId()))
......@@ -1003,7 +990,8 @@ public class UserOperationServiceImpl implements UserOperationService {
memberDTOS.setUserIptvId(null);
memberDTOS.setBindIptvPlatformType(null);
BeanUtils.copyProperties(memberDTOS, member);
return this.memberService.update(member);
MemberDTO memberDTO = this.memberService.update(member);
return memberDTO;
}
/**
......@@ -1177,4 +1165,15 @@ public class UserOperationServiceImpl implements UserOperationService {
public UserTvDTO findByPlatformAccount(String platformAccount) {
return this.userTvService.findByPlatformAccount(platformAccount);
}
@Override
public void minaUnbind(TvUnBindBean tvUnBindBean) {
Long memberId = tvUnBindBean.getMemberId();
MemberDTO memberDTO = this.memberService.findById(memberId);
UserTvDTO userTvDTO = this.userTvService.findById(memberDTO.getUserIptvId());
String platformAccount = userTvDTO.getPlatformAccount();
tvUnBindBean.setPlatformAccount(platformAccount);
this.tvUnbind(tvUnBindBean);
}
}
......
......@@ -15,7 +15,7 @@ public class RabbitMqConfig {
/** 队列-- */
public static final String UC_QUEUE_DIRECT_BBB = "uc.route.key.direct.event.bbb";
public static final String UC_QUEUE_DIRECT_CCC = "uc.route.key.direct.event.ccc";
public static final String UC_QUEUE_DIRECT_CCC = "uc.route.key.direct.event.ccc.new";
public static final String ENGINE_TO_IPTV_CONSUMER_MEMBER_DIRECT = "engine.iptv.consumer.member.direct";
......
......@@ -5,7 +5,7 @@ spring:
# url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# username: root
# password: Tjlh@2017
url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_iptv?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root
password: root
......@@ -109,7 +109,7 @@ engine:
# 部署类型 management:管理侧 service:服务侧
platform: service
# 可选参数 mobile:小屏 vis:大屏
type: mobile
type: vis
weixin:
list:
......
package com.topdraw.test.business.process.rest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.BaseTest;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
import com.topdraw.business.process.domian.weixin.BindBean;
import com.topdraw.business.process.domian.weixin.TvUnBindBean;
import com.topdraw.business.process.rest.TaskOperationController;
import com.topdraw.business.process.rest.UserOperationController;
import com.topdraw.business.process.service.dto.TaskOperationQueryCriteria;
import com.topdraw.common.ResultInfo;
import com.topdraw.module.mq.DataSyncMsg;
import com.topdraw.module.mq.EventType;
import org.junit.Test;
......@@ -15,26 +21,95 @@ import java.util.concurrent.FutureTask;
public class UserOperationControllerTest extends BaseTest {
@Autowired
TaskOperationController taskOperationController;
private UserOperationController userOperationController;
@Test
public void dealTask() {
public void minaUnbind() {
try {
DataSyncMsg dataSyncMsg = new DataSyncMsg();
dataSyncMsg.setEventType(EventType.VIEWING.name());
DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
msgData.setEvent(6); // 类型 1-登录 2-观影 3-参加活动 4-订购 5-优享会员 6-签到
msgData.setRemarks("remark");
msgData.setMemberId(2261L);
msgData.setDeviceType(2);
msgData.setAppCode("WEI_XIN_GOLD_PANDA");
dataSyncMsg.setMsg(msgData);
String s = JSON.toJSONString(dataSyncMsg);
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
System.out.println(s1);
this.taskOperationController.dealTask(pointsQueryCriteria);
TvUnBindBean bindBean = new TvUnBindBean();
// 小屏会员
bindBean.setMemberId(4L);
bindBean.setAutoModel(true);
ResultInfo weixinUserAndMember = this.userOperationController.minaUnbind(bindBean);
System.out.println(weixinUserAndMember);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void memberPreprocess() {
try {
String a = "{\"IPTVappid\":\"kids3\",\"platformAccount\":\"topdraw\"," +
"\"appid\":\"wx5d88c7fe99f89f32\",\"unionid\":\"oqDha5lxMuXYMGgT6gyLIFL7VumM\"," +
"\"nickname\":\"%E5%90%89%E8%B4%9D\"," +
"\"headimgurl\":\"https%3A%2F%2Fthirdwx.qlogo.cn%2Fmmopen%2Fvi_32%2FDYAIOgq83erGuDK9HlicY2iasIB5VHXTNWtuqfIZxIpzicQKWg9ogSRKRO1DeYtWicDHMMibpibHOEZRfp1Fvd4EQgrg%2F132\"}";
ResultInfo weixinUserAndMember = this.userOperationController.memberPreprocess(a);
System.out.println(weixinUserAndMember);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void tvUnbind() {
try {
TvUnBindBean bindBean = new TvUnBindBean();
bindBean.setPlatformAccount("topdraw");
// 小屏会员
bindBean.setMemberId(20559L);
bindBean.setAutoModel(true);
ResultInfo weixinUserAndMember = this.userOperationController.tvUnbind(bindBean);
System.out.println(weixinUserAndMember);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void changeMainAccount() {
try {
BindBean bindBean = new BindBean();
bindBean.setPlatformAccount("topdraw");
// 小屏会员
bindBean.setMemberId(20560L);
ResultInfo weixinUserAndMember = this.userOperationController.changeMainAccount(bindBean);
System.out.println(weixinUserAndMember);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void minaBind() {
try {
BindBean bindBean = new BindBean();
bindBean.setPlatformAccount("topdraw");
// 小屏会员
bindBean.setMemberId(4L);
ResultInfo weixinUserAndMember = this.userOperationController.minaBind(bindBean);
System.out.println(weixinUserAndMember);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void createWeixinUserAndMember() {
try {
String a = "{\n" +
"\"unionid\":\"oqDha5gjkNC4sivrcjbZSRq9foXM\",\n" +
"\"appid\":\"wx37ea49702cdc693b\", \n" +
"\"openid\":\"oM3jj5ke7o68I9-mIrAuQ8StkD_0\", \n" +
"\"authTime\":\"2022-03-22 20:10:43.47\"\n" +
"}";
UserWeixin parse = JSONObject.parseObject(a, UserWeixin.class);
ResultInfo weixinUserAndMember = this.userOperationController.createWeixinUserAndMember(parse);
System.out.println(weixinUserAndMember);
} catch (Exception e) {
e.printStackTrace();
}
......