分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-05-30 01a80700ea03a332785fb8cbd16aecaf7cce2ccb
´úÂë¹ÜÀí/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs
@@ -63,62 +63,60 @@
                        }
                        agvInWarehousePara outWarehousePara = new agvInWarehousePara()
                        {
                            //WorkOrder = task.jobID,
                            zoneID = inventorys.Key,
                            //processCode = task.agv_worktype.ToString(),
                            details = lists,
                            layerNo = 1,
                            stackID = "1",
                            warehouseName = "Agv库",
                            Operator = UserContext.Current.UserName,
                        };
                        Idt_info_to_mesRepository mesRepository = new dt_info_to_mesRepository(context);
                        var postJson = JsonConvert.SerializeObject(outWarehousePara);
                        var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvOutWarehouse");
                        if (mesData.Contains("连接尝试失败")) throw new Exception(mesData);
                        MES_Response requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData);
                        if (requestMes.code == "200" && requestMes.Type == "success")
                        dt_info_to_mes info_To_Mes = new dt_info_to_mes()
                        {
                            //日志记录上传数据成功
                            WriteWMSLog.LogAdd("", "成功", "MES", "PDA", postJson, mesData, "人工同步MES车轮出库", "agvOutWarehouse", requestMes.message);
                            Info = postJson,
                            ActionName = "agvOutWarehouse",
                            Createtime = DateTime.Now,
                            Remark = "人工同步MES车轮出库",
                            State = false
                        };
                        mesRepository.Add(info_To_Mes, true);
                            foreach (var inventory in inventorys)
                        foreach (var inventory in inventorys)
                        {
                            var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
                            station.quantity = station.quantity - 1;
                            if (station.quantity < 1)
                            {
                                var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
                                station.quantity = station.quantity - 1;
                                if (station.quantity == 0)
                                {
                                    station.stationType = string.Empty;
                                    station.heatNumber = string.Empty;
                                    station.Number = string.Empty;
                                    station.billetID = string.Empty;
                                    station.bindSN = string.Empty;
                                    station.enable = false;
                                    station.tray_status = string.Empty;
                                    station.location_state = LocationStateEnum.Empty.ToString();
                                }
                                else
                                {
                                    var bindSNS = station.bindSN.Split(",");
                                    station.bindSN = OperStr(bindSNS, inventory.SN);
                                    var billetS = station.billetID.Split(",");
                                    station.billetID = OperStr(billetS, inventory.BilletNumber.ToString());
                                }
                                #region å–消跟踪DbContext中被跟踪的实体
                                var currentEntry = stationinfoRepository.DbContext.ChangeTracker.Entries<dt_stationinfo>().FirstOrDefault();
                                if (currentEntry != null) currentEntry.State = EntityState.Detached;
                                #endregion
                                stationinfoRepository.Update(station, true);
                                inventoryRepository.Delete(inventory, true);
                                station.quantity = 0;
                                station.stationType = string.Empty;
                                station.heatNumber = string.Empty;
                                station.Number = string.Empty;
                                station.billetID = string.Empty;
                                station.bindSN = string.Empty;
                                station.enable = false;
                                station.tray_status = string.Empty;
                                station.location_state = LocationStateEnum.Empty.ToString();
                            }
                            WriteDBLog.Write($"人工出库成功 ", $"货位编号:{inventorys.Key};SN号:{str}", LogState.Sucess, "PDA", user);
                            else
                            {
                                var bindSNS = station.bindSN.Split(",");
                                station.bindSN = OperStr(bindSNS, inventory.SN);
                                var billetS = station.billetID.Split(",");
                                station.billetID = OperStr(billetS, inventory.BilletNumber.ToString());
                            }
                            #region å–消跟踪DbContext中被跟踪的实体
                            var currentEntry = stationinfoRepository.DbContext.ChangeTracker.Entries<dt_stationinfo>().FirstOrDefault();
                            if (currentEntry != null) currentEntry.State = EntityState.Detached;
                            #endregion
                            stationinfoRepository.Update(station, true);
                            inventoryRepository.Delete(inventory, true);
                        }
                        else
                        {
                            WriteWMSLog.LogAdd("", "失败", "MES", "PDA", postJson, mesData, "人工同步MES车轮出库", "agvOutWarehouse", requestMes.message);
                            throw new Exception("人工出库同步MES车轮出库失败!" + requestMes.message);
                        }
                        WriteDBLog.Write($"人工出库成功 ", $"货位编号:{inventorys.Key};SN号:{str}", LogState.Sucess, "PDA", user);
                    }
                    catch (Exception ex)
                    {