From f527a02d75103d09d0d2003945717f57fa7fdd70 Mon Sep 17 00:00:00 2001 From: FanLian Date: Fri, 16 Jun 2023 11:28:30 +0800 Subject: [PATCH 1/8] 1 --- WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 027be036..ea22ae7b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -74,7 +74,7 @@ namespace Tnb.WarehouseMgr // throw Oops.Oh(errorMessege); //} - //更新 + //更新主载具明细表的子载具ID和编号以及位置 var isOk = await _db.Updateable().SetColumns(it => it.membercarry_id == subCarry.id) .SetColumns(it => it.membercarry_code == subCarry.carry_code) .SetColumns(it => it.loc == input.data[nameof(WmsCarrybindH.loc)].ToString()) From 1a0df13ec4b5ee014eaaeba4f4c19dd7b3b7b8ac Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Fri, 16 Jun 2023 11:42:54 +0800 Subject: [PATCH 2/8] =?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 --- .../IBasMbomService.cs | 9 +- BasicData/Tnb.BasicData/BasMbomService.cs | 14 ++ .../Dto/PrdManage/MaterialReceiptInput.cs | 59 ++++++++ .../Entity/PrdMaterialReceiptD.cs | 42 ++++++ .../Entity/PrdMaterialReceiptH.cs | 92 +++++++++++++ .../IPrdMaterialReceiptService.cs | 19 +++ .../PrdMaterialReceiptService.cs | 129 ++++++++++++++++++ .../Tnb.ProductionMgr.csproj | 1 + 8 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMaterialReceiptService.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs diff --git a/BasicData/Tnb.BasicData.Interfaces/IBasMbomService.cs b/BasicData/Tnb.BasicData.Interfaces/IBasMbomService.cs index 4f85705e..1c048c98 100644 --- a/BasicData/Tnb.BasicData.Interfaces/IBasMbomService.cs +++ b/BasicData/Tnb.BasicData.Interfaces/IBasMbomService.cs @@ -5,10 +5,17 @@ namespace Tnb.BasicData.Interfaces public interface IBasMbomService { /// - /// idȡӦб + /// 根据物料id获取对应的子任务列表 /// /// bomid /// Task GetSubMoListByBomId([FromRoute] string bomId); + + /// + /// 根据生产bom工序id获取投入物料 + /// + /// id + /// + Task GetInputMaterialByMbomProcessId(Dictionary dic); } } \ No newline at end of file diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs index f92b105c..e16924c5 100644 --- a/BasicData/Tnb.BasicData/BasMbomService.cs +++ b/BasicData/Tnb.BasicData/BasMbomService.cs @@ -181,6 +181,20 @@ namespace Tnb.BasicData return result; } + [HttpPost] + public async Task GetInputMaterialByMbomProcessId(Dictionary dic) + { + string id = dic["id"]; + var result = await _repository.AsSugarClient().Queryable() + .Where(x => x.mbom_process_id == id) + .Select(x => new + { + material_id = x.material_id, + }).ToListAsync(); + return result; + + } + /// /// 根据物料id获取生产bom /// diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs new file mode 100644 index 00000000..5d0e22ad --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs @@ -0,0 +1,59 @@ +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class MaterialReceiptInput + { + public string id { get; set; } + + /// + /// 工位id + /// + public string station_id { get; set; } = string.Empty; + + /// + /// 任务单id + /// + public string? mo_task_id { get; set; } + + /// + /// 工序id + /// + public string? process_id { get; set; } + + /// + /// 设备id + /// + public string? equip_id { get; set; } + + /// + /// 车间id + /// + public string? workshop_id { get; set; } + + /// + /// 载具id + /// + public string? carry_id { get; set; } + + /// + /// 产线id + /// + public string? workline_id { get; set; } + + /// + /// 二维码信息 + /// + public string? carry_code { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 生产bom工序id + /// + public string? mbom_process_id { get; set; } + + public List> details { 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 new file mode 100644 index 00000000..76f17cd4 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs @@ -0,0 +1,42 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities; + +/// +/// 物料签收子表 +/// +[SugarTable("prd_material_receipt_d")] +public partial class PrdMaterialReceiptD : BaseEntity +{ + public PrdMaterialReceiptD() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 物料签收id + /// + public string material_receipt_id { get; set; } = string.Empty; + + /// + /// 物料id + /// + public string material_id { get; set; } = string.Empty; + + /// + /// 数量 + /// + public int num { get; set; } + + /// + /// 批次 + /// + public string? batch { get; set; } + + /// + /// 单位id + /// + public string? unit_id { get; set; } + +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs new file mode 100644 index 00000000..57ae28fe --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs @@ -0,0 +1,92 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities; + +/// +/// 物料签收主表 +/// +[SugarTable("prd_material_receipt_h")] +public partial class PrdMaterialReceiptH : BaseEntity +{ + public PrdMaterialReceiptH() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 工位id + /// + public string station_id { get; set; } = string.Empty; + + /// + /// 任务单id + /// + public string? mo_task_id { get; set; } + + /// + /// 工序id + /// + public string? process_id { get; set; } + + /// + /// 设备id + /// + public string? equip_id { get; set; } + + /// + /// 车间id + /// + public string? workshop_id { get; set; } + + /// + /// 载具id + /// + public string? carry_id { get; set; } + + /// + /// 产线id + /// + public string? workline_id { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 二维码信息 + /// + public string? carry_code { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + + /// + /// 生产bom工序id + /// + public string? mbom_process_id { get; set; } + +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMaterialReceiptService.cs new file mode 100644 index 00000000..3810560c --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMaterialReceiptService.cs @@ -0,0 +1,19 @@ +using Tnb.ProductionMgr.Entities.Dto; + +namespace Tnb.ProductionMgr.Interfaces +{ + /// + /// 物料签收服务接口 + /// + public interface IPrdMaterialReceiptService + { + /// + /// 根据铁片二维码获取信息 + /// + /// + /// + public Task GetInfoByQrCode(string qrCode); + + public Task SaveData(MaterialReceiptInput input); + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs new file mode 100644 index 00000000..f437c660 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs @@ -0,0 +1,129 @@ +using JNPF.Common.Core.Manager; +using JNPF.Common.Enums; +using JNPF.Common.Security; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using Microsoft.AspNetCore.Mvc; +using Microsoft.ClearScript.Util.Web; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.ProductionMgr.Entities; +using Tnb.ProductionMgr.Entities.Dto; +using Tnb.ProductionMgr.Entities.Dto.PrdManage; +using Tnb.ProductionMgr.Interfaces; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Dto; + +namespace Tnb.ProductionMgr +{ + /// + /// 业务实现:物料签收 + /// + [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + public class PrdMaterialReceiptService : IPrdMaterialReceiptService, IDynamicApiController, ITransient + { + private readonly ISqlSugarRepository _repository; + private readonly IUserManager _userManager; + + + public PrdMaterialReceiptService( + ISqlSugarRepository repository, + IUserManager userManager + ) + { + _repository = repository; + _userManager = userManager; + } + + + [HttpPost] + public async Task GetInfoByQrCode(string qrCode) + { + var db = _repository.AsSugarClient(); + var result = await db.Queryable() + .Where((a) => a.carry_code == qrCode) + .Select(a => new + { + carry_id = a.id, + carry_name = a.carry_name, + children = SqlFunc.Subqueryable() + .LeftJoin((b,c)=>b.material_id==c.id) + .Where((b,c)=>a.id==b.carry_id).ToList((b,c)=>new CarryCodeDetailOutput() + { + unit_id = c.unit_id, + barcode = b.barcode, + code_batch = b.code_batch, + codeqty = b.codeqty, + material_id = b.material_id, + material_code = c.code, + material_name = c.name + }) + }).FirstAsync(); + return result; + } + + [HttpPost] + public async Task SaveData(MaterialReceiptInput 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 inputMaterials = await db.Queryable() + .Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == input.mbom_process_id) + .Select(x=>x.material_id) + .ToListAsync(); + + PrdMaterialReceiptH prdMaterialReceiptH = new PrdMaterialReceiptH() + { + station_id = input.station_id, + mo_task_id = input.mo_task_id, + process_id = input.process_id, + equip_id = input.equip_id, + workshop_id = input.workshop_id, + carry_id = input.carry_id, + workline_id = input.workline_id, + carry_code = input.carry_code, + remark = input.remark, + mbom_process_id = input.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投入物料,不能签收"); + + list.Add(new PrdMaterialReceiptD + { + material_receipt_id = prdMaterialReceiptH.id, + material_id = item["material_id"], + num = Convert.ToInt32(item["num"]), + batch = item["batch"], + unit_id = item["unit_id"], + }); + } + } + else + { + throw new Exception("没有签收物料"); + } + + + await db.Insertable(prdMaterialReceiptH).ExecuteCommandAsync(); + await db.Insertable(list).ExecuteCommandAsync(); + + }); + + if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage); + return result.IsSuccess ? "签收成功" : result.ErrorMessage; + } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj b/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj index dc0d6697..0ea7ec46 100644 --- a/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj +++ b/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj @@ -12,6 +12,7 @@ + From d8a95aa1e0a3c6ca5265e114e1cb3d569dc61498 Mon Sep 17 00:00:00 2001 From: FanLian Date: Fri, 16 Jun 2023 13:26:35 +0800 Subject: [PATCH 3/8] 1 --- .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index ea22ae7b..807de664 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -15,6 +15,7 @@ using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; @@ -73,15 +74,26 @@ namespace Tnb.WarehouseMgr // string errorMessege = "新老载具规格应相同"; // throw Oops.Oh(errorMessege); //} + /* + * + */ + var insert_id = await _db.Insertable(new WmsCarryD { + carry_id = carry.id, + membercarry_id = subCarry.id, + membercarry_code = subCarry.carry_code, + loc = input.data[nameof(WmsCarrybindH.loc)].ToString() + }) + .ExecuteCommandAsync(); + if (insert_id<=0) throw Oops.Oh(ErrorCode.COM1000); //更新主载具明细表的子载具ID和编号以及位置 - var isOk = await _db.Updateable().SetColumns(it => it.membercarry_id == subCarry.id) - .SetColumns(it => it.membercarry_code == subCarry.carry_code) - .SetColumns(it => it.loc == input.data[nameof(WmsCarrybindH.loc)].ToString()) - .Where(it => it.id == carry.id) - .ExecuteCommandHasChangeAsync(); - if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - + /* var isOk = await _db.Updateable().SetColumns(it => it.membercarry_id == subCarry.id) + .SetColumns(it => it.membercarry_code == subCarry.carry_code) + .SetColumns(it => it.loc == input.data[nameof(WmsCarrybindH.loc)].ToString()) + .Where(it => it.id == carry.id) + .ExecuteCommandHasChangeAsync(); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + */ From 78f726d139001d3de12a7213e647b05a74addc71 Mon Sep 17 00:00:00 2001 From: FanLian Date: Fri, 16 Jun 2023 13:48:36 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=BD=BD=E5=85=B7=E8=A7=A3=E7=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/WmsCarrybindH.cs | 2 +- .../Entity/WmsCarryunbindH.cs | 5 + .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 95 +------------------ .../Tnb.WarehouseMgr/WmsCarryUnbindService.cs | 93 ++++++++++++++++++ 4 files changed, 100 insertions(+), 95 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarrybindH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarrybindH.cs index de0a98a1..1eb7a537 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarrybindH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarrybindH.cs @@ -25,7 +25,7 @@ public partial class WmsCarrybindH : BaseEntity public string? org_id { get; set; } /// - /// 所属组织ID + /// 载具ID /// public string? carry_id { get; set; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarryunbindH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarryunbindH.cs index 58865bce..0e5d78ba 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarryunbindH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsCarryunbindH.cs @@ -24,6 +24,11 @@ public partial class WmsCarryunbindH : BaseEntity /// public string? org_id { get; set; } + /// + /// 载具ID + /// + public string? carry_id { get; set; } + /// /// 载具编号 /// diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 807de664..647e5794 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -68,16 +68,7 @@ namespace Tnb.WarehouseMgr if (input == null) throw new ArgumentNullException(nameof(input)); var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarrybindH.carry_id)].ToString()); var subCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarrybindH.membercarry_id)].ToString()); - - //if (oldCarry.carrystd_id != newCarry.carrystd_id) - //{ - // string errorMessege = "新老载具规格应相同"; - // throw Oops.Oh(errorMessege); - //} - /* - * - */ - + //更新主载具明细表,增加新的数据 var insert_id = await _db.Insertable(new WmsCarryD { carry_id = carry.id, membercarry_id = subCarry.id, @@ -86,90 +77,6 @@ namespace Tnb.WarehouseMgr }) .ExecuteCommandAsync(); if (insert_id<=0) throw Oops.Oh(ErrorCode.COM1000); - //更新主载具明细表的子载具ID和编号以及位置 - /* var isOk = await _db.Updateable().SetColumns(it => it.membercarry_id == subCarry.id) - .SetColumns(it => it.membercarry_code == subCarry.carry_code) - .SetColumns(it => it.loc == input.data[nameof(WmsCarrybindH.loc)].ToString()) - .Where(it => it.id == carry.id) - .ExecuteCommandHasChangeAsync(); - if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - */ - - - - - - - /* - * db.Updateable(WmsCarryD).SetColumns(it => it.carry_id == newCarry.id).Where(it=>it.carry_id == oldCarry.id).ExecuteCommand(); - */ - - /* //入库取终点 - //var OutStockStrategyInput = new OutStockStrategyQuery { carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)].ToString(), Size = 1 }; - //var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsMoveOutstock.carry_id)].ToString()); - WmsPointH sPoint = null; - WmsPointH ePoint = null; - if (input.data.ContainsKey(nameof(WmsPointH.location_id))) - { - ePoint = await _db.Queryable().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString()); - } - if (carry != null) - { - sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id); - } - - if (sPoint != null && ePoint != null) - { - var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); - //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) - if (points?.Count > 0) - { - if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500); - var preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it => - { - var sPoint = it.FirstOrDefault(); - var ePoint = it.LastOrDefault(); - - WmsPretaskH preTask = new(); - preTask.org_id = _userManager.User.OrganizeId; - preTask.startlocation_id = sPoint?.location_id; - preTask.startlocation_code = sPoint?.location_code; - preTask.endlocation_id = ePoint?.location_id; - preTask.endlocation_code = ePoint?.location_code; - preTask.start_floor = sPoint?.floor.ToString(); - preTask.end_floor = ePoint?.floor.ToString(); - preTask.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(); - preTask.status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID; - preTask.biz_type = WmsWareHouseConst.BIZTYPE_WMSMOOUTSTK_ID; - preTask.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID; - preTask.carry_id = input.data[nameof(preTask.carry_id)]?.ToString()!; - preTask.carry_code = input.data[nameof(preTask.carry_code)]?.ToString()!; - preTask.area_id = sPoint?.area_id; - preTask.area_code = it.Key; - preTask.require_id = input.data["ReturnIdentity"].ToString(); - preTask.require_code = input.data[nameof(preTask.bill_code)]?.ToString()!; - preTask.create_id = _userManager.UserId; - preTask.create_time = DateTime.Now; - return preTask; - }).ToList(); - var isOk = await _wareHouseService.GenPreTask(preTasks); - if (isOk) - { - var preTaskUpInput = new GenPreTaskUpInput(); - preTaskUpInput.RquireId = input.data["ReturnIdentity"].ToString(); - preTaskUpInput.CarryId = input.data[nameof(WmsCarryD.carry_id)]?.ToString()!; - preTaskUpInput.CarryStartLocationId = points.FirstOrDefault().location_id; - preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault().location_code; - preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList(); - preTaskUpInput.PreTaskRecords = preTasks.Adapt>(); - preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId()); - await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, null, null); - - } - } - - }*/ - await _db.Ado.CommitTranAsync(); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs new file mode 100644 index 00000000..17b746c5 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Extension; +using JNPF.Common.Security; +using JNPF.FriendlyException; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Attributes; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具移出 + /// + [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYREPLACE_ID)] + public class WmsCarryUnbindService : BaseWareHouseService + { + private readonly ISqlSugarClient _db; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private readonly IWareHouseService _wareHouseService; + private readonly IBillRullService _billRullService; + private readonly IUserManager _userManager; + public WmsCarryUnbindService( + ISqlSugarRepository repository, + IRunService runService, + IVisualDevService visualDevService, + IWareHouseService wareHouseService, + IUserManager userManager, + IBillRullService billRullService) + { + _db = repository.AsSugarClient(); + _runService = runService; + _visualDevService = visualDevService; + _wareHouseService = wareHouseService; + _userManager = userManager; + _billRullService = billRullService; + OverideFuncs.CreateAsync = CarryUnbind; + } + + private async Task CarryUnbind(VisualDevModelDataCrInput input) + { + + try + { + await _db.Ado.BeginTranAsync(); + + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYMOOUTSTK_ID, true); + await _runService.Create(templateEntity, input); + + if (input == null) throw new ArgumentNullException(nameof(input)); + var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryunbindH.carry_id)].ToString()); + var subCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryunbindH.membercarry_id)].ToString()); + + + var deleteQty = await _db.Deleteable().Where(it => it.carry_id == carry.id ).ExecuteCommandAsync(); + + if (deleteQty <= 0) throw Oops.Oh(ErrorCode.COM1002); + + await _db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await _db.Ado.RollbackTranAsync(); + throw; + } + return Task.FromResult(true); + } + /* public override async Task ModifyAsync(WareHouseUpInput input) + { + if (input == null) throw new ArgumentNullException(nameof(input)); + var isOk = await _db.Updateable().SetColumns(it => new WmsCarryReplaceH { status = input.bizTypeId }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync(); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + }*/ + } +} From dd3ca9abd220492188771fc3f5d3e2f0eb0e45dc Mon Sep 17 00:00:00 2001 From: FanLian Date: Fri, 16 Jun 2023 13:48:54 +0800 Subject: [PATCH 5/8] 1 --- WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs index 17b746c5..947b0646 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs @@ -71,7 +71,6 @@ namespace Tnb.WarehouseMgr var deleteQty = await _db.Deleteable().Where(it => it.carry_id == carry.id ).ExecuteCommandAsync(); - if (deleteQty <= 0) throw Oops.Oh(ErrorCode.COM1002); await _db.Ado.CommitTranAsync(); From 489987091cfece1860b84ca3ea5ef2f5aaf6550c Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Fri, 16 Jun 2023 14:11:30 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AD=BE=E6=94=B6?= =?UTF-8?q?=E5=8D=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/PrdManage/MaterialReceiptInput.cs | 5 +++++ .../Entity/PrdMaterialReceiptH.cs | 6 ++++++ .../Tnb.ProductionMgr/PrdMaterialReceiptService.cs | 1 + 3 files changed, 12 insertions(+) diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs index 5d0e22ad..91ead988 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialReceiptInput.cs @@ -4,6 +4,11 @@ namespace Tnb.ProductionMgr.Entities.Dto { public string id { get; set; } + /// + /// 签收单号 + /// + public string code { get; set; } = string.Empty; + /// /// 工位id /// diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs index 57ae28fe..94958bc2 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptH.cs @@ -14,6 +14,12 @@ public partial class PrdMaterialReceiptH : BaseEntity { id = SnowflakeIdHelper.NextId(); } + + /// + /// 签收单号 + /// + public string code { get; set; } = string.Empty; + /// /// 工位id /// diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs index f437c660..8a77672c 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs @@ -78,6 +78,7 @@ namespace Tnb.ProductionMgr PrdMaterialReceiptH prdMaterialReceiptH = new PrdMaterialReceiptH() { + code = input.code, station_id = input.station_id, mo_task_id = input.mo_task_id, process_id = input.process_id, From 3d60c3b912bd86f42fb484284638e920cb80fc7e Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Fri, 16 Jun 2023 14:38:34 +0800 Subject: [PATCH 7/8] bug --- .../Entity/PrdMaterialReceiptD.cs | 2 +- .../Tnb.ProductionMgr/PrdMaterialReceiptService.cs | 12 +++++++++--- .../Consts/WmsCarryConst.cs | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs index 76f17cd4..dec2b972 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs @@ -27,7 +27,7 @@ public partial class PrdMaterialReceiptD : BaseEntity /// /// 数量 /// - public int num { get; set; } + public decimal num { get; set; } /// /// 批次 diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs index 8a77672c..5493423d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs @@ -4,6 +4,7 @@ using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; +using JNPF.Systems.Interfaces.System; using Microsoft.AspNetCore.Mvc; using Microsoft.ClearScript.Util.Web; using SqlSugar; @@ -14,6 +15,7 @@ using Tnb.ProductionMgr.Entities.Dto.PrdManage; using Tnb.ProductionMgr.Interfaces; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Consts; namespace Tnb.ProductionMgr { @@ -26,15 +28,18 @@ namespace Tnb.ProductionMgr { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; public PrdMaterialReceiptService( ISqlSugarRepository repository, + IBillRullService billRullService, IUserManager userManager ) { _repository = repository; _userManager = userManager; + _billRullService = billRullService; } @@ -75,10 +80,11 @@ namespace Tnb.ProductionMgr .Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == input.mbom_process_id) .Select(x=>x.material_id) .ToListAsync(); - + + string code = await _billRullService.GetBillNumber(WmsCarryConst.MATERIAL_RECEIPT_CODE); PrdMaterialReceiptH prdMaterialReceiptH = new PrdMaterialReceiptH() { - code = input.code, + code = code, station_id = input.station_id, mo_task_id = input.mo_task_id, process_id = input.process_id, @@ -106,7 +112,7 @@ namespace Tnb.ProductionMgr { material_receipt_id = prdMaterialReceiptH.id, material_id = item["material_id"], - num = Convert.ToInt32(item["num"]), + num = Convert.ToDecimal(item["num"]), batch = item["batch"], unit_id = item["unit_id"], }); diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsCarryConst.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsCarryConst.cs index 563ee215..468463fd 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsCarryConst.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsCarryConst.cs @@ -12,5 +12,12 @@ namespace Tnb.WarehouseMgr.Entities.Consts /// 载具更换EnCode业务编码 /// public const string WMS_CARRY_REPLACE_ENCODE = "WmsCarryReplace"; + + /// + /// 物料签收编码 + /// + public const string MATERIAL_RECEIPT_CODE = "MaterialReceipt"; + + } } From 9129277f96de50462e0ffeca6bdec1a0383436b6 Mon Sep 17 00:00:00 2001 From: FanLian Date: Fri, 16 Jun 2023 15:08:11 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BD=BD=E5=85=B7?= =?UTF-8?q?=E8=A7=A3=E7=BB=91,=E8=BD=BD=E5=85=B7=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 44 ++- .../WmsCarryReplaceService.cs | 250 +++++++++--------- .../Tnb.WarehouseMgr/WmsCarryUnbindService.cs | 30 ++- .../WmsPDACarryReplaceService.cs | 176 ++++++++++++ 4 files changed, 363 insertions(+), 137 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 647e5794..7d486bf9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -57,7 +57,7 @@ namespace Tnb.WarehouseMgr private async Task CarryBind(VisualDevModelDataCrInput input) { - + var isOk = false; try { await _db.Ado.BeginTranAsync(); @@ -66,19 +66,45 @@ namespace Tnb.WarehouseMgr await _runService.Create(templateEntity, input); if (input == null) throw new ArgumentNullException(nameof(input)); - var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarrybindH.carry_id)].ToString()); - var subCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarrybindH.membercarry_id)].ToString()); - //更新主载具明细表,增加新的数据 - var insert_id = await _db.Insertable(new WmsCarryD { + var carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var subCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var carry = await _db.Queryable().FirstAsync(it => it.id == carryId); + var subCarry = await _db.Queryable().FirstAsync(it => it.id == subCarryId); + WmsCarrybindH wmsCarrybindH = carry.Adapt(); + if (carryId != null && subCarryId != null) + { + wmsCarrybindH.id = SnowflakeIdHelper.NextId(); + wmsCarrybindH.org_id = carry.org_id; + wmsCarrybindH.carry_id = carry.id; + wmsCarrybindH.membercarry_id = subCarry.id; + wmsCarrybindH.membercarry_code = subCarry.carry_code; + wmsCarrybindH.loc = input.data[nameof(WmsCarrybindH.loc)].ParseToInt(1); + wmsCarrybindH.create_id = _userManager.UserId; + wmsCarrybindH.create_time = DateTime.Now; + var row = await _db.Insertable(wmsCarrybindH).ExecuteCommandAsync(); + carry.carry_status = "1"; + row = await _db.Updateable(carry).ExecuteCommandAsync(); + subCarry.carry_status = "1"; + row = await _db.Updateable(subCarry).ExecuteCommandAsync(); + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + + } + /* //更新主载具明细表,增加新的数据 + var row = await _db.Insertable(new WmsCarryD { + id = SnowflakeIdHelper.NextId(), + org_id = carry.org_id, carry_id = carry.id, membercarry_id = subCarry.id, membercarry_code = subCarry.carry_code, - loc = input.data[nameof(WmsCarrybindH.loc)].ToString() + loc = input.data[nameof(WmsCarrybindH.loc)].ToString(), + create_id = _userManager.UserId, + create_time = DateTime.Now }) .ExecuteCommandAsync(); - if (insert_id<=0) throw Oops.Oh(ErrorCode.COM1000); - - await _db.Ado.CommitTranAsync(); + if (row <= 0) throw Oops.Oh(ErrorCode.COM1000); + _db.Updateable().SetColumns(it=>it.carry_status == "1").Where(it=>it.id == input.data[nameof(WmsCarrybindH.carry_id)].ToString());*/ + await _db.Ado.CommitTranAsync(); } catch (Exception ex) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs index d11b4122..bd3368d2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs @@ -1,169 +1,175 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using JNPF.Common.Contracts; using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; -using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; using JNPF.FriendlyException; +using JNPF.Logging; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; -using JNPF.VisualDev.Entitys; -using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; -using Tnb.BasicData.Entities; +using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities; -using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr { /// - /// 载具移出 + /// 载具服务 /// - [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYREPLACE_ID)] - public class WmsCarryReplaceService : BaseWareHouseService + [OverideVisualDev(ModuleId)] + public class WmsCarryReplaceService : BaseWareHouseService, IWmsCarryService { + private const string ModuleId = "26188532491557"; private readonly ISqlSugarClient _db; - private readonly IRunService _runService; - private readonly IVisualDevService _visualDevService; - private readonly IWareHouseService _wareHouseService; - private readonly IBillRullService _billRullService; private readonly IUserManager _userManager; - public WmsCarryReplaceService( - ISqlSugarRepository repository, - IRunService runService, - IVisualDevService visualDevService, - IWareHouseService wareHouseService, - IUserManager userManager, - IBillRullService billRullService) + private readonly IBillRullService _billRullService; + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public WmsCarryReplaceService(ISqlSugarRepository repository, IUserManager userManager, IBillRullService billRullService) { _db = repository.AsSugarClient(); - _runService = runService; - _visualDevService = visualDevService; - _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; OverideFuncs.CreateAsync = CarryReplace; } - private async Task CarryReplace(VisualDevModelDataCrInput input) + /// + /// 更换载具 + /// + /// + /// 输入参数: + ///
{ + ///
old_carry_id:老载具id + ///
new_carry_id:新载具ID + ///
} + /// + /// + /// + [HttpPost] + public async Task CarryReplace(VisualDevModelDataCrInput input) { - + var isOk = false; try { await _db.Ado.BeginTranAsync(); + var oldCarryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var newCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var oldCarry = await _db.Queryable().FirstAsync(it => it.id == oldCarryId); + var newCarry = await _db.Queryable().FirstAsync(it => it.id == newCarryId); + if (oldCarry != null && newCarry != null) + { + ExChangeCarryInput carryInput = new() { old_carry_id = oldCarry.id, new_carry_id = newCarry.id }; + isOk = await _updateSubCarry(carryInput); + isOk = await _updateSubCarry(carryInput); + isOk = await _updateSubCarry(carryInput); - VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYMOOUTSTK_ID, true); - await _runService.Create(templateEntity, input); - if (input == null) throw new ArgumentNullException(nameof(input)); - var oldCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryReplaceH.carry_id)].ToString()); - var newCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryReplaceH.newcarry_id)].ToString()); - if (oldCarry.carrystd_id != newCarry.carrystd_id) - { - string errorMessege = "新老载具规格应相同"; - throw Oops.Oh(errorMessege); - } - if (oldCarry.carrystd_id == newCarry.carrystd_id) - { - var isOk = await _db.Updateable().SetColumns(it => it.carry_id == newCarry.id).Where(it => it.carry_id == oldCarry.id).ExecuteCommandHasChangeAsync(); - if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - isOk = await _db.Updateable().SetColumns(it => it.carry_id == newCarry.id).Where(it => it.carry_id == oldCarry.id).ExecuteCommandHasChangeAsync(); + newCarry.status = oldCarry.status; + newCarry.carry_status = oldCarry.carry_status; + newCarry.location_id = oldCarry.location_id; + newCarry.location_code = oldCarry.location_code; + newCarry.is_lock = oldCarry.is_lock; + newCarry.out_status = oldCarry.out_status; + newCarry.is_check = oldCarry.is_check; + newCarry.bale_num = oldCarry.bale_num; + newCarry.collocation_scheme_id = oldCarry.collocation_scheme_id; + newCarry.collocation_scheme_code = oldCarry.collocation_scheme_code; + newCarry.source_id = oldCarry.source_id; + newCarry.source_code = oldCarry.source_code; + newCarry.create_id = _userManager.UserId; + newCarry.create_time = DateTime.Now; + var row = await _db.Updateable(newCarry).ExecuteCommandAsync(); + WmsCarryReplaceH wmsCarryReplaceH = oldCarry.Adapt(); + wmsCarryReplaceH.id = SnowflakeIdHelper.NextId(); + wmsCarryReplaceH.org_id = oldCarry.org_id; + wmsCarryReplaceH.bill_code = await _billRullService.GetBillNumber(WmsCarryConst.WMS_CARRY_REPLACE_ENCODE); + wmsCarryReplaceH.carry_id = oldCarry.id; + wmsCarryReplaceH.carry_code = oldCarry.carry_code; + wmsCarryReplaceH.newcarry_id = newCarry.id; + wmsCarryReplaceH.newcarry_code = newCarry.carry_code; + row = await _db.Insertable(wmsCarryReplaceH).ExecuteCommandAsync(); + row = await UpdateNullCarry(oldCarry); + isOk = (row > 0); if (!isOk) throw Oops.Oh(ErrorCode.COM1001); } + else + { + if (oldCarry == null) + { + throw new AppFriendlyException("没有可用的旧载具", 500); + } + if (newCarry == null) + { + throw new AppFriendlyException("没有可用的新载具", 500); + } - /* - * db.Updateable(WmsCarryD).SetColumns(it => it.carry_id == newCarry.id).Where(it=>it.carry_id == oldCarry.id).ExecuteCommand(); - */ - - /* //入库取终点 - //var OutStockStrategyInput = new OutStockStrategyQuery { carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)].ToString(), Size = 1 }; - //var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsMoveOutstock.carry_id)].ToString()); - WmsPointH sPoint = null; - WmsPointH ePoint = null; - if (input.data.ContainsKey(nameof(WmsPointH.location_id))) - { - ePoint = await _db.Queryable().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString()); - } - if (carry != null) - { - sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id); - } - - if (sPoint != null && ePoint != null) - { - var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); - //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) - if (points?.Count > 0) - { - if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500); - var preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it => - { - var sPoint = it.FirstOrDefault(); - var ePoint = it.LastOrDefault(); - - WmsPretaskH preTask = new(); - preTask.org_id = _userManager.User.OrganizeId; - preTask.startlocation_id = sPoint?.location_id; - preTask.startlocation_code = sPoint?.location_code; - preTask.endlocation_id = ePoint?.location_id; - preTask.endlocation_code = ePoint?.location_code; - preTask.start_floor = sPoint?.floor.ToString(); - preTask.end_floor = ePoint?.floor.ToString(); - preTask.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(); - preTask.status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID; - preTask.biz_type = WmsWareHouseConst.BIZTYPE_WMSMOOUTSTK_ID; - preTask.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID; - preTask.carry_id = input.data[nameof(preTask.carry_id)]?.ToString()!; - preTask.carry_code = input.data[nameof(preTask.carry_code)]?.ToString()!; - preTask.area_id = sPoint?.area_id; - preTask.area_code = it.Key; - preTask.require_id = input.data["ReturnIdentity"].ToString(); - preTask.require_code = input.data[nameof(preTask.bill_code)]?.ToString()!; - preTask.create_id = _userManager.UserId; - preTask.create_time = DateTime.Now; - return preTask; - }).ToList(); - var isOk = await _wareHouseService.GenPreTask(preTasks); - if (isOk) - { - var preTaskUpInput = new GenPreTaskUpInput(); - preTaskUpInput.RquireId = input.data["ReturnIdentity"].ToString(); - preTaskUpInput.CarryId = input.data[nameof(WmsCarryD.carry_id)]?.ToString()!; - preTaskUpInput.CarryStartLocationId = points.FirstOrDefault().location_id; - preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault().location_code; - preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList(); - preTaskUpInput.PreTaskRecords = preTasks.Adapt>(); - preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId()); - await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, null, null); - - } - } - - }*/ - - + } await _db.Ado.CommitTranAsync(); } catch (Exception ex) { + Log.Error("载具更换失败", ex); await _db.Ado.RollbackTranAsync(); throw; } - return Task.FromResult(true); + return isOk; } - /* public override async Task ModifyAsync(WareHouseUpInput input) + + public async Task UpdateNullCarry(WmsCarryH carryObj) { - if (input == null) throw new ArgumentNullException(nameof(input)); - var isOk = await _db.Updateable().SetColumns(it => new WmsCarryReplaceH { status = input.bizTypeId }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync(); - if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - }*/ + var row = -1; + try + { + carryObj.status = 0; + carryObj.carry_status = "0"; + carryObj.location_id = null; + carryObj.location_code = null; + carryObj.out_status = "0"; + carryObj.is_check = 0; + carryObj.status = 1; + carryObj.bale_num = null; + carryObj.collocation_scheme_id = null; + carryObj.collocation_scheme_code = null; + carryObj.source_id = null; + carryObj.source_code = null; + row = await _db.Updateable(carryObj).ExecuteCommandAsync(); + } + catch (Exception ex) + { + + } + return row; + } + + private async Task _updateSubCarry(ExChangeCarryInput input) where T : BaseEntity, IWmsCarryEntity, new() + { + var row = -1; + var items = await _db.Queryable().Where(it => it.carry_id == input.old_carry_id).ToListAsync(); + if (items?.Count > 0) + { + List newItems = DeepCopyHelper.DeepCopyList(items); + if (newItems?.Count > 0) + { + newItems.ForEach(x => + { + x.id = SnowflakeIdHelper.NextId(); + x.carry_id = input.new_carry_id; + + }); + row = await _db.Insertable(newItems).ExecuteCommandAsync(); + } + if (row > 0) + { + row = await _db.Deleteable(items).ExecuteCommandAsync(); + } + } + return (row > 0); + } } -} +} \ No newline at end of file diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs index 947b0646..6ffdd5b1 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs @@ -57,7 +57,7 @@ namespace Tnb.WarehouseMgr private async Task CarryUnbind(VisualDevModelDataCrInput input) { - + var isOk = false; try { await _db.Ado.BeginTranAsync(); @@ -66,12 +66,30 @@ namespace Tnb.WarehouseMgr await _runService.Create(templateEntity, input); if (input == null) throw new ArgumentNullException(nameof(input)); - var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryunbindH.carry_id)].ToString()); - var subCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryunbindH.membercarry_id)].ToString()); + var carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var subCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var carry = await _db.Queryable().FirstAsync(it => it.id == carryId); + var subCarry = await _db.Queryable().FirstAsync(it => it.id == subCarryId); + //WmsCarryunbindH wmsCarryUnbindH = carry.Adapt(); + if (carryId != null && subCarryId != null) + { + //wmsCarryUnbindH.id = SnowflakeIdHelper.NextId(); + //wmsCarryUnbindH.org_id = carry.org_id; + //wmsCarryUnbindH.carry_id = carry.id; + //wmsCarryUnbindH.membercarry_id = subCarry.id; + //wmsCarryUnbindH.membercarry_code = subCarry.carry_code; + //wmsCarryUnbindH.loc = input.data[nameof(WmsCarryunbindH.loc)].ParseToInt(1); + //wmsCarryUnbindH.create_id = _userManager.UserId; + //wmsCarryUnbindH.create_time = DateTime.Now; + var row = await _db.Deleteable().Where(it=>it.carry_id == subCarry.id).ExecuteCommandAsync(); + carry.carry_status = "0"; + row = await _db.Updateable(carry).ExecuteCommandAsync(); + subCarry.carry_status = "0"; + row = await _db.Updateable(subCarry).ExecuteCommandAsync(); + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - - var deleteQty = await _db.Deleteable().Where(it => it.carry_id == carry.id ).ExecuteCommandAsync(); - if (deleteQty <= 0) throw Oops.Oh(ErrorCode.COM1002); + } await _db.Ado.CommitTranAsync(); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs new file mode 100644 index 00000000..e8b7e20a --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs @@ -0,0 +1,176 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Security; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using JNPF.Logging; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.Common.Utils; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Attributes; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Enums; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具服务 + /// + [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYREPLACEPDA_ID)] + public class WmsPDACarryReplaceService : BaseWareHouseService, IWmsCarryService + { + //private const string ModuleId = "26188532491557"; + private readonly ISqlSugarClient _db; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public WmsPDACarryReplaceService(ISqlSugarRepository repository, IUserManager userManager, IBillRullService billRullService) + { + _db = repository.AsSugarClient(); + _userManager = userManager; + _billRullService = billRullService; + OverideFuncs.CreateAsync = PDACarryReplace; + } + + /// + /// 更换载具 + /// + /// + /// 输入参数: + ///
{ + ///
old_carry_id:老载具id + ///
new_carry_id:新载具ID + ///
} + /// + /// + /// + [HttpPost] + public async Task PDACarryReplace(VisualDevModelDataCrInput input) + { + var isOk = false; + try + { + await _db.Ado.BeginTranAsync(); + var oldCarryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var newCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var oldCarry = await _db.Queryable().FirstAsync(it => it.id == oldCarryId); + var newCarry = await _db.Queryable().FirstAsync(it => it.id == newCarryId); + if (oldCarry != null && newCarry != null) + { + ExChangeCarryInput carryInput = new() { old_carry_id = oldCarry.id, new_carry_id = newCarry.id }; + isOk = await _updateSubCarry(carryInput); + isOk = await _updateSubCarry(carryInput); + isOk = await _updateSubCarry(carryInput); + + newCarry.status = oldCarry.status; + newCarry.carry_status = oldCarry.carry_status; + newCarry.location_id = oldCarry.location_id; + newCarry.location_code = oldCarry.location_code; + newCarry.is_lock = oldCarry.is_lock; + newCarry.out_status = oldCarry.out_status; + newCarry.is_check = oldCarry.is_check; + newCarry.bale_num = oldCarry.bale_num; + newCarry.collocation_scheme_id = oldCarry.collocation_scheme_id; + newCarry.collocation_scheme_code = oldCarry.collocation_scheme_code; + newCarry.source_id = oldCarry.source_id; + newCarry.source_code = oldCarry.source_code; + newCarry.create_id = _userManager.UserId; + newCarry.create_time = DateTime.Now; + var row = await _db.Updateable(newCarry).ExecuteCommandAsync(); + WmsCarryReplaceH wmsCarryReplaceH = oldCarry.Adapt(); + wmsCarryReplaceH.id = SnowflakeIdHelper.NextId(); + wmsCarryReplaceH.org_id = oldCarry.org_id; + wmsCarryReplaceH.bill_code = await _billRullService.GetBillNumber(WmsCarryConst.WMS_CARRY_REPLACE_ENCODE); + wmsCarryReplaceH.carry_id = oldCarry.id; + wmsCarryReplaceH.carry_code = oldCarry.carry_code; + wmsCarryReplaceH.newcarry_id = newCarry.id; + wmsCarryReplaceH.newcarry_code = newCarry.carry_code; + row = await _db.Insertable(wmsCarryReplaceH).ExecuteCommandAsync(); + row = await UpdateNullCarry(oldCarry); + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + } + else + { + if (oldCarry == null) + { + throw new AppFriendlyException("没有可用的旧载具", 500); + } + if (newCarry == null) + { + throw new AppFriendlyException("没有可用的新载具", 500); + } + + } + await _db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + Log.Error("载具更换失败", ex); + await _db.Ado.RollbackTranAsync(); + throw; + } + return isOk; + } + + public async Task UpdateNullCarry(WmsCarryH carryObj) + { + var row = -1; + try + { + carryObj.status = 0; + carryObj.carry_status = "0"; + carryObj.location_id = null; + carryObj.location_code = null; + carryObj.out_status = "0"; + carryObj.is_check = 0; + carryObj.status = 1; + carryObj.bale_num = null; + carryObj.collocation_scheme_id = null; + carryObj.collocation_scheme_code = null; + carryObj.source_id = null; + carryObj.source_code = null; + row = await _db.Updateable(carryObj).ExecuteCommandAsync(); + } + catch (Exception ex) + { + + } + return row; + } + + private async Task _updateSubCarry(ExChangeCarryInput input) where T : BaseEntity, IWmsCarryEntity, new() + { + var row = -1; + var items = await _db.Queryable().Where(it => it.carry_id == input.old_carry_id).ToListAsync(); + if (items?.Count > 0) + { + List newItems = DeepCopyHelper.DeepCopyList(items); + if (newItems?.Count > 0) + { + newItems.ForEach(x => + { + x.id = SnowflakeIdHelper.NextId(); + x.carry_id = input.new_carry_id; + + }); + row = await _db.Insertable(newItems).ExecuteCommandAsync(); + } + if (row > 0) + { + row = await _db.Deleteable(items).ExecuteCommandAsync(); + } + } + return (row > 0); + } + } +} \ No newline at end of file