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.SysEntity;
|
using WMS.IBLL.IBllSoServer;
|
namespace WMS.BLL.BllSoServer
|
{
|
public class ExportAllotServer : DbHelper<BllExportAllot>, IExportAllotServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
|
public ExportAllotServer() : base(Db)
|
{
|
}
|
|
//查询出库分配表信息
|
public List<ExportAllotDto> 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<int>();
|
|
if (!string.IsNullOrWhiteSpace(boxNo))
|
{
|
var detailList = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.BoxNo.Contains(boxNo.Trim())).Select(m => m.ExportAllotId).Distinct().ToList();
|
strList = detailList;
|
}
|
Expression<Func<BllExportAllot, bool>> item = Expressionable.Create<BllExportAllot>()
|
.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<SysLogisticsInfo>((a, b) => a.LogisticsId == b.Id)
|
.LeftJoin<SysUserInfor>((a, b, c) => a.CreateUser == c.Id)
|
.LeftJoin<SysUserInfor>((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)
|
.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);
|
int a = 0;
|
if (allot == null)
|
{
|
throw new Exception("未查询到要撤销的分配信息");
|
}
|
if (allot.Status != "0")
|
{
|
throw new Exception("要撤销的分配信息状态不是待下发,不能撤销");
|
}
|
//出库单
|
var notice = new BllExportNotice();
|
//出库单明细
|
var noticeDe = new BllExportNoticeDetail();
|
//库存明细
|
var stockDe = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.Id == allot.StockId);
|
//获取库存总表
|
var stock = Db.Queryable<DataStock>().First(s => s.IsDel == "0" && s.SkuNo == allot.SkuNo && s.LotNo == stockDe.LotNo);
|
//获取储位消息
|
var locat = Db.Queryable<SysStorageLocat>().First(l => l.IsDel == "0" && l.Status != "0" && l.LocatNo == stockDe.LocatNo);
|
if (allot.SkuNo != "100099" && allot.SkuNo != "100098" && allot.SkuNo != "100097")
|
{
|
a = 1;
|
notice = Db.Queryable<BllExportNotice>().First(m => m.IsDel == "0" && m.SONo == allot.SONo);
|
noticeDe = Db.Queryable<BllExportNoticeDetail>().First(m => m.IsDel == "0" && m.Id == allot.SODetailNo);
|
|
if (notice == null)
|
{
|
throw new Exception("未查询到出库单信息");
|
}
|
if (noticeDe == null)
|
{
|
throw new Exception("未查询到出库单明细信息");
|
}
|
}
|
if (stockDe == null)
|
{
|
throw new Exception("未查询到要分配的库存明细信息");
|
}
|
Db.BeginTran();
|
var time = DateTime.Now;
|
//删除出库分配信息
|
allot.IsDel = "1";
|
allot.UpdateTime = time;
|
allot.UpdateUser = userId;
|
if (a == 1)
|
{
|
//修改出库单明细
|
noticeDe.AllotQty -= allot.Qty;
|
noticeDe.UpdateTime = time;
|
noticeDe.UpdateUser = userId;
|
|
if (notice.Status == "2")
|
{
|
notice.Status = "1";
|
}
|
if (noticeDe.AllotQty == 0)
|
{
|
noticeDe.Status = "0";
|
var count = Db.Queryable<BllExportNoticeDetail>().Count(m =>
|
m.IsDel == "0" && m.Id != noticeDe.Id && m.SONo == allot.SONo && m.Status != "0");
|
if (count == 0)
|
{
|
notice.Status = "0";
|
}
|
}
|
}
|
//修改库存明细
|
stockDe.LockQty -= allot.Qty;
|
if (stockDe.LockQty == 0)
|
{
|
stockDe.Status = "0";
|
}
|
else if (stockDe.Status == "2")
|
{
|
stockDe.Status = "1";
|
}
|
|
if (a == 1)
|
{
|
Db.Updateable(notice).ExecuteCommand();
|
Db.Updateable(noticeDe).ExecuteCommand();
|
}
|
|
//修改储位信息
|
locat.Status = "1";
|
//修改库存总量
|
stock.LockQty -= allot.Qty;
|
|
Db.Updateable(allot).ExecuteCommand();
|
Db.Updateable(stock).ExecuteCommand();
|
Db.Updateable(stockDe).ExecuteCommand();
|
Db.Updateable(locat).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);
|
}
|
}
|
}
|
}
|