diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/InventorycheckInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/InventorycheckInput.cs new file mode 100644 index 00000000..d5bef8f4 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/InventorycheckInput.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Transactions; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class InventorycheckInput + { + /// + /// 盘点单号 + /// + public string? erp_bill_code { get; set; } + + /// + /// 部门编码 + /// + public string? dept_code { get; set; } + + /// + /// 业务员编码 + /// + public string? biller { get; set; } + + /// + /// 盘点仓库编码 + /// + public string? warehouse_code { get; set; } + + /// + /// 主表pk + /// + public string? erp_pk { get; set; } + + public List details { get; set; } + } + public class InventorycheckInputDetail + { + /// + /// 行号 + /// + public string? lineno { get; set; } + + /// + /// 物品代码 + /// + public string? material_code { get; set; } + + /// + /// 单位代码 + /// + public string? unit_code { get; set; } + + /// + /// 采购数量 + /// + public decimal? qty { get; set; } + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 生产日期 + /// + public DateTime? production_date { get; set; } + + /// + /// 子表主键 + /// + public string erp_line_pk { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckD.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckD.cs new file mode 100644 index 00000000..447feeb1 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckD.cs @@ -0,0 +1,112 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 盘点明细 +/// +[SugarTable("wms_inventorycheck_d")] +public partial class WmsInventorycheckD : BaseEntity +{ + public WmsInventorycheckD() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 盘点单id + /// + public string? bill_id { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + + /// + /// 物料id + /// + public string? material_id { get; set; } + + /// + /// 物料编号 + /// + public string? material_code { get; set; } + + /// + /// 物料名称 + /// + public string? material_name { get; set; } + + /// + /// 规格型号 + /// + public string? material_specification { get; set; } + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 单位id + /// + public string? unit_id { get; set; } + + /// + /// 单位编码 + /// + public string? unit_code { get; set; } + + /// + /// 数量 + /// + public decimal? qty { get; set; } + + /// + /// 生产日期 + /// + public DateTime? production_date { get; set; } + + /// + /// erp_line_pk + /// + public string? erp_line_pk { get; set; } + + /// + /// 行号 + /// + public string? lineno { get; set; } + + /// + /// 实际数量 + /// + public decimal? actual_qty { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckH.cs new file mode 100644 index 00000000..9f6cbb68 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckH.cs @@ -0,0 +1,87 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 盘点单 +/// +[SugarTable("wms_inventorycheck_h")] +public partial class WmsInventorycheckH : BaseEntity +{ + public WmsInventorycheckH() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 盘点单号 + /// + public string? bill_code { get; set; } + + /// + /// 仓库id + /// + public string? warehouse_id { get; set; } + + /// + /// 仓库编码 + /// + public string? warehouse_code { get; set; } + + /// + /// 仓库名称 + /// + public string? warehouse_name { get; set; } + + /// + /// 部门编码 + /// + public string? dept_code { get; set; } + + /// + /// 业务员编码 + /// + public string? biller { get; set; } + + /// + /// erp_pk + /// + public string? erp_pk { get; set; } + + /// + /// erp_bill_code + /// + public string? erp_bill_code { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckRecord.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckRecord.cs new file mode 100644 index 00000000..0939de14 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsInventorycheckRecord.cs @@ -0,0 +1,67 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 盘点记录 +/// +[SugarTable("wms_inventorycheck_record")] +public partial class WmsInventorycheckRecord : BaseEntity +{ + public WmsInventorycheckRecord() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 盘点单id + /// + public string? bill_id { get; set; } + + /// + /// 盘点单明细id + /// + public string? mat_bill_id { get; set; } + + /// + /// 载具id + /// + public string? carry_id { get; set; } + + /// + /// 载具编码 + /// + public string? carry_code { get; set; } + + /// + /// 库位id + /// + public string? location_id { get; set; } + + /// + /// 库位编码 + /// + public string? location_code { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs index 171f124d..fa30f338 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs @@ -2244,6 +2244,158 @@ namespace Tnb.WarehouseMgr } } + /// + /// 盘点单 + /// + [HttpPost, NonUnify, AllowAnonymous] + public async Task Inventorycheck(InventorycheckInput input) + { + + LoggerErp2Mes.LogInformation($"【Inventorycheck】ERP传入数据:{JsonConvert.SerializeObject(input)}"); + var db = _repository.AsSugarClient(); + + + try + { + if (string.IsNullOrEmpty(input.erp_pk)) + { + _LoggerErp2Mes.LogWarning($"【Inventorycheck】主表主键不能为空!"); + throw new AppFriendlyException($@"主表主键不能为空!", 500); + } + + int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count(); + if (count_erp_line_pk > 0) + { + _LoggerErp2Mes.LogWarning($@"【Inventorycheck】子表主键不能为空!"); + throw new AppFriendlyException($@"子表主键不能为空!", 500); + } + + var wmsInventorychecksDistinct = input.details.Select(r => new + { + material_id = r.material_code, + code_batch = r.code_batch, + }).Distinct(); + if (wmsInventorychecksDistinct.Count() < input.details.Count) + { + _LoggerErp2Mes.LogWarning($@"【Inventorycheck】表体存在物料和批号重复的明细!"); + throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500); + } + + WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable().Where(r => r.erp_warehousecode == input.warehouse_code).FirstAsync(); + if (wmsErpWarehouserelaH == null) + { + _LoggerErp2Mes.LogWarning($@"【Inventorycheck】不存在erp仓库类型{input.warehouse_code}对应wms系统的映射关系!"); + throw new AppFriendlyException($@"不存在erp仓库类型{input.warehouse_code}对应wms系统的映射关系!", 500); + } + + string warehouse_code = wmsErpWarehouserelaH.wms_warehousecode; + + BasWarehouse warehouse = await db.Queryable().Where(r => r.whcode == warehouse_code).FirstAsync(); + if (warehouse == null) + { + _LoggerErp2Mes.LogWarning($"【Inventorycheck】无法查询到出库仓库{warehouse_code}的档案记录!"); + return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{warehouse_code}的档案记录!"); + } + await db.Ado.BeginTranAsync(); + + // 判断是否重复传输 + WmsInventorycheckH wmsInventorycheckHRep = await db.Queryable().Where(r => r.erp_pk == input.erp_pk).FirstAsync(); + if (wmsInventorycheckHRep != null) + { + // 判断单据是否已经下发 + List _wmsSaleDs = await db.Queryable().Where(r => r.bill_id == wmsInventorycheckHRep.id).ToListAsync(); + bool isxf = _wmsSaleDs.Where(r => r.actual_qty > 0).Any(); + if (isxf) + { + _LoggerErp2Mes.LogWarning($@"【Inventorycheck】wms已下发使用盘点单{input.erp_bill_code}!"); + throw new AppFriendlyException($@"wms已下发使用盘点单{input.erp_bill_code}!", 500); + } + else // 删除数据重新插入 + { + await db.Deleteable().Where(r => r.id == wmsInventorycheckHRep.id).ExecuteCommandAsync(); + await db.Deleteable().Where(r => r.bill_id == wmsInventorycheckHRep.id).ExecuteCommandAsync(); + } + } + + WmsInventorycheckH wmsInventorycheckH = new WmsInventorycheckH(); + string Code = await _billRuleService.GetBillNumber("CheckStockCode"); + + wmsInventorycheckH.create_id = WmsWareHouseConst.ErpUserId; + wmsInventorycheckH.create_time = DateTime.Now; + wmsInventorycheckH.org_id = WmsWareHouseConst.AdministratorOrgId; + wmsInventorycheckH.bill_code = Code; + + wmsInventorycheckH.warehouse_id = warehouse.id; + wmsInventorycheckH.warehouse_code = warehouse.whcode; + wmsInventorycheckH.warehouse_name = warehouse.whname; + wmsInventorycheckH.dept_code = input.dept_code; + wmsInventorycheckH.biller = input.biller; + wmsInventorycheckH.erp_bill_code = input.erp_bill_code; + wmsInventorycheckH.erp_pk = input.erp_pk; + + await db.Insertable(wmsInventorycheckH).ExecuteCommandAsync(); + + + List wmsInventorycheckDs = new List(); + foreach (var detail in input.details) + { + WmsInventorycheckD wmsInventorycheckD = new WmsInventorycheckD(); + + wmsInventorycheckD.bill_id = wmsInventorycheckH.id; + wmsInventorycheckD.create_id = WmsWareHouseConst.ErpUserId; + wmsInventorycheckD.create_time = DateTime.Now; + wmsInventorycheckD.org_id = WmsWareHouseConst.AdministratorOrgId; + wmsInventorycheckD.production_date = detail.production_date; + + var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); + if (material != null) + { + wmsInventorycheckD.material_id = material.id; + wmsInventorycheckD.material_code = material.code; + wmsInventorycheckD.material_name = material.name; + wmsInventorycheckD.material_specification = material.material_specification; + } + + wmsInventorycheckD.qty = detail.qty; + wmsInventorycheckD.actual_qty = 0; + wmsInventorycheckD.code_batch = detail.code_batch; + wmsInventorycheckD.erp_line_pk = detail.erp_line_pk; + wmsInventorycheckD.lineno = detail.lineno; + + var erpExtendField = await db.Queryable().InnerJoin((a, b) => a.table_id == b.Id).Where((a, b) => b.EnCode == detail.unit_code).Select((a, b) => b).FirstAsync(); + if (erpExtendField != null) + { + wmsInventorycheckD.unit_id = erpExtendField.Id; + wmsInventorycheckD.unit_code = erpExtendField.EnCode; + } + else + { + _LoggerErp2Mes.LogWarning($@"【Inventorycheck】表体明细中单位{detail.unit_code}在wms系统中未找到!"); + throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500); + } + + wmsInventorycheckDs.Add(wmsInventorycheckD); + } + + await db.Insertable(wmsInventorycheckDs).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + + LoggerErp2Mes.LogInformation($"【Inventorycheck】成功生成单据:{Code}"); + return await ToApiResult(HttpStatusCode.OK, "成功"); + } + catch (Exception ex) + { + LoggerErp2Mes.LogError($"【Inventorycheck】{ex.Message}"); + LoggerErp2Mes.LogError($"【Inventorycheck】{ex.StackTrace}"); + await db.Ado.RollbackTranAsync(); + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); + } + finally + { + + } + } protected Task ToApiResult(HttpStatusCode statusCode, string msg) {