111
cjs
2025-06-17 84c580cccb118f5ec4a039d0009255935c3c2490
ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/WMSHelper.cs
@@ -423,40 +423,31 @@
                        }
                        else
                        {
                            var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("timeStamp", timeStamp), "TimeCuoInfoCom");
                            CMMLog.Info($"WMSIn-{startBit}:{ItemCode}:查询条件:timeStamp={timeStamp},读出 TimeCuoInfoComTwo 表数据为:{JsonConvert.SerializeObject(time)}");
                            if (ItemCode == "time" && time != null)
                            {
                                CMMLog.Info($"WMSIn-{startBit}:time获取时间戳数据为:{time.TimeCuo}!");
                                model.data.Add(new ItemData()
                                {
                                    //1楼拆盘机调WMS获取入库终点,传输时间戳数据(暂定)
                                    //isFold = time.isFold,
                                    //packingMachineNumber = time.packingMachineNumber,
                                    itemCode = time.productModel,
                                    lotNo = time.lotNo,
                                    machineNo = time.packingMachineNumber1.ToString(),
                                    packageCode = time.bagNumber1.ToString(),
                                    //palletLayers = time.bagNumber1.ToString(),
                                    foldingbag = time.isFold1.ToString(),
                                    //totalWeight = time.totalWeight,
                                    timeStamp = int.Parse(time.TimeCuo),
                                    //productType = time.productModel,
                                    //bagNumber = time.bagNumber,
                                    //needWeight = time.needWeight,
                                    realWeight = time.realWeight1,
                                    //batchNumber = time.batchNumber,
                                    //totalCount = time.totalCount,
                                    Jm_Item_Code = time.materialCode,
                                    Jm_Item_Name = time.materialName,
                                    Jm_Item_Model = time.productModel,
                                    Jm_Item_Unit = time.measurementUnit,
                                    Jm_Item_Staff = employee_id
                                });
                            }
                            //var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("timeStamp", timeStamp), "TimeCuoInfoCom");
                            //CMMLog.Info($"WMSIn-{startBit}:{ItemCode}:查询条件:timeStamp={timeStamp},读出 TimeCuoInfoComTwo 表数据为:{JsonConvert.SerializeObject(time)}");
                            //var erpItemTableInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(Query.EQ("item_code", time.materialCode), "ERPItemTable");
                            //CMMLog.Info($"WMSIn-{startBit}:查询条件:item_code={time.materialCode},读出 ERPItemTable 表数据为:{JsonConvert.SerializeObject(erpItemTableInfo)}");
                            //if (ItemCode == "time" && time != null && erpItemTableInfo != null)
                            //{
                            //    CMMLog.Info($"WMSIn-{startBit}:time获取时间戳数据为:{time.TimeCuo}!");
                            //    model.data.Add(new ItemData()
                            //    {
                            //        itemCode = time.productModel,
                            //        lotNo = time.lotNo,
                            //        machineNo = time.packingMachineNumber1.ToString(),
                            //        packageCode = time.bagNumber1.ToString(),
                            //        foldingbag = time.isFold1.ToString(),
                            //        timeStamp = int.Parse(time.TimeCuo),
                            //        realWeight = time.realWeight1,
                            //
                            //        Jm_Item_Code = time.materialCode,
                            //        Jm_Item_Name = time.materialName,
                            //        Jm_Item_Model = time.productModel,
                            //        Jm_Item_Unit = time.measurementUnit,
                            //        Jm_Item_Staff = employee_id
                            //    });
                            //}
                        }
                    }
                    else
                    {
@@ -539,6 +530,233 @@
            return result;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="startBit"></param>
        /// <param name="ItemCode"></param>
        /// <param name="taskNo"></param>
        /// <param name="trayCode"></param>
        /// <param name="timeStamp"></param>
        /// <param name="employee_id">员工编码</param>
        /// <returns></returns>
        public static bool WMSInTwo(string startBit, string ItemCode, ref string taskNo, ref string trayCode, string timeStamp = "", string employee_id = "", bool isTwo = false, string trayType = "")
        {
            //XMZ001A11-1
            //startBit = startBit.Substring(0, 9);
            bool result = false;
            HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS);
            string msg = "";
            if (hao != null)
            {
                //http://192.168.1.199:9001/api/wmsapi/InWorkArea
                WMSInModel model = new WMSInModel();
                model.startBit = startBit;
                model.isTransport = "N";
                model.needCreateAMSTask = "Y";
                model.projectCode = "glm";
                model.trayType = trayType;
                model.data = new List<ItemData>();
                CMMLog.Info($"WMSInTwo-{startBit}:ItemCode类型为:{ItemCode}");
                if (!string.IsNullOrEmpty(ItemCode))
                {
                    //var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.Or(Query.EQ("isNeedTray", 1), Query.EQ("isNeedTray", 2)), "TimeCuoInfoCom");
                    if (ItemCode == "time" || ItemCode == "拆盘变更")
                    {
                        if (!isTwo)
                        {
                            int timeInt = int.Parse(trayCode);
                            var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.EQ("timeStamp", timeInt), "TimeCuoInfoCom");
                            CMMLog.Info($"WMSInTwo-{startBit}:{ItemCode}:查询条件:timeStamp={timeInt},读出 TimeCuoInfoCom 表数据为:{JsonConvert.SerializeObject(time)}");
                            if (ItemCode == "time" && time != null)
                            {
                                int TimeStamp = string.IsNullOrEmpty(timeStamp) ? time.timeStamp : int.Parse(timeStamp);
                                CMMLog.Info($"WMSInTwo-{startBit}:time获取时间戳数据为:{TimeStamp}!");
                                model.data.Add(new ItemData()
                                {
                                    //1楼拆盘机调WMS获取入库终点,传输时间戳数据(暂定)
                                    //isFold = time.isFold,
                                    //packingMachineNumber = time.packingMachineNumber,
                                    itemCode = time.productModel,
                                    lotNo = time.batchNumber,
                                    machineNo = time.packingMachineNumber.ToString(),
                                    packageCode = time.bagNumber,
                                    palletLayers = time.isNeedTray.ToString(),
                                    foldingbag = time.isFold.ToString(),
                                    //totalWeight = time.totalWeight,
                                    timeStamp = TimeStamp,
                                    photoURL = time.photoURL,
                                    //productType = time.productModel,
                                    //bagNumber = time.bagNumber,
                                    //needWeight = time.needWeight,
                                    realWeight = time.realWeight,
                                    //batchNumber = time.batchNumber,
                                    //totalCount = time.totalCount,
                                    Jm_Item_Code = time.materialCode,
                                    Jm_Item_Name = time.materialName,
                                    Jm_Item_Model = time.productModel,
                                    Jm_Item_Unit = time.measurementUnit,
                                    Jm_Item_Staff = employee_id
                                });
                                // 非ERP变更流程可以直接删除 TimeCuoInfoCom 表
                                if (ERPService.ERPSwitch01 == "0")
                                {
                                    CMMLog.Info($"WMSInTwo-{startBit}:查询条件:timeStamp={timeInt},非ERP变更流程直接删除 TimeCuoInfoCom 表!");
                                    MongoDBSingleton.Instance.Remove<TimeCuoInfoCom>(Query.EQ("timeStamp", timeInt), RemoveFlags.Single);
                                }
                            }
                            else if (ItemCode == "拆盘变更")
                            {
                                model.data.Add(new ItemData()
                                {
                                    //1楼拆盘机调WMS获取入库终点,传输时间戳数据(暂定)
                                    //isFold = time.isFold,
                                    //packingMachineNumber = time.packingMachineNumber,
                                    itemCode = "1",
                                    lotNo = "1",
                                    machineNo = "1",
                                    packageCode = "1",
                                    palletLayers = "1",
                                    foldingbag = "1",
                                    //totalWeight = time.totalWeight,
                                    timeStamp = 1,
                                    photoURL = "1",
                                    //productType = time.productModel,
                                    //bagNumber = time.bagNumber,
                                    //needWeight = time.needWeight,
                                    realWeight = 1,
                                    //batchNumber = time.batchNumber,
                                    //totalCount = time.totalCount,
                                });
                            }
                        }
                        else
                        {
                            //var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("timeStamp", timeStamp), "TimeCuoInfoCom");
                            //CMMLog.Info($"WMSInTwo-{startBit}:{ItemCode}:查询条件:timeStamp={timeStamp},读出 TimeCuoInfoComTwo 表数据为:{JsonConvert.SerializeObject(time)}");
                            //if (ItemCode == "time" && time != null)
                            //{
                            //    CMMLog.Info($"WMSInTwo-{startBit}:time获取时间戳数据为:{time.TimeCuo}!");
                            //    model.data.Add(new ItemData()
                            //    {
                            //        //1楼拆盘机调WMS获取入库终点,传输时间戳数据(暂定)
                            //        //isFold = time.isFold,
                            //        //packingMachineNumber = time.packingMachineNumber,
                            //        itemCode = time.productModel,
                            //        lotNo = time.lotNo,
                            //        machineNo = time.packingMachineNumber1.ToString(),
                            //        packageCode = time.bagNumber1.ToString(),
                            //        //palletLayers = time.bagNumber1.ToString(),
                            //        foldingbag = time.isFold1.ToString(),
                            //        //totalWeight = time.totalWeight,
                            //        timeStamp = int.Parse(time.TimeCuo),
                            //        //productType = time.productModel,
                            //        //bagNumber = time.bagNumber,
                            //        //needWeight = time.needWeight,
                            //        realWeight = time.realWeight1,
                            //        //batchNumber = time.batchNumber,
                            //        //totalCount = time.totalCount,
                            //
                            //        Jm_Item_Code = time.materialCode,
                            //        Jm_Item_Name = time.materialName,
                            //        Jm_Item_Model = time.productModel,
                            //        Jm_Item_Unit = time.measurementUnit,
                            //        Jm_Item_Staff = employee_id
                            //    });
                            //}
                        }
                    }
                    else
                    {
                        var info = MongoDBSingleton.Instance.FindOne<MachineInfoTetracobalt>(Query.EQ("trayCode", ItemCode), "MachineInfoTetracobalt");
                        // ERP变更新增数据直接从  ERP物料中间表-ERPItemTable 获取(根据物料编码)
                        CMMLog.Info($"WMSInTwo-{startBit}:查询条件:trayCode={ItemCode},读出 MachineInfoTetracobalt 表数据为:{JsonConvert.SerializeObject(info)}");
                        if (info != null)
                        {
                            var erpItemTableInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(Query.EQ("item_code", info.materialCode), "ERPItemTable");
                            CMMLog.Info($"WMSInTwo-{startBit}:查询条件:item_code={info.materialCode},读出 ERPItemTable 表数据为:{JsonConvert.SerializeObject(erpItemTableInfo)}");
                            model.locationGear = info.secondNg.ToString();
                            model.trayCode = info.trayCode;
                            string product = !string.IsNullOrEmpty(info.productType) ? info.productType : erpItemTableInfo.item_spec;
                            model.data.Add(new ItemData()
                            {
                                itemCode = product,
                                lotNo = info.lotNo,
                                machineNo = info.machineNo,
                                packageCode = info.packageCode,
                                palletLayers = info.palletLayers,
                                foldingbag = info.overlappingLayers,
                                itemState = info.secondNg,
                                productWeight = info.productWeight,
                                trayCodeWeight = info.trayCodeWeight,
                                oneTrayWeight = info.oneTrayWeight,
                                //bagNo = info.bagNo,
                                //productType = info.productType,
                                //materialCode = info.materialCode,
                                //location = info.location,
                                //addWeight = info.addWeight,
                                //packNg = info.packNg,
                                //addState = info.addState,
                                Jm_Item_Code = info.materialCode,
                                Jm_Item_Name = erpItemTableInfo.item_name,
                                Jm_Item_Model = erpItemTableInfo.item_spec,
                                Jm_Item_Unit = erpItemTableInfo.item_uom,
                                Jm_Item_Staff = info.trayCodeWeight
                            });
                        }
                    }
                }
                string msgData = JsonConvert.SerializeObject(model);
                string reqStr = "物料名=" + ItemCode + ";数量";
                string feedback = "";
                CMMLog.Info($"WMSInTwo-{startBit}:【调用wms获取入库货位】:发送数据:{JsonConvert.SerializeObject(msgData)},物料条件:ItemCode:{ItemCode},trayCode:{trayCode}");
                var url = hao.WebUrl + "GlmInSendTask";
                try
                {
                    //hao.WebUrl = "http://192.168.1.199:9001/api/";
                    feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim();
                    Console.WriteLine(feedback);
                    CMMLog.Info($"WMSInTwo-{startBit}:【调用wms获取入库货位】:接收数据:" + feedback);
                    if (!string.IsNullOrEmpty(feedback))
                    {
                        //var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(feedback.Substring(1, feedback.Length - 2));
                        var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(feedback);
                        //var res = feedback.Replace("{", "").Replace("}", "").Replace(":", "=").Replace(",", ";").Replace('"', ' ');
                        if (wmsResponse.Success == true)
                        {
                            msg = $"WMSInTwo-{startBit}:【调用wms获取入库货位】成功!返回结果=" + wmsResponse.Success + ";调用WebUrl=" + url + ";输入参数=" + msgData;
                        }
                        else
                        {
                            string errMsg = wmsResponse.Code + "-" + wmsResponse.Msg;
                            msg = $"WMSInTwo-{startBit}:【调用wms获取入库货位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData;
                        }
                        result = wmsResponse.Success;
                    }
                    else
                    {
                        string errMsg = "参数反馈空值";
                        msg = $"WMSInTwo-{startBit}:【调用wms获取入库货位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData;
                    }
                }
                catch (Exception e)
                {
                    CMMLog.Error(string.Format($"WMSInTwo-{startBit}:【调用wms获取入库货位失败】异常{0}", e.Message), e);
                    msg = $"WMSInTwo-{startBit}:【调用wms获取入库货位】失败!解析返回值出错=" + feedback + ";调用WebUrl=" + url + ";输入参数=" + msgData;
                }
            }
            else msg = string.Format($"WMSInTwo-{startBit}:调用wms失败,ams工作中心没有设置!");
            CMMLog.Info(msg);
            Console.WriteLine(msg);
            return result;
        }
        public static bool WMSOut(string endBit, string ItemCode) {
            //endBit = endBit.Substring(0, 9);
            bool result = false;