package com.dsh.upms.controller; import cn.mb.cloud.common.core.exception.BusinessException; import cn.mb.cloud.common.core.util.ResponseData; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.dsh.upms.model.vo.LoginUserVo; import com.dsh.upms.service.SysUserService; import com.dsh.utils.login.LoginHelper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; /** * 后台登录控制器 */ @RestController @RequestMapping("/login") @Api("后台登录控制器") public class LoginController { @Autowired private SysUserService sysUserService; /** * 登录 * * @param username * @param password * @return */ // @SysLog("管理员登录") @PostMapping("/submit") @ApiOperation(value = "登录", tags = {"后台登录控制器"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "账号", name = "username", required = true, dataType = "String"), @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "String") }) public ResponseData submit(String username, String password) { try { return new ResponseData<>(sysUserService.login(username, password).getToken()); } catch (BusinessException e) { e.printStackTrace(); return ResponseData.fail(e.getMessage()); } } /** * 退出登录 * * @return */ @GetMapping("/logout") @ApiOperation(value = "退出登录", tags = {"后台登录控制器"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResponseData Logout() { try { return new ResponseData<>(LoginHelper.Logout()); } catch (Exception e) { e.printStackTrace(); return ResponseData.fail(e.getMessage()); } } }