From 7f15f7c59f103805a84e96b08a00ebe304746978 Mon Sep 17 00:00:00 2001 From: "yang.lee" Date: Wed, 8 Nov 2023 10:38:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E6=94=B6=E8=B4=A7=E3=80=81?= =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E8=B4=A7=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E3=80=81=E5=8F=8D=E5=AE=A1=E6=A0=B8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/Inputs/PurchaseAndSaleAuditUpInput.cs | 25 ++++++ .../Constraints/IPurchaseAndSaleAuitEntity.cs | 16 ++++ .../Entity/WmsPurchaseH.cs | 3 +- .../Entity/WmsSaleH.cs | 3 +- .../Enums/EnumAuditType.cs | 14 ++++ .../Tnb.WarehouseMgr/WmsOutStockService.cs | 13 +++- .../WmsPurchaseAndSaleCommonService.cs | 78 ++++++++----------- .../Tnb.WarehouseMgr/WmsPurchaseService.cs | 19 ++++- .../Tnb.WarehouseMgr/WmsSaleService.cs | 47 +++++++++-- 9 files changed, 161 insertions(+), 57 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/PurchaseAndSaleAuditUpInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/Constraints/IPurchaseAndSaleAuitEntity.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/EnumAuditType.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/PurchaseAndSaleAuditUpInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/PurchaseAndSaleAuditUpInput.cs new file mode 100644 index 00000000..34944d0c --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/PurchaseAndSaleAuditUpInput.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tnb.WarehouseMgr.Entities.Enums; + +namespace Tnb.WarehouseMgr.Entities.Dto.Inputs +{ + /// + /// 采购收货,销售发货,审核、审核反审核 输入参数 + /// + public class PurchaseAndSaleAuditUpInput + { + /// + /// 要更新的id集合列表 + /// + public List ids { get; set; } + /// + /// 1、审核 2、反审核 + /// + public EnumAuditType auditType { get; set; } + + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/Constraints/IPurchaseAndSaleAuitEntity.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/Constraints/IPurchaseAndSaleAuitEntity.cs new file mode 100644 index 00000000..0e1d9728 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/Constraints/IPurchaseAndSaleAuitEntity.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Entity.Constraints +{ + public interface IPurchaseAndSaleAuitEntity + { + /// + /// 审核状态 + /// + public int? audit_status { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseH.cs index 78b24706..fd0c9f7f 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseH.cs @@ -1,6 +1,7 @@ using JNPF.Common.Contracts; using JNPF.Common.Security; using SqlSugar; +using Tnb.WarehouseMgr.Entities.Entity.Constraints; namespace Tnb.WarehouseMgr.Entities; @@ -8,7 +9,7 @@ namespace Tnb.WarehouseMgr.Entities; /// 采购收货主表 /// [SugarTable("wms_purchase_h")] -public partial class WmsPurchaseH : BaseEntity +public partial class WmsPurchaseH : BaseEntity, IPurchaseAndSaleAuitEntity { public WmsPurchaseH() { diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs index 269fb93c..24e35d0b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs @@ -1,6 +1,7 @@ using JNPF.Common.Contracts; using JNPF.Common.Security; using SqlSugar; +using Tnb.WarehouseMgr.Entities.Entity.Constraints; namespace Tnb.WarehouseMgr.Entities; @@ -8,7 +9,7 @@ namespace Tnb.WarehouseMgr.Entities; /// 销售发货主表 /// [SugarTable("wms_sale_h")] -public partial class WmsSaleH : BaseEntity +public partial class WmsSaleH : BaseEntity, IPurchaseAndSaleAuitEntity { public WmsSaleH() { diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/EnumAuditType.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/EnumAuditType.cs new file mode 100644 index 00000000..90aeb6b5 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/EnumAuditType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Enums +{ + public enum EnumAuditType + { + 审核 = 1, + 反审核 = 2, + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs index 355db6b3..95856a78 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs @@ -131,10 +131,19 @@ namespace Tnb.WarehouseMgr List carryIds = new(); + var mapKeys = new List { "tablefield120", "details" }; //tablefield120 出库物料明细 - if (input.data.ContainsKey("tablefield120") && input.data["tablefield120"].IsNotEmptyOrNull()) + if (input.data.Keys.Where(k => mapKeys.Contains(k)).Any()) //input.data.ContainsKey("tablefield120") && input.data["tablefield120"].IsNotEmptyOrNull() { - List outStockDList = input.data["tablefield120"].ToObject>(); + List outStockDList = new(); + if (input.data.ContainsKey("tablefield120") && input.data["tablefield120"].IsNotEmptyOrNull()) + { + outStockDList = input.data["tablefield120"].ToObject>(); + } + else + { + outStockDList = input.data["details"].ToObject>(); + } if (outStockDList?.Count > 0) { List carryMats = new(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseAndSaleCommonService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseAndSaleCommonService.cs index a0288bf5..7e6db845 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseAndSaleCommonService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseAndSaleCommonService.cs @@ -13,6 +13,7 @@ using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Entity.Constraints; using Tnb.WarehouseMgr.Interfaces; @@ -21,71 +22,53 @@ namespace Tnb.WarehouseMgr /// /// 采购收货、销售发货,通用业务类 /// - /// - public class WmsPurchaseAndSaleCommonService : BaseWareHouseService where TEntity : BaseEntity, IPurchaseAndSaleEntity, IPurchaseAndSaleQueryEntity + /// + public class WmsPurchaseAndSaleCommonService : BaseWareHouseService where TSubEntity : BaseEntity, IPurchaseAndSaleEntity, IPurchaseAndSaleQueryEntity { private readonly ISqlSugarClient _db; private readonly IUserManager _userManager; - private readonly IWmsPDAScanInStockService _wmsPDAScanInStockService; - private readonly IWmsOutStockService _wmsOutStockService; private static Dictionary s_materialMap = new(); - public WmsPurchaseAndSaleCommonService(ISqlSugarRepository repo, IUserManager userManager, IWmsOutStockService? wmsOutStockService = null) + public WmsPurchaseAndSaleCommonService(ISqlSugarRepository repo, IUserManager userManager) { _db = repo.AsSugarClient(); _userManager = userManager; - _wmsOutStockService = wmsOutStockService!; } - protected async Task PurchaseAndSaleUpdate(PurchaseAndReceiveUpInput input) + protected async Task> PurchaseAndSaleUpdate(PurchaseAndReceiveUpInput input) { if (input == null) throw new ArgumentNullException("input"); if (input.details == null) throw new ArgumentNullException(nameof(input.details)); - - var dicMaterialPurchaseArriveQty = input.details.ToDictionary(x => x.material_id, x => x.purchase_arriveqty); var materialIds = input.details.Select(x => x.material_id).ToList(); - var purchaseDs = await _db.Queryable().Where(it => materialIds.Contains(it.material_id)).ToListAsync(); + var purchaseDs = await _db.Queryable().Where(it => materialIds.Contains(it.material_id)).ToListAsync(); if (purchaseDs?.Count > 0) { var errMaterialTipList = new List<(string materialName, decimal purchaseArriveQty, decimal topPurchaseQty)>(); + foreach (var pd in purchaseDs) { - pd.purchase_prqty += dicMaterialPurchaseArriveQty.ContainsKey(pd.material_id) ? dicMaterialPurchaseArriveQty[pd.material_id] : 0; var pdInput = input.details.Find(x => x.material_id == pd.material_id); if (pdInput != null) { + pd.purchase_prqty += pdInput.purchase_arriveqty; + var topPurchaseQty = pd.purchase_qty - pd.purchase_prqty; - if (pdInput.purchase_arriveqty > topPurchaseQty) + if (pdInput.purchase_arriveqty > topPurchaseQty && s_materialMap.ContainsKey(pdInput.material_id) && s_materialMap[pdInput.material_id] != null) { - if (s_materialMap.ContainsKey(pdInput.material_id) && s_materialMap[pdInput.material_id] != null) - { - errMaterialTipList.Add((s_materialMap[pdInput.material_id].ToString()!, pdInput.purchase_arriveqty, topPurchaseQty)); - continue; - } + errMaterialTipList.Add((s_materialMap[pdInput.material_id].ToString()!, pdInput.purchase_arriveqty, topPurchaseQty)); + continue; } } - if (pd.purchase_prqty >= pd.purchase_qty) - { - pd.line_status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID; - } - else - { - pd.line_status = WmsWareHouseConst.BILLSTATUS_ON_ID; - } + + pd.line_status = pd.purchase_prqty >= pd.purchase_qty ? WmsWareHouseConst.BILLSTATUS_COMPLETE_ID : WmsWareHouseConst.BILLSTATUS_ON_ID; } + if (errMaterialTipList.Count > 0) { - var errMsgList = new List(); - if (typeof(TEntity) == typeof(WmsPurchaseD)) - { - errMsgList = errMaterialTipList.Select(x => $"物料:{x.materialName},实际收货数:{x.purchaseArriveQty}已超出可收货数:{x.topPurchaseQty}").ToList(); - } - else - { - errMsgList = errMaterialTipList.Select(x => $"物料:{x.materialName},实际发货数:{x.purchaseArriveQty}已超出可发货数:{x.topPurchaseQty}").ToList(); - } + var itemType = typeof(TSubEntity) == typeof(WmsPurchaseD) ? "收货数" : "发货数"; + var errMsgList = errMaterialTipList.Select(x => $"物料:{x.materialName},实际{itemType}:{x.purchaseArriveQty}已超出可{itemType}:{x.topPurchaseQty}").ToList(); var errMsg = string.Join("\r\n", errMsgList); throw new AppFriendlyException(errMsg, 500); } @@ -95,40 +78,45 @@ namespace Tnb.WarehouseMgr x.modify_id = _userManager.UserId; x.modify_time = DateTime.Now; }); + await _db.Updateable(purchaseDs).ExecuteCommandAsync(); + if (purchaseDs.All(x => x.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)) { - var purchase = await _db.Queryable().FirstAsync(it => it.bill_code == input.bill_code); + var purchase = await _db.Queryable().FirstAsync(it => it.id == purchaseDs.First().bill_id); + if (purchase != null) { purchase.status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID; purchase.modify_id = _userManager.UserId; purchase.modify_time = DateTime.Now; + await _db.Updateable(purchase).UpdateColumns(it => it.status).ExecuteCommandAsync(); } } } - VisualDevModelDataCrInput visualDevModelDataInput = new(); - visualDevModelDataInput.data = PocoToDictionary.ToDictionary(input) as Dictionary; - if (_wmsOutStockService != null) - { - await _wmsOutStockService.OutStockApplyFor(visualDevModelDataInput); - } - - return await Task.FromResult(true); + + return await Task.FromResult(purchaseDs); } - protected async Task> GetDetailsByPkId(string pkId) + + protected async Task> GetDetailsByPkId(string pkId) { if (s_materialMap.Count == 0) { s_materialMap = await _db.Queryable().ToDictionaryAsync(x => x.id, x => x.name); } - var list = await _db.Queryable().Where(it => it.bill_id == pkId) + var list = await _db.Queryable().Where(it => it.bill_id == pkId) .Mapper(it => it.material_name = s_materialMap.ContainsKey(it.material_id) ? s_materialMap[it.material_id]?.ToString() ?? "" : "") .ToListAsync(); return list; } + + protected async Task Audit(PurchaseAndSaleAuditUpInput input) where TEntity : BaseEntity, IPurchaseAndSaleAuitEntity, new() + { + return await _db.Updateable().SetColumns(it => it.audit_status == (int)input.auditType).Where(it => input.ids.Contains(it.id)).ExecuteCommandHasChangeAsync(); + } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs index 293ffdb2..a340f849 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs @@ -63,8 +63,8 @@ namespace Tnb.WarehouseMgr { await _db.Ado.BeginTranAsync(); - blFlag = await PurchaseAndSaleUpdate(input); - if (blFlag) + var purchaseDs = await PurchaseAndSaleUpdate(input); + if (purchaseDs?.Count > 0) { var instock = input.Adapt(); instock.id = SnowflakeIdHelper.NextId(); @@ -73,7 +73,7 @@ namespace Tnb.WarehouseMgr instock.org_id = _userManager.User.OrganizeId; await _db.Insertable(instock).ExecuteCommandAsync(); - var instockD = input.details.Adapt(); + var instockD = purchaseDs.Adapt(); instockD.create_id = _userManager.UserId; instockD.create_time = DateTime.Now; instockD.org_id = _userManager.User.OrganizeId; @@ -101,5 +101,18 @@ namespace Tnb.WarehouseMgr { return await GetDetailsByPkId(id); } + + /// + /// 审核反审核 + /// + /// + /// + /// + /// + [HttpPost] + public async Task Audit(PurchaseAndSaleAuditUpInput input) + { + return await Audit(input); + } } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleService.cs index 4c59a752..47b614c5 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleService.cs @@ -4,10 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; +using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr @@ -17,23 +21,56 @@ namespace Tnb.WarehouseMgr /// public class WmsSaleService : WmsPurchaseAndSaleCommonService { + private readonly IWmsOutStockService _wmsOutStockService; + public WmsSaleService(ISqlSugarRepository repo, IUserManager userManager, IWmsOutStockService wmsOutStockService) - : base(repo, userManager, wmsOutStockService: wmsOutStockService) + : base(repo, userManager) { - + _wmsOutStockService = wmsOutStockService; } - + /// + /// 销售发货 + /// + /// + /// + /// + /// [HttpPost] public async Task Sale(PurchaseAndReceiveUpInput input) { - return await PurchaseAndSaleUpdate(input); + _ = await PurchaseAndSaleUpdate(input); + VisualDevModelDataCrInput visualDevModelDataInput = new(); + visualDevModelDataInput.data = PocoToDictionary.ToDictionary(input) as Dictionary; + visualDevModelDataInput.data["location_id"] = "26412597341221"; + visualDevModelDataInput.data["location_code"] = "YCL01-01-01"; + if (_wmsOutStockService != null) + { + await _wmsOutStockService.OutStockApplyFor(visualDevModelDataInput); + } + return await Task.FromResult(1); } - + /// + /// 根据销售发货主表Id获取子表明细 + /// + /// + /// [HttpGet("id")] public async Task GetSaleDetailsByBillId(string id) { return await GetDetailsByPkId(id); } + /// + /// 审核反审核 + /// + /// + /// + /// + /// + [HttpPost] + public async Task Audit(PurchaseAndSaleAuditUpInput input) + { + return await Audit(input); + } } }