| | |
| | | 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; |
| | | |
| | | using Utility; |
| | | |
| | | namespace Wms.Controllers |
| | | { |
| | | [Route("api/[controller]/[action]")] |
| | | [ApiController] |
| | | [Authorize] |
| | | [ServiceFilter(typeof(ApiResponseActionFilter))] |
| | | public class WeatherForecastController : ControllerBase |
| | | { |
| | | private static readonly string[] Summaries = new[] |
| | |
| | | _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; |
| | | } |
| | | //[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> |
| | | [AllowAnonymous] |
| | | [HttpPost] |
| | | public IActionResult Login(LoginVm model) |
| | | public async Task<string> Login(LoginVm model) |
| | | { |
| | | if (ModelState.IsValid) |
| | | { |
| | | try |
| | | { |
| | | var bolls = _userMan.LoginAdmin(model.LoginName, model.LoginPwd, out int userId); |
| | | var userId = await _userMan.LoginAdmin(model.LoginName, model.LoginPwd); |
| | | |
| | | if (bolls) // |
| | | if (userId != -1) // |
| | | { |
| | | if (userId != 0) //正确返回 |
| | | { |
| | | if (userId != 0) //正确返回 |
| | | { |
| | | Dictionary<string, string> keyValuePairs = new Dictionary<string, string> |
| | | 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 = "当前账号已被禁用" }); |
| | | } |
| | | var tnToken = tokenHelper.CreateToken(keyValuePairs); |
| | | return tnToken.TokenStr; |
| | | } |
| | | else //账号密码错误 |
| | | else //当前账号被禁用 |
| | | { |
| | | return Ok(new { code = 400, ErrorMsg = "当前账号或密码错误" }); |
| | | //return this.ErrorData($"当前账号已被禁用"); |
| | | throw Oops.Bah("当前账号已被禁用"); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | else //账号密码错误 |
| | | { |
| | | return Ok(new { code = 400, ErrorMsg = "请联系管理员/" + e.Message }); |
| | | throw Oops.Bah("当前账号或密码错误"); |
| | | } |
| | | } |
| | | else //数据格式错误 |
| | | { |
| | | return Ok(new { code = 400, ErrorMsg = "数据格式错误" }); |
| | | throw Oops.Bah("数据格式错误"); |
| | | } |
| | | } |
| | | /// <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(); |
| | | //[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 = "数据格式错误" }); |
| | | //} |
| | | } |
| | | // 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 = "数据格式错误" }); |
| | | // //} |
| | | //} |
| | | } |
| | | } |