|
@@ -0,0 +1,50 @@
|
|
1
|
+package com.njyunzhi.invoice.controller;
|
|
2
|
+
|
|
3
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
4
|
+import com.njyunzhi.invoice.common.BaseController;
|
|
5
|
+import com.njyunzhi.invoice.common.ResponseBean;
|
|
6
|
+import com.njyunzhi.invoice.common.StringUtils;
|
|
7
|
+import com.njyunzhi.invoice.entity.SysUser;
|
|
8
|
+import com.njyunzhi.invoice.service.ISysUserService;
|
|
9
|
+import com.njyunzhi.invoice.vo.LoginParm;
|
|
10
|
+import io.swagger.annotations.Api;
|
|
11
|
+import io.swagger.annotations.ApiOperation;
|
|
12
|
+import io.swagger.annotations.ApiParam;
|
|
13
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
14
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
15
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
16
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
17
|
+import org.springframework.web.bind.annotation.RestController;
|
|
18
|
+
|
|
19
|
+import java.util.HashMap;
|
|
20
|
+import java.util.Map;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+@Api(tags ="登录")
|
|
24
|
+@RestController
|
|
25
|
+@RequestMapping("/")
|
|
26
|
+public class LoginController extends BaseController {
|
|
27
|
+
|
|
28
|
+ @Autowired
|
|
29
|
+ ISysUserService iSysUserService;
|
|
30
|
+
|
|
31
|
+ @PostMapping("/admin/login")
|
|
32
|
+ @ApiOperation(value="后台登录", notes = "后台登录", httpMethod = "POST", response = ResponseBean.class)
|
|
33
|
+ public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParm loginParm) throws Exception {
|
|
34
|
+
|
|
35
|
+ if (StringUtils.isEmpty(loginParm.getUserName()) || StringUtils.isEmpty(loginParm.getPassword())) {
|
|
36
|
+ return ResponseBean.error("登录用户或者密码不能为空");
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ SysUser sysUser = iSysUserService.login(loginParm);
|
|
40
|
+
|
|
41
|
+ StpUtil.login(sysUser.getUserId(), "admin");
|
|
42
|
+ String tokenValue = StpUtil.getTokenValue();
|
|
43
|
+
|
|
44
|
+ Map<String, Object> result = new HashMap<>();
|
|
45
|
+ result.put("user", sysUser);
|
|
46
|
+ result.put("token", tokenValue);
|
|
47
|
+
|
|
48
|
+ return ResponseBean.success(result);
|
|
49
|
+ }
|
|
50
|
+}
|