From 793524a06f95118cd043f59d765dfef4e0b7e72c Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Tue, 7 Nov 2023 11:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E7=AD=BE=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/PrdManage/NewMaterialReceiptInput.cs | 37 +++++ .../Entity/PrdMaterialReceiptD.cs | 2 +- .../PrdMaterialReceiptService.cs | 127 +++++++++++++++++- .../Tnb.ProductionMgr/PrdMoService.cs | 6 +- 4 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/NewMaterialReceiptInput.cs diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/NewMaterialReceiptInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/NewMaterialReceiptInput.cs new file mode 100644 index 00000000..62dde488 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/NewMaterialReceiptInput.cs @@ -0,0 +1,37 @@ +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class NewMaterialReceiptInput + { + + /// + /// 工位id + /// + public string station_id { get; set; } = string.Empty; + + /// + /// 载具编号 + /// + public string? carry_code { get; set; } + + public List? details { get; set; } = new List(); + + /// + /// 存在不属于该任务单的原材料也要签收 + /// + public bool sure { get; set; } = false; + } + + public class NewMaterialReceiptDInput + { + public string material_id{get;set;} + public decimal num {get;set;} + public string batch {get;set;} + public string unit_id {get;set;} + public string barcode {get;set;} + public string member_carry_id {get;set;} + public string member_carry_code {get;set;} + public string supplier_id {get;set;} + public DateTime? instock_time {get;set;} + public string check_conclusion {get;set;} + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs index 27cadcf2..a693a3fd 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs @@ -77,7 +77,7 @@ public partial class PrdMaterialReceiptD : BaseEntity /// /// 入库时间 /// - public DateTime instock_time { get; set; } + public DateTime? instock_time { get; set; } /// /// 检验结论 /// diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs index 5cb24f52..a001b296 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs @@ -34,12 +34,13 @@ namespace Tnb.ProductionMgr private readonly IUserManager _userManager; private readonly IOrganizeService _organizeService; private readonly IBillRullService _billRullService; - + private readonly IPrdMoTaskService _prdMoTaskService; public PrdMaterialReceiptService( ISqlSugarRepository repository, IBillRullService billRullService, IOrganizeService organizeService, + IPrdMoTaskService prdMoTaskService, IUserManager userManager ) { @@ -47,6 +48,7 @@ namespace Tnb.ProductionMgr _userManager = userManager; _organizeService = organizeService; _billRullService = billRullService; + _prdMoTaskService = prdMoTaskService; } @@ -170,9 +172,9 @@ namespace Tnb.ProductionMgr { foreach (Dictionary item in input.details) { - if (!inputMaterials.Contains(item["material_id"]) && !input.sure) + if (!inputMaterials.Contains(item["material_id"])) { - throw new Exception("存在不属于生产bom的投入物料,确认签收吗"); + throw new Exception("该物料不是生产bom投入物料,不能签收"); } list.Add(new PrdMaterialReceiptD @@ -206,6 +208,125 @@ namespace Tnb.ProductionMgr }); + if (result.IsSuccess) + { + //签收后调用载具签收接口 + // await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput() + // { + // org_id = _userManager.GetUserInfo().Result.organizeId, + // create_id = _userManager.UserId, + // carry_code = input.carry_code ?? "", + // }); + + MESCarrySignInput mesCarrySignInput = new() + { + org_id = _userManager.GetUserInfo().Result.organizeId, + create_id = _userManager.UserId, + carry_code = input.carry_code ?? "", + }; + + string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host; + Dictionary header = new() + { + ["Authorization"] = App.HttpContext.Request.Headers["Authorization"] + }; + string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CARRY_SIGN, JsonConvert.SerializeObject(mesCarrySignInput), header); + Log.Information(sendResult); + AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); + result2 = authResponse.code != 200 + ? throw Oops.Bah(authResponse.msg) + : await db.Ado.UseTranAsync(async () => + { + _ = await db.Insertable(prdMaterialReceiptH).ExecuteCommandAsync(); + _ = await db.Insertable(list).ExecuteCommandAsync(); + }); + } + return !result.IsSuccess + ? throw Oops.Bah(result.ErrorMessage) + : !result2.IsSuccess ? throw Oops.Bah(result2.ErrorMessage) : (dynamic)"签收成功"; + } + + [HttpPost] + public async Task SaveDataNew(NewMaterialReceiptInput input) + { + ISqlSugarClient db = _repository.AsSugarClient(); + PrdMoTask moTask = await _prdMoTaskService.GetPrdMoTaskInfoByStationId(new Dictionary(){ + {"station_id",input.station_id} + }); + DbResult result2 = new(); + PrdMaterialReceiptH? prdMaterialReceiptH = null; + List list = new(); + DbResult result = await db.Ado.UseTranAsync(async () => + { + List inputMaterials = await db.Queryable() + .Where(x => x.mbom_id == moTask.bom_id) + .WhereIF(!string.IsNullOrEmpty(moTask.mbom_process_id), x => x.mbom_process_id == moTask.mbom_process_id) + .Select(x => x.material_id) + .ToListAsync(); + + string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.MATERIAL_RECEIPT_CODE); + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorklineCode); + OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorkshopCode); + WmsCarryH carry = await db.Queryable().Where(x=>x.carry_code==input.carry_code).FirstAsync(); + + + prdMaterialReceiptH = new PrdMaterialReceiptH() + { + code = code, + station_id = input.station_id, + mo_task_id = moTask.id, + process_id = moTask.process_id, + equip_id = moTask.eqp_id, + workshop_id = workshop?.Id ?? "", + carry_id = carry.id, + workline_id = workline?.Id ?? "", + carry_code = input.carry_code, + mbom_process_id = moTask.mbom_process_id, + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId + }; + + if (input.details != null && input.details.Count > 0) + { + foreach (var item in input.details) + { + if (!inputMaterials.Contains(item.material_id) && !input.sure) + { + throw new Exception("存在不属于生产bom的投入物料,确认签收吗"); + } + + list.Add(new PrdMaterialReceiptD + { + material_receipt_id = prdMaterialReceiptH.id, + material_id = item.material_id, + num = item.num, + batch = item.batch, + unit_id = item.unit_id, + carry_id = carry.id, + barcode = item.barcode, + is_all_feeding = 0, + member_carry_id = item.member_carry_id, + member_carry_code = item.member_carry_code, + feeding_num = 0, + supplier_id = item.supplier_id, + instock_time = item.instock_time, + check_conclusion = item.check_conclusion, + }); + } + } + else + { + throw new Exception("没有签收物料"); + } + + + // await db.Insertable(prdMaterialReceiptH).ExecuteCommandAsync(); + // await db.Insertable(list).ExecuteCommandAsync(); + + }); + + if (result.IsSuccess) { //签收后调用载具签收接口 diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs index bfeceab0..acaad592 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs @@ -735,7 +735,7 @@ namespace Tnb.ProductionMgr batch = a.batch, supplier_name = d.supplier_name, check_conclusion = c.check_conclusion, - instock_time = c.instock_time.ToString(DbTimeFormat.SS), + instock_time = c.instock_time==null ? "" : c.instock_time.Value.ToString(DbTimeFormat.SS), feeding_time = e.create_time == null ? "" : e.create_time.Value.ToString(DbTimeFormat.SS), }).ToListAsync(); @@ -848,8 +848,8 @@ namespace Tnb.ProductionMgr batch = a.batch, supplier_name = d.supplier_name, check_conclusion = c.check_conclusion, - instock_time = c.instock_time.ToString("yyyy-MM-dd HH:mm:ss"), - feeding_time = e.create_time == null ? "" : e.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"), + instock_time = c.instock_time==null ? "" : c.instock_time.Value.ToString(DbTimeFormat.SS), + feeding_time = e.create_time == null ? "" : e.create_time.Value.ToString(DbTimeFormat.SS), }); if (lastPrdReportIds != null && lastPrdReportIds.Count > 0)