| | |
| | | using System.Threading.Tasks; |
| | | using Dm; |
| | | using Model.InterFaceModel; |
| | | using Model.ModelDto; |
| | | using Model.ModelDto.BllCheckDto; |
| | | using Model.ModelDto.PdaDto; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using Utility; |
| | | using Utility.Tools; |
| | | using WMS.BLL.LogServer; |
| | | using WMS.DAL; |
| | | using WMS.Entity.BllAsnEntity; |
| | |
| | | { |
| | | throw Oops.Bah("托盘储位信息不存在,请检查!"); |
| | | } |
| | | if (models.WareHouseNo != "W02") |
| | | if (models.WareHouseNo != "W04") |
| | | { |
| | | throw Oops.Bah("该托盘未在平库内,请检查!"); |
| | | } |
| | |
| | | { |
| | | throw Oops.Bah("托盘储位信息不存在,请检查!"); |
| | | } |
| | | if (models.WareHouseNo != "W02") |
| | | if (models.WareHouseNo != "W04") |
| | | { |
| | | throw Oops.Bah("该托盘未在平库内,请检查!"); |
| | | } |
| | |
| | | throw Oops.Bah("储位信息不存在,请检查!"); |
| | | } |
| | | |
| | | if (storageLocat.AreaNo.Contains("B0")) |
| | | { |
| | | storageArea = await Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B0") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToListAsync(); |
| | | } |
| | | else |
| | | { |
| | | storageArea = await Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B1") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToListAsync(); |
| | | } |
| | | |
| | | storageArea = await Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo != storageLocat.AreaNo && w.WareHouseNo == "W04").OrderBy(o => o.AreaNo).ToListAsync(); |
| | | |
| | | } |
| | | return storageArea; |
| | | } |
| | |
| | | { |
| | | throw Oops.Bah("所选区域信息不存在,请检查!"); |
| | | } |
| | | EndLocat = await GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo, palletNo); |
| | | EndLocat = await GetLocat(areaNo); |
| | | } |
| | | else |
| | | { |
| | |
| | | throw Oops.Bah("储位信息不存在,请检查!"); |
| | | } |
| | | //目标储位信息 |
| | | var storageLocatEnd = new SysStorageLocat(); |
| | | if (!string.IsNullOrEmpty(areaNo)) |
| | | //var storageLocatEnd = new SysStorageLocat(); |
| | | |
| | | var storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0"); |
| | | if (storageLocatEnd == null) |
| | | { |
| | | storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0"); |
| | | if (storageLocatEnd == null) |
| | | { |
| | | throw Oops.Bah("目标储位信息不存在,请检查!"); |
| | | } |
| | | throw Oops.Bah("目标储位信息不存在,请检查!"); |
| | | } |
| | | |
| | | |
| | | //添加出库任务 |
| | | var taskNo = new Common().GetMaxNo("TK"); |
| | | var exTask = new LogTask |
| | | var moveTask = new LogTask |
| | | { |
| | | TaskNo = taskNo, |
| | | Sender = "WMS", |
| | | Receiver = "AGV", |
| | | Receiver = "WCS", |
| | | IsSuccess = 0, //是否下发成功 0失败 1成功 |
| | | |
| | | StartLocat = stockDetail.LocatNo,//起始位置 |
| | |
| | | |
| | | CreateTime = DateTime.Now |
| | | }; |
| | | await Db.Insertable(exTask).ExecuteCommandAsync(); |
| | | await Db.Insertable(moveTask).ExecuteCommandAsync(); |
| | | |
| | | //修改库存明细信息 |
| | | //stockDetail.Status = "4";//移库锁定 |
| | |
| | | //添加操作日志记录 |
| | | var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", palletNo, "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId); |
| | | |
| | | var outDto = new List<OutCommandDto>(); |
| | | outDto.Add(new OutCommandDto() |
| | | var outDto = new List<OutCommandDto> |
| | | { |
| | | PalletNo = exTask.PalletNo,//托盘号 |
| | | StartLocate = exTask.StartLocat, // 起始位置 |
| | | StartRoadway = storageLocat.RoadwayNo,//其实巷道 |
| | | EndLocate = EndLocat, // 目标位置 |
| | | TaskNo = exTask.TaskNo, // 任务号 |
| | | TaskType = "2",// 任务类型 (出库)0入 1出 2移 |
| | | OutMode = "", //出库口 |
| | | Order = 1 |
| | | new OutCommandDto() |
| | | { |
| | | TaskNo = moveTask.TaskNo, // 任务号 |
| | | TaskType = "2",// 任务类型 0入 1出 2移 |
| | | PalletNo = moveTask.PalletNo,//托盘号 |
| | | |
| | | }); |
| | | StartLocate = moveTask.StartLocat, // 起始位置 |
| | | EndLocate = EndLocat, // 目标位置 |
| | | |
| | | Order = 999, |
| | | Type = PLCTypeEnum.AGV |
| | | |
| | | } |
| | | }; |
| | | |
| | | // 正式运行程序放开 |
| | | var list2 = outDto.Select(m => m.TaskNo).ToList(); |
| | |
| | | try |
| | | { |
| | | var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss") |
| | | //response = HttpHelper.DoPost(url, jsonData, "下发给WCS出库命令", "WCS"); |
| | | response = HttpHelper.DoPost(url, jsonData, "下发给WCS出库命令", "WCS"); |
| | | var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss") |
| | | |
| | | //////解析返回数据 |
| | | //var wcsModel = JsonConvert.DeserializeObject<WcsModel>(response); |
| | | //if (wcsModel.StatusCode == 0) |
| | | //{ |
| | | // //更改任务的发送返回时间// |
| | | new TaskServer().EditTaskIssueOk(list2, time1, time2); |
| | | //} |
| | | //if (wcsModel.StatusCode == -1) |
| | | //{ |
| | | // new TaskServer().EditTaskIssueNo(list2, time1, time2, wcsModel.Msg); |
| | | // throw new Exception(wcsModel.Msg); |
| | | //} |
| | | //解析返回数据 |
| | | var wcsModel = JsonConvert.DeserializeObject<WcsModel2>(response); |
| | | if (wcsModel.code == 200) |
| | | { |
| | | // 更改任务的发送返回时间// |
| | | new TaskServer().EditTaskIssueOk(list2, time1, time2); |
| | | } |
| | | else |
| | | { |
| | | new TaskServer().EditTaskIssueNo(list2, time1, time2, wcsModel.message); |
| | | throw new Exception(wcsModel.message); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | throw Oops.Bah($"托盘号:{item.PalletNo}所在的储位信息不存在,请检查!"); |
| | | } |
| | | //获取目标储位 |
| | | EndLocat = await GetLocat(areaNo, item.SkuNo, item.LotNo, palletNo); |
| | | EndLocat = await GetLocat(areaNo); |
| | | if (string.IsNullOrEmpty(EndLocat)) |
| | | { |
| | | throw Oops.Bah("分配目标储位失败,请检查!"); |
| | |
| | | /// <param name="skuNo"></param> |
| | | /// <param name="lotNo"></param> |
| | | /// <returns></returns> |
| | | private async Task<string> GetLocat(string areaNo, string skuNo, string lotNo, string palletNo, string hasLocatNoList = "") |
| | | private async Task<string> GetLocat(string areaNo) |
| | | { |
| | | string endLocat = string.Empty;//目标储位 |
| | | //当然区域所有储位信息 |
| | | var storageLocatList = await Db.Queryable<SysStorageLocat>().Where(w => w.WareHouseNo == "W02" && w.AreaNo == areaNo).ToListAsync(); |
| | | //同区域同批次物料的储位信息 |
| | | List<string> locatList = await Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == skuNo && w.LotNo == lotNo && w.WareHouseNo == "W02" && w.AreaNo == areaNo && w.PalletNo != palletNo) |
| | | .OrderByDescending(o => o.LocatNo).Select(s => s.LocatNo).Distinct().ToListAsync(); |
| | | foreach (var item in locatList) |
| | | { |
| | | var locatInfo = storageLocatList.Where(w => w.LocatNo == item).First(); |
| | | //当前区域所有储位信息 |
| | | var storageLocatList = await Db.Queryable<SysStorageLocat>().Where(w => w.WareHouseNo == "W04" && w.AreaNo == areaNo).ToListAsync(); |
| | | |
| | | var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0") |
| | | .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First(); |
| | | |
| | | var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.LocatNo != locatInfo.LocatNo && w.Row == locatInfo.Row && !hasLocatNoList.Contains(w.LocatNo)) |
| | | .OrderByDescending(o => o.Column).First(); |
| | | if (locatInfo2 != null) |
| | | { |
| | | endLocat = locatInfo2.LocatNo; |
| | | } |
| | | } |
| | | if (string.IsNullOrEmpty(endLocat)) |
| | | if (locatInfo2 != null) |
| | | { |
| | | var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0" && !hasLocatNoList.Contains(w.LocatNo)) |
| | | .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First(); |
| | | |
| | | if (locatInfo3 != null) |
| | | { |
| | | endLocat = locatInfo3.LocatNo; |
| | | } |
| | | endLocat = locatInfo2.LocatNo; |
| | | } |
| | | |
| | | //if (string.IsNullOrEmpty(endLocat)) |
| | | //{ |
| | | // var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0") |
| | | // .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First(); |
| | | |
| | | // if (locatInfo3 != null) |
| | | // { |
| | | // endLocat = locatInfo3.LocatNo; |
| | | // } |
| | | //} |
| | | return endLocat; |
| | | } |
| | | #endregion |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 箱码拆箱贴标 |
| | | #region 箱码拆箱贴标、人工确认收货 |
| | | /// <summary> |
| | | /// 拆箱添加标签 |
| | | /// </summary> |
| | |
| | | Db.Updateable(boxInfo).ExecuteCommand(); |
| | | |
| | | var boxStr = boxInfo.BoxNo.Substring(0, boxInfo.BoxNo.Length - 6);//获取箱码前缀-除后六位流水外 |
| | | var maxBoxCode = Db.Queryable<BllBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0" && m.Origin == "WMS生成").Max(a => a.BoxNo); |
| | | var maxBoxCode1 = Db.Queryable<BllBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0" && m.Origin == "WMS生成").Max(a => a.BoxNo); |
| | | |
| | | var maxBoxCode2 = Db.Queryable<DataBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0").Max(a => a.BoxNo); |
| | | //如果结果为0,则说明两个字符串相等; ABC BCE |
| | | //如果结果小于0,则说明第一个字符串小于第二个字符串; |
| | | //如果结果大于0,则说明第一个字符串大于第二个字符串。 |
| | | var maxBoxCode = maxBoxCode1; |
| | | var bol = String.CompareOrdinal(maxBoxCode1, maxBoxCode2); |
| | | if (bol<0) |
| | | { |
| | | maxBoxCode = maxBoxCode2; |
| | | } |
| | | var boxNoNew = maxBoxCode.Substring(0, maxBoxCode.Length - 6) + (int.Parse(maxBoxCode.Substring(maxBoxCode.Length - 6, 6)) + 1).ToString().PadLeft(6, '0'); |
| | | |
| | | // 添加新箱码信息 |
| | |
| | | throw new Exception(e.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | public string GetReceiptSoNoByPallet(string palletNo) |
| | | { |
| | | try |
| | | { |
| | | var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.PalletNo == palletNo).GroupBy(m=>m.SONo).Select(m=>m.SONo).ToList(); |
| | | if (stockDetail.Count == 0) |
| | | { |
| | | throw new Exception("没有查询到托盘库存信息"); |
| | | } |
| | | if (stockDetail.Count != 1) |
| | | { |
| | | throw new Exception("库存托盘不是唯一出库单"); |
| | | } |
| | | var detail = stockDetail.First(); |
| | | if (string.IsNullOrWhiteSpace(detail)) |
| | | { |
| | | throw new Exception("托盘没有出库单信息"); |
| | | } |
| | | //var task = Db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "5"); |
| | | //if (task == null) |
| | | //{ |
| | | // throw new Exception("没有查询到托盘任务信息"); |
| | | //} |
| | | //if (task.Status != "5") |
| | | //{ |
| | | // throw new Exception("任务状态不是等待确认"); |
| | | //} |
| | | return detail; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new Exception(e.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 人工确认收货 |
| | | /// </summary> |
| | | /// <param name="palletNo"></param> |
| | | /// <param name="userId"></param> |
| | | public void ConfirmReceipt(string palletNo, int userId) |
| | | { |
| | | try |
| | | { |
| | | Db.BeginTran(); |
| | | //var task = Db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "5"); |
| | | //if (task == null) |
| | | //{ |
| | | // throw new Exception("没有查询到托盘任务信息"); |
| | | //} |
| | | //if (task.Status != "5") |
| | | //{ |
| | | // throw new Exception("任务状态不是等待确认"); |
| | | //} |
| | | ////任务状态变更为执行完成 |
| | | //task.Status = "2"; |
| | | //Db.Updateable(task).ExecuteCommand(); |
| | | var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).ToList(); |
| | | if (stockDetail.Count == 0) |
| | | { |
| | | throw new Exception("库存托盘没有信息"); |
| | | } |
| | | var locate = stockDetail.First().LocatNo; |
| | | var locatList = Db.Queryable<SysStorageLocat>().Where(m=>m.WareHouseNo == "W04" && (m.AreaNo == "B06" || m.AreaNo == "B07" || m.AreaNo == "B09") && m.IsDel == "0").ToList(); |
| | | var locat = locatList.FirstOrDefault(m => m.LocatNo == locate); |
| | | //判断托盘储位是否在车间 |
| | | if (locat == null) |
| | | { |
| | | throw new Exception("储位信息没有在车间工位上"); |
| | | } |
| | | locat.Status = "0"; |
| | | Db.Updateable(locat).ExecuteCommand(); |
| | | //判断托盘信息 |
| | | |
| | | foreach (var item in stockDetail) |
| | | { |
| | | if (item.UDF5 != "1" || string.IsNullOrWhiteSpace(item.SONo)) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | //item.WareHouseNo = ""; |
| | | //item.RoadwayNo = ""; |
| | | //item.AreaNo = ""; |
| | | item.LocatNo = ""; |
| | | //item.PalletNo = ""; |
| | | item.LockQty = 0; // 锁定数量更为0 |
| | | item.Status = "0"; // 状态变为待分配 |
| | | var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.StockDetailId == item.Id).ToList(); |
| | | foreach (var item2 in boxInfo) |
| | | { |
| | | item2.Status = "2"; //状态变为已入库 |
| | | } |
| | | |
| | | Db.Updateable(boxInfo).ExecuteCommand(); |
| | | } |
| | | Db.Updateable(stockDetail).ExecuteCommand(); |
| | | //托盘变更状态 |
| | | //var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNo); |
| | | //if (pallet == null) |
| | | //{ |
| | | // throw new Exception("没有查询到托盘信息"); |
| | | //} |
| | | //pallet.Status = "0"; |
| | | //Db.Updateable(pallet).ExecuteCommand(); |
| | | //添加操作日志 |
| | | new OperationCrServer().AddLogOperationCr("PDA模块", "车间收货", palletNo, "完成", $"车间收货:{palletNo}托盘收货", userId); |
| | | Db.CommitTran(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Db.RollbackTran(); |
| | | throw new Exception(e.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | } |