Blame view

Hh.Mes.Api/Controllers/SystemController.cs 4.21 KB
赖素文 authored
1
2
3
4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
HuXiYu authored
5
using Enyim.Caching.Configuration;
赖素文 authored
6
7
8
9
10
11
12
13
14
15
16
17
18
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>
    /// 系统公共的接口
赖素文 authored
19
    /// ps:新增方法需要在SystemVariable 注册 APIListEnumLog 新增枚举 ,方便接口日志定位查询
赖素文 authored
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    /// </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]
43
        [ActionName("Mes/V1/base/AppCheckVerByAppNameAndVer")]
HuXiYu authored
44
        public string AppCheckVerByAppNameAndVer(string appId, double ver)
赖素文 authored
45
        {
HuXiYu authored
46
            var result = service.AppCheckVerByAppNameAndVer(appId, ver);
赖素文 authored
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
            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>
赖素文 authored
63
64
        /// 登入 登入成功后自动在输出到缓存Cookies 头部
        /// 其他接口调用前 要先调用登入接口,或者使用配置文件忽略登入验证
赖素文 authored
65
66
67
68
69
70
71
72
73
74
        /// </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);
赖素文 authored
75
76
            bool isOk = result is string;
            if (!isOk)
HuXiYu authored
77
78
79
80
81
            {
                //写入cookies
                //https://www.cnblogs.com/land/archive/2009/04/10/1433074.html
                Response.Cookies.Append(Program.tokens, result.Token);
            }
赖素文 authored
82
83
84
            else {
                Response.Cookies.Append(Program.tokens, "");
            }
赖素文 authored
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
            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);
        }
    }
}