|
@@ -6,21 +6,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.om.constant.RedisConstant;
|
|
|
-import com.om.entity.dto.UserLoginDTO;
|
|
|
-import com.om.entity.dto.UserQueryPageDTO;
|
|
|
-import com.om.entity.po.User;
|
|
|
-import com.om.entity.po.UserVci;
|
|
|
-import com.om.entity.po.VciInfo;
|
|
|
+import com.om.entity.dto.*;
|
|
|
+import com.om.entity.po.*;
|
|
|
import com.om.entity.vo.UserAddVO;
|
|
|
import com.om.entity.vo.UserLoginVO;
|
|
|
import com.om.entity.vo.UserQueryPageVO;
|
|
|
+import com.om.entity.vo.VciInfoVO;
|
|
|
import com.om.exception.BadReqException;
|
|
|
import com.om.exception.CustomerAuthenticationException;
|
|
|
import com.om.mapper.UserMapper;
|
|
|
-import com.om.service.IUserService;
|
|
|
+import com.om.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.om.service.IUserVciService;
|
|
|
-import com.om.service.IVciInfoService;
|
|
|
import com.om.utils.JwtUtils;
|
|
|
import com.om.utils.Result;
|
|
|
import com.om.utils.UserContext;
|
|
@@ -32,6 +28,7 @@ import org.springframework.util.DigestUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -67,16 +64,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
@Resource
|
|
|
HttpServletRequest request;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IClientService clientService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IDistributorService distributorService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
- //TODO
|
|
|
- public Result login(UserLoginDTO dto) {
|
|
|
+ public Result<UserLoginVO> login(UserLoginDTO dto) {
|
|
|
//从dto中获取数据
|
|
|
String username = dto.getUsername();
|
|
|
String password = dto.getPassword();
|
|
|
String clientNum = dto.getClientNum();
|
|
|
String deviceSn = dto.getDeviceSn();
|
|
|
Integer type = dto.getType();
|
|
|
+ String appVersion = dto.getAppVersion();
|
|
|
|
|
|
//判断数据是否为空
|
|
|
if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(clientNum) ||
|
|
@@ -101,29 +104,58 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
if (!password.equals(user.getPassword())) {
|
|
|
throw new BadReqException("密码错误");
|
|
|
}
|
|
|
- // TODO 判断用户状态
|
|
|
-
|
|
|
- // TODO 绑定 客户端编号 和 设备 序列号 ( 判断type是登录(0)还是激活(1) )
|
|
|
+ if (user.getState()==0){
|
|
|
+ throw new BadReqException("该用户已被禁用");
|
|
|
+ }
|
|
|
+ // 绑定 客户端编号 和 设备 序列号 ( 判断type是登录(0)还是激活(1) )
|
|
|
+ if (type==1){
|
|
|
+ user.setDeviceSn(deviceSn);
|
|
|
+ }
|
|
|
+ Client client = clientService.lambdaQuery()
|
|
|
+ .eq(Client::getNumber, clientNum)
|
|
|
+ .one();
|
|
|
+ if (BeanUtil.isEmpty(client)){
|
|
|
+ throw new BadReqException("该客户端不存在");
|
|
|
+ }
|
|
|
|
|
|
// 生成token
|
|
|
Map<String, Object> claims = new HashMap<>();
|
|
|
claims.put("u_id", user.getId());
|
|
|
- String token = jwtUtils.generateToken(claims);
|
|
|
- //把token存入到redis中
|
|
|
- String key = RedisConstant.USER_TOKEN_PREFIX + user.getId();
|
|
|
- redisTemplate.opsForValue().set(key, token, RedisConstant.USER_TOKEN_TTL, TimeUnit.SECONDS);
|
|
|
+ claims.put("deviceSn", deviceSn);
|
|
|
+ claims.put("appVersion",appVersion);
|
|
|
+ claims.put("clientNum",clientNum);
|
|
|
+ String guid = jwtUtils.generateToken(claims);
|
|
|
|
|
|
//封装vo返回
|
|
|
UserLoginVO userLoginVO = new UserLoginVO();
|
|
|
- // TODO 查询 该用户所属的 维修厂
|
|
|
+ // 查询 该用户所属的 维修厂
|
|
|
Integer distributorId = user.getDistributorId();//用户所属的维修厂id
|
|
|
-
|
|
|
- //TODO 查询用户 所绑定的vci设备
|
|
|
+ Distributor distributor = distributorService.getById(distributorId);
|
|
|
+ BeanUtil.copyProperties(distributor,userLoginVO);
|
|
|
+
|
|
|
+ // 查询用户 所绑定的vci设备
|
|
|
+ List<UserVci> userVciList = userVciService.lambdaQuery()
|
|
|
+ .eq(UserVci::getUserId, user.getId())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (!BeanUtil.isEmpty(userVciList)){
|
|
|
+ List<VciInfoVO> vciInfoVOList = new ArrayList<>();
|
|
|
+ for (UserVci userVci : userVciList) {
|
|
|
+ VciInfoVO vciInfoVO = new VciInfoVO();
|
|
|
+ Integer vciInfoId = userVci.getVciInfoId();
|
|
|
+ VciInfo vciInfo = vciInfoService.getById(vciInfoId);
|
|
|
+ BeanUtil.copyProperties(vciInfo,vciInfoVO);
|
|
|
+
|
|
|
+ vciInfoVOList.add(vciInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ userLoginVO.setVciInfoList(vciInfoVOList);
|
|
|
+ }
|
|
|
|
|
|
//设置userLoginVO
|
|
|
userLoginVO.setUsername(username);
|
|
|
userLoginVO.setPassword(password);
|
|
|
- userLoginVO.setToken(token);
|
|
|
+ userLoginVO.setGuid(guid);
|
|
|
|
|
|
return Result.ok(userLoginVO);
|
|
|
}
|
|
@@ -238,19 +270,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result password(UserLoginDTO userLoginDTO) {
|
|
|
+ public Result password(AppUserUpdatePwdDTO dto) {
|
|
|
|
|
|
- if (userLoginDTO.getPassword()== userLoginDTO.getRePassword() || userLoginDTO.getRePassword() == null){
|
|
|
- return Result.error();
|
|
|
+ if (BeanUtil.isEmpty(dto)){
|
|
|
+ throw new BadReqException("参数为空");
|
|
|
}
|
|
|
+ String guid = dto.getGuid();
|
|
|
+ GuidDTO guidDTO = jwtUtils.getGuidDTOFromToken(guid);
|
|
|
+ Integer userId = guidDTO.getUserId();
|
|
|
|
|
|
- Integer userId = UserContext.getUserId();
|
|
|
User user = getById(userId);
|
|
|
if (user==null){
|
|
|
return Result.error();
|
|
|
}
|
|
|
- user.setPassword(DigestUtils.md5DigestAsHex(userLoginDTO.getRePassword().getBytes()));
|
|
|
- this.update(user,null);
|
|
|
+ user.setPassword(DigestUtils.md5DigestAsHex(dto.getNewPassword().getBytes()));
|
|
|
+ this.updateById(user);
|
|
|
|
|
|
|
|
|
return Result.ok();
|
|
@@ -272,21 +306,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result updateUserName(UserLoginDTO username) {
|
|
|
- Integer userId = UserContext.getUserId();
|
|
|
+ public Result updateUserName(AppBaseDTO dto) {
|
|
|
+ String guid = dto.getGuid();
|
|
|
+ GuidDTO guidDTO = jwtUtils.getGuidDTOFromToken(guid);
|
|
|
+ Integer userId = guidDTO.getUserId();
|
|
|
+
|
|
|
User user = getById(userId);
|
|
|
if (user==null){
|
|
|
return Result.error();
|
|
|
}
|
|
|
- if (username.getUsername()== user.getUsername() || username.getUsername() == null){
|
|
|
- return Result.error();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- user.setUsername(username.getUsername());
|
|
|
+ user.setUsername(dto.getUsername());
|
|
|
this.update(user,null);
|
|
|
-
|
|
|
-
|
|
|
return Result.ok();
|
|
|
|
|
|
}
|
|
@@ -311,32 +341,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result updateVci(UserLoginDTO userLoginDTO) {
|
|
|
- if (userLoginDTO.getDeviceSn() == null){
|
|
|
- return Result.error();
|
|
|
- }
|
|
|
+ public Result updateVci(AppBaseDTO dto) {
|
|
|
|
|
|
- Integer userId = UserContext.getUserId();
|
|
|
- QueryWrapper<UserVci> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.lambda().eq(UserVci::getUserId,userId);
|
|
|
- UserVci userVci = userVciService.getOne(queryWrapper);
|
|
|
- if (userVci == null){
|
|
|
- return Result.error();
|
|
|
+ if (BeanUtil.isEmpty(dto)){
|
|
|
+ throw new BadReqException("参数为空");
|
|
|
}
|
|
|
- Integer vciInfoId = userVci.getVciInfoId();
|
|
|
- VciInfo vciInfo = vciInfoService.getById(vciInfoId);
|
|
|
+ String guid = dto.getGuid();
|
|
|
+ GuidDTO guidDTO = jwtUtils.getGuidDTOFromToken(guid);
|
|
|
+ Integer userId = guidDTO.getUserId();
|
|
|
+ String vciSn = dto.getVciSn();
|
|
|
+ VciInfo vciInfo = vciInfoService.lambdaQuery()
|
|
|
+ .eq(VciInfo::getVciNum, vciSn)
|
|
|
+ .one();
|
|
|
if (vciInfo == null){
|
|
|
return Result.error();
|
|
|
}
|
|
|
- vciInfo.setVciNum(userLoginDTO.getDeviceSn());
|
|
|
+ UserVci userVci = userVciService.lambdaQuery()
|
|
|
+ .eq(UserVci::getUserId, userId)
|
|
|
+ .eq(UserVci::getIsDefault, true)
|
|
|
+ .one();
|
|
|
+ userVci.setVciInfoId(vciInfo.getId());
|
|
|
+
|
|
|
boolean update = vciInfoService.update(vciInfo, null);
|
|
|
if (!update){
|
|
|
return Result.error();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return Result.ok();
|
|
|
}
|
|
|
}
|