using AutoMapper;
|
using SqlSugar;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.CommonEnum;
|
using WIDESEA_Common.OrderEnum;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.CodeConfigEnum;
|
using WIDESEA_Core.DB;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.Seed;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_DTO.Inbound;
|
using WIDESEA_IBasicService;
|
using WIDESEA_IInboundService;
|
using WIDESEA_IRecordService;
|
using WIDESEA_IStockService;
|
using WIDESEA_Model.Models;
|
using WIDESEA_Model.Models.Basic;
|
|
namespace WIDESEA_InboundService
|
{
|
public class InboundOrderService : ServiceBase<Dt_InboundOrder, IRepository<Dt_InboundOrder>>, IInboundOrderService
|
{
|
private readonly IMapper _mapper;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
|
private readonly IRepository<Dt_Task> _taskRepository;
|
|
private IStockService _stockService;
|
private readonly IMaterialUnitService _materialUnitService;
|
private readonly IInboundOrderDetailService _inboundOrderDetailService;
|
private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
|
private readonly IRepository<Dt_StockInfoDetail> _stockDetailRepository;
|
private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
|
private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
|
private readonly IRepository<Dt_StockInfo> _stockRepository;
|
public IRepository<Dt_InboundOrder> Repository => BaseDal;
|
|
public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository,IRepository<Dt_StockInfo> stockRepository) : base(BaseDal)
|
{
|
_mapper = mapper;
|
_unitOfWorkManage = unitOfWorkManage;
|
_inboundOrderDetailRepository = inboundOrderDetailRepository;
|
_taskRepository = taskRepository;
|
_stockService = stockService;
|
_inboundOrderDetailService = inboundOrderDetailService;
|
_materialUnitService = materialUnitService;
|
_stockDetailRepository = stockDetailRepository;
|
_inboundOrderRepository = inboundOrderRepository;
|
_warehouseAreaRepository = warehouseAreaRepository;
|
_stockRepository = stockRepository;
|
}
|
|
public async Task<WebResponseContent> ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType)
|
{
|
try
|
{
|
return operateType switch
|
{
|
1 => await AddInboundOrder(models),
|
2 => await UpdateInboundOrder(models),
|
3 => DeleteInboundOrder(models),
|
|
_ => WebResponseContent.Instance.OK(),
|
};
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public async Task<WebResponseContent> AddInboundOrder(List<Dt_InboundOrder> models)
|
{
|
try
|
{
|
foreach (var model in models)
|
{
|
if (BaseDal.QueryFirst(x => x.UpperOrderNo == model.UpperOrderNo) != null)
|
{
|
return WebResponseContent.Instance.Error($"入库单号重复");
|
}
|
}
|
|
foreach (var model in models)
|
{
|
foreach (var item in model.Details)
|
{
|
var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
|
item.Unit = purchaseToStockResult.Unit;
|
item.OrderQuantity = purchaseToStockResult.Quantity;
|
}
|
|
model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
|
Db.InsertNav(model).Include(x => x.Details).ExecuteCommand();
|
}
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
public async Task<WebResponseContent> UpdateInboundOrder(List<Dt_InboundOrder> models)
|
{
|
try
|
{
|
foreach (var model in models)
|
{
|
Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First();
|
if (inboundOrder == null)
|
{
|
return WebResponseContent.Instance.Error($"未找到入库单信息");
|
}
|
if (inboundOrder.Details == null || inboundOrder.Details.Count == 0)
|
{
|
return WebResponseContent.Instance.Error($"未找到入库单明细信息");
|
}
|
List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
|
List<Dt_InboundOrderDetail> updateInboundOrderDetails = new List<Dt_InboundOrderDetail>();
|
List<int> detailIds = new List<int>();
|
foreach (var item in model.Details)
|
{
|
if (string.IsNullOrEmpty(item.Barcode))
|
{
|
|
}
|
else
|
{
|
Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode);
|
if (inboundOrderDetail == null)
|
{
|
inboundOrderDetail = new Dt_InboundOrderDetail()
|
{
|
OrderId = inboundOrder.Id,
|
lineNo = item.lineNo,
|
MaterielCode = item.MaterielCode,
|
SupplyCode = item.SupplyCode,
|
BatchNo = item.BatchNo,
|
Unit = item.Unit,
|
WarehouseCode = item.WarehouseCode,
|
Barcode = item.Barcode,
|
OutBoxbarcodes = item.OutBoxbarcodes,
|
BarcodeUnit = item.BarcodeUnit,
|
BarcodeQty = item.BarcodeQty,
|
OrderQuantity = item.OrderQuantity
|
};
|
var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
|
inboundOrderDetail.Unit = purchaseToStockResult.Unit;
|
inboundOrderDetail.OrderQuantity = purchaseToStockResult.Quantity;
|
|
inboundOrderDetails.Add(inboundOrderDetail);
|
}
|
else
|
{
|
inboundOrderDetail.lineNo = item.lineNo;
|
inboundOrderDetail.MaterielCode = item.MaterielCode;
|
inboundOrderDetail.SupplyCode = item.SupplyCode;
|
inboundOrderDetail.BatchNo = item.BatchNo;
|
inboundOrderDetail.Unit = item.Unit;
|
inboundOrderDetail.WarehouseCode = item.WarehouseCode;
|
inboundOrderDetail.Barcode = item.Barcode;
|
inboundOrderDetail.OutBoxbarcodes = item.OutBoxbarcodes;
|
inboundOrderDetail.BarcodeUnit = item.BarcodeUnit;
|
inboundOrderDetail.BarcodeQty = item.BarcodeQty;
|
inboundOrderDetail.OrderQuantity = item.OrderQuantity;
|
var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
|
inboundOrderDetail.Unit = purchaseToStockResult.Unit;
|
inboundOrderDetail.OrderQuantity = purchaseToStockResult.Quantity;
|
|
updateInboundOrderDetails.Add(inboundOrderDetail);
|
detailIds.Add(inboundOrderDetail.Id);
|
}
|
}
|
}
|
|
inboundOrder.UpperOrderNo = model.UpperOrderNo;
|
inboundOrder.BusinessType = model.BusinessType;
|
inboundOrder.IsBatch = model.IsBatch;
|
inboundOrder.FactoryArea = model.FactoryArea;
|
|
List<Dt_InboundOrderDetail> deletePurchaseOrderDetails = inboundOrder.Details.Where(x => !detailIds.Contains(x.Id)).ToList();
|
|
_unitOfWorkManage.BeginTran();
|
foreach (var item in deletePurchaseOrderDetails)
|
{
|
_inboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.自动删除);
|
}
|
|
_inboundOrderDetailRepository.UpdateData(updateInboundOrderDetails);
|
_inboundOrderDetailRepository.AddData(inboundOrderDetails);
|
|
BaseDal.UpdateData(inboundOrder);
|
_unitOfWorkManage.CommitTran();
|
|
|
}
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent DeleteInboundOrder(List<Dt_InboundOrder> models)
|
{
|
try
|
{
|
foreach (var model in models)
|
{
|
Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First();
|
if (inboundOrder == null)
|
{
|
return WebResponseContent.Instance.Error($"未找到入库单信息");
|
}
|
if (inboundOrder.Details == null || inboundOrder.Details.Count == 0)
|
{
|
return WebResponseContent.Instance.Error($"未找到入库单明细信息");
|
}
|
//Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
|
_unitOfWorkManage.BeginTran();
|
//BaseDal.DeleteAndMoveIntoHty(inboundOrder, OperateTypeEnum.自动删除);
|
foreach (var item in inboundOrder.Details)
|
{
|
_inboundOrderDetailRepository.DeleteData(item);
|
//_inboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.自动删除);
|
}
|
BaseDal.DeleteData(inboundOrder);
|
_unitOfWorkManage.CommitTran();
|
}
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
static object lock_code = new object();
|
public string CreateCodeByRule(string ruleCode)
|
{
|
lock (lock_code)
|
{
|
|
string code = string.Empty;
|
DateTime dateTime = DateTime.Now;
|
DateTime now = DateTime.Now;
|
try
|
{
|
if (string.IsNullOrEmpty(ruleCode))
|
throw new ArgumentNullException(nameof(ruleCode));
|
SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
|
{
|
IsAutoCloseConnection = true,
|
DbType = DbType.SqlServer,
|
ConnectionString = DBContext.ConnectionString
|
});
|
Dt_CodeRuleConfig codeRuleConfig = sugarClient.Queryable<Dt_CodeRuleConfig>().Where(x => x.RuleCode == ruleCode).First();
|
if (codeRuleConfig == null)
|
throw new ArgumentNullException(nameof(codeRuleConfig));
|
if (codeRuleConfig.ModifyDate != null)
|
{
|
dateTime = Convert.ToDateTime(codeRuleConfig.ModifyDate);
|
}
|
else
|
{
|
dateTime = Convert.ToDateTime(codeRuleConfig.CreateDate);
|
}
|
|
if (now.Year == dateTime.Year && now.Month == dateTime.Month && now.Day == dateTime.Day)
|
{
|
now = dateTime;
|
codeRuleConfig.CurrentVal = Convert.ToInt32(codeRuleConfig.CurrentVal) + 1;
|
}
|
else
|
{
|
codeRuleConfig.CurrentVal = 1;
|
}
|
codeRuleConfig.ModifyDate = DateTime.Now;
|
code = codeRuleConfig.StartStr + codeRuleConfig.Format;
|
code = code.Replace($"[{CodeFormatTypeEnum.YYYY}]", now.Year.ToString().PadLeft(4, '0'));
|
code = code.Replace($"[{CodeFormatTypeEnum.MM}]", now.Month.ToString().PadLeft(2, '0'));
|
code = code.Replace($"[{CodeFormatTypeEnum.DD}]", now.Day.ToString().PadLeft(2, '0'));
|
code = code.Replace($"[{CodeFormatTypeEnum.ST}]", codeRuleConfig.StartStr?.ToString() ?? "");
|
code = code.Replace($"[{CodeFormatTypeEnum.NUM}]", codeRuleConfig.CurrentVal.ToString().PadLeft(codeRuleConfig.Length, '0'));
|
Dictionary<string, object> keyValuePairs = new Dictionary<string, object>() { { nameof(codeRuleConfig.CurrentVal), codeRuleConfig.CurrentVal }, { nameof(codeRuleConfig.Id), codeRuleConfig.Id }, { nameof(codeRuleConfig.ModifyDate), DateTime.Now } };
|
sugarClient.Updateable(keyValuePairs).AS(MainDb.CodeRuleConfig).WhereColumns(nameof(codeRuleConfig.Id)).ExecuteCommand();
|
sugarClient.Updateable(codeRuleConfig);
|
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return code;
|
}
|
}
|
|
|
|
/// <summary>
|
/// 根据入库单号获取入库单(含明细)
|
/// </summary>
|
/// <param name="inboundOrderNo"></param>
|
/// <returns></returns>
|
public Dt_InboundOrder GetInboundOrder(string inboundOrderNo)
|
{
|
return BaseDal.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).First(x => x.InboundOrderNo == inboundOrderNo); ;
|
}
|
|
|
|
public WebResponseContent BarcodeMaterielGroup(BarcodeMaterielGroupDTO materielGroupDTO)
|
{
|
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
(bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
|
if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
|
|
// materielGroupDTO.WarehouseCode
|
var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x=>x.Code).First();
|
if(string.IsNullOrEmpty(code))
|
{
|
return content = WebResponseContent.Instance.Error($"仓库中没有该{materielGroupDTO.WarehouseType}编号。");
|
}
|
|
|
Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
|
|
var dbinboundOrderDetails = _inboundOrderDetailService.GetByBarcode(materielGroupDTO.Barcodes);
|
|
if (dbinboundOrderDetails != null && !dbinboundOrderDetails.Any())
|
{
|
return content = WebResponseContent.Instance.Error($"单据中没有该{materielGroupDTO.Barcodes}条码数据。");
|
}
|
|
List<string?> materielCodes = dbinboundOrderDetails.GroupBy(x => x.Barcode).Select(x => x.Key).ToList();
|
|
Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
|
|
|
|
(bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, materielCodes, inboundOrder, stockInfo);
|
if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
|
|
if (stockInfo == null)
|
{
|
stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None,LocationType=materielGroupDTO.locationType.ObjToInt() };
|
stockInfo.Details = new List<Dt_StockInfoDetail>();
|
}
|
|
foreach (var item in dbinboundOrderDetails)
|
{
|
stockInfo.Details.Add(new Dt_StockInfoDetail
|
{
|
StockId = stockInfo == null ? 0 : stockInfo.Id,
|
Barcode = item.Barcode,
|
MaterielCode = item.MaterielCode,
|
BatchNo = item.BatchNo,
|
Unit = item.Unit,
|
InboundOrderRowNo = item.lineNo,
|
SupplyCode = item.SupplyCode,
|
WarehouseCode = materielGroupDTO.WarehouseType,
|
StockQuantity = item.OrderQuantity,
|
BarcodeQty=item.BarcodeQty,
|
BarcodeUnit=item.BarcodeUnit,
|
FactoryArea= inboundOrder.FactoryArea,
|
Status = 0,
|
OrderNo = inboundOrder.InboundOrderNo,
|
BusinessType = inboundOrder.BusinessType,
|
|
});
|
|
item.ReceiptQuantity = item.BarcodeQty;
|
item.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
|
item.WarehouseCode = materielGroupDTO.WarehouseType;
|
}
|
|
if (stockInfo.Id == 0)
|
{
|
stockInfo.PalletCode = materielGroupDTO.PalletCode;
|
stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
|
}
|
stockInfo.PalletType = (int)PalletTypeEnum.None;
|
|
List<int> updateDetailIds = dbinboundOrderDetails.Select(x => x.Id).ToList();
|
if (inboundOrder.OrderStatus == InOrderStatusEnum.未开始.ObjToInt())
|
{
|
inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt();
|
}
|
inboundOrder.Operator = App.User.UserName;
|
content = MaterielGroupUpdateData(inboundOrder, dbinboundOrderDetails, stockInfo);
|
if (content.Status)
|
{
|
return WebResponseContent.Instance.OK("", stockInfo.Details);
|
}
|
else
|
{
|
content = WebResponseContent.Instance.Error(content.Message);
|
}
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
finally
|
{
|
|
}
|
return content;
|
|
}
|
|
|
public WebResponseContent EmptyMaterielGroup(EmptyBarcodeMaterielGroupDTO materielGroupDTO)
|
{
|
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
(bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
|
if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
|
|
bool code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Id == materielGroupDTO.WarehouseCode).Any();
|
if (!code)
|
{
|
return content = WebResponseContent.Instance.Error($"仓库中没有该{materielGroupDTO.WarehouseCode}编号。");
|
}
|
|
if(_stockRepository.QueryFirst(x=>x.PalletCode == materielGroupDTO.PalletCode)!=null){
|
return WebResponseContent.Instance.Error("该托盘已经组过盘");
|
}
|
|
Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
|
if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
|
{
|
return WebResponseContent.Instance.Error("已上架的托盘不能再次组盘");
|
}
|
|
if (_taskRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
|
{
|
return WebResponseContent.Instance.Error("该托盘号已有任务");
|
}
|
|
try
|
{
|
if (stockInfo == null)
|
{
|
stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.组盘暂存.ObjToInt(), PalletCode = materielGroupDTO.PalletCode,LocationType= materielGroupDTO.WarehouseCode.ObjToInt() };
|
stockInfo.Details = new List<Dt_StockInfoDetail>();
|
}
|
else
|
{
|
stockInfo.PalletType = PalletTypeEnum.Empty.ObjToInt();
|
stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
|
stockInfo.LocationType = materielGroupDTO.WarehouseCode.ObjToInt();
|
}
|
|
_unitOfWorkManage.BeginTran();
|
|
_stockService.StockInfoService.AddMaterielGroup(stockInfo);
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
|
|
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
finally
|
{
|
|
}
|
return content;
|
|
}
|
|
/// <summary>
|
/// 验证组盘数据
|
/// </summary>
|
/// <param name="materielGroupDTO">物料组盘DTO</param>
|
/// <param name="matSerialNumberDTOs">扫码序列号</param>
|
/// <param name="materielInfos">物料信息</param>
|
/// <param name="materielCodes">物料编号</param>
|
/// <param name="inboundOrder">入库单据</param>
|
/// <param name="stockInfo">组盘信息</param>
|
/// <returns></returns>
|
public (bool, string, object?) CheckMaterielGroupParam(BarcodeMaterielGroupDTO materielGroupDTO, List<string> barcodeCodes, Dt_InboundOrder inboundOrder, Dt_StockInfo stockInfo)
|
{
|
(bool, string, object?) result = ModelValidate.ValidateModelData(materielGroupDTO);
|
if (!result.Item1) return result;
|
|
if (_taskRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
|
{
|
return (false, "该托盘号已有任务", materielGroupDTO);
|
}
|
|
if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
|
{
|
return (false, "已上架的托盘不能再次组盘", materielGroupDTO);
|
}
|
|
if (_stockService.StockInfoDetailService.ExistBarcodes(barcodeCodes))
|
{
|
return (false, $"{barcodeCodes[0]} 条码在库存中已存在", materielGroupDTO);
|
}
|
//if (materielInfos.Count != materielCodes.Count)
|
//{
|
// return (false, "有物料信息未录入,请录入物料信息", materielGroupDTO);
|
//}
|
|
if (inboundOrder == null)
|
{
|
return (false, "单据不存在", materielGroupDTO);
|
}
|
|
if (inboundOrder.Details == null || inboundOrder.Details.Count == 0)
|
{
|
return (false, "无单据明细信息", materielGroupDTO);
|
}
|
|
if (inboundOrder.OrderStatus != InOrderStatusEnum.未开始.ObjToInt() && inboundOrder.OrderStatus != InOrderStatusEnum.入库中.ObjToInt())
|
{
|
return (false, "该单据不可再组盘", materielGroupDTO);
|
}
|
|
List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => barcodeCodes.Contains(x.Barcode)).ToList();
|
|
if (inboundOrderDetails.GroupBy(x => x.Barcode).Count() != barcodeCodes.Count)
|
{
|
return (false, "有物料不在单据内", materielGroupDTO);
|
}
|
|
IGrouping<string, Dt_InboundOrderDetail>? temp = inboundOrder.Details.Where(x => barcodeCodes.Contains(x.Barcode)).GroupBy(x => x.Barcode).FirstOrDefault(x => x.Sum(v => v.OverInQuantity) >= x.Sum(v => v.OrderQuantity) || x.Sum(v => v.ReceiptQuantity) >= x.Sum(v => v.OrderQuantity));
|
if (temp != null)
|
{
|
return (false, "有物料超出单据数量", materielGroupDTO);
|
}
|
|
return (true, "成功", materielGroupDTO);
|
}
|
|
/// <summary>
|
/// 组盘数据更新
|
/// </summary>
|
/// <param name="inboundOrder">入库单</param>
|
/// <param name="inboundOrderDetails">入库单明细</param>
|
/// <param name="stockInfo">组盘数据</param>
|
/// <returns></returns>
|
public WebResponseContent MaterielGroupUpdateData(Dt_InboundOrder inboundOrder, List<Dt_InboundOrderDetail> inboundOrderDetails, Dt_StockInfo stockInfo)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
UpdateData(inboundOrder);
|
_inboundOrderDetailService.UpdateData(inboundOrderDetails);
|
_stockService.StockInfoService.AddMaterielGroup(stockInfo);
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
|
public WebResponseContent UnPalletQuantity(string orderNo)
|
{
|
// 初始化返回DTO(默认值都为0,避免null)
|
var resultDTO = new PalletSumQuantityDTO
|
{
|
StockSumQuantity = 0,
|
StockCount = 0,
|
UniqueUnit = ""
|
};
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (string.IsNullOrWhiteSpace(orderNo))
|
{
|
return content.Error("传入的订单号orderNo为空或空白");
|
}
|
var orderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).Where(s => s.InboundOrderNo == orderNo).First();
|
if (orderDetail == null)
|
{
|
return content.Error("未找到单据");
|
}
|
var unitGroups = orderDetail.Details.GroupBy(d => d.Unit).ToList();
|
if (unitGroups.Count == 1)
|
{
|
resultDTO.UniqueUnit = unitGroups.First().Key;
|
}
|
else
|
{
|
resultDTO.UniqueUnit = "";
|
}
|
var validDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
|
resultDTO.StockSumQuantity = orderDetail.Details.Sum(d => d.OrderQuantity);
|
resultDTO.StockCount = orderDetail.Details.Count;
|
if (validDetails.Any())
|
{
|
resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
|
// 明细记录数:符合条件的有效记录条数
|
resultDTO.StockCount -= validDetails.Count;
|
}
|
return content.OK("", resultDTO);
|
}
|
catch (Exception ex)
|
{
|
return content.Error("SumQuantity 统计库存数量失败,订单号:{OrderNo}");
|
}
|
}
|
|
}
|
}
|