From 8db84793a19b02df61c8fb9e5d539c57b827da45 Mon Sep 17 00:00:00 2001 From: Administrator <Administrator@DESKTOP-5BIMHQ3> Date: 星期五, 28 六月 2024 16:53:58 +0800 Subject: [PATCH] 修改问题 --- Wms/WMS.BLL/BllTransServer/RcsServer.cs | 483 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 481 insertions(+), 2 deletions(-) diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs index f77469a..672a451 100644 --- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs +++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs @@ -1,10 +1,489 @@ -锘縰sing System; +锘縰sing Microsoft.IdentityModel.Protocols; +using Newtonsoft.Json; +using SqlSugar; +using System; using System.Collections.Generic; +using System.Linq; using System.Text; +using Utility.Tools; +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; namespace WMS.BLL.BllTransServer { - class RcsServer + public class RcsServer:IRcsServer { + private static readonly SqlSugarScope Db = DataContext.Db; + /// <summary> + /// 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(); + try + { + var house = "W01";//鍙《浣嶇疆锛屽悗缁牴鎹綅缃叧鑱旀垨瀹氫箟锛屾潵鍒ゆ柇鍙《浣嶇疆鎵�灞炶溅闂� + var url = "";//鍥炰紶MES鐨勬帴鍙e湴鍧� + var noticeno = "0";//鍑哄叆搴撳崟鎹槑缁咺D + var sql = "select PalletNo,LocatNo from DataStockDetail where Status = '0'"; + switch (pallnetmsg.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) + { + 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 = '{house}' 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 = item.PalletNo, + Type = "3", + Crtype = "0", + Noticedetailno = int.Parse(noticeno), + }; + CreateLotTask(ztask); + continue; + } + //涓嬪彂灏忚溅浠诲姟 + var task2 = new TaskDetial + { + Startport = item.LocatNo, + Endport = pallnetmsg.Location, + Pallno = item.PalletNo, + Type = pallnetmsg.Type, + Crtype = "1", + Noticedetailno = int.Parse(noticeno), + }; + CreateLotTask(task2); + return; + } + else + { + throw new Exception("鍥炰紶MES鍑�妗剁紪鍙峰け璐ワ紒"); + } + } + break; + case "1"://鍙枡妗讹紙娣锋枡锛� + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(pallnetmsg.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("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); + } + noticeno = ArriveMes.Id.ToString();*/ + //鏌ユ壘搴撳瓨涓槸鍚︽湁鍙敤鐨勬鎵规鐨勬贩鏂欐《 + sql= $"select PalletNo,LocatNo from DataStockDetail where LotNo = '{pallnetmsg.LotNo}'and AreaNo like '%02' " + + $"and WareHouseNo = '{house}' and status = '0' order by CompleteTime desc"; + pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); + if (pallet == null) + { + throw new Exception("鏆傛棤娣锋枡妗跺彲鍒嗛厤"); + } + + break; + case "2"://鍙枡妗讹紙涓嬫枡锛� + BllExportNoticeDetail bllSo = new BllExportNoticeDetail(); + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + { + throw new Exception("鎵规鍙蜂负绌猴紒"); + } + //鏌ユ壘鏄惁鏈夋鎵规鍑哄簱鍗� + sql = $"select * from BllExportNoticeDetail where LotNo = '{pallnetmsg.LotNo}' order by CreateTime desc"; + bllSo = Db.Ado.SqlQuery<BllExportNoticeDetail>(sql).FirstOrDefault(); + if (bllSo == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍑哄簱鍗�"); + } + noticeno = bllSo.Id.ToString(); + //鏌ユ壘搴撳瓨涓槸鍚︽湁姝ゆ壒娆$殑涓嬫枡妗� + sql = $"select PalletNo,LocatNo from DataStockDetail where LotNo = '{pallnetmsg.LotNo}'and AreaNo like '%03' " + + $"and WareHouseNo = '{house}' and status = '0' order by CompleteTime desc"; + pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); + if (pallet == null) + { + throw new Exception("鏆傛棤涓嬫枡妗跺彲鍒嗛厤"); + } + + 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) + { + throw new Exception("鏆傛棤鑴忔《鍙垎閰�"); + } + + break; + } + //涓嬪彂灏忚溅浠诲姟 + var task = new TaskDetial + { + Startport = pallet.LocatNo, + Endport = pallnetmsg.Location, + Pallno = pallet.PalletNo, + Type = pallnetmsg.Type, + Crtype = "1", + Noticedetailno = int.Parse(noticeno), + LotNo = pallnetmsg.LotNo, + }; + CreateLotTask(task); + return; + } + catch (Exception ex) + { + Db.Ado.RollbackTran(); + throw ex; + } + } + + /// <summary> + /// 鐢宠鍌ㄤ綅 + /// </summary> + /// <param name="PalletNo"></param> + /// <returns></returns> + public void ApplyLocatNo(Pallnetmsg pallnetmsg) + { + var sql = $"select LocatNo from SysStorageLocat where status = '0'"; + var sql2 = ""; + var house = "W01";//鈥︹�﹀彨妗朵綅缃紝鍚庣画鏍规嵁浣嶇疆鍏宠仈鎴栧畾涔夛紝鏉ュ垽鏂彨妗朵綅缃墍灞炶溅闂� + var noticeno = "0";//鍑哄叆搴撳崟鎹槑缁咺D + SysStorageLocat loction = new SysStorageLocat(); + BllArrivalNoticeDetail ArriveMes = new BllArrivalNoticeDetail(); + try + { + switch (pallnetmsg.Type) + { + case "0"://鍑�妗剁敵璇峰偍浣� + sql += $"and AreaNo like '%01' and WareHouseNo = '{house}'"; + loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + if (loction == null) + { + throw new Exception("搴撳唴鏆傛棤绌轰綑鍑�妗跺偍浣�"); + } + break; + case "1"://娣锋枡妗剁敵璇峰偍浣� + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + { + throw new Exception("鎵规鍙蜂负绌猴紒"); + } + //鏍¢獙姝ゆ壒娆℃槸鍚︽湁鍏ュ簱鍗� + /*sql2 = $"select * from BllArrivalNoticeDetail where LotNo = '{pallnetmsg.LotNo}' order by CreateTime desc"; + ArriveMes = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault(); + if (ArriveMes == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); + } + noticeno = ArriveMes.Id.ToString();*/ + sql += $"and AreaNo like '%02' and WareHouseNo = '{house}'"; + loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + if (loction == null) + { + throw new Exception("搴撳唴鏆傛棤绌轰綑娣锋枡妗跺偍浣�"); + } + break; + case "2"://鍗婃垚鍝佹《鐢宠鍌ㄤ綅 + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) + { + throw new Exception("鎵规鍙蜂负绌猴紒"); + } + //鏍¢獙姝ゆ壒娆℃槸鍚︽湁鍏ュ簱鍗� + sql2 = $"select * from BllArrivalNoticeDetail where LotNo = '{pallnetmsg.LotNo}' order by CreateTime desc"; + ArriveMes = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql2).FirstOrDefault(); + if (ArriveMes == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); + } + noticeno = ArriveMes.Id.ToString(); + sql += $"and AreaNo like '%03' and WareHouseNo = '{house}'"; + loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + if (loction == null) + { + throw new Exception("搴撳唴鏆傛棤绌轰綑鍗婃垚鍝佹《鍌ㄤ綅"); + } + break; + case "3"://鑴忔《鐢宠鍌ㄤ綅 + sql += $"and AreaNo like '%04' and WareHouseNo = '{house}'"; + loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); + if (loction == null) + { + throw new Exception("搴撳唴鏆傛棤绌轰綑鑴忔《鍌ㄤ綅"); + } + break; + } + var task = new TaskDetial + { + Startport = pallnetmsg.Location, + Endport = loction.LocatNo, + Pallno = pallnetmsg.Palletno, + Type = pallnetmsg.Type, + Crtype = "0", + Noticedetailno = int.Parse(noticeno), + LotNo = pallnetmsg.LotNo, + }; + 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() + { + positionCode = agv.startPos.ToString(), + type = "00", + }; + PositionCodePath pcd2 = new PositionCodePath() + { + 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; + } + catch (Exception ex) + { + throw ex; + } + } + + + /// <summary> + /// 鐢熸垚浠诲姟鍗曞埌LogTask + /// </summary> + /// <param name="req"></param> + /// <returns></returns> + public void CreateLotTask(TaskDetial taskDetial) + { + try + { + //寮�鍚簨鍔� + Db.BeginTran(); + var na = taskDetial.Crtype == "0"?"鍏ュ簱":"鍑哄簱"; + var bz = ""; + switch (taskDetial.Type) + { + case "0": + bz = "鍑�妗�"+na+"浠诲姟"; + break; + case "1": + bz = "棰勬贩鏂欐《" + na + "浠诲姟"; + break; + case "2": + bz = "鍗婃垚鍝佹枡妗�" + na + "浠诲姟"; + break; + case "3": + bz = "鑴忔《" + na + "浠诲姟"; + break; + } + var sql = ""; + var sql2 = ""; + var ordertype = "3"; + //娑夊強鍑哄叆搴撳崟鎹殑鐘舵�佷俊鎭敼鍙� + if (taskDetial.Type == "2" && taskDetial.Crtype =="1")//鍗婃垚鍝佸嚭搴� + { + ordertype = "1"; + sql = $"UPDATE BllExportNotice SET Status ='1' " + + $"where asnno = (select ASNNO from BllExportNoticeDetail where id = {taskDetial.Noticedetailno})"; + Db.Ado.ExecuteCommand(sql); + } + else if(taskDetial.Type =="2" && taskDetial.Crtype == "0")//鍗婃垚鍝佸叆搴� + { + ordertype = "0"; + var ArrivalMsg = Db.Queryable<BllArrivalNoticeDetail>().First(it => it.Id == taskDetial.Noticedetailno); + //淇敼鍏ュ簱鍗曟�昏〃涓崟鎹姸鎬佷负姝e湪鎵ц + sql = $"UPDATE BllArrivalNotice SET Status ='1' where asnno = '{ArrivalMsg.ASNNo}'"; + Db.Ado.ExecuteCommand(sql); + //搴撳瓨涓坊鍔犳鎵樼洏鐗╂枡缂栫爜鍜岀紪鐮佸悕绉� + sql2 = $"UPDATE DataStockDetail SET SkuNo = '{ArrivalMsg.SkuNo}',SkuName = '{ArrivalMsg.SkuName}' " + + $"where PalletNo = '{taskDetial.Pallno}'and LotNo = '{taskDetial.LotNo}'"; + Db.Ado.ExecuteCommand(sql2); + } + + //鍒ゆ柇浠诲姟鏄惁涓烘柊浠诲姟 + if (string.IsNullOrWhiteSpace(taskDetial.Taskno)) + { + taskDetial.Taskno = new Common().GetMaxNo("TK"); + } + var logTaskEntry = new LogTask + { + 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 绉诲簱浠诲姟 + OrderType = ordertype,//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3鍏朵粬 + Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + NoticeDetailNo = int.Parse(taskDetial.Noticedetailno.ToString()), + Msg = bz, //鍏抽敭淇℃伅 + }; + 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") + { + logTaskEntry.IsSuccess = 0; + Db.Insertable(logTaskEntry).ExecuteCommand(); + Db.CommitTran(); + throw new Exception("RCS浠诲姟涓嬪彂閿欒锛孯CS杩斿洖娑堟伅锛�" + chrep.message); + } + //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬� + logTaskEntry.IsSuccess = 1; + logTaskEntry.BackDate = DateTime.Now; + logTaskEntry.Status = "1"; + if (taskDetial.Crtype == "0") + { + sql = $"UPDATE SysStorageLocat SET Status = '2' where LocatNo = '{taskDetial.Endport}'"; + if (taskDetial.Type == "2") + { + sql2 = $"UPDATE DataStockDetail SET PalletStatus = '{taskDetial.Type}',LotNo = '{taskDetial.LotNo}' " + + $"where PalletNo = '{taskDetial.Pallno}'"; + Db.Ado.ExecuteCommand(sql2); + } + } + else + { + sql = $"UPDATE SysStorageLocat SET Status = '3' where LocatNo = '{taskDetial.Startport}' "; + } + Db.Insertable(logTaskEntry).ExecuteCommand(); + Db.Ado.ExecuteCommand(sql); + //鎻愪氦浜嬪姟 + Db.CommitTran(); + } + catch (Exception ex) + { + Db.RollbackTran(); + throw ex; + } + + } } } -- Gitblit v1.8.0