|
|
@@ -45,7 +45,7 @@ import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
@@ -81,6 +81,7 @@ public class UserService {
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
private GeneralProperties generalProperties;
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private PasswordEncoder passwordEncoder;
|
|
|
|
|
|
public User update(User user) {
|
|
|
if (!SecurityUtils.hasRole(AuthorityName.ROLE_ADMIN)) {
|
|
|
@@ -145,14 +146,33 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
public User create(UserRegister userRegister) {
|
|
|
+ long ts = System.currentTimeMillis();
|
|
|
User user = new User();
|
|
|
BeanUtils.copyProperties(userRegister, user);
|
|
|
user.setShareRatio(sysConfigService.getBigDecimal("share_ratio"));
|
|
|
user.setAuthStatus(AuthStatus.NOT_AUTH);
|
|
|
if (StringUtils.isNotBlank(userRegister.getPassword())) {
|
|
|
- user.setPassword(new BCryptPasswordEncoder().encode(userRegister.getPassword()));
|
|
|
+ user.setPassword(passwordEncoder.encode(userRegister.getPassword()));
|
|
|
}
|
|
|
- return userRepo.save(user);
|
|
|
+ log.info("copy user {}ms", System.currentTimeMillis() - ts);
|
|
|
+ ts = System.currentTimeMillis();
|
|
|
+ user = userRepo.save(user);
|
|
|
+ log.info("save user {}ms", System.currentTimeMillis() - ts);
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public User create(String username, String phone, String password) {
|
|
|
+ long ts = System.currentTimeMillis();
|
|
|
+ User user = new User();
|
|
|
+ user.setUsername(username);
|
|
|
+ user.setPhone(phone);
|
|
|
+ user.setShareRatio(BigDecimal.ZERO);
|
|
|
+ user.setAuthStatus(AuthStatus.NOT_AUTH);
|
|
|
+ log.info("copy user {}ms", System.currentTimeMillis() - ts);
|
|
|
+ ts = System.currentTimeMillis();
|
|
|
+ user = userRepo.save(user);
|
|
|
+ log.info("save user {}ms", System.currentTimeMillis() - ts);
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
@EventListener
|
|
|
@@ -246,79 +266,8 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
public User testPhoneRegister(String phone) {
|
|
|
- if (phone == null) {
|
|
|
- phone = "19" + RandomStringUtils.randomNumeric(11);
|
|
|
- }
|
|
|
- String password = "123456";
|
|
|
- String inviteCode = null;
|
|
|
- Long invitor = null;
|
|
|
- Long collectionId = null;
|
|
|
- String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
|
|
|
- Invite invite = null;
|
|
|
- if (StringUtils.isNotBlank(inviteCode)) {
|
|
|
- invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
|
|
|
- }
|
|
|
- Collection collection;
|
|
|
- if (collectionId != null) {
|
|
|
- collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
|
|
|
-// if (!collection.isOnShelf() || !collection.isSalable()) {
|
|
|
-// collectionId = null;
|
|
|
-// } else if (collection.isScheduleSale()) {
|
|
|
-// if (collection.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
-// collectionId = null;
|
|
|
-// }
|
|
|
-// }
|
|
|
- // 只看是否开去分享
|
|
|
- if (ObjectUtils.isEmpty(collection.getOpenQuota()) || !collection.getOpenQuota()) {
|
|
|
- collectionId = null;
|
|
|
- }
|
|
|
- }
|
|
|
- User user = create(UserRegister.builder()
|
|
|
- .username(name)
|
|
|
- .nickname(name)
|
|
|
- .password(password)
|
|
|
- .avatar(Constants.DEFAULT_AVATAR)
|
|
|
- .phone(phone)
|
|
|
- .invitorPhone(Optional.ofNullable(invite).map(Invite::getPhone).orElse(null))
|
|
|
- .invitorName(Optional.ofNullable(invite).map(Invite::getName).orElse(null))
|
|
|
- .inviteCode(Optional.ofNullable(invite).map(Invite::getCode).orElse(null))
|
|
|
- .collectionInvitor(invitor)
|
|
|
- .collectionId(collectionId)
|
|
|
- .build());
|
|
|
- if (invite != null) {
|
|
|
- inviteRepo.increaseNum(invite.getId());
|
|
|
- }
|
|
|
-
|
|
|
- // 加积分
|
|
|
-// if (collectionId != null && invitor != null) {
|
|
|
-// // 额度或者额度为空, 库存不为空
|
|
|
-// if (collection.getStock() > 0 && (collection.getVipQuota() > 0 || ObjectUtils.isEmpty(collection.getVipQuota()))) {
|
|
|
-// int countUser = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
-// // 邀请人数
|
|
|
-// if (countUser >= collection.getAssignment()) {
|
|
|
-// int point = pointRecordRepo.countByUserIdAndCollectionId(invitor, collectionId);
|
|
|
-// // 是否已有积分
|
|
|
-// if (point <= 0) {
|
|
|
-// long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
-// if (count >= collection.getAssignment()) {
|
|
|
-// // 扣除藏品额度
|
|
|
-// if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
|
|
|
-// collectionService.decreaseQuota(collectionId, 1);
|
|
|
-// }
|
|
|
-// userRepo.updateVipPoint(invitor, 1);
|
|
|
-// pointRecordRepo.save(PointRecord.builder()
|
|
|
-// .collectionId(collectionId)
|
|
|
-// .userId(invitor)
|
|
|
-// .type("VIP_POINT")
|
|
|
-// .point(1)
|
|
|
-// .build());
|
|
|
-//
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- return user;
|
|
|
+ return create(RandomStringUtils.randomNumeric(30),
|
|
|
+ RandomStringUtils.randomNumeric(30), "123456");
|
|
|
}
|
|
|
|
|
|
public void del(Long id) {
|
|
|
@@ -361,7 +310,7 @@ public class UserService {
|
|
|
throw new BusinessException("账号或密码错误");
|
|
|
}
|
|
|
if (StringUtils.isNoneEmpty(user.getPassword()) &&
|
|
|
- !new BCryptPasswordEncoder().matches(password, user.getPassword())) {
|
|
|
+ !passwordEncoder.matches(password, user.getPassword())) {
|
|
|
throw new BusinessException("账号或密码错误");
|
|
|
}
|
|
|
|
|
|
@@ -476,7 +425,7 @@ public class UserService {
|
|
|
|
|
|
public String setPassword(Long userId, String password) {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
- user.setPassword(new BCryptPasswordEncoder().encode(password));
|
|
|
+ user.setPassword(passwordEncoder.encode(password));
|
|
|
user = userRepo.save(user);
|
|
|
return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
|
|
|
}
|
|
|
@@ -552,13 +501,13 @@ public class UserService {
|
|
|
if (!StringUtils.equals(phone, user.getPhone())) {
|
|
|
throw new BusinessException("验证码无效");
|
|
|
}
|
|
|
- user.setTradeCode(new BCryptPasswordEncoder().encode(tradeCode));
|
|
|
+ user.setTradeCode(passwordEncoder.encode(tradeCode));
|
|
|
userRepo.save(user);
|
|
|
}
|
|
|
|
|
|
public void verifyTradeCode(Long userId, String tradeCode) {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
- if (!new BCryptPasswordEncoder().matches(tradeCode, user.getTradeCode())) {
|
|
|
+ if (!passwordEncoder.matches(tradeCode, user.getTradeCode())) {
|
|
|
throw new BusinessException("校验失败");
|
|
|
}
|
|
|
}
|