From aad4888c14dadaa24d4810e1e9e4333ff7ca0689 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Mon, 6 Nov 2023 10:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E8=88=AC=E5=87=BA=E5=BA=93=E7=94=B3?= =?UTF-8?q?=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Consts/DictConst.cs | 10 ++ .../Dto/PrdManage/GeneralOutstockInput.cs | 29 +++++ .../Entity/PrdOutstockD.cs | 2 +- .../IPrdOutstockService.cs | 8 +- .../Tnb.ProductionMgr/PrdOutstockService.cs | 122 +++++++++++++++++- 5 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GeneralOutstockInput.cs diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index da84b4d4..69611399 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -169,6 +169,16 @@ public static class DictConst /// public const string CHANCHENGPINRUKUDAN = "40"; + /// + /// 生产领料单 + /// + public const string SHENGCHANLINGLIAO = "23"; + + /// + /// 生产补料单 + /// + public const string SHENGCHANBULIAO = "24"; + #endregion diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GeneralOutstockInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GeneralOutstockInput.cs new file mode 100644 index 00000000..79368c6f --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GeneralOutstockInput.cs @@ -0,0 +1,29 @@ +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class GeneralOutstockInput + { + /// + /// 目标库位编号 + /// + public string location_code { get; set; } = string.Empty; + + /// 所属工位 + /// + public string? workstation_id { get; set; } + + /// + /// 任务单 + /// + public string? mo_task_id { get; set; } + + public List details { get; set; } = new List(); + } + + public class GeneralOutstockDInput + { + public string material_id { get; set; } + public string material_code { get; set; } + public string material_name { get; set; } + public decimal num { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutstockD.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutstockD.cs index 960834c6..86c1328a 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutstockD.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutstockD.cs @@ -32,7 +32,7 @@ public partial class PrdOutstockD : BaseEntity /// /// 出库需求数量 /// - public string? pr_qty { get; set; } + public decimal? pr_qty { get; set; } /// /// 来源单据id diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutstockService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutstockService.cs index 3d8bed0f..0a669e72 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutstockService.cs @@ -1,3 +1,5 @@ +using Tnb.ProductionMgr.Entities.Dto; + namespace Tnb.ProductionMgr.Interfaces { /// @@ -5,6 +7,10 @@ namespace Tnb.ProductionMgr.Interfaces /// public interface IPrdOutstockService { - + /// + /// 一般出库申请 + /// + /// + public Task GeneralOutstock(GeneralOutstockInput input); } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs index fef2d924..da415616 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs @@ -7,6 +7,9 @@ using JNPF.Extras.CollectiveOAuth.Models; using JNPF.Extras.CollectiveOAuth.Utils; using JNPF.FriendlyException; using JNPF.Logging; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Entitys.System; +using JNPF.Systems.Interfaces.Permission; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; @@ -14,10 +17,12 @@ using JNPF.VisualDev.Interfaces; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Spire.Pdf.Exporting.XPS.Schema; using SqlSugar; using Tnb.BasicData; using Tnb.BasicData.Entities; using Tnb.ProductionMgr.Entities; +using Tnb.ProductionMgr.Entities.Dto; using Tnb.ProductionMgr.Interfaces; using Tnb.WarehouseMgr.Entities.Dto.Inputs; @@ -37,10 +42,11 @@ namespace Tnb.ProductionMgr private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; private readonly IDictionaryDataService _dictionaryDataService; + private readonly IOrganizeService _organizeService; private readonly IUserManager _userManager; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); - public PrdOutstockService(ISqlSugarRepository repository, IRunService runService, IUserManager userManager,IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService) + public PrdOutstockService(ISqlSugarRepository repository, IOrganizeService organizeService,IRunService runService, IUserManager userManager,IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService) { _db = repository.AsSugarClient(); _runService = runService; @@ -48,6 +54,7 @@ namespace Tnb.ProductionMgr _dictionaryDataService = dictionaryDataService; _repository = repository; _userManager = userManager; + _organizeService = organizeService; OverideFuncs.CreateAsync = Create; } @@ -114,5 +121,118 @@ namespace Tnb.ProductionMgr } } + + public async Task GeneralOutstock(GeneralOutstockInput generalOutstockInput) + { + try + { + var db = _repository.AsSugarClient(); + string warehouse_id = "26103348825381";//二楼缓存仓 + + MESCreateOutstockInput input = new MESCreateOutstockInput(); + input.outstock = new MESWmsOutstockHInput(); + input.outstockDs = new List(); + + PrdMoTask prdMoTask = await db.Queryable().SingleAsync(x=>x.id==generalOutstockInput.mo_task_id); + BasLocation location = await db.Queryable().Where(x=>x.location_code==generalOutstockInput.location_code).FirstAsync(); + if (location == null) throw Oops.Bah("未找到库位"); + string locationId = location.id; + + input.outstock.bill_type = DictConst.SHENGCHANLINGLIAO; + // input.outstock.bill_date = visualDevModelDataCrInput.data.ContainsKey("bill_date") ? Convert.ToDateTime(visualDevModelDataCrInput.data["bill_date"].ToString()) : DateTime.Now; + input.outstock.bill_date = DateTime.Now; + input.outstock.org_id = _userManager.GetUserInfo().Result.organizeId; + input.outstock.warehouse_id = warehouse_id; + input.outstock.create_id = _userManager.UserId; + input.outstock.location_code = location?.location_code ?? ""; + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(generalOutstockInput.workstation_id, DictConst.RegionCategoryWorklineCode); + + List materialIds = generalOutstockInput.details.Select(x => x.material_id).ToList(); + Dictionary unitIdDic = await db.Queryable() + .LeftJoin((a, b) => b.EnCode == DictConst.MeasurementUnit) + .LeftJoin((a, b, c) => b.Id == c.DictionaryTypeId && a.unit_id == c.EnCode) + .Where((a,b,c)=>materialIds.Contains(a.id)) + .Select((a, b, c) => new + { + key = a.id, + value = c.Id + }) + .ToDictionaryAsync(x => x.key, x => x.value); + + foreach (var item in generalOutstockInput.details) + { + input.outstockDs.Add(new MESWmsOutstockDInput() + { + material_id = item.material_id, + material_code = item.material_code, + pr_qty = item.num, + unit_id = unitIdDic[item.material_id].ToString() + }); + } + + string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host; + Dictionary header = new Dictionary() + { + ["Authorization"] = App.HttpContext.Request.Headers["Authorization"] + }; + var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK,JsonConvert.SerializeObject(input),header); + Log.Information(sendResult); + + AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); + if (authResponse.code != 200) + { + throw Oops.Bah(authResponse.msg); + } + else + { + PrdOutstockH prdOutstockH = new PrdOutstockH(); + prdOutstockH.bill_type = DictConst.SHENGCHANLINGLIAO; + prdOutstockH.warehouse_id = warehouse_id; + prdOutstockH.location_code = generalOutstockInput.location_code; + prdOutstockH.create_id = _userManager.UserId; + prdOutstockH.org_id = _userManager.GetUserInfo().Result.organizeId; + prdOutstockH.bill_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + prdOutstockH.workstation = generalOutstockInput.workstation_id; + prdOutstockH.workline = workline?.Id ?? ""; + + List prdOutstockDs = new List(); + foreach (var item in generalOutstockInput.details) + { + prdOutstockDs.Add(new PrdOutstockD() + { + material_id = item.material_id, + material_code = item.material_code, + material_name = item.material_name, + pr_qty = item.num, + unit_id = unitIdDic[item.material_id].ToString(), + outstock_id = prdOutstockH.id, + source_id = prdMoTask.mo_task_code + }); + } + + DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => + { + await _repository.InsertAsync(prdOutstockH); + if (prdOutstockDs.Count > 0) + { + await db.Insertable(prdOutstockDs).ExecuteCommandAsync(); + } + }); + + if (!result.IsSuccess) + { + throw Oops.Bah(result.ErrorMessage); + } + + } + return await Task.FromResult(true); + } + catch (Exception e) + { + Console.WriteLine(e); + Log.Error(e.Message); + throw Oops.Bah(e.Message); + } + } } } \ No newline at end of file