From 78279bd340545f8c07d1ff08764bd859ba404c83 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期四, 19 十二月 2024 10:42:23 +0800 Subject: [PATCH] 修改问题 --- Wms/WMS.BLL/BllTransServer/RcsServer.cs | 1167 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 915 insertions(+), 252 deletions(-) diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs index 67dac3a..afa76e9 100644 --- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs +++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs @@ -1,19 +1,27 @@ -锘縰sing Microsoft.IdentityModel.Protocols; +锘縰sing Model.InterFaceModel; +using Model.ModelDto; +using Model.ModelDto.DataDto; +using Model.ModelDto.LogDto; using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; +using System.Security.Policy; using System.Text; +using System.Threading.Tasks; using Utility.Tools; +using WMS.BLL.LogServer; using WMS.DAL; using WMS.Entity.BllAsnEntity; +using WMS.Entity.BllSoEntity; using WMS.Entity.Context; using WMS.Entity.DataEntity; using WMS.Entity.LogEntity; using WMS.Entity.SysEntity; using WMS.IBLL.IBllTransServer; using static Model.InterFaceModel.RCSModel; +using static System.Collections.Specialized.BitVector32; namespace WMS.BLL.BllTransServer { @@ -21,360 +29,575 @@ { private static readonly SqlSugarScope Db = DataContext.Db; /// <summary> - /// RCS鍙《(鍑�妗跺拰鑴忔《) + /// RCS鍙《 /// </summary> - /// <param name="warehouseno">搴撳尯</param> - /// <param name="type">鍙枡绫诲瀷</param> - /// <returns></returns> - public void GetPalletNo(Pallnetmsg pallnetmsg) - { - DataStockDetail pallet = new DataStockDetail(); - SysStorageLocat locat = new SysStorageLocat(); + /// <param name="model"></param> + /// <param name="url"></param> + /// <param name="taskNo"></param> + /// <exception cref="Exception"></exception> + public void GetPalletNo(Pallnetmsg model, string url, out string taskNo) + { try { - var house = "W01";//鍙《浣嶇疆锛屽悗缁牴鎹綅缃叧鑱旀垨瀹氫箟锛屾潵鍒ゆ柇鍙《浣嶇疆鎵�灞炶溅闂� - var url = "";//鍥炰紶MES鐨勬帴鍙e湴鍧� - var noticeno = ""; - var sql = "select PalletNo,LocatNo from DataStockDetail where Status = '0'"; - switch (pallnetmsg.Type) + string taskMsg = ""; + if (string.IsNullOrEmpty(model.Location)) + { + throw new Exception("璁惧鎵�鍦ㄤ綅缃笉鍙负绌�"); + } + //鍙《璁惧鎵�鍦ㄥ偍浣嶄俊鎭紙鐩爣鍌ㄤ綅锛� + var endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location); + if (endLoction == null) + { + throw new Exception("璁惧鍌ㄤ綅淇℃伅涓嶅瓨鍦�"); + } + var houseNo = endLoction.WareHouseNo;//鍙《浣嶇疆锛屽悗缁牴鎹綅缃叧鑱旀垨瀹氫箟锛屾潵鍒ゆ柇鍙《浣嶇疆鎵�灞炶溅闂� + var urlMes = "";//鍥炰紶MES鐨勬帴鍙e湴鍧� + var noticeNo = "0";//鍑哄叆搴撳崟鎹槑缁咺D + var stockDetail = Db.Queryable<DataStockDetail>().Where(w => w.Status == "0");//鎵�鏈夊緟鍒嗛厤鐨勬《 + + //寮�濮嬩簨鍔� + Db.BeginTran(); + DataStockDetail pallet = new DataStockDetail(); + switch (model.Type) { case "0"://鍙噣妗� - List<DataStockDetail> jtpallet = new List<DataStockDetail>(); - sql += $"and WareHouseNo = '{house}' and AreaNo like '%01' order by CreateTime desc"; - jtpallet = Db.Ado.SqlQuery<DataStockDetail>(sql).ToList(); - if (jtpallet.Count == 0) + //鏌ユ壘鍒拌杞﹂棿鍑�妗跺尯 + List<string> areaNoList = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "0" && w.WareHouseNo == houseNo).Select(s=>s.AreaNo).ToList(); + //鏌ユ壘鍑�妗� + pallet = stockDetail.Where(w => w.WareHouseNo == houseNo && w.PalletStatus == "0" && w.Status == "0" + && areaNoList.Contains(w.AreaNo)).OrderByDescending(o => o.CreateTime).First(); + if (pallet == null) { throw new Exception("鏆傛棤鍑�妗跺彲鍒嗛厤"); - } - //閬嶅巻搴撳瓨鍑�妗讹紝杩斿洖MES楠岃瘉 - foreach (var item in jtpallet) - { - string jsonReq = JsonConvert.SerializeObject(item.PalletNo); - var response = HttpHelper.DoPost(url, jsonReq, "鍥炰紶MES鍑�妗剁紪鍙�", "RCS").ToString(); - var obj = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁 - if (obj.Success == "0") - { - if (obj.Result != "0")//鍙敤锛岀敓鎴愬皬杞︽媺鍑�妗朵换鍔� - { - //鏌ユ壘鏄惁鏈夌┖浣欒剰妗朵綅 - sql = $"select LocatNo from SysStorageLocat where AreaNo like '%04' and WareHouseNo = wareno and Status = 0"; - locat = Db.Ado.SqlQuery<SysStorageLocat>(sql).FirstOrDefault(); - if (locat == null) - { - Db.Ado.BeginTran(); - //鑴忔《鍖烘棤绌轰綑搴撲綅锛屽垯閿佸畾姝ゅ噣妗跺簱瀛�,骞堕噸鏂伴亶鍘� - sql = $"UPDATE DataStockDetail Set Status = '5' Where locat ='{locat.LocatNo}'"; - Db.Ado.ExecuteCommand(sql); - Db.Ado.CommitTran(); - break; - } - //鐢熸垚璋冨害灏忚溅鍑�妗跺幓鑴忔《鍖轰换鍔� - var ztask = new TaskDetial - { - Startport = item.LocatNo, - Endport = locat.LocatNo, - Pallno = pallnetmsg.Palletno, - Type = "4", - Crtype = "0", - Noticedetailno = int.Parse(noticeno), - }; - CreateLotTask(ztask); - return; - } - } - else - { - throw new Exception("鍥炰紶MES鍑�妗剁紪鍙峰け璐ワ紒"); - } - } + } + pallet.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰� + //鏇存柊妗跺簱瀛樻槑缁� + Db.Updateable(pallet).ExecuteCommand(); + + taskMsg = "璁惧鍙噣妗朵换鍔�"; break; case "1"://鍙枡妗讹紙娣锋枡锛� //鍒ゆ柇鏄惁鏈夋壒娆″彿 - if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + if (string.IsNullOrWhiteSpace(model.LotNo)) { throw new Exception("鎵规鍙蜂负绌猴紒"); } - BllArrivalNoticeDetail ArriveMes = new BllArrivalNoticeDetail(); - //鍒ゆ柇璇ユ壒娆℃槸鍚︽湁瀵瑰簲鍏ュ簱鍗� - sql = $"select * from BllArrivalNoticeDetail where LotNo = '{pallnetmsg.LotNo}' order by CreateTime desc"; - ArriveMes = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault(); - if (ArriveMes == null) - { - throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); - } + //鏌ユ壘鍒拌杞﹂棿棰勬贩鍖� + List<string> areaNoList2 = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "1" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); //鏌ユ壘搴撳瓨涓槸鍚︽湁鍙敤鐨勬鎵规鐨勬贩鏂欐《 - sql += $"where a.LotNo = '{pallnetmsg.LotNo}'and AreaNo like '%02' and a.WareHouseNo = '{house}' and b.status = '0' " + - $"order by CompleteTime desc"; - pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); + pallet = stockDetail.Where(w => w.WareHouseNo == houseNo && w.PalletStatus == "1" && w.Status == "0" && w.LotNo == model.LotNo + && areaNoList2.Contains(w.AreaNo)).OrderByDescending(o => o.CompleteTime).First(); if (pallet == null) { throw new Exception("鏆傛棤娣锋枡妗跺彲鍒嗛厤"); } + pallet.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰� + //鏇存柊妗跺簱瀛樻槑缁� + Db.Updateable(pallet).ExecuteCommand(); + taskMsg = "璁惧鍙枡妗舵贩鏂欎换鍔�"; break; case "2"://鍙枡妗讹紙涓嬫枡锛� //鍒ゆ柇鏄惁鏈夋壒娆″彿 - if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + if (string.IsNullOrWhiteSpace(model.LotNo)) { throw new Exception("鎵规鍙蜂负绌猴紒"); } - //鏌ユ壘搴撳瓨涓槸鍚︽湁姝ゆ壒娆$殑涓嬫枡妗� - sql += $"where a.LotNo = '{pallnetmsg.LotNo}'and AreaNo like '%03' and a.WareHouseNo = '{house}' and b.status = '0' " + - $"order by CompleteTime desc"; - pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); + //鏌ユ壘鏄惁鏈夋鎵规鍑哄簱鍗曟槑缁� + var soNoticeDetail = Db.Queryable<BllExportNoticeDetail>().Where(w => w.IsDel == "0" && w.LotNo == model.LotNo).OrderBy(o => o.CreateTime).First(); + if (soNoticeDetail == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍑哄簱鍗曟槑缁�"); + } + noticeNo = soNoticeDetail.Id.ToString(); + //鍑哄簱鎬诲崟 + var soNotice = Db.Queryable<BllExportNotice>().Where(w => w.IsDel == "0" && w.SONo == soNoticeDetail.SONo).First(); + if (soNotice == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍑哄簱鍗�"); + } + soNotice.Status = "3";//姝e湪鎵ц + soNotice.UpdateTime = DateTime.Now; + //鏇存柊鍑哄簱鍗� + Db.Updateable(soNotice).ExecuteCommand(); + + //鏌ユ壘鍒拌杞﹂棿鍗婃垚鍝佸尯 + List<string> areaNoList3 = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "2" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + //鏌ユ壘搴撳瓨涓槸鍚︽湁姝ゆ壒娆$殑鍚堟牸涓嬫枡妗� + pallet = stockDetail.Where(w => w.WareHouseNo == houseNo && w.PalletStatus == "2" && w.Status == "0" && w.LotNo == model.LotNo && w.InspectStatus=="1" + && areaNoList3.Contains(w.AreaNo)).OrderByDescending(o => o.CompleteTime).First(); if (pallet == null) { throw new Exception("鏆傛棤涓嬫枡妗跺彲鍒嗛厤"); } + pallet.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰� + //鏇存柊妗跺簱瀛樻槑缁� + Db.Updateable(pallet).ExecuteCommand(); + taskMsg = "璁惧鍙枡妗朵笅鏂欎换鍔�"; break; case "3"://鍙剰妗� - sql += $"and WareHouseNo = '{house}' and AreaNo like '%04' order by CreateTime desc"; - pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); - if (pallet == null) + //鏌ユ壘鍒拌杞﹂棿鑴忔《鍖� + List<string> areaNoList4 = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "3" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + List<DataStockDetail> palletList = stockDetail.Where(w => w.WareHouseNo == houseNo && w.PalletStatus == "3" && w.Status == "0" + && areaNoList4.Contains(w.AreaNo)).OrderByDescending(o => o.CompleteTime).ToList(); + if (palletList.Count <= 0) { throw new Exception("鏆傛棤鑴忔《鍙垎閰�"); } + //閬嶅巻搴撳瓨鑴忔《锛岃繑鍥濵ES楠岃瘉 + foreach (var item in palletList) + { + #region 鍘绘帀MES + //string jsonReq = JsonConvert.SerializeObject(item.PalletNo); + //var response = HttpHelper.DoPost(urlMes, jsonReq, "鍥炰紶MES鑴忔《缂栧彿", "RCS").ToString(); + //var obj = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁 + //if (obj.Success == "0") + //{ + // if (obj.Result != "1")//涓嶅彲娓呮礂锛屽皢鑴忔《鍐荤粨 + // { + // item.Status = "5";//寮傚父鍐荤粨 + // //淇敼璇ユ《搴撳瓨鐘舵�� + // Db.Updateable(item).ExecuteCommand(); + // continue; + // } + // //涓嬪彂灏忚溅浠诲姟 + // var task2 = new TaskDetial + // { + // Startport = item.LocatNo, + // Endport = model.Location, + // Pallno = item.PalletNo, + // Type = model.Type, + // Crtype = "1", + // Noticedetailno = int.Parse(noticeno), + // }; + // CreateLotTask(task2); + // return; + //} + //else + //{ + // throw new Exception("鍥炰紶MES鍑�妗剁紪鍙峰け璐ワ紒"); + //} + #endregion + + item.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰� + //鏇存柊妗跺簱瀛樻槑缁� + Db.Updateable(item).ExecuteCommand(); + //璧峰鍌ㄤ綅鍦板潃淇℃伅 + var startLoction2 = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == item.LocatNo); + if (startLoction2 == null) + { + throw new Exception($"璧峰鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦紝妗跺彿锛歿item.LocatNo}"); + } + + taskNo = new Common().GetMaxNo("TK");//浠诲姟鍙� + var logTaskEntry2 = new LogTask + { + TaskNo = taskNo, + Sender = "WMS", + Receiver = "RCS", + //IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 + SendDate = DateTime.Now, //鍙戦�佹椂闂� + //BackDate = DateTime.Now, //杩斿洖鏃堕棿 + StartLocat = item.LocatNo,//璧峰浣嶇疆 + EndLocat = model.Location,//鐩爣浣嶇疆 + PalletNo = item.PalletNo,//鎵樼洏鐮� + IsSend = 1,//鏄惁鍙啀娆′笅鍙� + IsCancel = 1,//鏄惁鍙彇娑� + IsFinish = 1,//鏄惁鍙畬鎴� + Type = "1",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 + OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3 绉诲簱 + Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + NoticeDetailNo = int.Parse(noticeNo), + Msg = taskMsg, //鍏抽敭淇℃伅 + }; + //缁勭粐涓嬪彂灏忚溅浠诲姟淇℃伅 + var task2 = new TaskDetial + { + Taskno = taskNo,//浠诲姟鍙� + Startport = item.LocatNo, + Endport = model.Location, + Pallno = item.PalletNo, + Crtype = "1",//鍙《 + }; + //缁欎笅杞︿笅鍙戜换鍔� + logTaskEntry2.SendDate = DateTime.Now;//鍙戦�佹椂闂� + var agvResult2 = CreateTaskForAgv(task2, url); + if (agvResult2)//鎴愬姛 + { + //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬� + logTaskEntry2.IsSuccess = 1; + logTaskEntry2.IsSend = 0; + //logTaskEntry2.IsCancel = 0; + logTaskEntry2.BackDate = DateTime.Now; + logTaskEntry2.Status = "1"; + Db.Insertable(logTaskEntry2).ExecuteCommand(); + + startLoction2.Status = "3";//鍑哄簱涓� + Db.Updateable(startLoction2).ExecuteCommand(); + + endLoction.Status = "2";//鍏ュ簱涓� + Db.Updateable(endLoction).ExecuteCommand(); + } + else//澶辫触 + { + logTaskEntry2.IsSuccess = 0; + Db.Insertable(logTaskEntry2).ExecuteCommand(); + + } + //鎻愪氦浜嬪姟 + Db.CommitTran(); + return; + } + + taskMsg = "璁惧鍙剰妗朵换鍔�"; break; + default: + throw new Exception("浠诲姟绫诲瀷鏃犳晥"); } - //涓嬪彂灏忚溅浠诲姟 + //璧峰鍌ㄤ綅鍦板潃淇℃伅 + var startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == pallet.LocatNo); + if (startLoction == null) + { + throw new Exception($"璧峰鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦紝妗跺彿锛歿pallet.LocatNo}"); + } + + taskNo = new Common().GetMaxNo("TK");//浠诲姟鍙� + //浠诲姟淇℃伅 + var logTaskEntry = new LogTask + { + TaskNo = taskNo, + Sender = "WMS", + Receiver = "RCS", + //IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 + SendDate = DateTime.Now, //鍙戦�佹椂闂� + //BackDate = DateTime.Now, //杩斿洖鏃堕棿 + StartLocat = pallet.LocatNo,//璧峰浣嶇疆 + EndLocat = model.Location,//鐩爣浣嶇疆 + PalletNo = pallet.PalletNo,//鎵樼洏鐮� + IsSend = 1,//鏄惁鍙啀娆′笅鍙� + IsCancel = 1,//鏄惁鍙彇娑� + IsFinish = 1,//鏄惁鍙畬鎴� + Type = "1",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 + OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3绉诲簱 + Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + NoticeDetailNo = int.Parse(noticeNo), + Msg = taskMsg, //鍏抽敭淇℃伅 + }; + + //缁勭粐涓嬪彂灏忚溅浠诲姟淇℃伅 var task = new TaskDetial { - Startport = pallnetmsg.Location, - Endport = pallet.LocatNo, - Pallno = pallnetmsg.Palletno, - Type = pallnetmsg.Type, - Crtype = "1", - Noticedetailno = int.Parse(noticeno), + Taskno= taskNo,//浠诲姟鍙� + Startport = pallet.LocatNo,//璧峰浣嶇疆 + Endport = model.Location,//鐩爣浣嶇疆 + Pallno = pallet.PalletNo,//妗跺彿 + Crtype = "1",//鍙《 }; - CreateLotTask(task); + //缁欎笅杞︿笅鍙戜换鍔� + logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂� + var agvResult = CreateTaskForAgv(task, url); + if (agvResult)//鎴愬姛 + { + //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬� + logTaskEntry.IsSuccess = 1; + logTaskEntry.IsSend = 0; + //logTaskEntry.IsCancel = 0; + logTaskEntry.BackDate = DateTime.Now; + logTaskEntry.Status = "1";//姝e湪鎵ц + Db.Insertable(logTaskEntry).ExecuteCommand(); + + startLoction.Status = "3";//鍑哄簱涓� + Db.Updateable(startLoction).ExecuteCommand(); + + endLoction.Status = "2";//鍏ュ簱涓� + Db.Updateable(endLoction).ExecuteCommand(); + } + else//澶辫触 + { + logTaskEntry.IsSuccess = 0; + Db.Insertable(logTaskEntry).ExecuteCommand(); + + } + //鎻愪氦浜嬪姟 + Db.CommitTran(); } catch (Exception ex) { - Db.Ado.RollbackTran(); - throw ex; + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + throw new Exception(ex.Message); } } /// <summary> /// 鐢宠鍌ㄤ綅 /// </summary> - /// <param name="PalletNo"></param> - /// <returns></returns> - public void ApplyLocatNo(Pallnetmsg pallnetmsg) - { - var sql = $"select LocatNo from SysStorageLocat where status = '0'"; - var house = "W01";//鈥︹�﹀彨妗朵綅缃紝鍚庣画鏍规嵁浣嶇疆鍏宠仈鎴栧畾涔夛紝鏉ュ垽鏂彨妗朵綅缃墍灞炶溅闂� - var noticeno = ""; - SysStorageLocat loction = new SysStorageLocat(); + /// <param name="model"></param> + /// <param name="url"></param> + /// <param name="taskNo"></param> + /// <exception cref="Exception"></exception> + public void ApplyLocatNo(Pallnetmsg model, string url, out string taskNo) + { try { - switch (pallnetmsg.Type) + string taskMsg = ""; + //鏌ユ壘璇ユ《鏈夋病鏈夋鍦ㄦ墽琛岀殑浠诲姟 + var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.PalletNo == model.PalletNo); + if (tasking != null) { - case "0"://鍑�妗剁敵璇峰偍浣� - sql += $"and AreaNo like '%01' and WareHouseNo = {house}"; - loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + throw new Exception($"璇ユ《鏈夋鍦ㄦ墽琛岀殑浠诲姟锛孭alletNo:{model.PalletNo}"); + } + //璁惧鎵�鍦ㄥ偍浣嶄俊鎭紙璧峰鍌ㄤ綅锛� + var deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location); + if (deviceLocatInfo == null) + { + throw new Exception($"鏈煡璇㈠埌璇ヨ澶囨墍鍦ㄥ偍浣嶄俊鎭紝Location:{model.Location}"); + } + var houseNo = deviceLocatInfo.WareHouseNo;//鐢宠鍌ㄤ綅璁惧鎵�鍦ㄨ溅闂寸紪鍙� + var noticeno = "0";//鍑哄叆搴撳崟鎹槑缁咺D + //妗跺簱瀛樹俊鎭� + var palletInfo = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == model.PalletNo); + if (palletInfo == null) + { + throw new Exception($"鏈煡璇㈠埌璇ユ《鐨勫簱瀛樹俊鎭紝PalletNo:{model.PalletNo}"); + } + + var storageLocat = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0"); + //寮�鍚簨鍔� + Db.BeginTran(); + + SysStorageLocat loction = new SysStorageLocat();//鐩爣鍌ㄤ綅淇℃伅 + switch (model.Type) + { + case "3"://娓呮礂璁惧鐢宠鍌ㄤ綅锛堝噣妗剁敵璇峰偍浣嶏級 + //鏌ユ壘鍒拌杞﹂棿鍑�妗跺尯 + //List<string> areaNoList = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "0" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + //loction = storageLocat.Where(w => w.WareHouseNo == houseNo && areaNoList.Contains(w.AreaNo) && w.Status == "0" && w.Flag == "0").OrderByDescending(o => o.CreateTime).First(); + loction = GetLocatModel(houseNo, "0"); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑鍑�妗跺偍浣�"); + throw new Exception("璇ヨ溅闂村噣妗跺尯鏆傛棤绌轰綑鍌ㄤ綅"); } + + taskMsg = "娓呮礂璁惧锛堝噣妗讹級鐢宠鍌ㄤ綅浠诲姟"; break; - case "1"://娣锋枡妗剁敵璇峰偍浣� + case "0"://鎺ユ枡璁惧鐢宠鍌ㄤ綅锛堥娣锋枡妗剁敵璇峰偍浣嶏級 //鍒ゆ柇鏄惁鏈夋壒娆″彿 - if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + if (string.IsNullOrWhiteSpace(model.LotNo)) { throw new Exception("鎵规鍙蜂负绌猴紒"); } - sql += $"and AreaNo like '%02' and WareHouseNo = {house}"; - loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + //鏌ユ壘鍒拌杞﹂棿棰勬贩鍖� + //List<string> areaNoList2 = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "1" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + //loction = storageLocat.Where(w => w.WareHouseNo == houseNo && areaNoList2.Contains(w.AreaNo) && w.Status == "0" && w.Flag == "0").OrderByDescending(o => o.CreateTime).First(); + loction = GetLocatModel(houseNo, "1"); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑娣锋枡妗跺偍浣�"); + throw new Exception("璇ヨ溅闂撮娣峰尯鏆傛棤绌轰綑鍌ㄤ綅"); } + palletInfo.LotNo = model.LotNo;//鎵规鍙� + //鏇存柊妗跺簱瀛樹俊鎭� + Db.Updateable(palletInfo).ExecuteCommand(); + + taskMsg = "鎺ユ枡璁惧锛堥娣锋枡妗讹級鐢宠鍌ㄤ綅浠诲姟"; break; - case "2"://鍗婃垚鍝佹《鐢宠鍌ㄤ綅 + case "1"://娣锋枡璁惧鐢宠鍌ㄤ綅锛堝崐鎴愬搧妗剁敵璇峰偍浣嶏級 //鍒ゆ柇鏄惁鏈夋壒娆″彿 - if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + if (string.IsNullOrWhiteSpace(model.LotNo)) { throw new Exception("鎵规鍙蜂负绌猴紒"); } - sql += $"and AreaNo like '%03' and WareHouseNo = {house}"; - loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + //鏍¢獙姝ゆ壒娆℃槸鍚︽湁鍏ュ簱鍗� + var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().Where(w => w.IsDel == "0" && w.Status == "0" && w.LotNo == model.LotNo).OrderByDescending(o => o.CreateTime).First(); + if (noticeDetail == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗曟槑缁�"); + } + noticeno = noticeDetail.Id.ToString(); + //鍏ュ簱鎬诲崟 + var notice = Db.Queryable<BllArrivalNotice>().Where(w => w.IsDel == "0" && w.ASNNo == noticeDetail.ASNNo).First(); + if (notice == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); + } + notice.Status = "1";//姝e湪鎵ц + //鏇存柊鍏ュ簱鍗曠姸鎬� + Db.Updateable(notice).ExecuteCommand(); + + //鏌ユ壘鍒拌杞﹂棿鍗婃垚鍝佸尯 + //List<string> areaNoList3 = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "2" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + //loction = storageLocat.Where(w => w.WareHouseNo == houseNo && areaNoList3.Contains(w.AreaNo) && w.Status == "0" && w.Flag == "0").OrderByDescending(o => o.CreateTime).First(); + loction = GetLocatModel(houseNo, "2"); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑鍗婃垚鍝佹《鍌ㄤ綅"); + throw new Exception("璇ヨ溅闂村崐鎴愬搧鍖烘殏鏃犵┖浣欏偍浣�"); } + + taskMsg = "鎺ユ枡璁惧锛堟贩鏂欐《锛夌敵璇峰偍浣嶄换鍔�"; break; - case "3"://鑴忔《鐢宠鍌ㄤ綅 - sql += $"and AreaNo like '%04' and WareHouseNo = {house}"; - loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + case "2"://涓嬫枡璁惧鐢宠鍌ㄤ綅锛堣剰妗剁敵璇峰偍浣嶏級 + //鏌ユ壘鍒拌杞﹂棿鑴忔《鍖� + //List<string> areaNoList4 = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == "3" && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + //loction = storageLocat.Where(w => w.WareHouseNo == houseNo && areaNoList4.Contains(w.AreaNo) && w.Status == "0" && w.Flag == "0").OrderByDescending(o => o.CreateTime).First(); + loction = GetLocatModel(houseNo, "3"); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑鑴忔《鍌ㄤ綅"); + throw new Exception("璇ヨ溅闂磋剰妗跺尯鏆傛棤绌轰綑鍌ㄤ綅"); } + + taskMsg = "涓嬫枡璁惧锛堣剰妗讹級鐢宠鍌ㄤ綅浠诲姟"; break; } + + taskNo = new Common().GetMaxNo("TK");//浠诲姟鍙� + //浠诲姟淇℃伅 + var logTaskEntry = new LogTask + { + TaskNo = taskNo, + Sender = "WMS", + Receiver = "RCS", + //IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 + SendDate = DateTime.Now, //鍙戦�佹椂闂� + //BackDate = DateTime.Now, //杩斿洖鏃堕棿 + StartLocat = model.Location,//璧峰浣嶇疆 + EndLocat = loction.LocatNo,//鐩爣浣嶇疆 + PalletNo = model.PalletNo,//妗跺彿 + IsSend = 1,//鏄惁鍙啀娆′笅鍙� + IsCancel = 1,//鏄惁鍙彇娑� + IsFinish = 1,//鏄惁鍙畬鎴� + Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 + OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3 绉诲簱 + Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + NoticeDetailNo = int.Parse(noticeno), + Msg = taskMsg, //鍏抽敭淇℃伅 + }; var task = new TaskDetial { - Startport = pallnetmsg.Location, + Taskno = taskNo,//浠诲姟鍙� + Startport = model.Location, Endport = loction.LocatNo, - Pallno = pallnetmsg.Palletno, - Type = pallnetmsg.Type, - Crtype = "1", - Noticedetailno = int.Parse(noticeno), + Pallno = model.PalletNo, + Crtype = "0",//鍏ュ簱 }; - CreateLotTask(task); - } - catch (Exception) - { - - throw; - } - } - - - /// <summary> - /// RCS鐢熸垚浠诲姟 - /// </summary> - /// <param name="taskCode"></param> - /// <param name="taskType"></param> - /// <param name="startPos">璧峰浣嶇疆</param> - /// <param name="endPos">鐩殑浣嶇疆</param> - /// <param name="agvCode"></param> - /// <param name="url">RCS鍦板潃</param> - /// <returns></returns> - public genAgvSchedulingTaskRep genAgvSchedulingTask(AgvTask agv,string url) - { - try - { - genAgvSchedulingTaskRep cbrep = new genAgvSchedulingTaskRep(); - PositionCodePath pcd1 = new PositionCodePath() + //缁欎笅杞︿笅鍙戜换鍔� + logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂� + var agvResult = CreateTaskForAgv(task, url); + if (agvResult)//鎴愬姛 { - positionCode = agv.startPos.ToString(), - type = "00", - }; - PositionCodePath pcd2 = new PositionCodePath() + //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬� + logTaskEntry.IsSuccess = 1; + logTaskEntry.IsSend = 0; + //logTaskEntry.IsCancel = 0; + logTaskEntry.BackDate = DateTime.Now; + logTaskEntry.Status = "1";//姝e湪鎵ц + Db.Insertable(logTaskEntry).ExecuteCommand(); + + deviceLocatInfo.Status = "3";//鍑哄簱涓� + Db.Updateable(deviceLocatInfo).ExecuteCommand(); + + loction.Status = "2";//鍏ュ簱涓� + Db.Updateable(loction).ExecuteCommand(); + } + else//澶辫触 { - positionCode = agv.endPos.ToString(), - type = "00", - }; - List<PositionCodePath> lst = new List<PositionCodePath>(); - lst.Add(pcd1); - lst.Add(pcd2); - genAgvSchedulingTaskReq cbreq = new genAgvSchedulingTaskReq() - { - reqCode = agv.taskCode.ToString(), - taskCode = agv.taskCode.ToString(), - taskTyp = agv.taskType, - positionCodePath = lst, - podCode = "", - agvCode = agv.agvCode, - ctnrTyp = "1", - //ctnrCode="2", - - }; - cbrep = genAgvSchedulingTask(cbreq,url); - - - return cbrep; - } - catch (Exception ex) { throw ex; } - } - - /// <summary> - /// 鐢熸垚浠诲姟鍗� - /// </summary> - /// <param name="req"></param> - /// <returns></returns> - private genAgvSchedulingTaskRep genAgvSchedulingTask(genAgvSchedulingTaskReq req,string url) - { - genAgvSchedulingTaskRep rep = new genAgvSchedulingTaskRep() - { - code = "-1", - message = "鐢熶骇浠诲姟鍗曞け璐�" - }; - if (req == null) - { - return rep; - } - try - { - string jsonReq = JsonConvert.SerializeObject(req); - - string jsonRep = HttpHelper.DoPost(url + "/genAgvSchedulingTask", jsonReq,"灏忚溅浠诲姟涓嬪彂","RCS"); - jsonRep = jsonRep.TrimStart('\"'); - jsonRep = jsonRep.TrimEnd('\"'); - jsonRep = jsonRep.Replace("\\", ""); - rep = JsonConvert.DeserializeObject<genAgvSchedulingTaskRep>(jsonRep); - return rep; + logTaskEntry.IsSuccess = 0; + Db.Insertable(logTaskEntry).ExecuteCommand(); + } + //鎻愪氦浜嬪姟 + Db.CommitTran(); } catch (Exception ex) { - throw ex; + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + throw new Exception(ex.Message); + } + } + /// <summary> + /// 鑾峰彇绌哄偍浣� + /// </summary> + /// <param name="houseNo">杞﹂棿缂栧彿</param> + /// <param name="Type">绫诲埆 0:鍑�妗跺尯 1:棰勬贩鍖� 2:鍗婃垚鍝佸尯 3:鑴忔《鍖�</param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + private SysStorageLocat GetLocatModel(string houseNo,string type) + { + try + { + //閫氳繃绫诲埆鏌ユ壘杞﹂棿鍖哄煙 + List<string> areaNoList = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Type == type && w.WareHouseNo == houseNo).Select(s => s.AreaNo).ToList(); + //鏌ユ壘鍌ㄤ綅 + var loctionModel = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.WareHouseNo == houseNo && areaNoList.Contains(w.AreaNo)) + .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First(); + if (loctionModel == null) + { + throw new Exception("璇ヨ溅闂村噣妗跺尯鏆傛棤绌轰綑鍌ㄤ綅"); + } + return loctionModel; + } + catch (Exception ex) + { + throw new Exception(ex.Message); } } /// <summary> - /// 鐢熸垚浠诲姟鍗曞埌LogTask + /// MES涓嬪彂灏嗗噣妗舵敼涓鸿剰妗跺苟鎷夊埌鑴忔《鍖� /// </summary> - /// <param name="req"></param> + /// <param name="PalletNo"></param> /// <returns></returns> - public void CreateLotTask(TaskDetial taskDetial) + public void ChangePalletStatus(string PalletNo,string url) { try { - var na = taskDetial.Crtype == "0"?"鍏ュ簱":"鍑哄簱"; - var sql = ""; + var detail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == PalletNo && w.PalletStatus == "0"); + if (detail == null) + { + throw new Exception($"搴撳瓨涓笉瀛樺湪妗跺彿涓猴細{PalletNo}鐨勫簱瀛�!"); + } + //璧峰鐩爣鍌ㄤ綅淇℃伅 + var statrtLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo == detail.AreaNo && w.LocatNo == detail.LocatNo); + if (statrtLocat == null) + { + throw new Exception($"璇ユ《鎵�鍦ㄧ殑鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"); + } //寮�鍚簨鍔� Db.BeginTran(); - //鍒ゆ柇浠诲姟鏄惁涓烘柊浠诲姟 - if (string.IsNullOrWhiteSpace(taskDetial.Taskno)) + + //鏌ユ壘鏄惁鏈夌┖浣欒剰妗朵綅 + var endLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo.Contains("04") && w.Status == "0" && w.Flag=="0"); + if (endLocat == null) { - taskDetial.Taskno = new Common().GetMaxNo("T"); - - var logTaskEntry = new LogTask + detail.Status = "5";//寮傚父閿佸畾 + detail.PalletStatus = "3";//鑴忔《 + //淇敼搴撳瓨鐘舵�� + Db.Updateable(detail).ExecuteCommand(); + } + else + { + //鐢熸垚璋冨害灏忚溅鍑�妗跺幓鑴忔《鍖轰换鍔� + var ztask = new TaskDetial { - TaskNo = taskDetial.Taskno, - Sender = "WMS", - Receiver = "RCS", - //IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 - SendDate = DateTime.Now, //鍙戦�佹椂闂� - //BackDate = DateTime.Now, //杩斿洖鏃堕棿 - StartLocat = taskDetial.Startport,//璧峰浣嶇疆 - EndLocat = taskDetial.Endport,//鐩爣浣嶇疆 - PalletNo = taskDetial.Pallno,//鎵樼洏鐮� - IsSend = 1,//鏄惁鍙啀娆′笅鍙� - IsCancel = 1,//鏄惁鍙彇娑� - IsFinish = 1,//鏄惁鍙畬鎴� - Type = taskDetial.Crtype,//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 - Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 - NoticeDetailNo = int.Parse(taskDetial.Noticedetailno.ToString()), - Msg = $"{taskDetial.Endport}鐨剓na}浠诲姟", //鍏抽敭淇℃伅 + Startport = detail.LocatNo, + Endport = endLocat.LocatNo, + Pallno = PalletNo, + Crtype = "2", }; - Db.Insertable(logTaskEntry).ExecuteCommand(); + string taskNo = ""; + CreateTaskForAgv(ztask, url); + + statrtLocat.Status = "3";//鍑哄簱涓� + //淇敼璧峰鍌ㄤ綅鐘舵�� + Db.Updateable(statrtLocat).ExecuteCommand(); + + detail.Status = "5";//寮傚父閿佸畾 + detail.PalletStatus = "3";//鑴忔《 + //淇敼搴撳瓨鐘舵�� + Db.Updateable(detail).ExecuteCommand(); } - var Agv = new AgvTask - { - taskCode = taskDetial.Taskno, - taskType = taskDetial.Type, - startPos = taskDetial.Startport, - endPos = taskDetial.Endport, - agvCode = "1",//鈥︹�﹂渶瑕佸拰AGV纭姝ゅ瓧娈靛�� - }; - //璇锋眰灏忚溅 - genAgvSchedulingTaskRep chrep =genAgvSchedulingTask(Agv, "url"); - if (chrep.code != "0") - { - sql = $"UPDATE LogTask SET IsSuccess = '0' WHERE TaskNo = {taskDetial.Taskno}"; - Db.Ado.ExecuteCommand(sql); - Db.CommitTran(); - throw new Exception("RCS浠诲姟涓嬪彂閿欒锛孯CS杩斿洖娑堟伅锛�"+chrep.message); - } - sql = $"UPDATE LogTask SET IsSuccess = 1,BackDate = {DateTime.Now},Status = '1' WHERE TaskNo = {taskDetial.Taskno}"; - Db.Ado.ExecuteCommand(sql); - //鎻愪氦浜嬪姟 Db.CommitTran(); } catch (Exception ex) @@ -382,7 +605,447 @@ Db.RollbackTran(); throw ex; } + } + /// <summary> + /// MES涓嬪彂娓呮礂閿佸畾鑴忔《 + /// </summary> + /// <param name="pallnetmsg"></param> + public void CleanPallet(Pallnetmsg pallnetmsg,string url) + { + try + { + var detail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == pallnetmsg.PalletNo && w.PalletStatus == "3"); + if (detail == null) + { + throw new Exception($"搴撳瓨涓笉瀛樺湪妗跺彿涓猴細{pallnetmsg.PalletNo}鐨勫簱瀛�!"); + } + //涓嬪彂灏忚溅浠诲姟 + var task = new TaskDetial + { + Startport = detail.LocatNo, + Endport = pallnetmsg.Location, + Pallno = detail.PalletNo, + Crtype = "1", + }; + string taskNo = ""; + CreateTaskForAgv(task,url); + } + catch (Exception ex) + { + throw ex; + } + } + + /// <summary> + /// 浠诲姟瀹屾垚 + /// </summary> + /// <param name="TaskNo"></param> + /// <param name="Status"></param> + /// <exception cref="Exception"></exception> + public void RCSFinishTask(string taskNo, string status, string comeFrom, int userId = 0) + { + try + { + #region 鏉′欢鍒ゆ柇 + var resultModel = new ErpModel() { Success = -1, Message = "" }; + if (string.IsNullOrEmpty(taskNo)) + { + throw new Exception("浠诲姟鍙蜂笉鍙负绌�"); + } + //浠诲姟淇℃伅 + var taskInfo = Db.Queryable<LogTask>().First(w => w.TaskNo == taskNo); + if (taskInfo == null) + { + throw new Exception($"浠诲姟鍙蜂负:{taskNo}鐨勪换鍔′笉瀛樺湪!"); + } + if (taskInfo.Status != "1" && comeFrom != "WMS") + { + throw new Exception($"浠诲姟鍙蜂负:{taskNo}鐨勪换鍔$姸鎬佸紓甯�"); + } + #endregion + //寮�鍚簨鍔� + Db.BeginTran(); + var comTime = DateTime.Now; + + if (status == "0") + { + taskInfo.Status = "3";//寮傚父缁撴潫 + //淇敼浠诲姟鐘舵�� + Db.Updateable(taskInfo).ExecuteCommand(); + + resultModel.Success = 0; + resultModel.Message = "鎴愬姛"; + + //鎻愪氦浜嬪姟 + Db.CommitTran(); + + return; + } + //搴撳瓨鏄庣粏 + var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == taskInfo.PalletNo); + if (stockDetail == null) + { + throw new Exception($"妗跺簱瀛樹俊鎭笉瀛樺湪"); + } + //璧峰鍌ㄤ綅淇℃伅 + var startLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.StartLocat && w.IsDel == "0"); + if (startLocatInfo == null) + { + throw new Exception($"璧峰鍌ㄤ綅淇℃伅涓嶅瓨鍦�"); + } + startLocatInfo.Status = "0";//绌哄偍浣� + //淇敼璧峰鍌ㄤ綅鐘舵�� + Db.Updateable(startLocatInfo).ExecuteCommand(); + + //鐩爣鍌ㄤ綅淇℃伅 + var endLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.EndLocat && w.IsDel == "0"); + if (endLocatInfo == null) + { + throw new Exception($"鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�"); + } + endLocatInfo.Status = "1";//鏈夌墿鍝� + //淇敼鐩爣鍌ㄤ綅鐘舵�� + Db.Updateable(endLocatInfo).ExecuteCommand(); + + //鐩爣鍌ㄤ綅鎵�灞炲尯鍩� + var endAreaInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.WareHouseNo == endLocatInfo.WareHouseNo && w.AreaNo == endLocatInfo.AreaNo); + if (endAreaInfo == null) + { + throw new Exception($"鐩爣鍌ㄤ綅鎵�灞炲尯鍩熶俊鎭笉瀛樺湪"); + } + + stockDetail.WareHouseNo = endLocatInfo.WareHouseNo;//鎵�灞炰粨搴� + stockDetail.RoadwayNo = endLocatInfo.RoadwayNo;//鎵�灞炲贩閬� + stockDetail.AreaNo = endLocatInfo.AreaNo;//鎵�灞炲尯鍩� + stockDetail.LocatNo = endLocatInfo.LocatNo;//鍌ㄤ綅鍦板潃 + if (endAreaInfo.Type == "0")//娲佸噣鍖� + { + stockDetail.PalletStatus = "0"; + stockDetail.Status = "0";//寰呭垎閰� + } + else if (endAreaInfo.Type == "1")//棰勬贩鍖� + { + stockDetail.PalletStatus = "1"; + stockDetail.Status = "0";//寰呭垎閰� + } + else if (endAreaInfo.Type == "2")//鍗婃垚鍝佸尯 + { + stockDetail.PalletStatus = "2"; + stockDetail.Status = "0";//寰呭垎閰� + } + else if (endAreaInfo.Type == "3")//鑴忔《鍖� + { + stockDetail.PalletStatus = "3"; + stockDetail.LotNo = "";//鎵规 + stockDetail.SkuNo = ""; + stockDetail.SkuName = ""; + stockDetail.Status = "0";//寰呭垎閰� + stockDetail.InspectStatus = "0";//寰呮楠� + } + //淇敼搴撳瓨鏄庣粏 + Db.Updateable(stockDetail).ExecuteCommand(); + //鍏ュ簱浠诲姟锛屽鐞嗗叆搴撳崟 + if (taskInfo.Type == "0" && taskInfo.NoticeDetailNo != 0) + { + var notice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.Status == "1"); + if (notice != null) + { + notice.Status = "2";//鎵ц瀹屾垚 + notice.UpdateTime = DateTime.Now; + notice.CompleteTime = DateTime.Now; + //淇敼鍏ュ簱鍗曠姸鎬� + Db.Updateable(notice).ExecuteCommand(); + } + } + //鍑哄簱浠诲姟锛屽鐞嗗嚭搴撳崟 + if (taskInfo.Type == "1" && taskInfo.NoticeDetailNo != 0)//鍏ュ簱 + { + var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.Status == "3"); + if (notice != null) + { + notice.Status = "4";//鎵ц瀹屾垚 + notice.UpdateTime = DateTime.Now; + notice.CompleteTime = DateTime.Now; + //淇敼鍏ュ簱鍗曠姸鎬� + Db.Updateable(notice).ExecuteCommand(); + } + } + + #region 鍘绘帀MES + //鍥炰紶妗剁姸鎬佺粰MES + //BackPalletStatus(taskInfo.PalletNo, sd3.PalletStatus); + #endregion + + taskInfo.Status = "2";//鎵ц瀹屾垚 + taskInfo.IsSend = 0; + taskInfo.IsCancel = 0; + taskInfo.IsFinish = 0; + taskInfo.FinishDate = DateTime.Now;//瀹屾垚鏃堕棿 + //淇敼浠诲姟鐘舵�� + Db.Updateable(taskInfo).ExecuteCommand(); + + if (comeFrom == "WMS") + { + //娣诲姞鎿嶄綔鏃ュ織璁板綍 + var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskInfo.TaskNo, "瀹屾垚", $"鐐瑰嚮瀹屾垚鎸夐挳銆佷换鍔″彿涓猴細{taskInfo.TaskNo}鐨勪换鍔�", userId); + } + //鎻愪氦浜嬪姟 + Db.CommitTran(); + } + catch (Exception ex) + { + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + throw new Exception(ex.Message); + } + } + + /// <summary> + /// 鎵嬪姩鍙栨秷浠诲姟 + /// </summary> + /// <param name="taskNo"></param> + /// <param name="userId"></param> + /// <exception cref="Exception"></exception> + public void CancelTask(string taskNo, int userId) + { + try + { + //寮�鍚簨鍔� + Db.BeginTran(); + //浠诲姟淇℃伅 + var task = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo && m.IsDel == "0"); + if (task == null) + { + throw new Exception("鏈煡璇㈠埌浠诲姟淇℃伅"); + } + //if (task.Status != "0") + //{ + // throw new Exception("鍙湁绛夊緟鎵ц鐨勪换鍔℃墠鍙彇娑�"); + //} + //淇敼浠诲姟 + task.IsSuccess = 0; + task.IsSend = 0; + task.IsCancel = 0; + task.IsFinish = 0; + task.Status = "4";//宸插彇娑� + task.CancelDate = DateTime.Now; + Db.Updateable(task).ExecuteCommand(); + + //淇敼璧峰鍌ㄤ綅淇℃伅 + var locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.StartLocat); + if (locat == null) + { + throw new Exception("鏈煡璇㈠埌璧峰浣嶇疆鍌ㄤ綅淇℃伅锛岃鏍稿疄锛�"); + } + locat.Status = "1"; //鏈夌墿鍝� + Db.Updateable(locat).ExecuteCommand(); + + //淇敼鐩爣鍌ㄤ綅淇℃伅 + var locatEnd = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.EndLocat); + if (locatEnd == null) + { + throw new Exception("鏈煡璇㈠埌鐩爣浣嶇疆鍌ㄤ綅淇℃伅锛岃鏍稿疄锛�"); + } + locatEnd.Status = "0"; //绌哄偍浣� + Db.Updateable(locatEnd).ExecuteCommand(); + + if (task.Type == "1")//鍑哄簱浠诲姟 + { + //淇敼搴撳瓨鏄庣粏 + var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == task.PalletNo && w.Status == "2"); + if (stockDetail == null) + { + throw new Exception("鏈煡璇㈠埌璇ユ《搴撳瓨淇℃伅,璇锋鏌�!"); + } + stockDetail.Status = "0";//寰呭垎閰� + Db.Updateable(stockDetail).ExecuteCommand(); + } + //娣诲姞鎿嶄綔鏃ュ織璁板綍 + var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "鍙栨秷", $"鐐瑰嚮鍙栨秷鎸夐挳銆佸彇娑堜簡浠诲姟鍙蜂负锛歿taskNo}鐨勪换鍔�", userId); + Db.CommitTran(); + } + catch (Exception e) + { + Db.RollbackTran(); + throw new Exception(e.Message); + } + } + /// <summary> + /// 鎵嬪姩涓嬪彂浠诲姟 + /// </summary> + /// <param name="taskNo"></param> + /// <param name="userId"></param> + /// <exception cref="Exception"></exception> + public void DownTask(string taskNo, int userId,string url) + { + try + { + //寮�鍚簨鍔� + Db.BeginTran(); + //浠诲姟淇℃伅 + var logTaskEntry = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo && m.IsDel == "0"); + if (logTaskEntry == null) + { + throw new Exception("鏈煡璇㈠埌浠诲姟淇℃伅"); + } + if (logTaskEntry.Status != "0") + { + throw new Exception("鍙湁绛夊緟鎵ц鐨勪换鍔℃墠鍙墜鍔ㄤ笅鍙�"); + } + //鏌ユ壘璇ユ《鏈夋病鏈夋鍦ㄦ墽琛岀殑浠诲姟 + var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.PalletNo == logTaskEntry.PalletNo); + if (tasking != null) + { + throw new Exception($"璇ユ《鏈夋鍦ㄦ墽琛岀殑浠诲姟"); + } + //璧峰鍌ㄤ綅淇℃伅 + var startLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == logTaskEntry.StartLocat); + if (startLocatInfo == null) + { + throw new Exception($"鏈煡璇㈠埌璧峰鍌ㄤ綅淇℃伅"); + } + if (startLocatInfo.Status != "1") + { + throw new Exception($"璧峰鍌ㄤ綅鐘舵�佸紓甯�"); + } + //鐩爣鍌ㄤ綅淇℃伅 + var endLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == logTaskEntry.EndLocat); + if (endLocatInfo == null) + { + throw new Exception($"鏈煡璇㈠埌鐩爣鍌ㄤ綅淇℃伅"); + } + if (endLocatInfo.Status != "0") + { + throw new Exception($"鐩爣鍌ㄤ綅鐘舵�佸紓甯�"); + } + //缁勭粐缁欏皬杞︿笅鍙戜换鍔′俊鎭� + var task = new TaskDetial + { + Taskno = taskNo,//浠诲姟鍙� + Startport = logTaskEntry.StartLocat, + Endport = logTaskEntry.EndLocat, + Pallno = logTaskEntry.PalletNo, + Crtype = logTaskEntry.Type, + }; + //缁欎笅杞︿笅鍙戜换鍔� + logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂� + var agvResult = CreateTaskForAgv(task, url); + if (agvResult)//鎴愬姛 + { + //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬� + logTaskEntry.IsSuccess = 1; + logTaskEntry.IsSend = 0; + logTaskEntry.IsCancel = 0; + logTaskEntry.BackDate = DateTime.Now; + logTaskEntry.Status = "1";//姝e湪鎵ц + Db.Insertable(logTaskEntry).ExecuteCommand(); + + startLocatInfo.Status = "3";//鍑哄簱涓� + Db.Updateable(startLocatInfo).ExecuteCommand(); + + endLocatInfo.Status = "2";//鍏ュ簱涓� + Db.Updateable(endLocatInfo).ExecuteCommand(); + } + else//澶辫触 + { + logTaskEntry.IsSuccess = 0; + Db.Insertable(logTaskEntry).ExecuteCommand(); + } + + //娣诲姞鎿嶄綔鏃ュ織璁板綍 + var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "涓嬪彂", $"鐐瑰嚮涓嬪彂鎸夐挳銆佷换鍔″彿涓猴細{taskNo}鐨勪换鍔�", userId); + Db.CommitTran(); + } + catch (Exception e) + { + Db.RollbackTran(); + throw new Exception(e.Message); + } + } + + /// <summary> + /// 鐢熸垚浠诲姟鍗曞埌LogTask + /// </summary> + /// <param name="req"></param> + /// <returns></returns> + public bool CreateTaskForAgv(TaskDetial taskDetial, string url) + { + bool result = false; + + #region 鍛煎彨灏忚溅浠g爜 + List<PositionCodePath> pahtList = new List<PositionCodePath>(); + //璧峰浣嶇疆 + PositionCodePath path1 = new PositionCodePath(); + path1.positionCode = taskDetial.Startport; + if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛� + { + path1.type = "05"; + } + else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛� + { + path1.type = "05"; + } + pahtList.Add(path1); + + //鐩爣浣嶇疆 + PositionCodePath path2 = new PositionCodePath(); + path2.positionCode = taskDetial.Endport; + if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛� + { + path2.type = "05"; + } + else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛� + { + path2.type = "05"; + } + pahtList.Add(path2); + + //涓嬭溅浠诲姟鍗� + AgvSchedulingTask agvTask = new AgvSchedulingTask(); + agvTask.reqCode = taskDetial.Taskno;//璇锋眰缂栧彿 + agvTask.taskCode = taskDetial.Taskno;//浠诲姟鍙� + agvTask.ctnrCode = taskDetial.Pallno;//妗跺彿 + agvTask.ctnrTyp = "1";// 1:妗� 3锛氭墭鐩� + agvTask.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//璇锋眰鏃堕棿 + agvTask.wbCode = ""; + agvTask.positionCodePath = pahtList;//灏忚溅璺緞 + agvTask.podCode = ""; + agvTask.userCallCode = "";//taskDetial.Endport;//鐩爣浣嶇疆 + if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛� + { + agvTask.taskTyp = "Z3";//浠诲姟绫诲瀷 绾胯竟鍒版墭鐩樻敹闆嗗櫒 Z1锛� 鎵樼洏鍨涚敵璇峰叆搴� Z2 + } + else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛� + { + agvTask.taskTyp = "Z4";//浠诲姟绫诲瀷 绾胯竟鍒版墭鐩樻敹闆嗗櫒 Z1锛� 鎵樼洏鍨涚敵璇峰叆搴� Z2 + } + + // 姝e紡杩愯绋嬪簭鏀惧紑 + var jsonData = JsonConvert.SerializeObject(agvTask); + string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV"); + //瑙f瀽杩斿洖鏁版嵁 + var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response); + if (agvModel.Code == "0") + { + result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔� + } + else + { + string logMsg = ""; + if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛� + { + logMsg = "鐢宠鍙《"; + } + else if (taskDetial.Crtype == "0")//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛� + { + logMsg = "鐢宠鍌ㄤ綅"; + } + var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; + LogFile.SaveLogToFile($"AGV{logMsg}寮傚父锛�( {agvModel.Message} ),", logStr); + } + return result; + #endregion } } } -- Gitblit v1.8.0