This commit is contained in:
tongfei
2023-12-08 14:00:44 +08:00
parent aea554b6c0
commit adc58439ee
17 changed files with 385 additions and 167 deletions

View File

@@ -57,8 +57,22 @@ namespace WMS.Web.Domain.Entitys
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 组织ID
/// </summary>
public int OrgId { get; set; }
/// <summary>
/// 组织编码
/// </summary>
public string OrgCode { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string StockCode { get; set; }
/// <summary>
/// 仓位ID
/// </summary>
public int SubStockId { get; set; }
/// <summary>
/// 明细
/// </summary>

View File

@@ -43,26 +43,26 @@ namespace WMS.Web.Domain.Entitys
/// 供应商ID
/// </summary>
public int SupplierId { get; set; }
/// <summary>
/// 组织ID
/// </summary>
public int OrgId { get; set; }
/// <summary>
/// 组织编码
/// </summary>
public string OrgCode { get; set; }
///// <summary>
///// 组织ID
///// </summary>
//public int OrgId { get; set; }
///// <summary>
///// 组织编码
///// </summary>
//public string OrgCode { get; set; }
/// <summary>
/// 物料ID
/// </summary>
public int MaterialId { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string StockCode { get; set; }
/// <summary>
/// 仓位ID
/// </summary>
public int SubStockId { get; set; }
///// <summary>
///// 仓库编码
///// </summary>
//public string StockCode { get; set; }
///// <summary>
///// 仓位ID
///// </summary>
//public int SubStockId { get; set; }
/// <summary>
/// 数量
/// </summary>

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace WMS.Web.Domain.Entitys
{
/// <summary>
/// wms入库单-汇总明细
/// </summary>
[Serializable]
[Table("t_wms_instock_total_details")]
public class InStockTotalDetails
{
/// <summary>
/// ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 入库单ID
/// </summary>
public int InStockId { get; set; }
/// <summary>
/// 任务单ID
/// </summary>
public int TaskId { get; set; }
/// <summary>
/// 来源单号
/// </summary>
public string SourceBillNo { get; set; }
/// <summary>
/// 供应商ID
/// </summary>
public int SupplierId { get; set; }
/// <summary>
/// 物料ID
/// </summary>
public int MaterialId { get; set; }
/// <summary>
/// 数量
/// </summary>
public decimal Qty { get; set; }
/// <summary>
/// 序列号集
/// </summary>
public List<string> SerialNumbers { get; set; } = new List<string>();
}
}

View File

@@ -59,7 +59,7 @@ namespace WMS.Web.Domain.IService
/// <param name="dtoDatas"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<Result> GenerateInStockBox(List<InStock> dtoDatas, bool isTransaction);
Task<Result> GenerateInStockBox(InStock dtoDatas, bool isTransaction);
/// <summary>
/// 出库单-箱库存的变更

View File

@@ -73,6 +73,13 @@ namespace WMS.Web.Domain.IService.Public
/// <returns></returns>
string GetOrgName(List<ErpOrgDto> erpOrgs, string orgCode);
/// <summary>
/// 获取组织ID
/// </summary>
/// <param name="erpOrgs"></param>
/// <param name="orgCode"></param>
int GetOrgId(List<ErpOrgDto> erpOrgs, string orgCode);
/// <summary>
/// 获取供应商名称
/// </summary>

View File

@@ -42,5 +42,13 @@ namespace WMS.Web.Domain.Infrastructure
/// <param name="id"></param>
/// <returns></returns>
Task<InStockInfoResponse> GetInfo(int id);
/// <summary>
/// 批量添加:入库汇总明细
/// </summary>
/// <param name="entitys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<bool> AddRangeTotalDetails(List<InStockTotalDetails> entitys, bool isTransaction = true);
}
}

View File

@@ -35,6 +35,8 @@ namespace WMS.Web.Domain.Mappers
CreateMap<SaveInStockDetailsRequest, InStockDetails>().ReverseMap();
CreateMap<NoPurchaseShelfDetailsRequest, InStockDetails>().ReverseMap();
CreateMap<SaveInStockDetailsRequest, InStockTotalDetails>();
CreateMap<NoPurchaseShelfDetailsRequest, InStockTotalDetails>();
CreateMap<NoPurchaseShelfDetailsRequest, BoxInventoryGenerateDetailsDto>();

View File

@@ -440,33 +440,31 @@ namespace WMS.Web.Domain.Services
/// <param name="dtoDatas"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<Result> GenerateInStockBox(List<InStock> dtoDatas, bool isTransaction)
public async Task<Result> GenerateInStockBox(InStock dtoData, bool isTransaction)
{
//1.判断来源数据是否存在
if (dtoDatas == null || dtoDatas.Count == 0)
if (dtoData == null)
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
//物料收发明细dtos
var InventoryInOutDetailsGenerateDtoList = new List<InventoryInOutDetailsGenerateDto>();
#region
//2.组装-按箱入库
var dtoDatas_details_Method_box = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Box).SelectMany(x => x.Details).ToList();
var generateDtoList_Metod_Box = dtoDatas_details_Method_box.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId })
//2.组装-按箱和按产品入库
var generateDtoList = dtoData.Details.GroupBy(x => new { x.BoxId })
.Select(x => new BoxInventoryGenerateDto()
{
BoxId = x.Key.BoxId,
OrgCode = x.Key.OrgCode,
StockCode = x.Key.StockCode,
SubStockId = x.Key.SubStockId,
InventoryInOutMethod = (int)InventoryInOutMethod.Box,
OrgCode = dtoData.OrgCode,
StockCode = dtoData.StockCode,
SubStockId = dtoData.SubStockId,
InventoryInOutMethod = (int)dtoData.Method,
InventoryInOutType = (int)InventoryInOutType.In
}).ToList();
//2.1.遍历:组装明细
generateDtoList_Metod_Box.ForEach(x =>
generateDtoList.ForEach(x =>
{
foreach (var detItem in dtoDatas_details_Method_box)
foreach (var detItem in dtoData.Details)
{
//2.1箱是当前的
if (detItem.BoxId == x.BoxId)
@@ -480,63 +478,21 @@ namespace WMS.Web.Domain.Services
}
}
});
#endregion
#region
//3.组装-按产品入库
var dtoDatas_details_Method_Product = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Product).SelectMany(x => x.Details).ToList();
var generateDtoList_Metod_Product = dtoDatas_details_Method_Product.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId })
.Select(x => new BoxInventoryGenerateDto()
{
BoxId = x.Key.BoxId,
OrgCode = x.Key.OrgCode,
StockCode = x.Key.StockCode,
SubStockId = x.Key.SubStockId,
InventoryInOutMethod = (int)InventoryInOutMethod.Product,
InventoryInOutType = (int)InventoryInOutType.In
}).ToList();
//3.1.遍历:组装明细
generateDtoList_Metod_Product.ForEach(x =>
{
foreach (var detItem in dtoDatas_details_Method_Product)
{
//3.1箱是当前的
if (detItem.BoxId == x.BoxId)
{
//3.2组装明细
var det = new BoxInventoryGenerateDetailsDto();
det.MaterialId = detItem.MaterialId;
det.Qty = detItem.Qty;
det.SerialNumbers = detItem.SerialNumbers;
x.Details.Add(det);
}
}
});
#endregion
//整合一起
var generateDtoList = new List<BoxInventoryGenerateDto>();
generateDtoList.AddRange(generateDtoList_Metod_Box);
generateDtoList.AddRange(generateDtoList_Metod_Product);
//提交处理
var result = await this.ExeInStockBox(generateDtoList, isTransaction);
if (!result.IsSuccess)
return result;
//5.组装物料收发明细dto
foreach (var item in dtoDatas.SelectMany(x => x.Details).ToList())
foreach (var item in dtoData.Details)
{
var entity = dtoDatas.Where(x => x.Id == item.Fid).FirstOrDefault();
if (entity != null)
{
var inventoryInOutDet = _inventoryInOutDetailsService.GenerateDto(
item.BoxId, item.MaterialId,
item.OrgCode, item.StockCode,
item.SubStockId, InStockTypeConvert(entity.Type),
item.SourceBillNo, item.Qty, InventoryInOutType.In);
InventoryInOutDetailsGenerateDtoList.Add(inventoryInOutDet);
}
var inventoryInOutDet = _inventoryInOutDetailsService.GenerateDto(
item.BoxId, item.MaterialId,
dtoData.OrgCode, dtoData.StockCode,
dtoData.SubStockId, InStockTypeConvert(dtoData.Type),
item.SourceBillNo, item.Qty, InventoryInOutType.In);
InventoryInOutDetailsGenerateDtoList.Add(inventoryInOutDet);
}
//5.提交物料收发明细:新增
if (InventoryInOutDetailsGenerateDtoList.Count != 0)
@@ -565,16 +521,16 @@ namespace WMS.Web.Domain.Services
var InventoryInOutDetailsGenerateDtoList = new List<InventoryInOutDetailsGenerateDto>();
//找出所有的箱库存
var boxIds = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x=>x.BoxId).Select(x => x.Key).ToList();
var boxIds = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
var boxInventorys = await _boxInventoryRepositories.GetList(boxIds);
//判断箱库存是否存在
foreach (var bid in boxIds)
{
var isHaveBoxInvetory= boxInventorys.Where(x => x.BoxId == bid).Any();
var isHaveBoxInvetory = boxInventorys.Where(x => x.BoxId == bid).Any();
if (!isHaveBoxInvetory)
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
}
//2.组装
var generateDtoList = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => new { x.BoxId })
@@ -590,7 +546,7 @@ namespace WMS.Web.Domain.Services
{
//从箱库存找到:组织、仓库、仓位、进行赋值;
var current_box_invetory = boxInventorys.Where(t => t.BoxId == x.BoxId).FirstOrDefault();
if (current_box_invetory != null && current_box_invetory.BoxId==x.BoxId)
if (current_box_invetory != null && current_box_invetory.BoxId == x.BoxId)
{
x.OrgCode = current_box_invetory.OrgCode;
x.StockCode = current_box_invetory.StockCode;
@@ -1439,7 +1395,7 @@ namespace WMS.Web.Domain.Services
/// <param name="boxInventorys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
private async Task<Result> ExeOutStockBox(List<BoxInventoryGenerateDto> dtoDatas,List<BoxInventory> boxInventorys, bool isTransaction)
private async Task<Result> ExeOutStockBox(List<BoxInventoryGenerateDto> dtoDatas, List<BoxInventory> boxInventorys, bool isTransaction)
{
//1.判断来源数据是否存在
if (dtoDatas == null || dtoDatas.Count == 0)

View File

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using WMS.Web.Core.Dto;
using WMS.Web.Core.Dto.ChangeBoxRecord;
using WMS.Web.Core.Dto.Erp;
using WMS.Web.Core.Dto.Erp.Org;
using WMS.Web.Core.Dto.InStock;
using WMS.Web.Core.Dto.InStockTask;
using WMS.Web.Core.Dto.Inventory;
@@ -217,8 +218,19 @@ namespace WMS.Web.Domain.Services
/// <returns></returns>
private async Task<Result> ShelfSave(PurchaseShelfRequest dto, InstockType type, LoginInDto loginInfo, bool isTransaction = true)
{
// 组织集合
var orgs = new List<ErpOrgDto>();
var orgs_result = await _erpService.BillQueryForOrg();
if (orgs_result.IsSuccess)
orgs = orgs_result.Data.ToList();
var currentOrg= orgs.Where(x => x.Number == dto.OrgCode).FirstOrDefault();
var entity = new InStock();
entity.Type = type;
entity.OrgId = currentOrg == null ? 0 : currentOrg.Id;
entity.StockCode = dto.StockCode;
entity.OrgCode = dto.OrgCode;
entity.SubStockId = dto.SubStockId;
entity.Method = InventoryInOutMethod.Box;
entity.Details = _mapper.Map<List<InStockDetails>>(dto.Details);
entity.Create(loginInfo.UserInfo.StaffId);
@@ -242,6 +254,22 @@ namespace WMS.Web.Domain.Services
if (entity == null)
return Result.ReFailure(ResultCodes.DateWriteError);
//处理添加入库汇总明细
var totalDetails = dto.Details.GroupBy(x => new { x.TaskId, x.SourceBillNo, x.SupplierId, x.MaterialId })
.Select(x => new InStockTotalDetails
{
InStockId= entity.Id,
TaskId=x.Key.TaskId,
SourceBillNo=x.Key.SourceBillNo,
SupplierId=x.Key.SupplierId,
MaterialId=x.Key.MaterialId,
Qty=x.Sum(t=>t.Qty),
SerialNumbers= x.SelectMany(t=>t.SerialNumbers).ToList()
}).ToList();
var isSuccess= await _inStockRepositories.AddRangeTotalDetails(totalDetails, isTransaction);
if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError);
//同步金蝶后,反写任务单的已交数量
var taskIds = dto.Details.GroupBy(x => x.TaskId).Select(x => x.Key).ToList();
var tasks = await _inStockTaskRepositories.GetList(taskIds);
@@ -262,7 +290,7 @@ namespace WMS.Web.Domain.Services
task.Shelf(loginInfo.UserInfo.StaffId);
}
var isSuccess = await _inStockTaskRepositories.UpdateRange(tasks, isTransaction);
isSuccess = await _inStockTaskRepositories.UpdateRange(tasks, isTransaction);
if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError);
}
@@ -273,9 +301,7 @@ namespace WMS.Web.Domain.Services
return serialNumber_result;
//箱库存变动
var dtoDatas = new List<InStock>();
dtoDatas.Add(entity);
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(dtoDatas, isTransaction);
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(entity, isTransaction);
if (!boxInventoryResult.IsSuccess)
return boxInventoryResult;
@@ -306,6 +332,10 @@ namespace WMS.Web.Domain.Services
//2.生成:入库单
var entity = new InStock();
entity.Type = task.Type;
entity.OrgId = task.Details.Select(x => x.OrgId).FirstOrDefault();
entity.StockCode = dto.StockCode;
entity.OrgCode = dto.OrgCode;
entity.SubStockId = dto.SubStockId;
entity.Method = dto.ShelfMethod == (int)ShelfMethod.Box ? InventoryInOutMethod.Box : InventoryInOutMethod.Product;
entity.Details = new List<InStockDetails>();
@@ -321,10 +351,10 @@ namespace WMS.Web.Domain.Services
item.TaskId = dto.TaskId;
item.SourceBillNo = task.SourceBillNo;
item.BoxId = box.BoxId;
item.SubStockId = dto.SubStockId;
item.StockCode = dto.StockCode;
item.OrgCode = dto.OrgCode;
item.OrgId = task.Details.Select(x => x.OrgId).FirstOrDefault();
//item.SubStockId = dto.SubStockId;
//item.StockCode = dto.StockCode;
//item.OrgCode = dto.OrgCode;
//item.OrgId = task.Details.Select(x => x.OrgId).FirstOrDefault();
});
//3.3添加到临时集合中
temps.AddRange(dets);
@@ -356,6 +386,22 @@ namespace WMS.Web.Domain.Services
if (entity == null)
return Result.ReFailure(ResultCodes.DateWriteError);
//处理添加入库汇总明细
var totalDetails = dto.Boxs.SelectMany(x=>x.Details).GroupBy(x => new { x.MaterialId })
.Select(x => new InStockTotalDetails
{
InStockId = entity.Id,
TaskId =dto.TaskId,
SourceBillNo = task.SourceBillNo,
MaterialId = x.Key.MaterialId,
Qty = x.Sum(t => t.Qty),
SerialNumbers = x.SelectMany(t => t.SerialNumbers).ToList()
}).ToList();
var isSuccess = await _inStockRepositories.AddRangeTotalDetails(totalDetails, isTransaction);
if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError);
//同步金蝶后,反写任务单的已交数量
if (task != null)
{
@@ -422,9 +468,7 @@ namespace WMS.Web.Domain.Services
return serialNumber_result;
//箱库存变动
var dtoDatas = new List<InStock>();
dtoDatas.Add(entity);
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(dtoDatas, isTransaction);
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(entity, isTransaction);
if (!boxInventoryResult.IsSuccess)
return boxInventoryResult;

View File

@@ -168,6 +168,18 @@ namespace WMS.Web.Domain.Services.Public
return org == null ? "" : org.Name;
}
/// <summary>
/// 获取组织id
/// </summary>
/// <param name="erpOrgs"></param>
/// <param name="orgCode"></param>
/// <returns></returns>
public int GetOrgId(List<ErpOrgDto> erpOrgs, string orgCode)
{
var org = erpOrgs.Where(x => x.Number == orgCode).FirstOrDefault();
return org == null ? 0 : org.Id;
}
/// <summary>
/// 获取供应商名称
/// </summary>

View File

@@ -321,7 +321,7 @@ namespace WMS.Web.Domain.Services
{
var box = boxList.FirstOrDefault(f => f.Id == entity.BoxId);
var instockDetail = inStock.Details.FirstOrDefault(f => f.MaterialId == entity.MaterialId);
var subStock = _singleDataService.GetSingleData(SingleAction.SubStocks, loginInfo.UserInfo.CompanyId, instockDetail.SubStockId);
var subStock = _singleDataService.GetSingleData(SingleAction.SubStocks, loginInfo.UserInfo.CompanyId, inStock.SubStockId);
//修改序列号和箱绑定关系
entity.InStock(instockDetail.SourceBillNo, inStock.Type);