| | |
| | | using Microsoft.IdentityModel.Protocols; |
| | | using 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.SysEntity; |
| | | using WMS.IBLL.IBllTransServer; |
| | | using static Model.InterFaceModel.RCSModel; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | |
| | | namespace WMS.BLL.BllTransServer |
| | | { |
| | |
| | | { |
| | | 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的接口地址 |
| | | var noticeno = "0";//出入库单据明细ID |
| | | 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的接口地址 |
| | | var noticeNo = "0";//出入库单据明细ID |
| | | 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);//解析返回数据 |
| | | 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 = item.PalletNo, |
| | | Type = "4", |
| | | Crtype = "0", |
| | | Noticedetailno = int.Parse(noticeno), |
| | | }; |
| | | CreateLotTask(ztask); |
| | | return; |
| | | } |
| | | //下发小车任务 |
| | | 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净桶编号失败!"); |
| | | } |
| | | } |
| | | } |
| | | 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("该批次没有对应的入库单"); |
| | | } |
| | | noticeno = ArriveMes.Id.ToString();*/ |
| | | //查找到该车间预混区 |
| | | 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= $"select PalletNo,LocatNo from DataStockDetail 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"://叫料桶(下料) |
| | | BllExportNoticeDetail bllSo = new BllExportNoticeDetail(); |
| | | //判断是否有批次号 |
| | | if (string.IsNullOrWhiteSpace(pallnetmsg.LotNo)) |
| | | if (string.IsNullOrWhiteSpace(model.LotNo)) |
| | | { |
| | | throw new Exception("批次号为空!"); |
| | | } |
| | | //查找是否有此批次出库单 |
| | | sql = $"select * from BllSoNoticeDetail where LotNo = '{pallnetmsg.LotNo}' order by CreateTime desc"; |
| | | bllSo = Db.Ado.SqlQuery<BllExportNoticeDetail>(sql).FirstOrDefault(); |
| | | if (bllSo == null) |
| | | //查找是否有此批次出库单明细 |
| | | 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("该批次没有对应的出库单"); |
| | | } |
| | | noticeno = bllSo.Id.ToString(); |
| | | //查找库存中是否有此批次的下料桶 |
| | | sql += $"select PalletNo,LocatNo from DataStockDetail 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(); |
| | | soNotice.Status = "3";//正在执行 |
| | | 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("暂无脏桶可分配"); |
| | | } |
| | | //遍历库存脏桶,返回MES验证 |
| | | 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);//解析返回数据 |
| | | //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正在执行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正在执行2执行完成 |
| | | NoticeDetailNo = int.Parse(noticeNo), |
| | | Msg = taskMsg, //关键信息 |
| | | }; |
| | | |
| | | //组织下发小车任务信息 |
| | | var task = new TaskDetial |
| | | { |
| | | Startport = pallet.LocatNo, |
| | | Endport = pallnetmsg.Location, |
| | | Pallno = pallet.PackagNo, |
| | | Type = pallnetmsg.Type, |
| | | Crtype = "1", |
| | | Noticedetailno = int.Parse(noticeno), |
| | | Taskno= taskNo,//任务号 |
| | | Startport = pallet.LocatNo,//起始位置 |
| | | Endport = model.Location,//目标位置 |
| | | Pallno = pallet.PalletNo,//桶号 |
| | | Crtype = "1",//叫桶 |
| | | }; |
| | | CreateLotTask(task); |
| | | return; |
| | | //给下车下发任务 |
| | | 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";//正在执行 |
| | | 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 sql2 = ""; |
| | | var house = "W01";//……叫桶位置,后续根据位置关联或定义,来判断叫桶位置所属车间 |
| | | var noticeno = "";//出入库单据明细ID |
| | | SysStorageLocat loction = new SysStorageLocat(); |
| | | BllArrivalNoticeDetail ArriveMes = new BllArrivalNoticeDetail(); |
| | | /// <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(); |
| | | 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>(sql).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; |
| | | throw new Exception($"该桶有正在执行的任务,PalletNo:{model.PalletNo}"); |
| | | } |
| | | var task = new TaskDetial |
| | | //设备所在储位信息(起始储位) |
| | | var deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location); |
| | | if (deviceLocatInfo == null) |
| | | { |
| | | Startport = pallnetmsg.Location, |
| | | Endport = loction.LocatNo, |
| | | Pallno = pallnetmsg.Palletno, |
| | | Type = pallnetmsg.Type, |
| | | Crtype = "0", |
| | | Noticedetailno = int.Parse(noticeno), |
| | | }; |
| | | 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 |
| | | { |
| | | var na = taskDetial.Crtype == "0"?"入库":"出库"; |
| | | var sql = ""; |
| | | var sql2 = ""; |
| | | var ordertype = "3"; |
| | | if (taskDetial.Type == "2" && taskDetial.Crtype =="1") |
| | | { |
| | | ordertype = "1"; |
| | | throw new Exception($"未查询到该设备所在储位信息,Location:{model.Location}"); |
| | | } |
| | | else if(taskDetial.Type =="2" && taskDetial.Crtype == "0") |
| | | var houseNo = deviceLocatInfo.WareHouseNo;//申请储位设备所在车间编号 |
| | | var noticeno = "0";//出入库单据明细ID |
| | | //桶库存信息 |
| | | var palletInfo = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == model.PalletNo); |
| | | if (palletInfo == null) |
| | | { |
| | | ordertype = "0"; |
| | | throw new Exception($"未查询到该桶的库存信息,PalletNo:{model.PalletNo}"); |
| | | } |
| | | |
| | | var storageLocat = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0"); |
| | | //开启事务 |
| | | Db.BeginTran(); |
| | | //判断任务是否为新任务 |
| | | if (string.IsNullOrWhiteSpace(taskDetial.Taskno)) |
| | | |
| | | SysStorageLocat loction = new SysStorageLocat();//目标储位信息 |
| | | switch (model.Type) |
| | | { |
| | | taskDetial.Taskno = new Common().GetMaxNo("T"); |
| | | 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)).OrderByDescending(o => o.CreateTime).First(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("该车间净桶区暂无空余储位"); |
| | | } |
| | | |
| | | taskMsg = "清洗设备(净桶)申请储位任务"; |
| | | break; |
| | | case "0"://接料设备申请储位(预混料桶申请储位) |
| | | //判断是否有批次号 |
| | | if (string.IsNullOrWhiteSpace(model.LotNo)) |
| | | { |
| | | 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(); |
| | | loction = storageLocat.Where(w => w.WareHouseNo == houseNo && areaNoList2.Contains(w.AreaNo)).OrderByDescending(o => o.CreateTime).First(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("该车间预混区暂无空余储位"); |
| | | } |
| | | palletInfo.LotNo = model.LotNo;//批次号 |
| | | //更新桶库存信息 |
| | | Db.Updateable(palletInfo).ExecuteCommand(); |
| | | |
| | | taskMsg = "接料设备(预混料桶)申请储位任务"; |
| | | break; |
| | | case "1"://混料设备申请储位(半成品桶申请储位) |
| | | //判断是否有批次号 |
| | | if (string.IsNullOrWhiteSpace(model.LotNo)) |
| | | { |
| | | throw new Exception("批次号为空!"); |
| | | } |
| | | //校验此批次是否有入库单 |
| | | 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";//正在执行 |
| | | //更新入库单状态 |
| | | 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)).OrderByDescending(o => o.CreateTime).First(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("该车间半成品区暂无空余储位"); |
| | | } |
| | | |
| | | taskMsg = "接料设备(混料桶)申请储位任务"; |
| | | break; |
| | | 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)).OrderByDescending(o => o.CreateTime).First(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("该车间脏桶区暂无空余储位"); |
| | | } |
| | | |
| | | taskMsg = "下料设备(脏桶)申请储位任务"; |
| | | break; |
| | | } |
| | | var logTaskEntry = new LogTask |
| | | |
| | | taskNo = new Common().GetMaxNo("TK");//任务号 |
| | | //任务信息 |
| | | var logTaskEntry = new LogTask |
| | | { |
| | | TaskNo = taskDetial.Taskno, |
| | | TaskNo = taskNo, |
| | | Sender = "WMS", |
| | | Receiver = "RCS", |
| | | //IsSuccess = 1, //是否下发成功 0失败 1成功 |
| | | SendDate = DateTime.Now, //发送时间 |
| | | //BackDate = DateTime.Now, //返回时间 |
| | | StartLocat = taskDetial.Startport,//起始位置 |
| | | EndLocat = taskDetial.Endport,//目标位置 |
| | | PalletNo = taskDetial.Pallno,//托盘码 |
| | | StartLocat = model.Location,//起始位置 |
| | | EndLocat = loction.LocatNo,//目标位置 |
| | | PalletNo = model.PalletNo,//桶号 |
| | | IsSend = 1,//是否可再次下发 |
| | | IsCancel = 1,//是否可取消 |
| | | IsFinish = 1,//是否可完成 |
| | | Type = taskDetial.Crtype,//任务类型 0 入库任务 1 出库任务 2 移库任务 |
| | | OrderType = ordertype,//单据类型 0 入库 1 出库 3其他 |
| | | Type = "0",//任务类型 0 入库任务 1 出库任务 2 移库任务 |
| | | OrderType = "3",//单据类型 0 入库 1 出库 3 移库 |
| | | Status = "0",//任务状态0:等待执行1正在执行2执行完成 |
| | | NoticeDetailNo = int.Parse(taskDetial.Noticedetailno.ToString()), |
| | | Msg = $"{taskDetial.Endport}的{na}任务", //关键信息 |
| | | NoticeDetailNo = int.Parse(noticeno), |
| | | Msg = taskMsg, //关键信息 |
| | | }; |
| | | var Agv = new AgvTask |
| | | var task = new TaskDetial |
| | | { |
| | | taskCode = taskDetial.Taskno, |
| | | taskType = taskDetial.Type, |
| | | startPos = taskDetial.Startport, |
| | | endPos = taskDetial.Endport, |
| | | agvCode = "1",//……需要和AGV确认此字段值 |
| | | Taskno = taskNo,//任务号 |
| | | Startport = model.Location, |
| | | Endport = loction.LocatNo, |
| | | Pallno = model.PalletNo, |
| | | Crtype = "0",//入库 |
| | | }; |
| | | //请求小车 |
| | | genAgvSchedulingTaskRep chrep =genAgvSchedulingTask(Agv, "url"); |
| | | if (chrep.code != "0") |
| | | //给下车下发任务 |
| | | 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";//正在执行 |
| | | Db.Insertable(logTaskEntry).ExecuteCommand(); |
| | | |
| | | deviceLocatInfo.Status = "3";//出库中 |
| | | Db.Updateable(deviceLocatInfo).ExecuteCommand(); |
| | | |
| | | loction.Status = "2";//入库中 |
| | | Db.Updateable(loction).ExecuteCommand(); |
| | | } |
| | | else//失败 |
| | | { |
| | | logTaskEntry.IsSuccess = 0; |
| | | Db.Insertable(logTaskEntry).ExecuteCommand(); |
| | | Db.CommitTran(); |
| | | throw new Exception("RCS任务下发错误,RCS返回消息:" + chrep.message); |
| | | } |
| | | logTaskEntry.IsSuccess = 1; |
| | | logTaskEntry.BackDate = DateTime.Now; |
| | | logTaskEntry.Status = "1"; |
| | | if (taskDetial.Crtype == "0") |
| | | //提交事务 |
| | | Db.CommitTran(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //回滚事务 |
| | | Db.RollbackTran(); |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <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) |
| | | { |
| | | sql = $"UPDATE SysStorageLocat SET Status = '2' where LocatNo = '{taskDetial.Endport}'"; |
| | | sql2 = $"UPDATE DataStockDetail SET PalletStatus = '{taskDetial.Type}' where PalletNo = '{taskDetial.Pallno}'"; |
| | | Db.Ado.ExecuteCommand(sql2); |
| | | 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 |
| | | { |
| | | sql = $"UPDATE SysStorageLocat SET Status = '3' where LocatNo = '{taskDetial.Startport}' "; |
| | | //生成调度小车净桶去脏桶区任务 |
| | | var ztask = new TaskDetial |
| | | { |
| | | Startport = detail.LocatNo, |
| | | Endport = endLocat.LocatNo, |
| | | Pallno = PalletNo, |
| | | Crtype = "2", |
| | | }; |
| | | string taskNo = ""; |
| | | CreateTaskForAgv(ztask, url); |
| | | |
| | | statrtLocat.Status = "3";//出库中 |
| | | //修改起始储位状态 |
| | | Db.Updateable(statrtLocat).ExecuteCommand(); |
| | | |
| | | detail.Status = "5";//异常锁定 |
| | | detail.PalletStatus = "3";//脏桶 |
| | | //修改库存状态 |
| | | Db.Updateable(detail).ExecuteCommand(); |
| | | } |
| | | Db.Insertable(logTaskEntry).ExecuteCommand(); |
| | | Db.Ado.ExecuteCommand(sql); |
| | | //提交事务 |
| | | 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, |
| | | 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";//正在执行 |
| | | 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 呼叫小车代码 |
| | | 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 = taskDetial.Taskno;//请求编号 |
| | | agvTask.taskCode = taskDetial.Taskno;//任务号 |
| | | agvTask.ctnrCode = taskDetial.Pallno;//桶号 |
| | | 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); |
| | | |
| | | // 正式运行程序放开 |
| | | 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 = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV"); |
| | | //解析返回数据 |
| | | 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 |
| | | } |
| | | } |
| | | } |