SystemController.cs
4.21 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Enyim.Caching.Configuration;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.Service;
using Hh.Mes.Service.SystemAuth;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MySqlX.XDevAPI.Common;
using NetTaste;
using SqlSugar;
namespace Hh.Mes.Api.Controllers
{
/// <summary>
/// 系统公共的接口
/// ps:新增方法需要在SystemVariable 注册 APIList、EnumLog 新增枚举 ,方便接口日志定位查询
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class SystemController : BaseController
{
private readonly SystemService service;
public SystemController(SystemService systemService, IHttpContextAccessor accessor)
{
service = systemService;
context = accessor.HttpContext;
var sysUserApi = base.GetUser(context);
this.service.sysUserApi = sysUserApi;
}
#region 登入 ,退出,检查版本,获取枚举
/// <summary>
/// app检查
/// </summary>
/// <returns></returns>
[HttpGet]
[ActionName("Mes/V1/base/AppCheckVerByAppNameAndVer")]
public string AppCheckVerByAppNameAndVer(string appId, double ver)
{
var result = service.AppCheckVerByAppNameAndVer(appId, ver);
return Serialize(result);
}
/// <summary>
/// 登入退出 【删除redis,删除 sys_user_online】
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionName("Mes/V1/Login/Logout")]
public string Logout()
{
var token = GetToken(HttpContext);
return Serialize(service.Logout(token));
}
/// <summary>
/// 登入 登入成功后自动在输出到缓存Cookies 头部
/// 其他接口调用前 要先调用登入接口,或者使用配置文件忽略登入验证
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionName("Mes/V1/Login")]
public string Login()
{
string userName = Request.Form["username"].ToString().Trim();
var password = Request.Form["password"].ToString().Trim();
//登录
var result = service.Login(userName, password, Program.AppKey, Program.AppSecret);
bool isOk = result is string;
if (!isOk)
{
//写入cookies
//https://www.cnblogs.com/land/archive/2009/04/10/1433074.html
Response.Cookies.Append(Program.tokens, result.Token);
}
else {
Response.Cookies.Append(Program.tokens, "");
}
return Serialize(result);
}
/// <summary>
/// 判断token是否存在,过期
/// </summary>
[HttpPost]
[ActionName("Mes/V1/AppCheckToken")]
public string AppCheckToken()
{
var token = GetToken(context);
return Serialize(service.AppCheckToken(token));
}
/// <summary>
/// 枚举对象
/// </summary>
/// <returns></returns>
[HttpGet]
[ActionName("Mes/V1/GetState")]
public string GetState()
{
return service.GetState();
}
/// <summary>
/// 获取PDA用户可访问的模块列表
/// </summary>
[HttpPost]
[ActionName("Mes/V1/GetPDAModules")]
public string GetPDAModules()
{
var token = GetToken(context);
return Serialize(service.GetPDAModules(token));
}
#endregion
/// <summary>
/// 第3方登入
/// </summary>
/// <returns></returns>
[HttpGet]
[ActionName("Mes/V1/Login/OtherLogin")]
public string OtherLogin(string token)
{
//登录
var result = service.OtherLogin(token);
//写入cookies
//https://www.cnblogs.com/land/archive/2009/04/10/1433074.html
//Response.Cookies.Append(Program.tokens, result.Token);
return Serialize(result);
}
}
}