release- 邀请码改为: 第一第二位是大写英文,后面四位数字

release-2024-04-25
huangyw 3 days ago
parent 3fa10a10f3
commit 04d378247c

@ -57,6 +57,7 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
public class UserInfoService { public class UserInfoService {
private final UserInfoDao userInfoDao; private final UserInfoDao userInfoDao;
private final IdWorker idWorker; private final IdWorker idWorker;
@ -82,7 +83,8 @@ public class UserInfoService {
private final UserPointLogDao userPointLogDao; private final UserPointLogDao userPointLogDao;
public UserInfoService(UserInfoDao userInfoDao, IdWorker idWorker, RedisTemplate redisTemplate, public UserInfoService(UserInfoDao userInfoDao, IdWorker idWorker, RedisTemplate redisTemplate,
RabbitTemplate rabbitTemplate, BCryptPasswordEncoder encoder, HttpServletRequest request, RabbitTemplate rabbitTemplate, BCryptPasswordEncoder encoder,
HttpServletRequest request,
JwtUtil jwtUtil, UserRealNameDao userRealNameDao, UserBankDao userBankDao, JwtUtil jwtUtil, UserRealNameDao userRealNameDao, UserBankDao userBankDao,
WithdrawDao withdrawDao, UserPointLogService userPointLogService, WithdrawDao withdrawDao, UserPointLogService userPointLogService,
UserPointLogDao userPointLogDao) { UserPointLogDao userPointLogDao) {
@ -221,7 +223,8 @@ public class UserInfoService {
userInfo.setLastUseDeviceId(deviceId); userInfo.setLastUseDeviceId(deviceId);
userInfo.setLastUseDeviceBrand(deviceBrand); userInfo.setLastUseDeviceBrand(deviceBrand);
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(), return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(),
userInfo.getNickName(),
userLoginDto.getRoles(), userLoginDto.getAvatar()); userLoginDto.getRoles(), userLoginDto.getAvatar());
} }
@ -268,7 +271,8 @@ public class UserInfoService {
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
String token = Constants.TOKEN_PREFIX String token = Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(),
Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
if (isNewUser) { if (isNewUser) {
// 只有新用户会获得积分 // 只有新用户会获得积分
userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token);
@ -291,19 +295,26 @@ public class UserInfoService {
userInfo.setInvitationUserId(userInfoDaoByInvitationCode.getId()); userInfo.setInvitationUserId(userInfoDaoByInvitationCode.getId());
this.update(userInfo); this.update(userInfo);
// 邀请人与被邀请人同时获取积分 // 邀请人与被邀请人同时获取积分
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.NEW_USER_INVITE, userInfoDaoByInvitationCode.getId()); userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.NEW_USER_INVITE,
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.NEW_USER_INVITE, userInfo.getId()); userInfoDaoByInvitationCode.getId());
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.NEW_USER_INVITE,
userInfo.getId());
} }
List<UserPointLog> list = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(userInfoDaoByInvitationCode.getId(), TaskPointIdConstants.NEW_USER_INVITE); List<UserPointLog> list = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
userInfoDaoByInvitationCode.getId(), TaskPointIdConstants.NEW_USER_INVITE);
if (list.size() == 3) { if (list.size() == 3) {
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_3, userInfoDaoByInvitationCode.getId()); userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_3,
userInfoDaoByInvitationCode.getId());
} else if (list.size() == 6) { } else if (list.size() == 6) {
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_6, userInfoDaoByInvitationCode.getId()); userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_6,
userInfoDaoByInvitationCode.getId());
} else if (list.size() == 10) { } else if (list.size() == 10) {
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_10, userInfoDaoByInvitationCode.getId()); userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_10,
userInfoDaoByInvitationCode.getId());
} else if (list.size() == 20) { } else if (list.size() == 20) {
userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_20, userInfoDaoByInvitationCode.getId()); userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_20,
userInfoDaoByInvitationCode.getId());
} }
} }
@ -341,7 +352,8 @@ public class UserInfoService {
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
String token = Constants.TOKEN_PREFIX String token = Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(),
Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
if (isNewUser) { if (isNewUser) {
// 只有新用户会获得积分 // 只有新用户会获得积分
@ -382,7 +394,8 @@ public class UserInfoService {
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
String token = Constants.TOKEN_PREFIX String token = Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(),
Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
if (isNewUser) { if (isNewUser) {
// 只有新用户会获得积分 // 只有新用户会获得积分
userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token);
@ -422,14 +435,14 @@ public class UserInfoService {
public String wechatlogin(UserInfo loginUserInfo) { public String wechatlogin(UserInfo loginUserInfo) {
if (!UserStatusEnum.ENABLE.getStatus().equals(loginUserInfo.getStatus())) { if (!UserStatusEnum.ENABLE.getStatus().equals(loginUserInfo.getStatus())) {
return null; return null;
} }
loginUserInfo.setLastLoginTime(new Date()); loginUserInfo.setLastLoginTime(new Date());
userInfoDao.save(loginUserInfo); userInfoDao.save(loginUserInfo);
return Constants.TOKEN_PREFIX return Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(loginUserInfo.getId(), loginUserInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, loginUserInfo.getAvatar()); + jwtUtil.createJWT(loginUserInfo.getId(), loginUserInfo.getNickName(),
Constants.TOKEN_ROLE_APP_USER, loginUserInfo.getAvatar());
} }
@ -468,7 +481,8 @@ public class UserInfoService {
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
String token = Constants.TOKEN_PREFIX String token = Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(),
Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
if (isNewUser) { if (isNewUser) {
// 只有新用户会获得积分 // 只有新用户会获得积分
userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token);
@ -482,7 +496,8 @@ public class UserInfoService {
} }
public List<UserInfo> cmsOrderByField(List<String> idList) { public List<UserInfo> cmsOrderByField(List<String> idList) {
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList()); return orderByField(idList).stream().map(this::updateAvatarPath)
.collect(Collectors.toList());
} }
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) { public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
@ -516,16 +531,20 @@ public class UserInfoService {
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId())); predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
} }
if (StringUtils.isNotBlank(queryReq.getMobile())) { if (StringUtils.isNotBlank(queryReq.getMobile())) {
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile())); predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class),
queryReq.getMobile()));
} }
if (StringUtils.isNotBlank(queryReq.getNickName())) { if (StringUtils.isNotBlank(queryReq.getNickName())) {
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%')); predicateList.add(criteriaBuilder.like(root.get("nickName"),
'%' + queryReq.getNickName() + '%'));
} }
if (StringUtils.isNotBlank(queryReq.getBadge())) { if (StringUtils.isNotBlank(queryReq.getBadge())) {
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge())); predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class),
queryReq.getBadge()));
} }
if (Objects.nonNull(queryReq.getStatus())) { if (Objects.nonNull(queryReq.getStatus())) {
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus())); predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class),
queryReq.getStatus()));
} }
/* /*
* if(Objects.nonNull(queryReq.getOnlineStatus())){ * if(Objects.nonNull(queryReq.getOnlineStatus())){
@ -534,11 +553,13 @@ public class UserInfoService {
*/ */
if (Objects.nonNull(queryReq.getCreateDateStart())) { if (Objects.nonNull(queryReq.getCreateDateStart())) {
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class), predicateList.add(
criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
queryReq.getCreateDateStart())); queryReq.getCreateDateStart()));
} }
if (Objects.nonNull(queryReq.getCreateDateEnd())) { if (Objects.nonNull(queryReq.getCreateDateEnd())) {
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class), predicateList.add(
criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
queryReq.getCreateDateEnd())); queryReq.getCreateDateEnd()));
} }
Predicate[] predicates = new Predicate[predicateList.size()]; Predicate[] predicates = new Predicate[predicateList.size()];
@ -569,7 +590,8 @@ public class UserInfoService {
*/ */
public UserInfo findByUserNameAndPassword(String userName, String password) { public UserInfo findByUserNameAndPassword(String userName, String password) {
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName); UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
if (userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) { if (userInfoByUserName != null && encoder.matches(password,
userInfoByUserName.getPassword())) {
return userInfoByUserName; return userInfoByUserName;
} else { } else {
return null; return null;
@ -627,7 +649,8 @@ public class UserInfoService {
throw new BizException(ErrorConstants.REAL_NAME_IS_CHECKED); throw new BizException(ErrorConstants.REAL_NAME_IS_CHECKED);
} }
if (ObjectUtils.equals(UserRealNameStateEnum.FAIL.getCode(), userRealNameCheckDto.getState()) if (ObjectUtils.equals(UserRealNameStateEnum.FAIL.getCode(),
userRealNameCheckDto.getState())
&& StringUtils.isBlank(userRealNameCheckDto.getContent())) { && StringUtils.isBlank(userRealNameCheckDto.getContent())) {
// 必须填写拒绝理由 // 必须填写拒绝理由
throw new BizException(ErrorConstants.REASONS_FOR_REFUSAL_MUST_BE_GIVEN); throw new BizException(ErrorConstants.REASONS_FOR_REFUSAL_MUST_BE_GIVEN);
@ -723,7 +746,8 @@ public class UserInfoService {
userBank.setCreateUser(user.getUserId()); userBank.setCreateUser(user.getUserId());
userBank.setState(UserBankStateEnum.BIND.getCode()); userBank.setState(UserBankStateEnum.BIND.getCode());
List<UserBank> checkList = userBankDao.findAllByBankCardAndStateAndUserId(userBank.getBankCard(), userBank.getState(), userBank.getUserId()); List<UserBank> checkList = userBankDao.findAllByBankCardAndStateAndUserId(
userBank.getBankCard(), userBank.getState(), userBank.getUserId());
if (checkList.isEmpty()) { if (checkList.isEmpty()) {
// 先解绑所有已绑定的银行卡 // 先解绑所有已绑定的银行卡
userBankDao.untieAllCard(user.getUserId()); userBankDao.untieAllCard(user.getUserId());
@ -768,7 +792,8 @@ public class UserInfoService {
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE); throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
} }
return userBankDao.findAllByUserIdAndState(user.getUserId(), UserBankStateEnum.BIND.getCode()); return userBankDao.findAllByUserIdAndState(user.getUserId(),
UserBankStateEnum.BIND.getCode());
} }
/** /**
@ -821,7 +846,9 @@ public class UserInfoService {
List<Withdraw> content = withdrawPage.getContent(); List<Withdraw> content = withdrawPage.getContent();
for (Withdraw withdraw : content) { for (Withdraw withdraw : content) {
if (withdraw.getState() != null) { if (withdraw.getState() != null) {
withdraw.setStateStr(Objects.requireNonNull(WithdrawStateEnum.getByCode(withdraw.getState())).getDesc()); withdraw.setStateStr(
Objects.requireNonNull(WithdrawStateEnum.getByCode(withdraw.getState()))
.getDesc());
} }
} }
return new PageResult<>(totalElements, content); return new PageResult<>(totalElements, content);
@ -888,9 +915,9 @@ public class UserInfoService {
return byId.getInvitationCode(); return byId.getInvitationCode();
} }
String invitationCode = RandomStringUtils.randomNumeric(6); String invitationCode = generateUniqueInvitationCode();
while (userInfoDao.findByInvitationCode(invitationCode) != null) { while (userInfoDao.findByInvitationCode(invitationCode) != null) {
invitationCode = RandomStringUtils.randomNumeric(6); invitationCode = generateUniqueInvitationCode();
} }
byId.setInvitationCode(invitationCode); byId.setInvitationCode(invitationCode);
@ -899,6 +926,16 @@ public class UserInfoService {
return invitationCode; return invitationCode;
} }
/**
*
* @return
*/
private static String generateUniqueInvitationCode() {
String firstTwoChars = RandomStringUtils.random(2, true, false).toUpperCase();
String lastFourChars = RandomStringUtils.randomNumeric(4);
return firstTwoChars + lastFourChars;
}
/** /**
* *
* *

Loading…
Cancel
Save