MaterialUpCict.cs 3.42 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.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Newtonsoft.Json;
using NPOI.POIFS.FileSystem;
using System;
using System.Collections.Generic;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        /// <summary>
        /// 信科物料基础信息 同步
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public Response MaterialUpCict()
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT<Response>(() =>
            {
                var urlDic = "UrlMaterialCict" + ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend1;//AppCustomExtend1:"_onLine/_off"
                var url = GetDictionaryDictValue(urlDic, "GetUrl")+ "api/BulletinBoard/Mes/V1/ReadData1";
                //var url = GetDictionaryDictValue(urlDic, "GetUrl") + "wms/sszx/material/queryForMes";//海能发实际地址
        
                response = HttpMan(url, null, EnumLog.Cict物料信息反馈.ToString(), method:"get");
                if (response.Code == 200)
                {
                    //do someing 
                    var cictResult = JsonConvert.DeserializeObject<MaterialUpCictEntity>(response.Result);
                    response.Message = SystemVariable.dataActionOk;
                    response.Result = null;
                    return response;
                }
                //Log4NetHelper.Instance.Error($"【返回结果】" + response.Result);
                response.Result =null;
                return response.ResponseError($"【信科】物料基础信息同步错误,原因:{response.Message}");
            });
        }


        private dynamic HandleData(List<base_material> list)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                foreach (var model in list)
                {
                    var isExist = Context.Queryable<base_material>().Where(i => i.id == model.id).ToList();
                    if (isExist.Count < 0)
                    {
                        var rate = new base_material_rate
                        {
                            materialCode = model.materialCode,
                            materialName = model.materialName,
                            mtClassify = model.mtClassify,
                            unitCode = model.unitCode,
                            specifications = model.specifications,
                            materialKeys = model.keys,
                            quantityRate = 1,
                            createBy = model.createBy,
                            createTime = DateTime.Now,//?
                        };
                        Context.Insertable<base_material>(model).AddQueue();
                        Context.Insertable<base_material_rate>(model).AddQueue();
                        Context.SaveQueues();
                    }
                    else
                    {
                        response.Status = Context.Updateable(model).Where(u => u.id == model.id).ExecuteCommand() > 0;
                        if (!response.Status) response.Message = SystemVariable.dataActionError;
                    }
                }
                return response;
            });
        }
    }
}