Commit bc32e2f6 bc32e2f6da1b654b34454c1fc37305d6d3bb388e by xianghan

1.修改绑定、解绑实现

1 parent b3ece12e
Showing 18 changed files with 789 additions and 3 deletions
package com.topdraw.business.module.member.domain;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/27 15:38
* @version: :
* @modified By:
* @since : modified in 2022/6/27 15:38
*/
public interface MemberTypeConstant {
// 大屏
Integer vis = 1;
// 微信
Integer weixin = 2;
// app
Integer app = 3;
}
package com.topdraw.business.module.user.app.domain;
import lombok.Data;
import lombok.experimental.Accessors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_app")
public class UserApp implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 会员id
@Column(name = "member_id")
private Long memberId;
// 用户名(一般为手机号)
@Column(name = "username", nullable = false)
private String username;
// 密码
@Column(name = "password")
private String password;
// 类型 0:苹果;1:安卓;-1:未知
@Column(name = "type", nullable = false)
private Integer type;
// 状态 0:禁用;1:生效;-1:注销
@Column(name = "status", nullable = false)
private Integer status;
// 昵称
@Column(name = "nickname")
private String nickname;
// 头像地址
@Column(name = "headimgurl")
private String headimgurl;
// 邮箱
@Column(name = "email")
private String email;
// 手机号
@Column(name = "cellphone")
private String cellphone;
// 性别 0:女;1:男;-1:其他
@Column(name = "gender")
private Integer gender;
// 生日
@Column(name = "birthday")
private String birthday;
// 最近活跃时间
@Column(name = "last_active_time")
private Timestamp lastActiveTime;
// 注销时间
@Column(name = "delete_time")
private Timestamp deleteTime;
// 标签
@Column(name = "tags")
private String tags;
// 描述
@Column(name = "description")
private String description;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(UserApp source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.app.domain;
import lombok.Data;
import lombok.experimental.Accessors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="uc_user_app_bind")
public class UserAppBind implements Serializable {
// 主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
@Column(name = "account_type", nullable = false)
private Integer accountType;
// 第三方账号
@Column(name = "account", nullable = false)
private String account;
// app账号id
@Column(name = "user_app_id", nullable = false)
private Long userAppId;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(UserAppBind source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.user.app.repository;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppBindRepository extends JpaRepository<UserAppBind, Long>, JpaSpecificationExecutor<UserAppBind> {
}
package com.topdraw.business.module.user.app.repository;
import com.topdraw.business.module.user.app.domain.UserApp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppRepository extends JpaRepository<UserApp, Long>, JpaSpecificationExecutor<UserApp> {
Optional<UserApp> findByUsername(String username);
Optional<UserApp> findByUsernameAndPassword(String username, String password);
}
package com.topdraw.business.module.user.app.rest;
import com.topdraw.annotation.AnonymousAccess;
import com.topdraw.common.ResultInfo;
import com.topdraw.annotation.Log;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.service.UserAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Api(tags = "UserApp管理")
@RestController
@RequestMapping("/uce/userApp")
@Slf4j
public class UserAppController {
@Autowired
private UserAppService userAppService;
@Log
@PostMapping
@ApiOperation("新增UserApp")
@AnonymousAccess
public ResultInfo create(@Validated @RequestBody UserApp resources) {
log.info("新增App账号 ==>> param ==>> [addLogin#{}]", resources);
this.userAppService.create(resources);
return ResultInfo.success();
}
@Log
@PutMapping
@ApiOperation("修改UserApp")
@AnonymousAccess
public ResultInfo update(@Validated @RequestBody UserApp resources) {
this.userAppService.update(resources);
return ResultInfo.success();
}
@Log
@DeleteMapping(value = "/{id}")
@ApiOperation("删除UserApp")
@AnonymousAccess
public ResultInfo delete(@PathVariable Long id) {
this.userAppService.delete(id);
return ResultInfo.success();
}
}
package com.topdraw.business.module.user.app.service;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppBindService {
/**
* 根据ID查询
* @param id ID
* @return UserAppBindDTO
*/
UserAppBindDTO findById(Long id);
/**
*
* @param resources
*/
void create(UserAppBind resources);
/**
*
* @param resources
*/
void update(UserAppBind resources);
/**
*
* @param id
*/
void delete(Long id);
}
package com.topdraw.business.module.user.app.service;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
/**
* @author XiangHan
* @date 2022-06-27
*/
public interface UserAppService {
/**
* 根据ID查询
* @param id ID
* @return UserAppDTO
*/
UserAppDTO findById(Long id);
/**
* 检查账号和秘密
* @param username
* @return
*/
UserAppDTO findByUserName(String username);
/**
* 检查账号和秘密
* @param username
* @param password
* @return
*/
UserAppDTO findByUserNameAndPassword(String username, String password);
/**
* 检查账号和验证码
* @param username
* @param VerificationCode
* @return
*/
UserAppDTO findByUserNameAndVerificationCode(String username, String VerificationCode);
/**
* 检查通过第三方账号
* @param relationAccount
* @return
*/
UserAppDTO findByRelationAccount(String relationAccount);
/**
*
* @param resources
*/
UserAppDTO create(UserApp resources);
/**
*
* @param resources
*/
UserAppDTO update(UserApp resources);
/**
*
* @param id
*/
void delete(Long id);
}
package com.topdraw.business.module.user.app.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Data
public class UserAppBindDTO implements Serializable {
// 主键
private Long id;
// 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
private Integer accountType;
// 第三方账号
private String account;
// app账号id
private Long userAppId;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
}
package com.topdraw.business.module.user.app.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Data
public class UserAppDTO implements Serializable {
// ID
private Long id;
// 会员id
private Long memberId;
// 用户名(一般为手机号)
private String username;
// 密码
private String password;
// 类型 0:苹果;1:安卓;-1:未知
private Integer type;
// 状态 0:禁用;1:生效;-1:注销
private Integer status;
// 昵称
private String nickname;
// 头像地址
private String headimgurl;
// 邮箱
private String email;
// 手机号
private String cellphone;
// 性别 0:女;1:男;-1:其他
private Integer gender;
// 生日
private String birthday;
// 最近活跃时间
private Timestamp lastActiveTime;
// 注销时间
private Timestamp deleteTime;
// 标签
private String tags;
// 描述
private String description;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
}
package com.topdraw.business.module.user.app.service.impl;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.user.app.repository.UserAppBindRepository;
import com.topdraw.business.module.user.app.service.UserAppBindService;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
import com.topdraw.business.module.user.app.service.mapper.UserAppBindMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import com.topdraw.utils.PageUtil;
import com.topdraw.utils.QueryHelp;
import java.util.List;
import java.util.Map;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserAppBindServiceImpl implements UserAppBindService {
@Autowired
private UserAppBindRepository userAppBindRepository;
@Autowired
private UserAppBindMapper userAppBindMapper;
@Override
public UserAppBindDTO findById(Long id) {
UserAppBind userAppBind = this.userAppBindRepository.findById(id).orElseGet(UserAppBind::new);
ValidationUtil.isNull(userAppBind.getId(),"UserAppBind","id",id);
return this.userAppBindMapper.toDto(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(UserAppBind resources) {
this.userAppBindRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(UserAppBind resources) {
UserAppBind userAppBind = this.userAppBindRepository.findById(resources.getId()).orElseGet(UserAppBind::new);
ValidationUtil.isNull( userAppBind.getId(),"UserAppBind","id",resources.getId());
userAppBind.copy(resources);
this.userAppBindRepository.save(userAppBind);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
UserAppBind UserAppBind = this.userAppBindRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserAppBind.class, id), 1));
this.userAppBindRepository.delete(UserAppBind);
}
}
package com.topdraw.business.module.user.app.service.impl;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.domain.MemberBuilder;
import com.topdraw.business.module.member.domain.MemberTypeConstant;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.user.app.repository.UserAppRepository;
import com.topdraw.business.module.user.app.service.UserAppService;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
import com.topdraw.business.module.user.app.service.mapper.UserAppMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import java.util.Objects;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class UserAppServiceImpl implements UserAppService {
@Autowired
private UserAppRepository userAppRepository;
@Autowired
private UserAppMapper userAppMapper;
@Autowired
private MemberService memberService;
@Override
@Transactional(readOnly = true)
public UserAppDTO findById(Long id) {
UserApp userApp = this.userAppRepository.findById(id).orElseGet(UserApp::new);
ValidationUtil.isNull(userApp.getId(),"UserApp","id",id);
return this.userAppMapper.toDto(userApp);
}
@Override
@Transactional(readOnly = true)
public UserAppDTO findByUserName(String username) {
UserApp userApp = this.userAppRepository.findByUsername(username).orElseGet(UserApp::new);
return this.userAppMapper.toDto(userApp);
}
@Override
@Transactional(readOnly = true)
public UserAppDTO findByUserNameAndPassword(String username, String password) {
UserApp userApp = this.userAppRepository.findByUsernameAndPassword(username, password).orElseGet(UserApp::new);
return this.userAppMapper.toDto(userApp);
}
@Override
@Transactional(readOnly = true)
public UserAppDTO findByUserNameAndVerificationCode(String username, String VerificationCode) {
UserApp userApp = null;
return this.userAppMapper.toDto(userApp);
}
@Override
@Transactional(readOnly = true)
public UserAppDTO findByRelationAccount(String relationAccount) {
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserAppDTO create(UserApp resources) {
UserApp userApp = this.userAppRepository.save(resources);
return this.userAppMapper.toDto(userApp);
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserAppDTO update(UserApp resources) {
UserApp userApp = this.userAppRepository.findById(resources.getId()).orElseGet(UserApp::new);
ValidationUtil.isNull( userApp.getId(),"UserApp","id",resources.getId());
userApp.copy(resources);
UserApp _userApp = this.userAppRepository.save(userApp);
if (Objects.nonNull(_userApp.getId())) {
return this.userAppMapper.toDto(_userApp);
}
return this.userAppMapper.toDto(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
Assert.notNull(id, "The given id must not be null!");
UserApp UserApp = this.userAppRepository.findById(id).orElseThrow(
() -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserApp.class, id), 1));
this.userAppRepository.delete(UserApp);
}
}
package com.topdraw.business.module.user.app.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserAppBindMapper extends BaseMapper<UserAppBindDTO, UserAppBind> {
}
package com.topdraw.business.module.user.app.service.mapper;
import com.topdraw.base.BaseMapper;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author XiangHan
* @date 2022-06-27
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserAppMapper extends BaseMapper<UserAppDTO, UserApp> {
}
......@@ -5,11 +5,13 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.annotation.AnonymousAccess;
import com.topdraw.annotation.Log;
import com.topdraw.business.module.common.validated.CreateGroup;
import com.topdraw.business.module.common.validated.UpdateGroup;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
......@@ -66,6 +68,74 @@ public class UserOperationController {
private static final String UNSUBSCRIBE = "unsubscribe";
private static final Integer SUBSCRIBE_STATUS = 1;
/******************************************************* APP ************************************/
@Log
@PostMapping(value = "/appLogin")
@ApiOperation("app登录")
@AnonymousAccess
public ResultInfo appLogin(@Validated @RequestBody UserApp resources) {
log.info("新增App账号 ==>> param ==>> [addLogin#{}]", resources);
this.userOperationService.appLogin(resources);
return ResultInfo.success();
}
@Log
@PostMapping(value = "/appLogin")
@ApiOperation("app登录")
@AnonymousAccess
public ResultInfo updateAppCount(@Validated @RequestBody UserApp resources) {
log.info("新增App账号 ==>> param ==>> [addLogin#{}]", resources);
this.userOperationService.appLogin(resources);
return ResultInfo.success();
}
@PostMapping("/appBind")
@ApiOperation("微信小程序绑定大屏")
@AnonymousAccess
public ResultInfo appBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources);
Long memberId = resources.getMemberId();
if (Objects.isNull(memberId)) {
return ResultInfo.failure("参数错误,memberId 不存在");
}
String platformAccount = resources.getPlatformAccount();
if (StringUtils.isBlank(platformAccount)) {
return ResultInfo.failure("参数错误,大屏账号不存在");
}
boolean result = this.userOperationService.appBind(resources);
return ResultInfo.success(result);
}
@PostMapping("/appUnbind")
@ApiOperation("小屏解绑")
@AnonymousAccess
public ResultInfo appUnbind(@Validated(value = {UnbindGroup.class}) @RequestBody WeixinUnBindBean weixinUnBindBean) {
log.info("UserOperationController ==> minaUnbind ==>> param ==> [{}]", weixinUnBindBean);
Long memberId = weixinUnBindBean.getMemberId();
if (Objects.isNull(memberId)) {
log.error("小屏解绑失败,参数错误,memberId不存在");
return ResultInfo.failure("参数错误,会员id不存在");
}
boolean b = this.userOperationService.minaUnbind(weixinUnBindBean);
if (b) {
return ResultInfo.success("解绑成功");
} else {
return ResultInfo.failure("解绑失败");
}
}
/******************************************************* weixin ************************************/
@PutMapping(value = "/updateWeixin")
@ApiOperation("修改UserWeixin")
@AnonymousAccess
......@@ -566,6 +636,7 @@ public class UserOperationController {
return ResultInfo.success();
}
}
......
package com.topdraw.business.process.service;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
......@@ -113,6 +114,13 @@ public interface UserOperationService {
boolean minaBind(BindBean resources);
/**
* app绑定大屏
* @param resources
* @return
*/
boolean appBind(BindBean resources);
/**
*
* @param memberDTO
* @param platformAccount
......@@ -160,4 +168,10 @@ public interface UserOperationService {
*/
UserTvDTO updateUserTv(UserTv resources);
/**
*
* @param resources
*/
void appLogin(UserApp resources);
}
......
......@@ -11,6 +11,7 @@ import com.topdraw.business.module.member.domain.MemberBuilder;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.iptv.domain.UserConstant;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.domain.UserTvBuilder;
......@@ -107,6 +108,14 @@ public class UserOperationServiceImpl implements UserOperationService {
@Value("${uc.app.appletAppid:wxc57d42de3d351cec}")
private String appletAppid;
@Override
@Transactional(rollbackFor = Exception.class)
public void appLogin(UserApp resources) {
}
/**
* 创建大屏账户同时创建会员
*
......@@ -1036,6 +1045,11 @@ public class UserOperationServiceImpl implements UserOperationService {
return true;
}
@Override
public boolean appBind(BindBean resources) {
return this.minaBind(resources);
}
/**
*
* @param resource 会员信息
......@@ -1387,6 +1401,7 @@ public class UserOperationServiceImpl implements UserOperationService {
@AsyncMqSend
public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {}
@AsyncMqSend
......
......@@ -39,16 +39,16 @@ public class GeneratorCode extends BaseTest {
@Rollback(value = false)
@Transactional(rollbackFor = Exception.class)
public void generator() {
var dbName = "uc_wechat_share_record";
var dbName = "uc_user_app_bind";
// 表名称,支持多表
var tableNames = Arrays.asList(dbName);
String[] s = dbName.split("_");
var pre = s[0];
var target1 = s[s.length-1];
var preRoute = "com.topdraw.business.module.user.weixin.";
var preRoute = "com.topdraw.business.module.user.app";
StringBuilder builder = new StringBuilder(preRoute);
builder.append("wechatshare");
// builder.append("wechatshare");
// builder.append(target);
tableNames.forEach(tableName -> {
......