|
@@ -15,10 +15,7 @@ import com.om.exception.CustomerAuthenticationException;
|
|
|
import com.om.mapper.UserMapper;
|
|
|
import com.om.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.om.utils.AesUtil;
|
|
|
-import com.om.utils.JwtUtils;
|
|
|
-import com.om.utils.Result;
|
|
|
-import com.om.utils.UserContext;
|
|
|
+import com.om.utils.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -71,7 +68,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result<UserLoginVO> login(UserLoginDTO dto) {
|
|
|
+ public Result login(UserLoginDTO dto) {
|
|
|
//从dto中获取数据
|
|
|
String username = dto.getUsername();
|
|
|
String password = dto.getPassword();
|
|
@@ -83,7 +80,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
//判断数据是否为空
|
|
|
if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(clientNum) ||
|
|
|
StringUtils.isBlank(deviceSn) || type == null) {
|
|
|
- throw new BadReqException("数据为空!!");
|
|
|
+ return Result.fail("未获取到数据").result(ResultCode.NO_DATA);
|
|
|
}
|
|
|
|
|
|
//根据用户名查询用户
|
|
@@ -93,25 +90,27 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
//判断用户是否存在
|
|
|
if (BeanUtil.isEmpty(user)) {
|
|
|
- throw new BadReqException("该用户不存在!!");
|
|
|
+ return Result.fail("用户不存在").result(ResultCode.USER_NO_EXIST);
|
|
|
}
|
|
|
|
|
|
|
|
|
//密码加密
|
|
|
try {
|
|
|
password = AesUtil.Encrypt(password);
|
|
|
- System.out.println(password);
|
|
|
} catch (Exception e) {
|
|
|
- throw new BizException("密码加密出错");
|
|
|
+ throw new BizException("密码加密出错",ResultCode.PASSWORD_ENCRYPT_ERROR);
|
|
|
}
|
|
|
//判断密码是否正确
|
|
|
- if (!password.equals(user.getPassword())) {
|
|
|
- throw new BadReqException("密码错误");
|
|
|
+ if (StringUtils.equals(password,user.getPassword())) {
|
|
|
+ return Result.fail("密码错误").result(ResultCode.PASSWORD_ERROR);
|
|
|
}
|
|
|
if (user.getState() == 0) {
|
|
|
- throw new BadReqException("该用户已被禁用");
|
|
|
+ return Result.fail("用户被禁用").result(ResultCode.USER_DISABLED);
|
|
|
}
|
|
|
// 绑定 客户端编号 和 设备 序列号 ( 判断type是登录(0)还是激活(1) )
|
|
|
+ if (!user.getDeviceSn().equals(dto.getDeviceSn())){
|
|
|
+ return Result.error().message("账号尚未激活").result(ResultCode.USER_NO_ACTIVATE);
|
|
|
+ }
|
|
|
if (type == 1) {
|
|
|
user.setDeviceSn(deviceSn);
|
|
|
}
|
|
@@ -144,12 +143,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
if (!BeanUtil.isEmpty(userVciList)) {
|
|
|
List<VciInfoVO> vciInfoVOList = new ArrayList<>();
|
|
|
+ int defaultCount = 0;
|
|
|
for (UserVci userVci : userVciList) {
|
|
|
VciInfoVO vciInfoVO = new VciInfoVO();
|
|
|
Integer vciInfoId = userVci.getVciInfoId();
|
|
|
VciInfo vciInfo = vciInfoService.getById(vciInfoId);
|
|
|
+ if (BeanUtil.isEmpty(vciInfo)){
|
|
|
+ throw new BadReqException("该VCI设备不存在");
|
|
|
+ }
|
|
|
if (userVci.getIsDefault() == 1) {
|
|
|
userLoginVO.setVciSn(vciInfo.getVciNum());
|
|
|
+ defaultCount++;
|
|
|
}
|
|
|
vciInfoVO.setVciNum(vciInfo.getVciNum());
|
|
|
vciInfoVO.setState(String.valueOf(vciInfo.getState()));
|
|
@@ -159,6 +163,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
vciInfoVOList.add(vciInfoVO);
|
|
|
}
|
|
|
+ if (defaultCount!=1){
|
|
|
+ return Result.fail("设备已是默认状态").result(ResultCode.VCI_DEFAULTED);
|
|
|
+ }
|
|
|
|
|
|
userLoginVO.setVciInfoList(vciInfoVOList);
|
|
|
}
|
|
@@ -304,7 +311,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
public Result password(AppUserUpdatePwdDTO dto) {
|
|
|
|
|
|
if (BeanUtil.isEmpty(dto)) {
|
|
|
- throw new BadReqException("参数为空");
|
|
|
+ return Result.fail("未获取到数据").result(ResultCode.NO_DATA);
|
|
|
}
|
|
|
String guid = dto.getGuid();
|
|
|
GuidDTO guidDTO = AesUtil.getGuidDTOFromGuid(guid);
|
|
@@ -313,12 +320,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
User user = getById(userId);
|
|
|
if (user == null) {
|
|
|
- return Result.error();
|
|
|
+ return Result.error().message("用户不存在").result(ResultCode.USER_NO_EXIST);
|
|
|
}
|
|
|
try {
|
|
|
user.setPassword(AesUtil.Encrypt(dto.getNewPassword()));
|
|
|
} catch (Exception e) {
|
|
|
- throw new BizException("密码加密出错");
|
|
|
+ return Result.fail("密码加密出错").result(ResultCode.PASSWORD_ENCRYPT_ERROR);
|
|
|
}
|
|
|
this.updateById(user);
|
|
|
|
|
@@ -330,20 +337,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
public Result register(UserLoginDTO userLoginDTO) {
|
|
|
User user = new User();
|
|
|
if (userLoginDTO.getUsername() == null || userLoginDTO.getPassword() == null) {
|
|
|
- return Result.error().message("用户名密码为空");
|
|
|
+ return Result.error().message("用户名密码为空").result(ResultCode.NO_DATA);
|
|
|
}
|
|
|
if (userLoginDTO.getPassword().equals(userLoginDTO.getRePassword())){
|
|
|
- return Result.error().message("两次密码不一样");
|
|
|
+ return Result.error().message("两次密码不一样").result(ResultCode.PASSWORD_ERROR);
|
|
|
}
|
|
|
user.setUsername(userLoginDTO.getUsername());
|
|
|
try {
|
|
|
user.setPassword(AesUtil.Encrypt(userLoginDTO.getPassword()));
|
|
|
} catch (Exception e) {
|
|
|
- throw new BizException("密码加密出错");
|
|
|
+ return Result.error().message("密码加密错误").result(ResultCode.PASSWORD_ENCRYPT_ERROR);
|
|
|
}
|
|
|
boolean save = save(user);
|
|
|
if (!save) {
|
|
|
- return Result.error();
|
|
|
+ throw new BizException("数据库操作失败");
|
|
|
}
|
|
|
return Result.ok();
|
|
|
}
|
|
@@ -356,7 +363,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
User user = getById(userId);
|
|
|
if (user == null) {
|
|
|
- return Result.error();
|
|
|
+ return Result.error().message("用户不存在").result(ResultCode.USER_NO_EXIST);
|
|
|
}
|
|
|
user.setUsername(dto.getUsername());
|
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
|
@@ -389,7 +396,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
public Result updateVci(AppBaseDTO dto) {
|
|
|
|
|
|
if (BeanUtil.isEmpty(dto)) {
|
|
|
- throw new BadReqException("参数为空");
|
|
|
+ return Result.error().message("参数为空").result(ResultCode.NO_DATA);
|
|
|
}
|
|
|
String guid = dto.getGuid();
|
|
|
GuidDTO guidDTO = AesUtil.getGuidDTOFromGuid(guid);
|
|
@@ -399,7 +406,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
.eq(VciInfo::getVciNum, vciSn)
|
|
|
.one();
|
|
|
if (vciInfo == null) {
|
|
|
- return Result.error();
|
|
|
+ return Result.error().message("VCI设备不存在").result(ResultCode.SERVICE_HANDLE_ERROR);
|
|
|
}
|
|
|
UserVci userVci = userVciService.lambdaQuery()
|
|
|
.eq(UserVci::getUserId, userId)
|
|
@@ -411,7 +418,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
queryWrapper.eq(VciInfo::getId, vciInfo.getId());
|
|
|
boolean update = vciInfoService.update(vciInfo, queryWrapper);
|
|
|
if (!update) {
|
|
|
- return Result.error();
|
|
|
+ throw new BizException("数据库操作失败");
|
|
|
}
|
|
|
|
|
|
return Result.ok();
|
|
@@ -419,13 +426,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
@Override
|
|
|
public Result bindingVci(AppBindVO bindVO) {
|
|
|
+ if (BeanUtil.isEmpty(bindVO)){
|
|
|
+ return Result.error().message("参数为空").result(ResultCode.NO_DATA);
|
|
|
+ }
|
|
|
Integer userId = bindVO.getAppUserId();
|
|
|
String vciNum = bindVO.getSn();
|
|
|
|
|
|
LambdaQueryWrapper<VciInfo> vciInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
vciInfoLambdaQueryWrapper.eq(VciInfo::getVciNum, vciNum);
|
|
|
VciInfo vciInfo = vciInfoService.getOne(vciInfoLambdaQueryWrapper);
|
|
|
-
|
|
|
+ if (vciInfo == null) {
|
|
|
+ return Result.error().message("VCI设备不存在").result(ResultCode.SERVICE_HANDLE_ERROR);
|
|
|
+ }
|
|
|
UserVci userVci = new UserVci();
|
|
|
userVci.setUserId(userId);
|
|
|
userVci.setVciInfoId(vciInfo.getId());
|