啊鑫
2025-06-05 44a7c47a724c154c54e256727c75e79d31fd42e2
StandardPda/MESApplication/Controllers/Base/LoginController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,146 @@
using System.Dynamic;
using MES.Service.Dto.@base;
using MES.Service.service;
using MES.Service.util;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MESApplication.Controllers.Base;
/// <summary>
///     ç”¨æˆ·
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class LoginController : ControllerBase
{
    /// <summary>
    ///     ç™»å½•
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost("login")]
    public ResponseResult login([FromBody] LoginModel model)
    {
        //登录
        try
        {
            dynamic resultInfos = new ExpandoObject();
            var tbBillList =
                new LoginService().login(model.userID, model.userPass);
            resultInfos.tbBillList = tbBillList;
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    /// <summary>
    ///     é‡è®¾å¯†ç 
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("resetPassword")]
    public ResponseResult resetPassword([FromBody] JObject data)
    {
        var name = data["name"].ToString();
        var pwd = data["pwd"].ToString();
        var newPwd = data["newPwd"].ToString();
        //登录
        try
        {
            dynamic resultInfos = new ExpandoObject();
            var tbBillList =
                new LoginService().resetPassword(newPwd, name, pwd);
            if (tbBillList > 0)
                return new ResponseResult
                {
                    status = 0,
                    message = "修改成功",
                    data = resultInfos
                };
            return new ResponseResult
            {
                status = 1,
                message = "修改失败",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    /// <summary>
    ///     ç”¨æˆ·èœå•
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("getUserMenu")]
    public ResponseResult getUserMenu([FromBody] JObject data)
    {
        var name = data["name"].ToString();
        try
        {
            dynamic resultInfos = new ExpandoObject();
            var tbBillList = new LoginService().getUserMenu(name);
            resultInfos.tbBillList = tbBillList;
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    /// <summary>
    ///     èŽ·å–App最新版本信息
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("getAppUpgradeInfo")]
    public async Task<ResponseResult> getAppUpgradeInfo()
    {
        try
        {
            HttpClient client = new();
            var requestUrl =
                "http://192.168.1.104:8081/UpgradeInformation.json";
            var response = await client.GetAsync(requestUrl);
            response.EnsureSuccessStatusCode(); // æ£€æŸ¥HTTP状态码
            var responseContent = await response.Content.ReadAsStringAsync();
            var a = JsonConvert.DeserializeObject<Root>(responseContent);
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = a
            };
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public class Root
    {
        public string version { get; set; }
        public string apkUrl { get; set; }
    }
}