Commit 89edbf40 authored by killer's avatar killer

销户

parent 80f3d2e8
...@@ -231,4 +231,7 @@ public interface Constants { ...@@ -231,4 +231,7 @@ public interface Constants {
*/ */
String VERIFY_TYPE_QG = "qg"; String VERIFY_TYPE_QG = "qg";
// -- End -- 验证码常量组 // -- End -- 验证码常量组
/** 注销用户后再次允许注册时间间隔-天数 */
int DELETE_USER_AGAIN_REGISTER_INTERVAL = 90;
} }
...@@ -21,6 +21,7 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica ...@@ -21,6 +21,7 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica
/** /**
* 根据手机号查询用户UUID * 根据手机号查询用户UUID
*
* @param phoneNo - 手机号 * @param phoneNo - 手机号
* @return user表的uuid * @return user表的uuid
*/ */
...@@ -29,6 +30,7 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica ...@@ -29,6 +30,7 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica
/** /**
* 根据身份证号查询用户UUID * 根据身份证号查询用户UUID
*
* @param idNo - 身份证号 * @param idNo - 身份证号
* @return user表的uuid * @return user表的uuid
*/ */
...@@ -51,4 +53,11 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica ...@@ -51,4 +53,11 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica
List<User> findByUuidIn(List<String> uuids); List<User> findByUuidIn(List<String> uuids);
/**
* 根据userId删除用户
*
* @param userId 用户id
*/
void deleteById(Long userId);
} }
...@@ -6,6 +6,7 @@ import cn.quantgroup.xyqb.entity.Contact; ...@@ -6,6 +6,7 @@ import cn.quantgroup.xyqb.entity.Contact;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDeregisterRecord; import cn.quantgroup.xyqb.entity.UserDeregisterRecord;
import cn.quantgroup.xyqb.event.RegisterEvent; import cn.quantgroup.xyqb.event.RegisterEvent;
import cn.quantgroup.xyqb.exception.UserRegisterLoginException;
import cn.quantgroup.xyqb.model.UserRegisterParam; import cn.quantgroup.xyqb.model.UserRegisterParam;
import cn.quantgroup.xyqb.service.register.IUserDeregisterService; import cn.quantgroup.xyqb.service.register.IUserDeregisterService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
...@@ -13,8 +14,8 @@ import cn.quantgroup.xyqb.service.user.IUserService; ...@@ -13,8 +14,8 @@ import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.DateUtils; import cn.quantgroup.xyqb.util.DateUtils;
import cn.quantgroup.xyqb.util.PasswordUtil; import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.TenantUtil; import cn.quantgroup.xyqb.util.TenantUtil;
import cn.quantgroup.xyqb.util.encrypt.Md5Util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -22,7 +23,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -22,7 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.function.Predicate;
import static cn.quantgroup.xyqb.Constants.DELETE_USER_AGAIN_REGISTER_INTERVAL;
/** /**
* @author liqing * @author liqing
...@@ -44,6 +46,10 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -44,6 +46,10 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(Long registerFrom, String phoneNo) { public User register(Long registerFrom, String phoneNo) {
/* 用户销户检查 */
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -60,6 +66,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -60,6 +66,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(Long registerFrom, String phoneNo, Integer tenantId) { public User register(Long registerFrom, String phoneNo, Integer tenantId) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -78,6 +87,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -78,6 +87,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId, Long btRegisterChannelId) { public User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId, Long btRegisterChannelId) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -97,6 +109,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -97,6 +109,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId, Long btRegisterChannelId, Integer tenantId) { public User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId, Long btRegisterChannelId, Integer tenantId) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -148,6 +163,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -148,6 +163,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean register(String phoneNo, String password, Long registerFrom, String ip, Long channelId, Long btRegisterChannelId, String dimension) { public boolean register(String phoneNo, String password, Long registerFrom, String ip, Long channelId, Long btRegisterChannelId, String dimension) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo).password(password) .phoneNo(phoneNo).password(password)
...@@ -166,6 +184,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -166,6 +184,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(String phoneNo, Long channelId, Long registerFrom, String appChannel, Long btRegisterChannelId, String dimension) { public User register(String phoneNo, Long channelId, Long registerFrom, String appChannel, Long btRegisterChannelId, String dimension) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -185,6 +206,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -185,6 +206,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(String phoneNo, Long channelId, Long registerFrom, String appChannel, Long btRegisterChannelId, String dimension, Integer tenantId) { public User register(String phoneNo, Long channelId, Long registerFrom, String appChannel, Long btRegisterChannelId, String dimension, Integer tenantId) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registerFrom) .registerFrom(registerFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -205,6 +229,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -205,6 +229,9 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo, Address addressObj, String contacts, List<Contact> contactList, Long btRegisterChannelId) { public User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo, Address addressObj, String contacts, List<Contact> contactList, Long btRegisterChannelId) {
deregisterCheck(phoneNo);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registeredFrom) .registerFrom(registeredFrom)
.phoneNo(phoneNo) .phoneNo(phoneNo)
...@@ -225,10 +252,16 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -225,10 +252,16 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
} }
private void registerCheck(String phoneNo) { /**
// todo 手机号md5值 * 注册校验-销户校验
List<UserDeregisterRecord> deregisterRecords = userDeregisterService.queryByPhoneNo(phoneNo); *
* @param phoneNo 手机号
*/
private void deregisterCheck(String phoneNo) {
List<UserDeregisterRecord> deregisterRecords = userDeregisterService.queryByPhoneNo(Md5Util.build(phoneNo));
/* 获取最新销户记录 */
Optional<UserDeregisterRecord> lastOne = deregisterRecords.stream() Optional<UserDeregisterRecord> lastOne = deregisterRecords.stream()
.max(Comparator.comparing(UserDeregisterRecord::getDeregisterTime)); .max(Comparator.comparing(UserDeregisterRecord::getDeregisterTime));
...@@ -236,6 +269,10 @@ public class UserRegisterServiceImpl implements IUserRegisterService { ...@@ -236,6 +269,10 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
return; return;
} }
/* 销户时间小于90天不允许再次注册 */
int diffDay = DateUtils.dayDiff(new Date(), lastOne.get().getDeregisterTime()); int diffDay = DateUtils.dayDiff(new Date(), lastOne.get().getDeregisterTime());
if (DELETE_USER_AGAIN_REGISTER_INTERVAL >= diffDay) {
throw new UserRegisterLoginException("距离上次销户时间小于90天,无法再次注册");
}
} }
} }
...@@ -25,7 +25,7 @@ public interface IUserService { ...@@ -25,7 +25,7 @@ public interface IUserService {
User findByPhoneInDb(String phone); User findByPhoneInDb(String phone);
User findSlaveByPhoneInDb(String phone); User findSlaveByPhoneInDb(String phone);
User findByUuidInDb(String uuid); User findByUuidInDb(String uuid);
...@@ -92,14 +92,22 @@ public interface IUserService { ...@@ -92,14 +92,22 @@ public interface IUserService {
/** /**
* 按照userid 或者 uuid 批量查询 * 按照userid 或者 uuid 批量查询
*
* @param vals * @param vals
* @param type * @param type
* @return * @return
*/ */
List<User> findByUuidsOrUserIds(List<String> vals,Integer type, Integer tenantId); List<User> findByUuidsOrUserIds(List<String> vals, Integer type, Integer tenantId);
/** /**
* 登出 * 登出
*/ */
void logout(String token); void logout(String token);
/**
* 通过userId删除用户记录
*
* @param userId 用户id
*/
void deleteByUserId(Long userId);
} }
...@@ -524,4 +524,9 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -524,4 +524,9 @@ public class UserServiceImpl implements IUserService, IBaseController {
sessionService.deleteSession(token); sessionService.deleteSession(token);
} }
@Override
public void deleteByUserId(Long userId) {
userRepository.deleteById(userId);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment