| | |
| | | string taskMsg = ""; |
| | | if (string.IsNullOrEmpty(model.Location)) |
| | | { |
| | | throw new Exception("设备所在位置不可为空"); |
| | | throw new Exception("设备编码不可为空"); |
| | | } |
| | | //叫桶设备所在储位信息(目标储位) |
| | | var endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location); |
| | | if (endLoction == null) |
| | | //通过设备号查找到所属设备(区域) |
| | | var deviceInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode == model.Location); |
| | | if (deviceInfo == null) |
| | | { |
| | | throw new Exception("设备储位信息不存在"); |
| | | throw new Exception("设备信息不存在"); |
| | | } |
| | | var houseNo = endLoction.WareHouseNo;//叫桶位置,后续根据位置关联或定义,来判断叫桶位置所属车间 |
| | | var houseNo = deviceInfo.WareHouseNo;//叫桶设备所属车间编号 |
| | | |
| | | //叫桶设备所在储位信息(目标储位) |
| | | var endLoction = new SysStorageLocat(); |
| | | |
| | | var urlMes = "";//回传MES的接口地址 |
| | | var noticeNo = "0";//出入库单据明细ID |
| | | var stockDetail = Db.Queryable<DataStockDetail>().Where(w => w.Status == "0");//所有待分配的桶 |
| | | |
| | | //所有待分配的桶 |
| | | var stockDetail = Db.Queryable<DataStockDetail>().Where(w => w.Status == "0"); |
| | | //分配桶信息 |
| | | var pallet = new DataStockDetail(); |
| | | |
| | | //开始事务 |
| | | Db.BeginTran(); |
| | | DataStockDetail pallet = new DataStockDetail(); |
| | | |
| | | switch (model.Type) |
| | | { |
| | | case "0"://叫净桶 |
| | | case "0"://接料设备叫净桶 |
| | | { |
| | | //叫桶目标储位地址信息 |
| | | endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | if (endLoction == null) |
| | | { |
| | | throw new Exception("叫桶设备目标储位信息不存在"); |
| | | } |
| | | //查找到该车间净桶区 |
| | | 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(); |
| | | //查找净桶 |
| | |
| | | Db.Updateable(pallet).ExecuteCommand(); |
| | | |
| | | taskMsg = "设备叫净桶任务"; |
| | | } |
| | | break; |
| | | case "1"://叫料桶(混料) |
| | | case "1"://混料设备叫料桶(混料) |
| | | { |
| | | //叫桶目标储位地址信息 |
| | | endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | if (endLoction == null) |
| | | { |
| | | throw new Exception("叫桶设备目标储位信息不存在"); |
| | | } |
| | | //判断是否有批次号 |
| | | if (string.IsNullOrWhiteSpace(model.LotNo)) |
| | | { |
| | |
| | | Db.Updateable(pallet).ExecuteCommand(); |
| | | |
| | | taskMsg = "设备叫料桶混料任务"; |
| | | } |
| | | break; |
| | | case "2"://叫料桶(下料) |
| | | case "2"://下料设备叫料桶(下料) |
| | | { |
| | | if (houseNo == "M04")//除了喷干车间下料口都是2个储位(投料储位、投完料储位) |
| | | { |
| | | //叫桶目标储位地址信息 |
| | | endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | } |
| | | else |
| | | { |
| | | //叫桶目标储位地址信息 |
| | | endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo && w.Column == 1);// Column=1 投料储位,Column=2 投完料储位 |
| | | } |
| | | if (endLoction == null) |
| | | { |
| | | throw new Exception("叫桶设备目标储位信息不存在"); |
| | | } |
| | | //判断是否有批次号 |
| | | if (string.IsNullOrWhiteSpace(model.LotNo)) |
| | | { |
| | |
| | | Db.Updateable(pallet).ExecuteCommand(); |
| | | |
| | | taskMsg = "设备叫料桶下料任务"; |
| | | } |
| | | break; |
| | | case "3"://叫脏桶 |
| | | case "3"://清洗设备叫脏桶 |
| | | { |
| | | //叫桶目标储位地址信息 |
| | | endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo && w.Column == 1);// Column=1 清洗储位,Column=2 清洗完料储位 |
| | | if (endLoction == null) |
| | | { |
| | | throw new Exception("叫桶设备目标储位信息不存在"); |
| | | } |
| | | //查找到该车间脏桶区 |
| | | 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" |
| | |
| | | { |
| | | throw new Exception("暂无脏桶可分配"); |
| | | } |
| | | taskMsg = "设备叫脏桶任务"; |
| | | //遍历库存脏桶,返回MES验证 |
| | | foreach (var item in palletList) |
| | | { |
| | |
| | | Endport = model.Location, |
| | | Pallno = item.PalletNo, |
| | | Crtype = "1",//叫桶 |
| | | WareHouseNo = houseNo |
| | | }; |
| | | //给下车下发任务 |
| | | logTaskEntry2.SendDate = DateTime.Now;//发送时间 |
| | |
| | | Db.CommitTran(); |
| | | return; |
| | | } |
| | | |
| | | taskMsg = "设备叫脏桶任务"; |
| | | } |
| | | break; |
| | | default: |
| | | throw new Exception("任务类型无效"); |
| | |
| | | Endport = model.Location,//目标位置 |
| | | Pallno = pallet.PalletNo,//桶号 |
| | | Crtype = "1",//叫桶 |
| | | WareHouseNo = houseNo//车间编码 |
| | | }; |
| | | //给下车下发任务 |
| | | logTaskEntry.SendDate = DateTime.Now;//发送时间 |
| | |
| | | { |
| | | throw new Exception($"该桶有正在执行的任务,PalletNo:{model.PalletNo}"); |
| | | } |
| | | //通过设备号查找到所属设备(区域) |
| | | var deviceInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode == model.Location); |
| | | if (deviceInfo == null) |
| | | { |
| | | throw new Exception("设备信息不存在"); |
| | | } |
| | | var houseNo = deviceInfo.WareHouseNo;//申请储位设备所在车间编号 |
| | | //设备所在储位信息(起始储位) |
| | | var deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location); |
| | | var deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | if (deviceLocatInfo == null) |
| | | { |
| | | throw new Exception($"未查询到该设备所在储位信息,Location:{model.Location}"); |
| | | } |
| | | var houseNo = deviceLocatInfo.WareHouseNo;//申请储位设备所在车间编号 |
| | | |
| | | var noticeno = "0";//出入库单据明细ID |
| | | //桶库存信息 |
| | | var palletInfo = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == model.PalletNo); |
| | |
| | | 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(); |
| | | { |
| | | //设备所在储位信息(起始储位) |
| | | deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo && w.Column == 2);// Column=1 清洗储位,Column=2 清洗完料储位 |
| | | if (deviceLocatInfo == null) |
| | | { |
| | | throw new Exception($"未查询到该设备所在储位信息,Location:{model.Location}"); |
| | | } |
| | | //查找到该车间净桶区; |
| | | loction = GetLocatModel(houseNo, "0"); |
| | | if (loction == null) |
| | | { |
| | |
| | | } |
| | | |
| | | taskMsg = "清洗设备(净桶)申请储位任务"; |
| | | } |
| | | break; |
| | | case "0"://接料设备申请储位(预混料桶申请储位) |
| | | { |
| | | //设备所在储位信息(起始储位) |
| | | deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | if (deviceLocatInfo == null) |
| | | { |
| | | throw new Exception($"未查询到该设备所在储位信息,Location:{model.Location}"); |
| | | } |
| | | //判断是否有批次号 |
| | | 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) && w.Status == "0" && w.Flag == "0").OrderByDescending(o => o.CreateTime).First(); |
| | | loction = GetLocatModel(houseNo, "1"); |
| | | if (loction == null) |
| | | { |
| | |
| | | Db.Updateable(palletInfo).ExecuteCommand(); |
| | | |
| | | taskMsg = "接料设备(预混料桶)申请储位任务"; |
| | | } |
| | | break; |
| | | case "1"://混料设备申请储位(半成品桶申请储位) |
| | | { |
| | | //设备所在储位信息(起始储位) |
| | | deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | if (deviceLocatInfo == null) |
| | | { |
| | | throw new Exception($"未查询到该设备所在储位信息,Location:{model.Location}"); |
| | | } |
| | | //判断是否有批次号 |
| | | if (string.IsNullOrWhiteSpace(model.LotNo)) |
| | | { |
| | |
| | | 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) |
| | | { |
| | |
| | | } |
| | | |
| | | taskMsg = "接料设备(混料桶)申请储位任务"; |
| | | } |
| | | break; |
| | | case "2"://下料设备申请储位(脏桶申请储位) |
| | | { |
| | | if (houseNo == "M04")//除了喷干车间下料口都是2个储位(投料储位、投完料储位) |
| | | { |
| | | //设备所在储位信息(起始储位) |
| | | deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo); |
| | | } |
| | | else |
| | | { |
| | | //设备所在储位信息(起始储位) |
| | | deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo && w.Column == 2);//Column=1 投料储位,Column=2 投完料储位 |
| | | } |
| | | if (deviceLocatInfo == null) |
| | | { |
| | | throw new Exception($"未查询到该设备所在储位信息,Location:{model.Location}"); |
| | | } |
| | | //查找到该车间脏桶区 |
| | | //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) |
| | | { |
| | |
| | | } |
| | | |
| | | taskMsg = "下料设备(脏桶)申请储位任务"; |
| | | } |
| | | break; |
| | | } |
| | | |
| | |
| | | Endport = loction.LocatNo, |
| | | Pallno = model.PalletNo, |
| | | Crtype = "0",//入库 |
| | | WareHouseNo = houseNo |
| | | }; |
| | | //给下车下发任务 |
| | | logTaskEntry.SendDate = DateTime.Now;//发送时间 |
| | |
| | | //入库任务,处理入库单 |
| | | if (taskInfo.Type == "0" && taskInfo.NoticeDetailNo != 0) |
| | | { |
| | | var notice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.Status == "1"); |
| | | if (notice != null) |
| | | //入库单明细 |
| | | var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.Id == taskInfo.NoticeDetailNo); |
| | | if (noticeDetail != null) |
| | | { |
| | | noticeDetail.CompleteQty += 1;//完成数量 |
| | | |
| | | if (noticeDetail.CompleteQty >= noticeDetail.Qty) |
| | | { |
| | | noticeDetail.CompleteTime = DateTime.Now;//完成时间 |
| | | |
| | | //入库单 |
| | | var notice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.ASNNo == noticeDetail.ASNNo); |
| | | |
| | | var noticeDetailList = Db.Queryable<BllArrivalNoticeDetail>().Where(w => w.IsDel == "0" && w.CompleteQty < w.Qty && w.Id != noticeDetail.Id).ToList(); |
| | | if (noticeDetailList.Count <= 0) |
| | | { |
| | | notice.Status = "2";//执行完成 |
| | | notice.UpdateTime = DateTime.Now; |
| | |
| | | Db.Updateable(notice).ExecuteCommand(); |
| | | } |
| | | } |
| | | //修改入库单明细 |
| | | Db.Updateable(noticeDetail).ExecuteCommand(); |
| | | } |
| | | } |
| | | //出库任务,处理出库单 |
| | | if (taskInfo.Type == "1" && taskInfo.NoticeDetailNo != 0)//入库 |
| | | { |
| | | var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.Status == "3"); |
| | | if (notice != null) |
| | | var noticeDetail = Db.Queryable<BllExportNoticeDetail>().First(w => w.IsDel == "0" && w.Id==taskInfo.NoticeDetailNo); |
| | | if (noticeDetail != null) |
| | | { |
| | | noticeDetail.CompleteQty += 1;//完成数量 |
| | | |
| | | if (noticeDetail.CompleteQty >= noticeDetail.Qty) |
| | | { |
| | | var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.SONo == noticeDetail.SONo); |
| | | |
| | | var noticeDetailList = Db.Queryable<BllExportNoticeDetail>().Where(w => w.IsDel == "0" && w.CompleteQty < w.Qty && w.Id != noticeDetail.Id).ToList(); |
| | | if (noticeDetailList.Count <= 0) |
| | | { |
| | | notice.Status = "4";//执行完成 |
| | | notice.UpdateTime = DateTime.Now; |
| | |
| | | //修改入库单状态 |
| | | Db.Updateable(notice).ExecuteCommand(); |
| | | } |
| | | } |
| | | //修改入库单明细 |
| | | Db.Updateable(noticeDetail).ExecuteCommand(); |
| | | } |
| | | |
| | | } |
| | | |
| | | #region 去掉MES |
| | |
| | | { |
| | | path1.type = "05"; |
| | | } |
| | | else//申请储位(桶入库) |
| | | else if (taskDetial.Crtype == "0")//申请储位(桶入库) |
| | | { |
| | | path1.type = "00"; |
| | | } |
| | | else//同车间平层搬运 |
| | | { |
| | | path1.type = "05"; |
| | | } |
| | |
| | | path2.positionCode = taskDetial.Endport; |
| | | if (taskDetial.Crtype == "1")//叫桶(桶出库) |
| | | { |
| | | path2.type = "00"; |
| | | } |
| | | else if (taskDetial.Crtype == "1")//申请储位(桶入库) |
| | | { |
| | | path2.type = "05"; |
| | | } |
| | | else//申请储位(桶入库) |
| | | else //同车间平层搬运 |
| | | { |
| | | path2.type = "05"; |
| | | } |
| | |
| | | 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.WareHouseNo == "M04")//喷干车间 |
| | | { |
| | | agvTask.ctnrTyp = "2";// 1:桶 2:桶(小) 3:托盘 |
| | | } |
| | | else |
| | | { |
| | | agvTask.ctnrTyp = "1";// 1:桶 2:桶(小) 3:托盘 |
| | | } |
| | | //判断任务类型 |
| | | if (taskDetial.Crtype == "1")//叫桶(桶出库) |
| | | { |
| | | agvTask.taskTyp = "Z3";//任务类型 线边到托盘收集器 Z1, 托盘垛申请入库 Z2 |
| | | } |
| | | else//申请储位(桶入库) |
| | | else if (taskDetial.Crtype == "0")//申请储位(桶入库) |
| | | { |
| | | agvTask.taskTyp = "Z4";//任务类型 线边到托盘收集器 Z1, 托盘垛申请入库 Z2 |
| | | } |
| | | else//同车间平层搬运 |
| | | { |
| | | agvTask.taskTyp = "Z5"; |
| | | } |
| | | |
| | | // 正式运行程序放开 |
| | | var jsonData = JsonConvert.SerializeObject(agvTask); |