From 0203cec1ca17408a978ecdc70d4f218d1a7d962b Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Fri, 14 Jul 2023 14:32:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E7=AD=BE=E6=94=B6=E6=96=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/PrdManage/MaterialReceiptNewInput.cs | 27 ++++ .../IPrdFeedingService.cs | 7 + .../Tnb.ProductionMgr/PrdFeedingService.cs | 132 ++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptNewInput.cs diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptNewInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptNewInput.cs new file mode 100644 index 00000000..452fc14a --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptNewInput.cs @@ -0,0 +1,27 @@ +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class MaterialReceiptNewInput + { + /// + /// 工位id + /// + public string station_id { get; set; } = string.Empty; + + /// + /// 任务单id + /// + public string? mo_task_id { get; set; } + + /// + /// 设备id + /// + public string? equip_id { get; set; } + + /// + /// 二维码信息 + /// + public string? carry_code { get; set; } + + public List>? details { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdFeedingService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdFeedingService.cs index 0cbfd649..c719944a 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdFeedingService.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdFeedingService.cs @@ -14,5 +14,12 @@ namespace Tnb.ProductionMgr.Interfaces /// /// public Task SaveData(MaterialReceiptInput input); + + /// + /// 保存数据 + /// + /// + /// + public Task SaveDataNew(MaterialReceiptNewInput input); } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs index e45e0109..9e5a8039 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs @@ -4,6 +4,7 @@ using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; +using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Interfaces.System; using Microsoft.AspNetCore.Mvc; using Microsoft.ClearScript.Util.Web; @@ -13,6 +14,8 @@ using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities.Dto; using Tnb.ProductionMgr.Interfaces; using Tnb.ProductionMgr.Entities.Consts; +using Tnb.WarehouseMgr; +using Tnb.WarehouseMgr.Entities; namespace Tnb.ProductionMgr { @@ -26,16 +29,20 @@ namespace Tnb.ProductionMgr private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; private readonly IBillRullService _billRullService; + private readonly WmsSignForDeliveryService _wmsSignForDeliveryService; + public PrdFeedingService( ISqlSugarRepository repository, IBillRullService billRullService, + WmsSignForDeliveryService wmsSignForDeliveryService, IUserManager userManager ) { _repository = repository; _userManager = userManager; + _wmsSignForDeliveryService = _wmsSignForDeliveryService; _billRullService = billRullService; } @@ -132,6 +139,131 @@ namespace Tnb.ProductionMgr await db.Insertable(list).ExecuteCommandAsync(); }); + + if (result.IsSuccess) + { + //签收后调用载具签收接口 + await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput() + { + org_id = _userManager.GetUserInfo().Result.organizeId, + create_id = _userManager.UserId, + carry_code = input.carry_code ?? "", + }); + } + + if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage); + return result.IsSuccess ? "签收成功" : result.ErrorMessage; + } + + [HttpPost] + public async Task SaveDataNew(MaterialReceiptNewInput input) + { + var db = _repository.AsSugarClient(); + DbResult result = await db.Ado.UseTranAsync(async () => + { + var moTask = await db.Queryable().FirstAsync(x => x.id == input.mo_task_id); + var parentMoTask = await db.Queryable().FirstAsync(x => x.id == moTask.parent_id); + var carry = await db.Queryable().SingleAsync(x => x.carry_code == input.carry_code); + var workline = await db.Queryable().SingleAsync(x => x.Id == parentMoTask.workline_id); + var workshop = await db.Queryable().SingleAsync(x=>x.Id==workline.ParentId); + var inputMaterials = await db.Queryable() + .Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == moTask.mbom_process_id) + .Select(x=>x.material_id) + .ToListAsync(); + + + + string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.FEEDING_CODE); + PrdFeedingH prdFeedingH = new PrdFeedingH() + { + code = code, + station_id = input.station_id, + mo_task_id = input.mo_task_id, + process_id = moTask.process_id, + equip_id = input.equip_id, + workshop_id = workshop?.Id, + carry_id = carry.id, + workline_id = moTask.workline_id, + carry_code = input.carry_code, + // remark = input.remark, + mbom_process_id = moTask.mbom_process_id, + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId + }; + + List list = new List(); + if (input.details != null && input.details.Count > 0) + { + foreach (var item in input.details) + { + if(!inputMaterials.Contains(item["material_id"])) + throw new Exception("该物料不是生产bom投入物料,不能签收"); + + var detail = await db.Queryable() + .Where(x => x.carry_id == carry.id && x.is_all_feeding == 0).FirstAsync(); + decimal num = Convert.ToDecimal(item["num"]); + list.Add(new PrdFeedingD + { + feeding_id = prdFeedingH.id, + material_receipt_detail_id = detail?.id, + material_id = item["material_id"], + num = num, + batch = item["batch"], + unit_id = item["unit_id"], + carry_id = carry.id, + status = "0", + use_num = 0, + }); + + if (detail != null) + { + if(detail.feeding_num + num > detail.num) + { + throw new Exception("投料数量不能大于签收数量"); + }else if (detail.feeding_num + num == detail.num) + { + await db.Updateable() + .SetColumns(x => x.feeding_num == x.feeding_num + num) + .SetColumns(x => x.is_all_feeding == 1) + .Where(x => x.id == detail.id) + .ExecuteCommandAsync(); + } + else + { + await db.Updateable() + .SetColumns(x => x.feeding_num == x.feeding_num + num) + .Where(x => x.id == detail.id) + .ExecuteCommandAsync(); + } + } + else + { + throw new Exception("没有签收单,无法投料"); + } + } + } + else + { + throw new Exception("没有签收物料"); + } + + + await db.Insertable(prdFeedingH).ExecuteCommandAsync(); + await db.Insertable(list).ExecuteCommandAsync(); + + }); + + if (result.IsSuccess) + { + //签收后调用载具签收接口 + await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput() + { + org_id = _userManager.GetUserInfo().Result.organizeId, + create_id = _userManager.UserId, + carry_code = input.carry_code ?? "", + }); + } if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage); return result.IsSuccess ? "签收成功" : result.ErrorMessage;