|
|
@@ -8,6 +8,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.izouma.imt.config.Constants;
|
|
|
import com.izouma.imt.domain.User;
|
|
|
+import com.izouma.imt.domain.vendor.Operating;
|
|
|
import com.izouma.imt.domain.vendor.VendorInfo;
|
|
|
import com.izouma.imt.dto.PageQuery;
|
|
|
import com.izouma.imt.dto.UserDTO;
|
|
|
@@ -16,6 +17,7 @@ import com.izouma.imt.enums.AuthorityName;
|
|
|
import com.izouma.imt.enums.UserIdentity;
|
|
|
import com.izouma.imt.exception.BusinessException;
|
|
|
import com.izouma.imt.repo.UserRepo;
|
|
|
+import com.izouma.imt.repo.vendor.OperatingRepo;
|
|
|
import com.izouma.imt.repo.vendor.VendorInfoRepo;
|
|
|
import com.izouma.imt.security.Authority;
|
|
|
import com.izouma.imt.security.JwtTokenUtil;
|
|
|
@@ -23,6 +25,7 @@ import com.izouma.imt.security.JwtUserFactory;
|
|
|
import com.izouma.imt.service.sms.SmsService;
|
|
|
import com.izouma.imt.service.storage.StorageService;
|
|
|
import com.izouma.imt.utils.JpaUtils;
|
|
|
+import com.izouma.imt.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
@@ -36,7 +39,9 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
@@ -52,6 +57,7 @@ public class UserService {
|
|
|
private JwtTokenUtil jwtTokenUtil;
|
|
|
private CaptchaService captchaService;
|
|
|
private VendorInfoRepo vendorInfoRepo;
|
|
|
+ private OperatingRepo operatingRepo;
|
|
|
|
|
|
public Page<User> all(PageQuery pageQuery) {
|
|
|
return userRepo.findAll(JpaUtils.toSpecification(pageQuery, User.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -184,7 +190,7 @@ public class UserService {
|
|
|
.build());
|
|
|
return user;
|
|
|
}
|
|
|
- if (ObjectUtil.isNull(vendorInfo.getLogo())){
|
|
|
+ if (ObjectUtil.isNull(vendorInfo.getLogo())) {
|
|
|
vendorInfo.setLogo(avatarUrl);
|
|
|
vendorInfoRepo.save(vendorInfo);
|
|
|
}
|
|
|
@@ -206,7 +212,7 @@ public class UserService {
|
|
|
.build());
|
|
|
return user;
|
|
|
}
|
|
|
- if (ObjectUtil.isNull(vendorInfo.getLogo())){
|
|
|
+ if (ObjectUtil.isNull(vendorInfo.getLogo())) {
|
|
|
vendorInfo.setLogo(avatarUrl);
|
|
|
vendorInfoRepo.save(vendorInfo);
|
|
|
}
|
|
|
@@ -312,7 +318,7 @@ public class UserService {
|
|
|
/*
|
|
|
修改邮箱
|
|
|
*/
|
|
|
- public void setEmail(Long userId, String password, String email) {
|
|
|
+ public void setEmail(Long userId, String password, String email, HttpServletRequest request) {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
User byEmail = userRepo.findByEmail(email);
|
|
|
if (ObjectUtil.isNotNull(byEmail)) {
|
|
|
@@ -321,14 +327,26 @@ public class UserService {
|
|
|
if (!new BCryptPasswordEncoder().matches(password, user.getPassword())) {
|
|
|
throw new BusinessException("密码错误");
|
|
|
}
|
|
|
+ String old = user.getEmail();
|
|
|
user.setEmail(email);
|
|
|
userRepo.save(user);
|
|
|
+ vendorInfoRepo.findByUserId(userId).ifPresent(vendorInfo -> {
|
|
|
+ Operating operating = Operating.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .ip(SecurityUtils.getIp2(request))
|
|
|
+ .operate("修改")
|
|
|
+ .time(LocalDateTime.now())
|
|
|
+ .content("邮箱" + old + "为" + email)
|
|
|
+ .vendorInfoId(vendorInfo.getId())
|
|
|
+ .build();
|
|
|
+ operatingRepo.save(operating);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
修改密码
|
|
|
*/
|
|
|
- public String setPassword(Long userId, String oldPassword, String newPassword) {
|
|
|
+ public String setPassword(Long userId, String oldPassword, String newPassword, HttpServletRequest request) {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
|
|
if (!encoder.matches(oldPassword, user.getPassword())) {
|
|
|
@@ -336,6 +354,17 @@ public class UserService {
|
|
|
}
|
|
|
user.setPassword(new BCryptPasswordEncoder().encode(newPassword));
|
|
|
user = userRepo.save(user);
|
|
|
+ vendorInfoRepo.findByUserId(userId).ifPresent(vendorInfo -> {
|
|
|
+ Operating operating = Operating.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .ip(SecurityUtils.getIp2(request))
|
|
|
+ .operate("修改")
|
|
|
+ .time(LocalDateTime.now())
|
|
|
+ .content("密码")
|
|
|
+ .vendorInfoId(vendorInfo.getId())
|
|
|
+ .build();
|
|
|
+ operatingRepo.save(operating);
|
|
|
+ });
|
|
|
return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
|
|
|
}
|
|
|
|
|
|
@@ -389,7 +418,7 @@ public class UserService {
|
|
|
.identity(user.getIdentity())
|
|
|
.chCompanyName(user.getChCompanyName())
|
|
|
.enCompanyName(user.getEnCompanyName())
|
|
|
- .nickname(user.getNickname()+"-子")
|
|
|
+ .nickname(user.getNickname() + "-子")
|
|
|
.del(false)
|
|
|
.build();
|
|
|
|
|
|
@@ -401,7 +430,7 @@ public class UserService {
|
|
|
/*
|
|
|
修改手机号
|
|
|
*/
|
|
|
- public void setPhone(Long userId, String newPhone, String code) {
|
|
|
+ public void setPhone(Long userId, String newPhone, String code, HttpServletRequest request) {
|
|
|
User byPhone = userRepo.findByPhone(newPhone);
|
|
|
if (byPhone != null) {
|
|
|
throw new BusinessException("该手机号已注册");
|
|
|
@@ -413,8 +442,20 @@ public class UserService {
|
|
|
throw new BusinessException("验证码错误");
|
|
|
}
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ String old = user.getPhone();
|
|
|
user.setPhone(newPhone);
|
|
|
userRepo.save(user);
|
|
|
+ vendorInfoRepo.findByUserId(userId).ifPresent(vendorInfo -> {
|
|
|
+ Operating operating = Operating.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .ip(SecurityUtils.getIp2(request))
|
|
|
+ .operate("修改")
|
|
|
+ .time(LocalDateTime.now())
|
|
|
+ .content("手机号" + old + "为" + newPhone)
|
|
|
+ .vendorInfoId(vendorInfo.getId())
|
|
|
+ .build();
|
|
|
+ operatingRepo.save(operating);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -517,7 +558,7 @@ public class UserService {
|
|
|
return users;
|
|
|
}
|
|
|
|
|
|
- public List<Long> getParent(Object userId){
|
|
|
+ public List<Long> getParent(Object userId) {
|
|
|
Long parent = 0L;
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
if (ObjectUtil.isNotNull(userId)) {
|