|
|
@@ -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)) {
|
|
|
@@ -98,14 +99,16 @@ public class UserService {
|
|
|
userRepo.updateOrderMinter(orig.getId());
|
|
|
userRepo.updateHistoryFromUser(orig.getId());
|
|
|
userRepo.updateHistoryToUser(orig.getId());
|
|
|
+ userRepo.updateShowroomToUser(orig.getId());
|
|
|
cacheService.clearCollection();
|
|
|
cacheService.clearUserMy(user.getId());
|
|
|
return orig;
|
|
|
}
|
|
|
|
|
|
public User save(User user) {
|
|
|
- cacheService.clearUserInfo(user.getId());
|
|
|
- cacheService.clearUser(user.getUsername());
|
|
|
+ if (user.getId() != null) {
|
|
|
+ cacheService.clearUserMy(user.getId());
|
|
|
+ }
|
|
|
return userRepo.save(user);
|
|
|
}
|
|
|
|
|
|
@@ -144,18 +147,14 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
public User create(UserRegister userRegister) {
|
|
|
- if (StringUtils.isNoneEmpty(userRegister.getPhone()) && userRepo.findByPhoneAndDelFalse(userRegister.getPhone())
|
|
|
- .orElse(null) != null) {
|
|
|
- throw new BusinessException("该手机号已注册");
|
|
|
- }
|
|
|
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);
|
|
|
+ return save(user);
|
|
|
}
|
|
|
|
|
|
@EventListener
|
|
|
@@ -164,7 +163,7 @@ public class UserService {
|
|
|
user.setNftAccount(event.getAccount().getAccountId());
|
|
|
user.setKmsId(event.getAccount().getAccountKmsId());
|
|
|
user.setPublicKey(event.getAccount().getPublicKey());
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -191,7 +190,6 @@ public class UserService {
|
|
|
}
|
|
|
}
|
|
|
User user = create(UserRegister.builder()
|
|
|
- .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
.username(name)
|
|
|
.nickname(name)
|
|
|
.password(password)
|
|
|
@@ -249,79 +247,14 @@ public class UserService {
|
|
|
return redisTemplate.opsForValue().get("register::" + phone);
|
|
|
}
|
|
|
|
|
|
- public User testPhoneRegister() {
|
|
|
- String 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()
|
|
|
- .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
- .username(name)
|
|
|
- .nickname(name)
|
|
|
- .password(password)
|
|
|
+ public User testPhoneRegister(String phone) {
|
|
|
+ return create(UserRegister.builder()
|
|
|
.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)
|
|
|
+ .username(RandomStringUtils.randomAlphabetic(32))
|
|
|
+ .nickname(RandomStringUtils.randomAlphabetic(32))
|
|
|
+ .phone(RandomStringUtils.randomNumeric(16))
|
|
|
+ .password("123456")
|
|
|
.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;
|
|
|
}
|
|
|
|
|
|
public void del(Long id) {
|
|
|
@@ -333,7 +266,7 @@ public class UserService {
|
|
|
if (StringUtils.isNoneEmpty(user.getPhone())) {
|
|
|
user.setPhone(user.getPhone() + "###" + RandomStringUtils.randomAlphabetic(8));
|
|
|
}
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
//删除实名认证
|
|
|
identityAuthRepo.softDeleteByUserId(id);
|
|
|
}
|
|
|
@@ -364,7 +297,21 @@ 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("账号或密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public User loginByUsernamePwd(String username, String password) {
|
|
|
+ if (StringUtils.isEmpty(username)) {
|
|
|
+ throw new BusinessException("用户名错误");
|
|
|
+ }
|
|
|
+ User user = userRepo.findByUsernameAndDelFalse(username).orElseThrow(new BusinessException("账号或密码错误"));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getPassword())
|
|
|
+ || !passwordEncoder.matches(password, user.getPassword())) {
|
|
|
throw new BusinessException("账号或密码错误");
|
|
|
}
|
|
|
|
|
|
@@ -390,7 +337,7 @@ public class UserService {
|
|
|
.authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
.authStatus(AuthStatus.NOT_AUTH)
|
|
|
.build();
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
}
|
|
|
return user;
|
|
|
}
|
|
|
@@ -419,7 +366,7 @@ public class UserService {
|
|
|
.authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
.authStatus(AuthStatus.NOT_AUTH)
|
|
|
.build();
|
|
|
- userInfo = userRepo.save(userInfo);
|
|
|
+ userInfo = save(userInfo);
|
|
|
return userInfo;
|
|
|
} catch (WxErrorException e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -462,7 +409,7 @@ public class UserService {
|
|
|
.city(wxUserInfo.getCity())
|
|
|
.authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
.build();
|
|
|
- user = userRepo.save(user);
|
|
|
+ user = save(user);
|
|
|
|
|
|
} else {
|
|
|
user.setAvatar(avatarUrl);
|
|
|
@@ -471,7 +418,7 @@ public class UserService {
|
|
|
user.setCountry(wxUserInfo.getCountry());
|
|
|
user.setProvince(wxUserInfo.getProvince());
|
|
|
user.setCity(wxUserInfo.getCity());
|
|
|
- user = userRepo.save(user);
|
|
|
+ user = save(user);
|
|
|
}
|
|
|
|
|
|
return user;
|
|
|
@@ -479,8 +426,8 @@ 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 = userRepo.save(user);
|
|
|
+ user.setPassword(passwordEncoder.encode(password));
|
|
|
+ user = save(user);
|
|
|
return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
|
|
|
}
|
|
|
|
|
|
@@ -508,7 +455,7 @@ public class UserService {
|
|
|
});
|
|
|
|
|
|
user.setPhone(phone);
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
}
|
|
|
|
|
|
public UserDTO toDTO(User user) {
|
|
|
@@ -555,13 +502,13 @@ public class UserService {
|
|
|
if (!StringUtils.equals(phone, user.getPhone())) {
|
|
|
throw new BusinessException("验证码无效");
|
|
|
}
|
|
|
- user.setTradeCode(new BCryptPasswordEncoder().encode(tradeCode));
|
|
|
- userRepo.save(user);
|
|
|
+ user.setTradeCode(passwordEncoder.encode(tradeCode));
|
|
|
+ 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("校验失败");
|
|
|
}
|
|
|
}
|
|
|
@@ -620,13 +567,13 @@ public class UserService {
|
|
|
|
|
|
adapayMerchantService.createMemberForAll(userId.toString(), user.getPhone(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
user.setMemberId(user.getId().toString());
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
|
|
|
String accountId = adapayMerchantService.createSettleAccountForAll
|
|
|
(user.getMemberId(), identityAuth.getRealName(),
|
|
|
identityAuth.getIdNo(), phone, bankNo);
|
|
|
user.setSettleAccountId(Optional.ofNullable(accountId).orElse("1"));
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
|
|
|
userBankCardRepo.save(UserBankCard.builder()
|
|
|
.bank(bankValidate.getBank())
|
|
|
@@ -646,7 +593,7 @@ public class UserService {
|
|
|
if (StringUtils.isNotBlank(user.getSettleAccountId()) && StringUtils.isNotBlank(user.getMemberId())) {
|
|
|
adapayMerchantService.delSettleAccountForAll(user.getMemberId());
|
|
|
user.setSettleAccountId(null);
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
userBankCardRepo.deleteByUserId(userId);
|
|
|
} else {
|
|
|
throw new BusinessException("未绑定");
|
|
|
@@ -657,7 +604,7 @@ public class UserService {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
if (user.getAuthStatus() == AuthStatus.SUCCESS) {
|
|
|
user.setAuthStatus(AuthStatus.NOT_AUTH);
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
identityAuthRepo.deleteAll(identityAuthRepo.findByUserIdAndDelFalse(userId));
|
|
|
}
|
|
|
}
|
|
|
@@ -753,7 +700,7 @@ public class UserService {
|
|
|
userBankCardRepo.save(userBankCard);
|
|
|
} catch (Exception e) {
|
|
|
user.setSettleAccountId(null);
|
|
|
- userRepo.save(user);
|
|
|
+ save(user);
|
|
|
userBankCardRepo.deleteByUserId(user.getId());
|
|
|
}
|
|
|
count.getAndIncrement();
|
|
|
@@ -763,7 +710,10 @@ public class UserService {
|
|
|
|
|
|
@Cacheable(value = "myUserInfo", key = "#id")
|
|
|
public User my(Long id) {
|
|
|
- return userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ User user = userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ user.setPassword(null);
|
|
|
+ user.setTradeCode(null);
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
}
|