using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Model.ModelDto.BllSoDto; using SqlSugar; using WMS.BLL.LogServer; using WMS.DAL; using WMS.Entity.BllSoEntity; using WMS.Entity.Context; using WMS.Entity.DataEntity; using WMS.Entity.LogEntity; using WMS.Entity.SysEntity; using WMS.IBLL.IBllSoServer; namespace WMS.BLL.BllSoServer { public class ExportAllotServer : DbHelper, IExportAllotServer { private static readonly SqlSugarScope Db = DataContext.Db; public ExportAllotServer() : base(Db) { } //查询出库分配表信息 public List GetExportAllotList(string no, string waveNo, string palletNo, string skuNo, string skuName, string lotNo, string status, string boxNo, int page, int limit, out int count) { try { var strList = new List(); if (!string.IsNullOrWhiteSpace(boxNo)) { var detailList = Db.Queryable().Where(m => m.IsDel == "0" && m.BoxNo.Contains(boxNo.Trim())).Select(m => m.ExportAllotId).Distinct().ToList(); strList = detailList; } Expression> item = Expressionable.Create() .AndIF(!string.IsNullOrWhiteSpace(no), it => it.SONo.Contains(no.Trim())) .AndIF(!string.IsNullOrWhiteSpace(waveNo), it => it.WaveNo.Contains(waveNo.Trim())) .AndIF(!string.IsNullOrWhiteSpace(palletNo), it => it.PalletNo.Contains(palletNo.Trim())) .AndIF(!string.IsNullOrWhiteSpace(skuNo), it => it.SkuNo.Contains(skuNo.Trim())) .AndIF(!string.IsNullOrWhiteSpace(skuName), it => it.SkuName.Contains(skuName.Trim())) .AndIF(!string.IsNullOrWhiteSpace(lotNo), it => it.LotNo.Contains(lotNo.Trim())) .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status) .AndIF(!string.IsNullOrWhiteSpace(boxNo), m => strList.Contains(m.Id)) .ToExpression();//注意 这一句 不能少 var total = 0; var data = GetAllWhereAsync(item) .LeftJoin((a, b) => a.LogisticsId == b.Id) .LeftJoin((a, b, c) => a.CreateUser == c.Id) .LeftJoin((a, b, c, d) => a.CreateUser == d.Id) .Select((a, b, c, d) => new ExportAllotDto() { Id = a.Id, SONo = a.SONo, WaveNo = a.WaveNo, SODetailNo = a.SODetailNo, StockId = a.StockId, TaskNo = a.TaskNo, LotNo = a.LotNo, LotText = a.LotText, SupplierLot = a.SupplierLot, SkuNo = a.SkuNo, SkuName = a.SkuName, Standard = a.Standard, PalletNo = a.PalletNo, IsBale = a.IsBale, IsBelt = a.IsBelt, Qty = a.Qty, CompleteQty = a.CompleteQty, Status = a.Status, LogisticsId = a.LogisticsId, LogisticsName = b.CarrierName, IsAdvance = a.IsAdvance, OutMode = a.OutMode, CreateUserName = c.RealName, UpdateUserName = d.RealName, CreateTime = a.CreateTime, UpdateTime = a.UpdateTime }).OrderByDescending(a => a.CreateTime).OrderBy(a => a.Status).OrderBy(a => a.SkuNo).ToOffsetPage(page, limit, ref total); count = total; return data; } catch (Exception e) { throw new Exception(e.Message); } } //撤销分配(删除) public void DelExportAllot(int id, int userId) { try { var allot = GetOneById(id); if (allot == null) { throw new Exception("未查询到要撤销的分配信息"); } if (allot.Status != "0") { throw new Exception("要撤销的分配信息状态不是待下发,不能撤销"); } //出库单 var notice = Db.Queryable().First(m => m.IsDel == "0" && m.SONo == allot.SONo); //出库单明细 var noticeDe = Db.Queryable().First(m => m.IsDel == "0" && m.Id == allot.SODetailNo); //库存明细 var stockDe = Db.Queryable().First(m => m.IsDel == "0" && m.Id == allot.StockId); //库存总单 var stock = Db.Queryable().First(a => a.IsDel == "0" && a.SkuNo == stockDe.SkuNo); //任务 var task = Db.Queryable().First(a => a.IsDel == "0" && a.PalletNo == allot.PalletNo && a.Status == "4"); if (notice == null) { throw new Exception("未查询到出库单信息"); } if (noticeDe == null) { throw new Exception("未查询到出库单明细信息"); } if (stockDe == null) { throw new Exception("未查询到要分配的库存明细信息"); } if (stock == null) { throw new Exception("未查询到要分配的库存总量信息"); } //验证任务信息是否存在 if (task == null) { throw new Exception("未查询到当前托盘任务信息"); } //验证任务状态是否为正在执行 if (task.Status == "0" || task.Status == "1" || task.Status == "2") { throw new Exception("当前任务等待执行或正在执行,请取消后删除"); } Db.BeginTran(); var time = DateTime.Now; //修改任务信息 //task.IsSend = 0; //是否可下发 //task.UpdateTime = time; //task.UpdateUser = userId; //删除出库分配信息 allot.IsDel = "1"; allot.UpdateTime = time; allot.UpdateUser = userId; //allot.TaskNo = ""; //修改出库单明细 noticeDe.AllotQty -= allot.Qty; noticeDe.UpdateTime = time; noticeDe.UpdateUser = userId; //修改库存明细 stockDe.LockQty -= allot.Qty; if (notice.Status == "2") { notice.Status = "1"; } if (noticeDe.AllotQty == 0) { noticeDe.Status = "0"; var count = Db.Queryable().Count(m => m.IsDel == "0" && m.Id != noticeDe.Id && m.SONo == allot.SONo && m.Status != "0"); if (count == 0) { notice.Status = "0"; } } if (stockDe.LockQty == 0) { stockDe.Status = "0"; } else if (stockDe.Status == "2") { stockDe.Status = "1"; } //stock.LockQty -= allot.Qty; Db.Updateable(notice).ExecuteCommand(); Db.Updateable(noticeDe).ExecuteCommand(); Db.Updateable(allot).ExecuteCommand(); Db.Updateable(stockDe).ExecuteCommand(); //Db.Updateable(task).ExecuteCommand(); //Db.Updateable(stock).ExecuteCommand(); //添加操作日志记录 var k = new OperationSOServer().AddLogOperationSo("出库作业", "拣货明细", notice.SONo, "撤销", $"撤销了单据号为{notice.SONo}、托盘码为:{allot.PalletNo}的单据分配信息", userId); Db.CommitTran(); } catch (Exception e) { Db.RollbackTran(); throw new Exception(e.Message); } } } }