1
cjs
2025-07-04 e3d6e8ddbfc930db88bef1e7f170ddfe71b06cf1
ams/Hanhe.iWCS.JingmenGEMTwoProtocol/ERPService.cs
@@ -1,4 +1,5 @@
using Hanhe.iWCS.Common;
using Hanhe.iWCS.DeviceDriver;
using Hanhe.iWCS.MData;
using Hanhe.iWCS.Model;
using MongoDB.Bson;
@@ -14,10 +15,13 @@
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ApiHelper;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.MESHelper;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.PLCControl;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ProtocolAnalysis;
namespace Hanhe.iWCS.JingmenGEMTwoProtocol
{
@@ -35,6 +39,7 @@
        static WebApiHelper api = new WebApiHelper();
        public const string ERPSwitch01 = "1";// ERP变更流程开关
        public static HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS);
        public static List<string> SendERPTaskType = Settings.SendERPTaskType.Split(',').ToList();//回报任务类型
        public static List<string> LoginInfo = Settings.LoginInfo.Split(',').ToList();// ERP登录接口传输信息
@@ -2035,39 +2040,78 @@
        }
        internal static void senderpTaskDG(string startBit)
        internal static bool senderpTaskDG(string startBit, string trayCode)
        {
            try
            {
                //通过托盘号调用wms接口获取物料信息
                CMMLog.Info("插入SendErpTaskInfoTable 表 开始:" + startBit);
                var erpInfo = MongoDBSingleton.Instance.FindOne<SendErpTaskInfoTable>(Query.EQ("Bit", startBit), "SendErpTaskInfoTable");
                CMMLog.Info("SendErpTaskInfoTableDG 表查询 开始:" + startBit);
                var url = hao.WebUrl + "GlmTrayItemSet";
                var erpInfo = MongoDBSingleton.Instance.FindOne<SendErpTaskInfoTableDG>(Query.EQ("Bit", startBit), "SendErpTaskInfoTableDG");
                if (erpInfo == null)
                {
                    //string fEntryId = time.FEntryID_1.ToString() + (time.FEntryID_2 == 0 ? "" : ";" + time.FEntryID_2.ToString()) + (time.FEntryID_3 == 0 ? "" : ";" + time.FEntryID_3.ToString()) + (time.FEntryID_4 == 0 ? "" : ";" + time.FEntryID_4.ToString());
                    string materiCode = "";
                    string lotCode = "";
                    int totalWeight = 0;
                    string productTime = "";
                    CMMLog.Info("插入SendErpTaskInfoTable 表 1");
                    MongoDBSingleton.Instance.Insert<SendErpTaskInfoTable>(new SendErpTaskInfoTable
                    //根据托盘号获取入库物料信息
                    CJWareNum model = new CJWareNum
                    {
                        Bit = startBit,
                        //materiCode = time.materialCode,
                        //lotCode = time.batchNumber,
                        //productTime = Convert.ToDateTime(time.ProductionDate).AddHours(8),
                        //invalidationTime = Convert.ToDateTime(time.ProductionDate).AddHours(8).AddDays(365),
                        dateTime = DateTime.Now.AddHours(8),
                        //变更注释
                        mesSucess = "0"
                    }, "SendErpTaskInfoTable");
                        TrayCode = trayCode
                    };
                    string msgData = JsonConvert.SerializeObject(model);
                    var feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim();
                    CMMLog.Info($"SendErpTaskInfoTableDG:【调用wms获取物料信息】:接收数据:" + feedback);
                    if (!string.IsNullOrEmpty(feedback))
                    {
                        var wmsResponse = JsonConvert.DeserializeObject<LKInfoResModel>(feedback);
                        if (wmsResponse.Success == true)
                        {
                            materiCode = wmsResponse.Data.CN_S_ITEM_CODE;
                            lotCode = wmsResponse.Data.CN_S_LOT_NO;
                            totalWeight = (int)wmsResponse.Data.CN_F_QUANTITY * wmsResponse.Data.CN_N_CONUT;
                            productTime = wmsResponse.Data.CN_T_PRODUCTION_S;
                        }
                    }
                    CMMLog.Info("SendErpTaskInfoTableDG表 1");
                    if (!string.IsNullOrEmpty(materiCode) && !string.IsNullOrEmpty(lotCode) && totalWeight != 0 && !string.IsNullOrEmpty(productTime))
                    {
                        MongoDBSingleton.Instance.Insert<SendErpTaskInfoTableDG>(new SendErpTaskInfoTableDG
                        {
                            Bit = startBit,
                            materiCode = materiCode,
                            lotCode = lotCode,
                            totalWeight = totalWeight,
                            productTime = Convert.ToDateTime(productTime).AddHours(8),
                            invalidationTime = Convert.ToDateTime(productTime).AddHours(8).AddDays(365),
                            dateTime = DateTime.Now.AddHours(8),
                            //变更注释
                            mesSucess = "0"
                        }, "SendErpTaskInfoTableDG");
                        return true;
                    }
                    else
                    {
                        CMMLog.Info($"SendErpTaskInfoTableDG:获取数据错误,materiCode:{materiCode},lotCode:{lotCode},totalWeight:{totalWeight},productTime:{productTime}");
                    }
                }
                CMMLog.Info("插入SendErpTaskInfoTable 表 结束");
                CMMLog.Info("插入SendErpTaskInfoTableDG表 结束");
            }
            catch (Exception ex)
            {
                CMMLog.Info("插入SendErpTaskInfoTable 表 err:" + ex.Message);
                CMMLog.Info("插入SendErpTaskInfoTableDG表 err:" + ex.Message);
            }
            return false;
        }
        internal static void SendERPTaskCompleteFuncDG()