|
|
|
@ -5,14 +5,13 @@ import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.supervision.domain.UserInfo;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.model.User;
|
|
|
|
|
import com.supervision.pojo.vo.LoginReqVO;
|
|
|
|
|
import com.supervision.service.UserService;
|
|
|
|
|
import com.supervision.util.TokenUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
@ -25,16 +24,16 @@ public class UserController {
|
|
|
|
|
private final UserService userService;
|
|
|
|
|
|
|
|
|
|
@ApiOperation("登录")
|
|
|
|
|
@GetMapping("login")
|
|
|
|
|
public String login(String userAccount, String password) {
|
|
|
|
|
if (!StrUtil.isAllNotBlank(userAccount, password)) {
|
|
|
|
|
@PostMapping("login")
|
|
|
|
|
public String login(@RequestBody LoginReqVO reqVO) {
|
|
|
|
|
if (!StrUtil.isAllNotBlank(reqVO.getUserAccount(), reqVO.getPassword())) {
|
|
|
|
|
throw new BusinessException("用户名不能为空");
|
|
|
|
|
}
|
|
|
|
|
Optional<User> user = userService.lambdaQuery().eq(User::getAccount, userAccount).last("limit 1").oneOpt();
|
|
|
|
|
Optional<User> user = userService.lambdaQuery().eq(User::getAccount, reqVO.getUserAccount()).last("limit 1").oneOpt();
|
|
|
|
|
if (!user.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到用户");
|
|
|
|
|
}
|
|
|
|
|
if (!user.get().getPassword().equals(password)) {
|
|
|
|
|
if (!user.get().getPassword().equals(reqVO.getPassword())) {
|
|
|
|
|
throw new BusinessException("密码错误");
|
|
|
|
|
}
|
|
|
|
|
return TokenUtil.creatToken(JSONUtil.toJsonStr(user.get()));
|
|
|
|
|