chengsc
2025-04-19 16865166b741233bad83756ab30899440ecc0dd3
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
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;
using Model.ModelVm;
using WMS.Entity.Context;
using WMS.IBLL.ISysServer;
using Wms.Tools;
using Utility;
 
namespace Wms.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ServiceFilter(typeof(ApiResponseActionFilter))]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };
        private readonly ITokenHelper tokenHelper = null;
        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IUserInforServer _userMan;
        private readonly DataContext Db = new DataContext();
 
        public WeatherForecastController(ITokenHelper _tokenHelper, ILogger<WeatherForecastController> logger, IUserInforServer userMan)
        {
            tokenHelper = _tokenHelper;
            _logger = logger;
            _userMan = userMan;
        }
 
        //[HttpGet]
        //public IEnumerable<WeatherForecast> Get()
        //{
        //    var rng = new Random();
        //    var data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
        //    {
        //        Date = DateTime.Now.AddDays(index),
        //        TemperatureC = rng.Next(-20, 55),
        //        Summary = Summaries[rng.Next(Summaries.Length)]
        //    })
        //    .ToArray();
        //    var list = JsonConvert.SerializeObject(data);
        //    _logger.LogWarning("接收物料转移任务:(" + list + "),");
        //    return data;
        //}
 
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="model">登录名</param> 
        /// <returns></returns>
        [HttpPost]
        public async Task<string> Login(LoginVm model)
        {
            if (ModelState.IsValid)
            {
                var userId = await _userMan.LoginAdmin(model.LoginName, model.LoginPwd);
 
                if (userId != -1) //
                {
                    if (userId != 0) //正确返回
                    {
                        Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
                            {
                                {"loginID", userId.ToString()},
                                {"LoginName", model.LoginName}
                            };
                        var tnToken = tokenHelper.CreateToken(keyValuePairs);
                        return tnToken.TokenStr;
                    }
                    else //当前账号被禁用
                    {
                        //return this.ErrorData($"当前账号已被禁用");
                        throw Oops.Bah("当前账号已被禁用");
                    }
                }
                else //账号密码错误
                {
                    throw Oops.Bah("当前账号或密码错误");
                }
            }
            else //数据格式错误
            {
                throw Oops.Bah("数据格式错误");
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns> 
        //[HttpPost]
        //public IActionResult ceshi()
        //{
        //    //if (ModelState.IsValid)
        //    //{
        //    try
        //    {
        //        //获取当前登录的用户ID
        //        var claimsIdentity = this.User.Identity as ClaimsIdentity;
        //        var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
        //        var bolls = _userMan.CeShi();
 
        //        return Ok(new { code = 200, data = bolls });
 
        //    }
        //    catch (Exception e)
        //    {
        //        return Ok(new { code = 400, ErrorMsg = "请联系管理员/" + e.Message });
        //    }
        //    //}
        //    //else //数据格式错误
        //    //{
        //    //    return Ok(new { code = 400, ErrorMsg = "数据格式错误" });
        //    //}
        //}
    }
}