bklLiudl
2024-06-14 a96cc2b95893bb2e7282a1f581dbc19bb5835700
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
139
140
141
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Model.ModelVm;
using Newtonsoft.Json;
using Utility.Tools;
using WMS.Entity.Context;
using WMS.IBLL.ISysServer;
using Wms.Tools;
 
 
namespace Wms.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    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;
        }
 
        [AllowAnonymous]
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            //Db.Init();
            _logger.LogError("这是记录的信息");
 
           
            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);
            string LogAddress = @".\log\CreatMesTask物料转移" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            LogFile.SaveLogToFile("接收物料转移任务:(" + list + "),", LogAddress);
            return data;
        }
 
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="model">登录名</param> 
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public IActionResult Login(LoginVm model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var bolls = _userMan.LoginAdmin(model.LoginName, model.LoginPwd, out int userId);
 
                    if (bolls) //
                    {
                        if (userId != 0) //正确返回
                        {
                            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
                            {
                                {"loginID", userId.ToString()},
                                {"LoginName", model.LoginName}
                            };
                            var tnToken = tokenHelper.CreateToken(keyValuePairs);
                            return Ok(new { code = 200, ToKen = tnToken });
                        }
                        else //当前账号被禁用
                        {
                            //return this.ErrorData($"当前账号已被禁用");
                            return Ok(new { code = 400, ErrorMsg = "当前账号已被禁用" });
                        }
                    }
                    else //账号密码错误
                    {
                        return Ok(new { code = 400, ErrorMsg = "当前账号或密码错误" });
                    }
                }
                catch (Exception e)
                {
                    return Ok(new { code = 400, ErrorMsg = "请联系管理员/" + e.Message });
                }
            }
            else //数据格式错误
            {
                return Ok(new { code = 400, ErrorMsg = "数据格式错误" });
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns> 
        [AllowAnonymous]
        [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 = "数据格式错误" });
            //}
        }
    }
}