AndonUpMom.cs 3.04 KB
using Hh.Mes.Common.config;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Newtonsoft.Json;


namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        /// <summary>
        /// ANDON信息反馈
        /// </summary>
        /// <remarks>
        /// <para><a href="https://kdocs.cn/l/caBR6DBb2LpP">MOM-产线中控接口文档</a></para>
        /// <para><a href="https://www.bejson.com/">Josn在线解析工具</a></para>
        /// </remarks>
        /// <returns><see cref="Response"/></returns>
        public Response AndonUpMom(AndonUpMomEntity andonUpMomEntity)
        {
            var response = new Response();

            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var resultToken = GetMomToken();
                if (!resultToken.Item1) return response.ResponseError(resultToken.Item2);

                var urlDic = "UrlAndonUpMom" + ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend1;
                var url = GetDictionaryDictValue(urlDic, "GetUrl");
                //var url = "http://10.77.101.247:51001/mom/intf/intfMbosLineTaskAndon/receive";

                #region 测试数据
                //var sendData = new AndonUpMomEntity();
                //var item = new AndonUpMomDetail()
                //{
                //    id = "01",
                //    line_code = "TZTTHW",
                //    device_information = "xxx",
                //    device_fault_type = "xxx",
                //    device_fault_description = "xxx",
                //    device_status = "1",
                //    start_time = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss"),
                //    end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                //    ylzd1 = "1",
                //    type = EnumAction.I.ToString()
                //};
                //sendData.andon_list.Add(item);
                #endregion

                var json = JsonConvert.SerializeObject(andonUpMomEntity);
                //var json = "{\"andon_list\":[{\"id\":\"01\",\"line_code\":\"zjqzzz\",\"device_information\":\"xxx\",\"device_fault_type\":\"xxx\",\"device_fault_description\":\"xxx\",\"device_status\":\"1\",\"start_time\":\"2008-02-21 12:00:00\",\"end_time\":\"2014-02-21 12:00:00\",\"ylzd1\":\"1\",\"type\":\"i\"}]}";

                response = HttpMan(url, json, EnumLog.ANDON报警.ToString(), token: resultToken.Item2);
                if (response.Code == 200)
                {
                    return response.ResponseSuccess();
                }
                //Log4NetHelper.Instance.Error($"【MOM返回结果】" + response.Result);
                MOMResult momResult = JsonConvert.DeserializeObject<MOMResult>(response.Result);
                response.Message = $"【MOM】PLMEID:{momResult.PLMEID},错误原因:{momResult.MSG},STATUS:{momResult.STATUS}";
                response.Result = "";
                return response;
            });
        }

    }
}