分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-05-21 2d3d006620bb15a2350c516f050058e5f84c7bf8
´úÂë¹ÜÀí/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs
@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -8,6 +10,7 @@
using WIDESEA_Comm.MES_Info.Request;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Common;
using WIDESEA_Core.BaseProvider;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.ManageUser;
using WIDESEA_Core.Utilities;
@@ -22,6 +25,125 @@
{
    public partial class ToMesServer
    {
        /// <summary>
        /// äººå·¥å‡ºåº“
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent Outsource(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext context = new VOLContext();
            Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context);
            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
            string sn = saveModel.MainData["dataSN"].ToString();   //车轮SN号
            string user = saveModel.MainData["creator"].ToString();
            string str = "";
            try
            {
                List<string> list = new List<string>();
                foreach (var SN in sn.Split(","))
                {
                    if (!string.IsNullOrEmpty(SN))
                        list.Add(SN);
                }
                var inventoryList = inventoryRepository.Find(x => list.Contains(x.SN)).ToList();
                foreach (var inventorys in inventoryList.GroupBy(x => x.stationCode))
                {
                    try
                    {
                        List<detail> lists = new List<detail>();
                        foreach (var inventory in inventorys)
                        {
                            detail detail = new detail();
                            detail.sn = inventory.SN;
                            lists.Add(detail);
                            str += str == "" ? inventory.SN : "," + inventory.SN;
                        }
                        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,
                        };
                        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")
                        {
                            //日志记录上传数据成功
                            WriteWMSLog.LogAdd("", "成功", "MES", "PDA", postJson, mesData, "人工同步MES车轮出库", "agvOutWarehouse", requestMes.message);
                            foreach (var inventory in inventorys)
                            {
                                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);
                            }
                            WriteDBLog.Write($"人工出库成功 ", $"货位编号:{inventorys.Key};SN号:{str}", LogState.Sucess, "PDA", user);
                        }
                        else
                        {
                            WriteWMSLog.LogAdd("", "失败", "MES", "PDA", postJson, mesData, "人工同步MES车轮出库", "agvOutWarehouse", requestMes.message);
                            throw new Exception("人工出库同步MES车轮出库失败!" + requestMes.message);
                        }
                    }
                    catch (Exception ex)
                    {
                        content.Message = ex.Message;
                        WriteDBLog.Write($"人工出库失败 ", new { é”™è¯¯ä¿¡æ¯ = ex.Message, æ•°æ® = str }, LogState.Error, "PDA", user);
                    }
                }
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error($"人工出库失败!:{ex.Message}");
                WriteDBLog.Write($"人工出库失败 ", new { é”™è¯¯ä¿¡æ¯ = ex.Message, æ•°æ® = sn }, LogState.Error, "PDA", user);
            }
            return content;
        }
        public static string OperStr(string[] strArrty, string SN)
        {
            string[] newstr = strArrty.Where(x => x != SN).ToArray();
            string Newsn = string.Join(",", newstr);
            return Newsn;
        }
        /// <summary>
        /// å¤–协出库(检测上料)
        /// </summary>
@@ -75,7 +197,7 @@
                        count++;
                        bindSN += bindSN == "" ? item : "," + item;
                         mes_Work = freeDB.Select<VV_Mes_Workinfo>().Where(x => x.SN == item && x.processCode == "28").First();
                        mes_Work = freeDB.Select<VV_Mes_Workinfo>().Where(x => x.SN == item && x.processCode == "28").First();
                        if (mes_Work == null)
                            return content.Error($"第{count}个车轮无检测上料工单信息,请核查工单后在扫描!");
                        //info = freeDB.Select<dt_mes_detail>().Where(x => x.SN == item).First();