|
|
|
@ -8,14 +8,19 @@ import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.model.User;
|
|
|
|
|
import com.supervision.pojo.vo.LoginReqVO;
|
|
|
|
|
import com.supervision.pojo.vo.LoginResVO;
|
|
|
|
|
import com.supervision.pojo.vo.UserInfoReqVo;
|
|
|
|
|
import com.supervision.pojo.vo.UserInfoResVo;
|
|
|
|
|
import com.supervision.service.UserManageService;
|
|
|
|
|
import com.supervision.service.UserService;
|
|
|
|
|
import com.supervision.util.TokenUtil;
|
|
|
|
|
import com.supervision.util.UserUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
@Api(tags = "用户管理")
|
|
|
|
@ -28,6 +33,8 @@ public class UserController {
|
|
|
|
|
|
|
|
|
|
private final RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
|
|
|
|
private final UserManageService userManageService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("登录")
|
|
|
|
|
@PostMapping("login")
|
|
|
|
@ -39,6 +46,9 @@ public class UserController {
|
|
|
|
|
if (!user.isPresent() || !user.get().getPassword().equals(reqVO.getPassword())) {
|
|
|
|
|
throw new BusinessException("用户名或密码有误!");
|
|
|
|
|
}
|
|
|
|
|
// 更新用户最近的登录时间
|
|
|
|
|
user.get().setRecentLoginTime(LocalDateTime.now());
|
|
|
|
|
userService.updateById(user.get());
|
|
|
|
|
String token = TokenUtil.creatToken(JSONUtil.toJsonStr(user.get()));
|
|
|
|
|
|
|
|
|
|
LoginResVO loginResVO = BeanUtil.toBean(user.get(), LoginResVO.class);
|
|
|
|
@ -53,4 +63,20 @@ public class UserController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("修改用户信息")
|
|
|
|
|
@PutMapping("updateUserInfo")
|
|
|
|
|
public boolean updateUserInfo(@RequestBody UserInfoReqVo userInfo) {
|
|
|
|
|
|
|
|
|
|
return userManageService.updateUserInfo(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查看账号信息")
|
|
|
|
|
@GetMapping("getUserAccountInfo")
|
|
|
|
|
public UserInfoResVo getUserAccountInfo() {
|
|
|
|
|
|
|
|
|
|
User user = UserUtil.getUser();
|
|
|
|
|
return userManageService.getUserAccountInfo(user.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|