From 01a80700ea03a332785fb8cbd16aecaf7cce2ccb Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 30 五月 2024 10:29:18 +0800
Subject: [PATCH] 添加人工下料和切换托盘日志

---
 代码管理/WMS/WMS_Server/WIDESEA_WMS/ToMes/agvTransferList.cs |   65 +++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 11 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/agvTransferList.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/agvTransferList.cs"
index 7073360..60a8b53 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/agvTransferList.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/agvTransferList.cs"
@@ -1,17 +1,23 @@
 锘縰sing Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using System.Xml.Linq;
 using WIDESEA_Comm;
 using WIDESEA_Comm.LogInfo;
 using WIDESEA_Comm.MES_Info;
 using WIDESEA_Comm.MES_Info.Request;
+using WIDESEA_Comm.TaskNo;
 using WIDESEA_Common;
+using WIDESEA_Core.EFDbContext;
 using WIDESEA_Core.ManageUser;
 using WIDESEA_Core.Utilities;
 using WIDESEA_Entity.DomainModels;
 using WIDESEA_Entity.DomainModels.Mes;
 using WIDESEA_WMS.Common;
+using WIDESEA_WMS.IRepositories;
+using WIDESEA_WMS.Repositories;
 using static WIDESEA_Comm.MES_Info.BasicSN;
 
 namespace WIDESEA_WMS
@@ -27,24 +33,32 @@
         {
 
             WebResponseContent content = new WebResponseContent();
+            string postJson = "";
+            string mesData = "";
             try
             {
                 string sn = saveModel.MainData["sn"].ToString();
                 string user = saveModel.MainData["creator"].ToString();
-
-                return content.Error($"{user}鏃犳搷浣滄潈闄�!");
+                VOLContext Context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+                Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(Context);
+                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
+                //return content.Error($"{user}鏃犳搷浣滄潈闄�!");
                 //宸ュ崟鍙风敓鎴�
                 string jobID = "TW" + DateTime.Now.ToString("HH-mm-ss-ff");
 
                 //鏍规嵁搴撳瓨鏌ヨ杞﹁疆淇℃伅
-                dt_inventory inventory = freeDB.Select<dt_inventory>().Where(x => x.SN.Contains(sn)).First();
+                dt_inventory inventory = inventoryRepository.Find(x => x.SN.Contains(sn)).FirstOrDefault();
                 if (inventory == null)
                 {
                     return content.Error($"鏃犳杞﹁疆{sn}SN鍙�,璇锋牳鏌ュ簱瀛樿褰�!");
                 }
-
+                var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
+                //if (!station.enable) return content.Error($"搴撲綅{station.stationCode}鏈惎鐢紝璇锋牳瀹烇紒");
+                if (agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode || x.agv_toaddress == station.stationCode).Any())
+                    return content.Error($"搴撲綅{station.stationCode}瀛樺湪AGV浠诲姟锛岃鏍稿疄锛�");
                 List<detail> list = new List<detail>(); //杞﹁疆淇℃伅
-                foreach (var item in inventory.SN.Split(","))
+                foreach (var item in station.bindSN.Split(","))
                 {
                     detail detail = new detail();
                     detail.sn = item;
@@ -54,29 +68,58 @@
                 agvTransferListPara listPara = new agvTransferListPara
                 {
                     details = list,
-                    transferListID = jobID,
+                    transferListID = jobID,// station.Number,
                     toWarehouse = "姣涜疆搴�",
                     fromWarehouse = "AGV搴�",
                     updateTime = DateTime.Now.ToString(),
-                    drawingNoVer = "",
-                    materialCode = "",
+                    drawingNoVer = inventory.drawingNoVer,
+                    materialCode = inventory.materialCode,
                     Operator = user == null ? "admin" : user
                 };
 
-                var postJson = JsonConvert.SerializeObject(listPara);
-                string mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvTransferList");
+                postJson = JsonConvert.SerializeObject(listPara);
+                mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvTransferList");
+                if (mesData.Contains("杩炴帴灏濊瘯澶辫触"))
+                    throw new Exception(mesData);
                 var requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData);
 
                 if (requestMes.code == "200" && requestMes.Type == "success")
                 {
-                    return content.OK("绉诲簱浜ゆ帴鎴愬姛锛�");
+                    dt_agvtask agvtask = new dt_agvtask()
+                    {
+                        agv_fromaddress = station.stationCode,
+                        agv_id = Guid.NewGuid(),
+                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+                        agv_grade = 0,
+                        agv_createtime = DateTime.Now,
+                        agv_taskstate = "Queue",
+                        agv_materielid = station.stationType,
+                        agv_qty = station.quantity,
+                        agv_tasktype = "TaskType_OutsourceCarry",
+                        agv_toaddress = "",
+                        agv_userid = user,//"绯荤粺",
+                        jobID = jobID,// mes_head.jobID,
+                        bindSN = station.bindSN,
+                        agv_worktype = 101, //Convert.ToInt32(mes_head.processCode),
+                        agv_materbarcode = inventory.materialCode,
+                        agv_Traytype = station.tray_type,
+                        agv_TrayStatus = station.tray_status
+                    };
+                    agvtaskRepository.Add(agvtask, true);
+                    station.location_state = LocationStateEnum.OutBusy.ToString();
+                    stationinfoRepository.Update(station, true);
+                    content.OK("涓嬪彂绉诲簱澶栧崗鎴愬姛锛�");
                     //鏃ュ織璁板綍涓婁紶鏁版嵁鎴愬姛
+                    WriteWMSLog.LogAdd("", "鎴愬姛", "MES", "WMS", postJson, mesData, "AB搴撶Щ搴撳鍗�", "agvTransferList", requestMes.message);
                 }
+                else
+                    throw new Exception(requestMes.message);
 
             }
             catch (Exception ex)
             {
                 content.Error(ex.Message);
+                WriteWMSLog.LogAdd("", "澶辫触", "MES", "WMS", postJson, mesData, "AB搴撶Щ搴撳鍗�", "agvTransferList", ex.Message);
             }
             return content;
         }

--
Gitblit v1.9.3