|
@@ -10,6 +10,7 @@ import com.smcic.api.user.entity.User;
|
|
import com.smcic.api.user.mapper.UserMapper;
|
|
import com.smcic.api.user.mapper.UserMapper;
|
|
import com.smcic.api.user.service.IUserService;
|
|
import com.smcic.api.user.service.IUserService;
|
|
import com.smcic.core.advice.APIException;
|
|
import com.smcic.core.advice.APIException;
|
|
|
|
+import com.smcic.core.advice.BizException;
|
|
import com.smcic.core.auth.AESUtil;
|
|
import com.smcic.core.auth.AESUtil;
|
|
import com.smcic.core.auth.HttpContextUtil;
|
|
import com.smcic.core.auth.HttpContextUtil;
|
|
import org.apache.http.util.TextUtils;
|
|
import org.apache.http.util.TextUtils;
|
|
@@ -29,7 +30,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
.oneOpt();
|
|
.oneOpt();
|
|
|
|
|
|
if (!optionalUser.isPresent()) {
|
|
if (!optionalUser.isPresent()) {
|
|
- throw new APIException("用户不存在");
|
|
|
|
|
|
+ throw new BizException("用户不存在");
|
|
}
|
|
}
|
|
|
|
|
|
Long id = optionalUser.get().getId();
|
|
Long id = optionalUser.get().getId();
|
|
@@ -44,12 +45,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
public User getLoginUser() {
|
|
public User getLoginUser() {
|
|
Optional<String> token = HttpContextUtil.getToken();
|
|
Optional<String> token = HttpContextUtil.getToken();
|
|
if (!token.isPresent()) {
|
|
if (!token.isPresent()) {
|
|
- throw new APIException("获取token异常");
|
|
|
|
|
|
+ throw new BizException("获取token异常");
|
|
}
|
|
}
|
|
String userId = AESUtil.decryptStr(token.get());
|
|
String userId = AESUtil.decryptStr(token.get());
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(userId)).one();
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(userId)).one();
|
|
if (user == null) {
|
|
if (user == null) {
|
|
- throw new APIException("用户不存在");
|
|
|
|
|
|
+ throw new BizException("用户不存在");
|
|
}
|
|
}
|
|
|
|
|
|
return user;
|
|
return user;
|
|
@@ -59,7 +60,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
String userId = AESUtil.decryptStr(token);
|
|
String userId = AESUtil.decryptStr(token);
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(userId)).one();
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(userId)).one();
|
|
if (user == null) {
|
|
if (user == null) {
|
|
- throw new APIException("用户不存在");
|
|
|
|
|
|
+ throw new BizException("用户不存在");
|
|
}
|
|
}
|
|
return user;
|
|
return user;
|
|
}
|
|
}
|
|
@@ -84,12 +85,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
public void logout(){
|
|
public void logout(){
|
|
Optional<String> token = HttpContextUtil.getToken();
|
|
Optional<String> token = HttpContextUtil.getToken();
|
|
if (!token.isPresent()) {
|
|
if (!token.isPresent()) {
|
|
- throw new APIException("获取token异常");
|
|
|
|
|
|
+ throw new BizException("获取token异常");
|
|
}
|
|
}
|
|
String userId = AESUtil.decryptStr(token.get());
|
|
String userId = AESUtil.decryptStr(token.get());
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(userId)).one();
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(userId)).one();
|
|
if (user == null) {
|
|
if (user == null) {
|
|
- throw new APIException("用户不存在");
|
|
|
|
|
|
+ throw new BizException("用户不存在");
|
|
}
|
|
}
|
|
user.setLogoutTime(LocalDateTime.now());
|
|
user.setLogoutTime(LocalDateTime.now());
|
|
updateById(user);
|
|
updateById(user);
|
|
@@ -101,7 +102,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
String uid = AESUtil.decryptStr(token.get());
|
|
String uid = AESUtil.decryptStr(token.get());
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(uid)).eq(User::getLoginPassword, pwdResetDTO.getOldPwd()).one();
|
|
User user = this.lambdaQuery().eq(User::getId, Long.parseLong(uid)).eq(User::getLoginPassword, pwdResetDTO.getOldPwd()).one();
|
|
if(null == user){
|
|
if(null == user){
|
|
- throw new APIException(40001, "原密码错误");
|
|
|
|
|
|
+ throw new BizException("原密码错误");
|
|
}
|
|
}
|
|
|
|
|
|
user.setLoginPassword(pwdResetDTO.getPwd());
|
|
user.setLoginPassword(pwdResetDTO.getPwd());
|
|
@@ -114,7 +115,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
public void updateRole(UserDTO userDTO){
|
|
public void updateRole(UserDTO userDTO){
|
|
User user = getById(userDTO.getId());
|
|
User user = getById(userDTO.getId());
|
|
if(null == user){
|
|
if(null == user){
|
|
- throw new APIException(40001, "不存在的用户");
|
|
|
|
|
|
+ throw new BizException("不存在的用户");
|
|
}
|
|
}
|
|
|
|
|
|
if(userDTO.getRoleId() != null && userDTO.getRoleId() > 0)
|
|
if(userDTO.getRoleId() != null && userDTO.getRoleId() > 0)
|