From 6c3738d337fe68c2008b38ad58861aa4b48d5530 Mon Sep 17 00:00:00 2001 From: DESKTOP-9BNTV8O <DESKTOP-9BNTV8O@163.com> Date: 星期五, 13 十二月 2024 14:46:40 +0800 Subject: [PATCH] 修改问题 --- Wms/WMS.BLL/BllTransServer/RcsServer.cs | 652 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 480 insertions(+), 172 deletions(-) diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs index 9e5242b..1576fe2 100644 --- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs +++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs @@ -1,20 +1,25 @@ -锘縰sing Microsoft.IdentityModel.Protocols; +锘縰sing Model.InterFaceModel; using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; +using System.Security.Policy; 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 { - public class RcsServer + public class RcsServer:IRcsServer { private static readonly SqlSugarScope Db = DataContext.Db; /// <summary> @@ -23,99 +28,252 @@ /// <param name="warehouseno">搴撳尯</param> /// <param name="type">鍙枡绫诲瀷</param> /// <returns></returns> - public void GetPalletNo(string warehouseno, string type, out string palletno, out string locatno) + public void GetPalletNo(Pallnetmsg model,string url,out string taskNo) { - var sql = "select LocatNo,palletno from SysStorageLocat where status = '1'"; - SysStorageLocat pallet = new SysStorageLocat(); + DataStockDetail pallet = new DataStockDetail(); try { - switch (type) + if (string.IsNullOrEmpty(model.Location)) + { + throw new Exception("璁惧鎵�鍦ㄤ綅缃笉鍙负绌�"); + } + var locatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location); + if (locatInfo == null) + { + throw new Exception("璁惧鍌ㄤ綅淇℃伅涓嶅瓨鍦�"); + } + var house = locatInfo.WareHouseNo;//鍙《浣嶇疆锛屽悗缁牴鎹綅缃叧鑱旀垨瀹氫箟锛屾潵鍒ゆ柇鍙《浣嶇疆鎵�灞炶溅闂� + var urlMes = "";//鍥炰紶MES鐨勬帴鍙e湴鍧� + var noticeno = "0";//鍑哄叆搴撳崟鎹槑缁咺D + var sql = "select PalletNo,LocatNo from DataStockDetail where Status = '0'"; + switch (model.Type) { case "0"://鍙噣妗� - sql += $"and WareHouseNo = 'A01' and WareHouseNo = '{warehouseno}' order by updatetime desc"; - pallet = Db.Ado.SqlQuery<SysStorageLocat>(sql).FirstOrDefault(); + sql += $"and WareHouseNo = '{house}' and (AreaNo like '%01' or AreaNo like '%11' or AreaNo like '%21' or AreaNo like '%31') and PalletStatus = '0' order by CreateTime desc"; + pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); if (pallet == null) { throw new Exception("鏆傛棤鍑�妗跺彲鍒嗛厤"); } - break; - case "3"://鍙剰妗� - sql += $"and WareHouseNo = 'A04' and WareHouseNo = '{warehouseno}' order by updatetime desc"; - pallet = Db.Ado.SqlQuery<SysStorageLocat>(sql).FirstOrDefault(); - if (pallet == null) - { - throw new Exception("鏆傛棤鑴忔《鍙垎閰�"); - } - break; - } - palletno = pallet.PalletNo; - locatno = pallet.LocatNo; - } - catch (Exception) - { - throw; - } - } - - /// <summary> - /// RCS鍙《(娣锋枡妗跺拰涓嬫枡妗�) - /// </summary> - /// <param name="warehouseno">搴撳尯</param> - /// <param name="type">鍙枡绫诲瀷</param> - /// <param name="lotno">鍙枡鎵规</param> - /// <returns></returns> - public void GetPalletNo(string warehouseno, string type, string lotno, out string palletno, out string locatno) - { - var sql = ""; - var pallet = ""; - DataStockDetail SoMes = new DataStockDetail(); - try - { - switch (type) - { + break; case "1"://鍙枡妗讹紙娣锋枡锛� - BllArrivalNoticeDetail ArriveMes = new BllArrivalNoticeDetail(); - //鍒ゆ柇璇ユ壒娆℃槸鍚︽湁瀵瑰簲鍏ュ簱鍗� - sql += $"select * from BllArrivalNoticeDetail where LotNo = '{lotno}' order by CreateTime desc"; - ArriveMes = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault(); - if (ArriveMes == null) + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(model.LotNo)) { - throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); + throw new Exception("鎵规鍙蜂负绌猴紒"); } //鏌ユ壘搴撳瓨涓槸鍚︽湁鍙敤鐨勬鎵规鐨勬贩鏂欐《 - sql = $"select LocatNo,palletno from DataStockDetail " + - $"left join SysStorageLocat b on a.LocatNo = b.LocatNo " + - $"where a.LotNo = '{lotno}'and a.WareHouseNo = '{warehouseno}' and b.status = '1' " + - $"order by CompleteTime desc"; - SoMes = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); + sql= $@"select PalletNo,LocatNo from DataStockDetail where LotNo = '{model.LotNo}'and (AreaNo like '%02' or AreaNo like '%12' or AreaNo like '%22' or AreaNo like '%32') + and WareHouseNo = '{house}' and status = '0' and PalletStatus = '1' order by CompleteTime desc"; + pallet = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); if (pallet == null) { throw new Exception("鏆傛棤娣锋枡妗跺彲鍒嗛厤"); } + break; case "2"://鍙枡妗讹紙涓嬫枡锛� - //鏌ユ壘搴撳瓨涓槸鍚︽湁姝ゆ壒娆$殑涓嬫枡妗� - sql = $"select LocatNo,palletno from DataStockDetail" + - $"left join SysStorageLocat b on a.LocatNo = b.LocatNo " + - $"where a.LotNo = '{lotno}'and a.WareHouseNo = '{warehouseno}' and b.status = '1'" + - $" order by CompleteTime desc"; - SoMes = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); + BllExportNoticeDetail bllSo = new BllExportNoticeDetail(); + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(model.LotNo)) + { + throw new Exception("鎵规鍙蜂负绌猴紒"); + } + //鏌ユ壘鏄惁鏈夋鎵规鍑哄簱鍗� + sql = $"select * from BllExportNoticeDetail where LotNo = '{model.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 = '{model.LotNo}'and (AreaNo like '%03' or AreaNo like '%13' or AreaNo like '%23' or AreaNo like '%33') + and WareHouseNo = '{house}' and status = '0' and PalletStatus = '2' and InspectStatus = '1' 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' or AreaNo like '%14' or AreaNo like '%24' or AreaNo like '%34') and PalletStatus='3' order by CreateTime desc"; + List<DataStockDetail> palletList = Db.Ado.SqlQuery<DataStockDetail>(sql).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 + + //涓嬪彂灏忚溅浠诲姟 + var task2 = new TaskDetial + { + Startport = item.LocatNo, + Endport = model.Location, + Pallno = item.PalletNo, + Type = model.Type, + Crtype = "1", + Noticedetailno = int.Parse(noticeno), + }; + CreateLotTask(task2, url, out taskNo); + return; + } + break; + default: + throw new Exception("浠诲姟绫诲瀷鏃犳晥"); } - palletno = SoMes.PalletNo; - locatno = SoMes.LocatNo; - + //涓嬪彂灏忚溅浠诲姟 + var task = new TaskDetial + { + Startport = pallet.LocatNo,//璧峰浣嶇疆 + Endport = model.Location,//鐩爣浣嶇疆 + Pallno = pallet.PalletNo,//妗跺彿 + Type = model.Type,//妗剁被鍨� + Crtype = "1", + Noticedetailno = int.Parse(noticeno), + LotNo = model.LotNo, + }; + CreateLotTask(task, url, out taskNo); + return; } - catch (Exception) + catch (Exception ex) { + Db.Ado.RollbackTran(); + throw new Exception(ex.Message); + } + } - throw; + /// <summary> + /// MES涓嬪彂灏嗗噣妗舵敼涓鸿剰妗跺苟鎷夊埌鑴忔《鍖� + /// </summary> + /// <param name="PalletNo"></param> + /// <returns></returns> + public void ChangePalletStatus(string PalletNo,string url) + { + try + { + 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(); + + //鏌ユ壘鏄惁鏈夌┖浣欒剰妗朵綅 + var endLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo.Contains("04") && w.Status == "0" && w.Flag=="0"); + if (endLocat == null) + { + detail.Status = "5";//寮傚父閿佸畾 + detail.PalletStatus = "3";//鑴忔《 + //淇敼搴撳瓨鐘舵�� + Db.Updateable(detail).ExecuteCommand(); + } + else + { + //鐢熸垚璋冨害灏忚溅鍑�妗跺幓鑴忔《鍖轰换鍔� + var ztask = new TaskDetial + { + Startport = detail.LocatNo, + Endport = endLocat.LocatNo, + Pallno = PalletNo, + Type = "3", + Crtype = "2", + Noticedetailno = 0, + }; + string taskNo = ""; + CreateLotTask(ztask, url, out taskNo); + + statrtLocat.Status = "3";//鍑哄簱涓� + //淇敼璧峰鍌ㄤ綅鐘舵�� + Db.Updateable(statrtLocat).ExecuteCommand(); + + detail.Status = "5";//寮傚父閿佸畾 + detail.PalletStatus = "3";//鑴忔《 + //淇敼搴撳瓨鐘舵�� + Db.Updateable(detail).ExecuteCommand(); + } + Db.CommitTran(); + } + catch (Exception ex) + { + 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, + Type = "3", + Crtype = "1", + Noticedetailno = 0, + LotNo = "", + }; + string taskNo = ""; + CreateLotTask(task,url, out taskNo); + } + catch (Exception ex) + { + throw ex; } } @@ -124,160 +282,310 @@ /// </summary> /// <param name="PalletNo"></param> /// <returns></returns> - public void ApplyLocatNo(string palletno, string type, out string locatno) + public void ApplyLocatNo(Pallnetmsg model,string url, out string taskNo) { var sql = $"select LocatNo from SysStorageLocat where status = '0'"; - SysStorageLocat loction = new SysStorageLocat(); + var sql2 = ""; + var houseNo = "";//鐢宠鍌ㄤ綅璁惧鎵�鍦ㄨ溅闂寸紪鍙� + var noticeno = "0";//鍑哄叆搴撳崟鎹槑缁咺D + SysStorageLocat loction = new SysStorageLocat();//鐩爣鍌ㄤ綅淇℃伅 + BllArrivalNoticeDetail noticeDetail = new BllArrivalNoticeDetail();//鍏ュ簱鍗曟槑缁� try { - switch (type) + //璁惧鎵�鍦ㄥ偍浣嶄俊鎭� + var deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LotNo); + if (deviceLocatInfo == null) { - case "0"://鍑�妗剁敵璇峰偍浣� - sql += $"and WareHouseNo = 'A01'"; + throw new Exception($"鏈煡璇㈠埌璇ヨ澶囨墍鍦ㄥ偍浣嶄俊鎭紝Location:{model.Location}"); + } + houseNo = deviceLocatInfo.WareHouseNo;//璁惧鎵�灞炶溅闂� + switch (model.Type) + { + case "3"://娓呮礂璁惧鐢宠鍌ㄤ綅锛堝噣妗剁敵璇峰偍浣嶏級 + sql += $" and (AreaNo like '%01' or AreaNo like '%11' or AreaNo like '%21' or AreaNo like '%31') and WareHouseNo = '{houseNo}'"; loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑鍑�妗跺偍浣�"); + throw new Exception("璇ヨ溅闂村噣妗跺尯鏆傛棤绌轰綑鍌ㄤ綅"); } break; - case "1"://娣锋枡妗剁敵璇峰偍浣� - sql += $"and WareHouseNo = 'A02'"; + case "0"://鎺ユ枡璁惧鐢宠鍌ㄤ綅锛堥娣锋枡妗剁敵璇峰偍浣嶏級 + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(model.LotNo)) + { + throw new Exception("鎵规鍙蜂负绌猴紒"); + } + sql += $" and (AreaNo like '%02' or AreaNo like '%12' or AreaNo like '%22' or AreaNo like '%32') and WareHouseNo = '{houseNo}'"; loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑娣锋枡妗跺偍浣�"); + throw new Exception("璇ヨ溅闂撮娣峰尯鏆傛棤绌轰綑鍌ㄤ綅"); } break; - case "2"://鍗婃垚鍝佹《鐢宠鍌ㄤ綅 - sql += $"and WareHouseNo = 'A03'"; + case "1"://娣锋枡璁惧鐢宠鍌ㄤ綅锛堝崐鎴愬搧妗剁敵璇峰偍浣嶏級 + //鍒ゆ柇鏄惁鏈夋壒娆″彿 + if (string.IsNullOrWhiteSpace(model.LotNo)) + { + throw new Exception("鎵规鍙蜂负绌猴紒"); + } + //鏍¢獙姝ゆ壒娆℃槸鍚︽湁鍏ュ簱鍗� + sql2 = $"select * from BllArrivalNoticeDetail where LotNo = '{model.LotNo}' order by CreateTime desc"; + noticeDetail = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql2).FirstOrDefault(); + if (noticeDetail == null) + { + throw new Exception("璇ユ壒娆℃病鏈夊搴旂殑鍏ュ簱鍗�"); + } + noticeno = noticeDetail.Id.ToString(); + sql += $" and (AreaNo like '%03' or AreaNo like '%13' or AreaNo like '%23' or AreaNo like '%33') and WareHouseNo = '{houseNo}'"; loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑鍗婃垚鍝佹《鍌ㄤ綅"); + throw new Exception("璇ヨ溅闂村崐鎴愬搧鍖烘殏鏃犵┖浣欏偍浣�"); } break; - case "3"://鑴忔《鐢宠鍌ㄤ綅 - sql += $"and WareHouseNo = 'A04'"; + case "2"://涓嬫枡璁惧鐢宠鍌ㄤ綅锛堣剰妗剁敵璇峰偍浣嶏級 + sql += $" and (AreaNo like '%04' or AreaNo like '%14' or AreaNo like '%24' or AreaNo like '%34') and WareHouseNo = '{houseNo}'"; loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); if (loction == null) { - throw new Exception("搴撳唴鏆傛棤绌轰綑鑴忔《鍌ㄤ綅"); + throw new Exception("璇ヨ溅闂磋剰妗跺尯鏆傛棤绌轰綑鍌ㄤ綅"); } break; } - locatno = loction.PalletNo; - } - 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 string genAgvSchedulingTask(string taskCode, string taskType, string startPos, string endPos, string agvCode,string url, ref genAgvSchedulingTaskRep cbrep) - { - try - { - PositionCodePath pcd1 = new PositionCodePath() + var task = new TaskDetial { - positionCode = startPos.ToString(), - type = "00", + Startport = model.Location, + Endport = loction.LocatNo, + Pallno = model.PalletNo, + Type = model.Type, + Crtype = "0",//鍏ュ簱 + Noticedetailno = int.Parse(noticeno), + LotNo = model.LotNo, }; - PositionCodePath pcd2 = new PositionCodePath() - { - positionCode = endPos.ToString(), - type = "00", - }; - List<PositionCodePath> lst = new List<PositionCodePath>(); - lst.Add(pcd1); - lst.Add(pcd2); - genAgvSchedulingTaskReq cbreq = new genAgvSchedulingTaskReq() - { - reqCode = taskCode.ToString(), - taskCode = taskCode.ToString(), - taskTyp = taskType, - positionCodePath = lst, - podCode = "", - agvCode = agvCode, - ctnrTyp = "1", - //ctnrCode="2", - - }; - if (startPos == "50") - { - cbreq.ctnrTyp = "4"; - } - cbrep = genAgvSchedulingTask(cbreq,url); - - - return cbrep.code; - } - 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; + CreateLotTask(task, url, out taskNo); } catch (Exception ex) { - throw ex; + throw new Exception(ex.Message); } } - /// <summary> /// 鐢熸垚浠诲姟鍗曞埌LogTask /// </summary> /// <param name="req"></param> /// <returns></returns> - public void CreateLotTask(string startport,string endport,string type,string tasktype) + public void CreateLotTask(TaskDetial taskDetial,string url,out string taskNo) { try { + var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == taskDetial.Pallno);//妗跺簱瀛樻槑缁� + if (stockDetail == null) + { + throw new Exception($"璇ユ《鏈湪搴撳瓨涓紝妗跺彿锛歿taskDetial.Pallno}"); + } + //寮�鍚簨鍔� + Db.BeginTran(); + var typeDesc = ""; + switch (taskDetial.Crtype) + { + case "0": + typeDesc = "鍏ュ簱"; + break; + case "1": + typeDesc = "鍑哄簱"; + break; + case "2": + typeDesc = "绉诲簱"; + break; + } + var msg = ""; + switch (taskDetial.Type) + { + case "0": + msg = "鍑�妗�"+ typeDesc + "浠诲姟"; + break; + case "1": + msg = "棰勬贩鏂欐《" + typeDesc + "浠诲姟"; + break; + case "2": + msg = "鍗婃垚鍝佹枡妗�" + typeDesc + "浠诲姟"; + break; + case "3": + msg = "鑴忔《" + typeDesc + "浠诲姟"; + break; + } + #region 鍌ㄤ綅淇℃伅 + //璧峰鍌ㄤ綅鍦板潃淇℃伅 + var startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel=="0" && w.LocatNo == taskDetial.Startport); + if (startLoction == null) + { + throw new Exception($"璧峰鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦紝妗跺彿锛歿taskDetial.Startport}"); + } + //鐩爣鍌ㄤ綅鍦板潃淇℃伅 + var endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == taskDetial.Endport); + if (endLoction == null) + { + throw new Exception($"鐩爣鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦紝妗跺彿锛歿taskDetial.Endport}"); + } + #endregion + var sql = ""; + var sql2 = ""; + var ordertype = "3"; + //娑夊強鍑哄叆搴撳崟鎹殑鐘舵�佷俊鎭敼鍙� + if (taskDetial.Type == "2" && taskDetial.Crtype == "1")//鍗婃垚鍝佸嚭搴� + { + ordertype = "1"; + sql = $"UPDATE BllExportNotice SET Status ='1' " + + $"where SoNO = (select SoNO from BllExportNoticeDetail where id = {taskDetial.Noticedetailno})"; + Db.Ado.ExecuteCommand(sql); + } + else if (taskDetial.Type == "0" && taskDetial.Crtype == "0")//鎺ユ枡璁惧鐢宠鍌ㄤ綅锛堟贩鏂欐《鐢宠鍌ㄤ綅锛� + { + stockDetail.LotNo = taskDetial.LotNo;//鎵规鍙� + //鏇存柊妗跺簱瀛樻槑缁嗘壒娆″彿 + Db.Updateable(stockDetail).ExecuteCommand(); + } + else if (taskDetial.Type == "1" && 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 = msg, //鍏抽敭淇℃伅 + }; + taskNo = logTaskEntry.TaskNo; + #region 鍛煎彨灏忚溅浠g爜 + List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>(); + 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 = logTaskEntry.TaskNo;//浠诲姟鍙� + agvTask.ctnrTyp = "1"; + 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 + } + agvTaskList.Add(agvTask); + + // 姝e紡杩愯绋嬪簭鏀惧紑 + string str = ""; + var list2 = agvTaskList.Select(m => m.reqCode).ToList(); + var jsonData = JsonConvert.SerializeObject(agvTaskList); + jsonData = jsonData.Substring(1); + jsonData = jsonData.Substring(0, jsonData.Length - 1); + string response = ""; + try + { + logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂� + + response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV"); + //瑙f瀽杩斿洖鏁版嵁 + var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response); + if (agvModel.Code == "0") + { + str += "涓嬪彂鎴愬姛"; + + //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬� + logTaskEntry.IsSuccess = 1; + logTaskEntry.BackDate = DateTime.Now; + logTaskEntry.Status = "1"; + Db.Insertable(logTaskEntry).ExecuteCommand(); + + startLoction.Status = "3";//鍑哄簱涓� + Db.Updateable(startLoction).ExecuteCommand(); + + endLoction.Status = "2";//鍏ュ簱涓� + Db.Updateable(endLoction).ExecuteCommand(); + } + if (agvModel.Code == "1") + { + logTaskEntry.IsSuccess = 0; + Db.Insertable(logTaskEntry).ExecuteCommand(); + Db.CommitTran(); + throw new Exception("RCS浠诲姟涓嬪彂閿欒锛孯CS杩斿洖娑堟伅锛�" + agvModel.Message); + } + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + #endregion + //鎻愪氦浜嬪姟 + Db.CommitTran(); } - catch (Exception) + catch (Exception ex) { - - throw; + Db.RollbackTran(); + throw ex; } - } } } -- Gitblit v1.8.0