huyao
2022-09-29 50e0d4741b19a5071741b200ff76a4d69504fce3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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());
        }
    }
}