From a055ac33ef6810f5f1ab94656121e06a20af17c0 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Mon, 6 Nov 2023 15:30:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=B7=A5=E4=BD=8Did=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E8=BF=9B=E8=A1=8C=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=8D=95=20=E7=94=9F=E4=BA=A7=E6=8A=95?= =?UTF-8?q?=E6=96=99=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IPrdMoTaskService.cs | 9 +- .../Tnb.ProductionMgr/PrdFeedingService.cs | 126 ++++++++++++++++++ .../Tnb.ProductionMgr/PrdMoTaskService.cs | 21 ++- 3 files changed, 154 insertions(+), 2 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs index 29f0b0aa..ba1668ad 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs @@ -25,6 +25,13 @@ namespace Tnb.ProductionMgr.Interfaces /// /// Task GetMaterialPreparationPlan(); - + + /// + /// 根据工位获取进行中的任务单信息 + /// + /// + /// + Task GetPrdMoTaskInfoByStationId(Dictionary dic); + } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs index 183953d8..61872a53 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs @@ -36,6 +36,7 @@ namespace Tnb.ProductionMgr { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; + private readonly IPrdMoTaskService _prdMoTaskService; private readonly IBillRullService _billRullService; // private readonly WmsSignForDeliveryService _wmsSignForDeliveryService; @@ -44,12 +45,14 @@ namespace Tnb.ProductionMgr public PrdFeedingService( ISqlSugarRepository repository, IBillRullService billRullService, + IPrdMoTaskService prdMoTaskService, // WmsSignForDeliveryService wmsSignForDeliveryService, IUserManager userManager ) { _repository = repository; _userManager = userManager; + _prdMoTaskService = prdMoTaskService; // _wmsSignForDeliveryService = _wmsSignForDeliveryService; _billRullService = billRullService; } @@ -331,6 +334,129 @@ namespace Tnb.ProductionMgr if(!result.IsSuccess) throw Oops.Bah(result.ErrorMessage); return result.IsSuccess ? "签收成功" : result.ErrorMessage; } + + + /// + /// 生产投料 + /// + /// + /// + /// + /// + [HttpPost] + public async Task Feeding(MaterialReceiptNewInput input) + { + var db = _repository.AsSugarClient(); + var moTask = await _prdMoTaskService.GetPrdMoTaskInfoByStationId(new Dictionary() + { + {"station_id",input.station_id} + }); + + if (moTask == null) throw Oops.Bah("找不到任务单"); + PrdFeedingH prdFeedingH = null; + List list = new List(); + DbResult result2 = new DbResult(); + DbResult result = await db.Ado.UseTranAsync(async () => + { + var parentMoTask = await db.Queryable().FirstAsync(x => x.id == moTask.parent_id); + string worklineId = moTask.workline_id; + if (parentMoTask != null && !string.IsNullOrEmpty(parentMoTask.workline_id)) + { + worklineId = parentMoTask.workline_id; + } + var carry = await db.Queryable().SingleAsync(x => x.carry_code == input.carry_code); + var workline = await db.Queryable().SingleAsync(x => x.Id == worklineId); + 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 = new PrdFeedingH() + { + code = code, + station_id = input.station_id, + mo_task_id = moTask.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 + }; + + 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.member_carry_code == input.carry_code && 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) throw Oops.Bah(result.ErrorMessage); + return result.IsSuccess ? "签收成功" : result.ErrorMessage; + } [HttpPost] public async Task GetFeedingRecordTree() diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 7f2dea96..0a34213d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -1447,6 +1447,7 @@ namespace Tnb.ProductionMgr var row = -1; var report = await db.Queryable().FirstAsync(it => it.mo_task_id == input.mo_task_id); var prdMoTask = await db.Queryable().SingleAsync(x => x.id == input.mo_task_id); + var equip = await db.Queryable().SingleAsync(x=>x.id==prdMoTask.eqp_id); var prdMo = await db.Queryable().SingleAsync(x => x.id == prdMoTask.mo_id); var mbomProcess = await db.Queryable().SingleAsync(x => x.id == prdMoTask.mbom_process_id); @@ -1724,6 +1725,11 @@ namespace Tnb.ProductionMgr // } // } + if (equip.tube == "1") + { + + } + }); if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage); @@ -2627,6 +2633,7 @@ namespace Tnb.ProductionMgr rate_num = SqlFunc.Subqueryable().Where(o => o.id == a.bom_id) .OrderByDesc(o => o.create_time).Select(o => o.num), parent_id = b.parent_id, + workstation_id = b.workstation_id, material_id = b.material_id, material_code = c.code, children = SqlFunc.Subqueryable() @@ -2643,7 +2650,7 @@ namespace Tnb.ProductionMgr var prdMoTaskList = await _db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) - .Where(a => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id) && a.estimated_start_date.Value.ToString("yyyy-MM-dd") == now) + .Where(a => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id) && a.estimated_start_date.Value.ToString("yyyy-MM-dd") == now && (a.mo_task_status==DictConst.MoStatusPauseCode || a.mo_task_status==DictConst.ToBeScheduledEncode || a.mo_task_status==DictConst.ToBeStartedEnCode || a.mo_task_status==DictConst.InProgressEnCode)) .Select((a,b)=>new MaterialPreparationPlanOutput() { mo_task_id = a.id, @@ -2672,6 +2679,18 @@ namespace Tnb.ProductionMgr return prdMoTaskList; } + /// + /// 根据工位获取进行中的任务单信息 + /// + /// + /// + public async Task GetPrdMoTaskInfoByStationId(Dictionary dic) + { + string station_id = dic.ContainsKey("station_id") ? dic["station_id"] : ""; + if (string.IsNullOrEmpty(station_id)) throw Oops.Bah("工位错误"); + + return await _db.Queryable().Where(x => x.workstation_id == station_id && x.parent_id!=null && x.mo_task_status==DictConst.InProgressEnCode).FirstAsync(); + } }