From bb929bd0809eefc1108dd779846ff07d997f7ef0 Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期五, 19 七月 2024 09:25:14 +0800
Subject: [PATCH] 反馈MES工单完成

---
 代码管理/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs |  281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 280 insertions(+), 1 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs"
index a893838..a1ca6f8 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs"
@@ -17,6 +17,26 @@
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.AspNetCore.Http;
 using WIDESEA_WMS.IRepositories;
+using System.Configuration;
+using WIDESEA_Comm.LogInfo;
+using WIDESEA_Core.ManageUser;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using WIDESEA_Core.EFDbContext;
+using WIDESEA_WMS.Repositories;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using static WIDESEA_Comm.MES_Info.BasicSN;
+using System.Collections;
+using static FreeSql.Internal.GlobalFilter;
+using WIDESEA_Comm.MES_Info.Request;
+using System.Xml.Linq;
+using Newtonsoft.Json;
+using Confluent.Kafka;
+using WIDESEA_WMS.Common;
+using WIDESEA_Comm.MES_Info;
+using System.Reflection;
+using static System.Collections.Specialized.BitVector32;
+using WIDESEA_Comm;
 
 namespace WIDESEA_WMS.Services
 {
@@ -37,5 +57,264 @@
             //澶氱鎴蜂細鐢ㄥ埌杩檌nit浠g爜锛屽叾浠栨儏鍐靛彲浠ヤ笉鐢�
             //base.Init(dbRepository);
         }
-  }
+
+
+        /// <summary>
+        /// 娣诲姞搴撳瓨
+        /// </summary>
+        /// <param name="saveDataModel"></param>
+        /// <returns></returns>
+        public override WebResponseContent Add(SaveModel saveDataModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            VOLContext context = new VOLContext();
+            IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
+            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+            var stationCode = saveDataModel.MainData["stationCode"].ToString();
+            try
+            {
+                if (string.IsNullOrEmpty(stationCode)) throw new Exception($"缂撳瓨鏋剁紪鍙蜂笉鑳戒负绌�!");
+                if (!stationCode.Contains("B") && !stationCode.Contains("C") && !stationCode.Contains("D")) throw new Exception($"缂撳瓨鏋剁被鍨嬫湁璇�!");
+                var station = stationinfoRepository.Find(x => x.stationCode == stationCode).FirstOrDefault();
+                if (station == null) throw new Exception($"鏈壘鍒拌揣浣峽stationCode}");
+                var bindSNs = saveDataModel.MainData["SN"].ToString().Split(",");
+                var SNS = bindSNs.GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key);
+                foreach (var SN in SNS)
+                {
+                    throw new Exception($"閲嶅鐨凷N鍙穥SN}");
+                }
+                List<detail> list = new List<detail>();
+                List<VV_Mes_Workinfo> workinfos = new List<VV_Mes_Workinfo>();
+                foreach (var item in bindSNs)
+                {
+                    var work = workinfoRepository.Find(x => x.SN == item && x.processCode == "17").FirstOrDefault();
+                    if (work == null) throw new Exception($"鏈壘鍒拌溅杞甋N鍙凤細{item}鐨勫伐鍗曚俊鎭紒");
+                    workinfos.Add(work);
+                    detail detail = new detail();
+                    detail.sn = item;
+                    list.Add(detail);
+                }
+                agvInWarehousePara outWarehousePara = new agvInWarehousePara()
+                {
+                    //WorkOrder = task.jobID,
+                    zoneID = stationCode,
+                    //processCode = task.agv_worktype.ToString(),
+                    details = list,
+                    layerNo = 1,
+                    stackID = "1",
+                    warehouseName = "Agv搴�",
+                    Operator = UserContext.Current.UserName,
+                };
+                var postJson = JsonConvert.SerializeObject(outWarehousePara);
+                var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvInWarehouse");
+                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", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍏ュ簱", "agvInWarehouse", requestMes.message);
+                    foreach (var workinfo in workinfos)
+                    {
+                        dt_inventory inventory = new dt_inventory()
+                        {
+                            SN = workinfo.SN,
+                            Name = workinfo.productName,
+                            FigureNumber = workinfo.drawingNo,
+                            materialCode = workinfo.materialCode,
+                            HeatNumber = workinfo.heatID,
+                            drawingNoVer = workinfo.drawingNoVer,
+                            BilletNumber = workinfo.billetID,
+                            OnlineTime = DateTime.Now,
+                            Operator = "admin",
+                            stationCode = stationCode,
+                            area = station.area,
+                            jobID = workinfo.jobID,
+                            workOrder = workinfo.workOrder,
+                            ID = Guid.NewGuid()
+                        };
+                        _repository.Add(inventory, true);
+                    }
+                    WriteDBLog.Write($"鎵嬪姩娣诲姞搴撳瓨 ", $"璐т綅缂栧彿锛歿stationCode}锛汼N鍙凤細{saveDataModel.MainData["SN"]}", LogState.Sucess, "WMS", UserContext.Current.UserName);
+                }
+                else
+                {
+                    WriteWMSLog.LogAdd("", "澶辫触", "MES", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍏ュ簱", "agvInWarehouse", requestMes.message);
+                    throw new Exception("浜哄伐鍚屾MES杞﹁疆鍏ュ簱澶辫触锛�" + requestMes.message);
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Message = ex.Message;
+                WriteDBLog.Write($"鎵嬪姩娣诲姞搴撳瓨 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = $"璐т綅缂栧彿锛歿stationCode}锛汼N鍙凤細{saveDataModel.MainData["SN"]}" }, LogState.Error, "WMS", UserContext.Current.UserName);
+            }
+            return content;
+            //return base.Add(saveDataModel);
+        }
+        /// <summary>
+        /// 淇敼搴撳瓨
+        /// </summary>
+        /// <param name="saveModel"></param>
+        /// <returns></returns>
+        public override WebResponseContent Update(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            string str = "";
+            try
+            {
+                VOLContext context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+                var stationCode = saveModel.MainData["stationCode"].ToString();
+                if (string.IsNullOrEmpty(stationCode)) throw new Exception($"缂撳瓨鏋剁紪鍙蜂笉鑳戒负绌�!");
+                if (!stationCode.Contains("B") && !stationCode.Contains("C") && !stationCode.Contains("D")) throw new Exception($"缂撳瓨鏋剁被鍨嬫湁璇�!");
+                if (!stationinfoRepository.Find(x => x.stationCode == stationCode).Any()) throw new Exception($"鏈壘鍒拌揣浣峽stationCode}");
+                var inventory = _repository.Find(x => x.ID.ToString() == saveModel.MainData["ID"].ToString()).FirstOrDefault();
+                str = $"鍘熻揣浣嶇紪鍙凤細{inventory.stationCode}锛涚幇璐т綅缂栧彿锛歿stationCode}锛汼N鍙凤細{inventory.SN}";
+                List<detail1> list1 = new List<detail1>();
+                detail1 detail = new detail1();
+                detail.sn = inventory.SN;
+                list1.Add(detail);
+                agvMoveWarehousePara moveWarehousePara = new agvMoveWarehousePara()
+                {
+                    fromZoneID = inventory.stationCode,
+                    toZoneID = stationCode,
+                    details = list1,
+                    fromLayerNo = "1",
+                    fromStackID = "1",
+                    fromWarehouseName = "Agv搴�",
+                    toLayerNo = "1",
+                    toStackID = "1",
+                    toWarehouseName = "Agv搴�",
+                    Operator = UserContext.Current.UserName,
+                };
+                Idt_info_to_mesRepository mesRepository = new dt_info_to_mesRepository(context);
+
+                var postJson = JsonConvert.SerializeObject(moveWarehousePara);
+                dt_info_to_mes info_To_Mes = new dt_info_to_mes()
+                {
+                    Info = postJson,
+                    ActionName = "agvMoveWarehouse",
+                    Createtime = DateTime.Now,
+                    Remark = "浜哄伐鍚屾MES杞﹁疆绉诲簱",
+                    State = false
+                };
+                mesRepository.Add(info_To_Mes, true);
+
+                inventory.stationCode = stationCode;
+                _repository.Update(inventory, true);
+                WriteDBLog.Write($"浜哄伐绉诲簱", str, LogState.Sucess, "WMS", UserContext.Current.UserName);
+
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Message = ex.Message;
+                WriteDBLog.Write($"浜哄伐绉诲簱", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = str }, LogState.Error, "WMS", UserContext.Current.UserName);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鍒犻櫎搴撳瓨
+        /// </summary>
+        /// <param name="keys"></param>
+        /// <param name="delList"></param>
+        /// <returns></returns>
+        public override WebResponseContent Del(object[] keys, bool delList = true)
+        {
+            WebResponseContent content = new WebResponseContent();
+            VOLContext context = new VOLContext();
+            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+            string str = "";
+            try
+            {
+                List<string> KeyList = new List<string>();
+                foreach (string key in keys)
+                {
+                    KeyList.Add(key);
+                }
+                var inventoryList = _repository.Find(x => KeyList.Contains(x.ID.ToString())).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()
+                        {
+                            zoneID = inventorys.Key,
+                            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);
+                        dt_info_to_mes info_To_Mes = new dt_info_to_mes()
+                        {
+                            Info = postJson,
+                            ActionName = "agvOutWarehouse",
+                            Createtime = DateTime.Now,
+                            Remark = "浜哄伐鍚屾MES杞﹁疆鍑哄簱",
+                            State = false
+                        };
+                        mesRepository.Add(info_To_Mes, true);
+
+                        foreach (var inventory in inventorys)
+                        {
+                            var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
+                            station.quantity = station.quantity - 1;
+                            if (station.quantity < 1)
+                            {
+                                station.quantity = 1;
+                                station.stationType = string.Empty;
+                                station.heatNumber = string.Empty;
+                                station.Number = string.Empty;
+                                station.billetID = string.Empty;
+                                station.bindSN = string.Empty;
+                                station.tray_status = "EmptyTrayss";
+                                station.location_state = LocationStateEnum.Stroge.ToString();
+                            }
+                            else
+                            {
+                                var bindSNS = station.bindSN.Split(",");
+                                station.bindSN = ToMesServer.OperStr(bindSNS, inventory.SN);
+                                var billetS = station.billetID.Split(",");
+                                station.billetID = ToMesServer.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);
+                            _repository.Delete(inventory, true);
+                        }
+                        WriteDBLog.Write($"浜哄伐鍑哄簱鎴愬姛 ", $"璐т綅缂栧彿锛歿inventorys.Key}锛汼N鍙凤細{str}", LogState.Sucess, "WMS", UserContext.Current.UserName);
+                    }
+                    catch (Exception ex)
+                    {
+                        content.Message = ex.Message;
+                        WriteDBLog.Write($"浜哄伐鍑哄簱澶辫触 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = str }, LogState.Error, "WMS", UserContext.Current.UserName);
+                    }
+
+                }
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Message = ex.Message;
+                WriteDBLog.Write($"浜哄伐鍑哄簱澶辫触 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = str }, LogState.Error, "WMS", UserContext.Current.UserName);
+            }
+
+            return content;
+        }
+    }
 }

--
Gitblit v1.9.3