You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virtual-patient/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java

41 lines
1.4 KiB
Java

2 years ago
package com.supervision.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
2 years ago
import com.supervision.domain.UserInfo;
import com.supervision.exception.BusinessException;
import com.supervision.model.User;
import com.supervision.service.UserService;
2 years ago
import com.supervision.util.TokenUtil;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
2 years ago
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;
@Api(tags = "用户管理")
2 years ago
@RestController
@RequestMapping("user")
@RequiredArgsConstructor
2 years ago
public class UserController {
private final UserService userService;
2 years ago
@GetMapping("login")
public String login(String userAccount, String password) {
if (!StrUtil.isAllNotBlank(userAccount, password)) {
2 years ago
throw new BusinessException("用户名不能为空");
}
Optional<User> user = userService.lambdaQuery().eq(User::getAccount, userAccount).last("limit 1").oneOpt();
if (!user.isPresent()) {
throw new BusinessException("未找到用户");
}
if (!user.get().getPassword().equals(password)) {
throw new BusinessException("密码错误");
}
return TokenUtil.creatToken(JSONUtil.toJsonStr(user.get()));
2 years ago
}
}