From 863d9cf470c000d1f1351fd78ddef61336110f9e Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Fri, 2 Jun 2023 17:39:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=85=B7=E4=BF=9D=E5=85=BB=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=EF=BC=8C=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ToolMoldMaintainRunService.cs | 70 +++++++----- .../Dto/CarryCodeDetailOutput.cs | 4 + .../IBasRegionUserService.cs | 15 +++ .../IWmsCarryLedgerService.cs | 15 +++ .../Tnb.WarehouseMgr/BasRegionUserService.cs | 62 ++++++++++ .../Tnb.WarehouseMgr/WmsCarryLedgerService.cs | 106 ++++++++++++++++++ .../Tnb.WarehouseMgr/WmsCarryService.cs | 1 + .../Tnb.WarehouseMgr/WmsFeedingService.cs | 17 +-- 8 files changed, 254 insertions(+), 36 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IBasRegionUserService.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryLedgerService.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/BasRegionUserService.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs index 49215a5e..f9b3691d 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs @@ -135,7 +135,6 @@ namespace Tnb.EquipMgr item_name = e.name, }) .ToListAsync(); - //items.ForEach(it => it.status = 0); var checkItems = await _db.Queryable().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new { plan_id = it.plan_id, @@ -143,16 +142,15 @@ namespace Tnb.EquipMgr item_group_id = it.item_group_id, mold_id = it.mold_id, }).ToListAsync(); + var dicCheckItems = checkItems.GroupBy(g => $"{g.plan_id}{g.mold_id}{g.item_group_id}{g.item_id}").ToDictionary(x => x.Key, x => x.FirstOrDefault()); if (items?.Count > 0 && checkItems?.Count > 0) { foreach (var item in items) { - foreach (var checkItem in checkItems) + var key = $"{item.plan_id}{item.mold_id}{item.item_group_id}{item.item_id}"; + if (dicCheckItems.ContainsKey(key) && dicCheckItems[key] != null) { - if (item.plan_id == checkItem.plan_id && item.mold_id == checkItem.mold_id && item.item_group_id == checkItem.item_group_id && item.item_id == checkItem.item_id) - { - item.status = 1; - } + item.status = 1; } } } @@ -269,33 +267,49 @@ namespace Tnb.EquipMgr [HttpPost] public async Task MaintainFinish(MoldMaintainRunUpInput input) { - if (input == null) throw new ArgumentNullException("input"); - var grpIds = await _db.Queryable() - .LeftJoin((a, b) => a.mold_id == b.id) - .Where(a => a.mold_id == input.mold_id) - .Select((a, b) => a.item_group_id) - .Distinct() - .ToListAsync(); - var itemIds = await _db.Queryable().Where(it => grpIds.Contains(it.item_group_id)).Select(it => it.item_id).ToListAsync(); - if (itemIds?.Count > 0) + var items = await _db.Queryable() + .InnerJoin((a, b) => a.mold_id == b.mold_id) + .InnerJoin((a, b, c) => b.item_group_id == c.item_group_id) + .InnerJoin((a, b, c, d) => c.item_group_id == d.id) + .InnerJoin((a, b, c, d, e) => c.item_id == e.id) + .Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id) + .Select((a, b, c, d, e) => new CheckItemOutput + { + plan_id = a.maintain_plan_id, + mold_id = a.mold_id, + item_group_id = d.id, + item_group_name = d.name, + item_id = e.id, + item_name = e.name, + }) + .ToListAsync(); + var checkItems = await _db.Queryable().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new { - var items = await _db.Queryable().Where(it => it.mold_id == input.mold_id && it.status == 1).ToListAsync(); - if (items?.Count < itemIds.Count) + plan_id = it.plan_id, + item_id = it.item_id, + item_group_id = it.item_group_id, + mold_id = it.mold_id, + }).ToListAsync(); + var dicCheckItems = checkItems.GroupBy(g => $"{g.plan_id}{g.mold_id}{g.item_group_id}{g.item_id}").ToDictionary(x => x.Key, x => x.FirstOrDefault()); + var maintainedItems = items.Where(it => dicCheckItems.ContainsKey($"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}") && dicCheckItems[$"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}"] != null).ToList(); + if ((items?.Count > 0 && maintainedItems?.Count > 0 )|| (maintainedItems == null || maintainedItems.Count < 1)) + { + if (maintainedItems.Count < items.Count || (maintainedItems == null || maintainedItems.Count < 1)) { throw new AppFriendlyException("当前模具有未完成的保养项目", 500); } - var row = await _db.Updateable().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync(); - if (row < 1) throw Oops.Oh(ErrorCode.COM1001); - var allMoldStatus = await _db.Queryable().InnerJoin((a, b) => a.mold_id == b.id) - .Where((a, b) => a.maintain_plan_id == input.plan_id) - .Select((a, b) => b.mold_status) - .ToListAsync(); - if (allMoldStatus?.Count > 0 && allMoldStatus.All(x => x == MoldUseStatus.MOLD_USE_STATUS_ZK_ID)) - { - row = await _db.Updateable().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync(); - } - if (row < 1) throw Oops.Oh(ErrorCode.COM1001); } + var row = await _db.Updateable().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync(); + var allMoldStatus = await _db.Queryable().InnerJoin((a, b) => a.mold_id == b.id) + .Where((a, b) => a.maintain_plan_id == input.plan_id) + .Select((a, b) => b.mold_status) + .ToListAsync(); + if (allMoldStatus?.Count > 0 && allMoldStatus.All(x => x == MoldUseStatus.MOLD_USE_STATUS_ZK_ID)) + { + row = await _db.Updateable().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync(); + } + if (row < 1) throw Oops.Oh(ErrorCode.COM1001); + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/CarryCodeDetailOutput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/CarryCodeDetailOutput.cs index 6dc718df..bf05164c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/CarryCodeDetailOutput.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/CarryCodeDetailOutput.cs @@ -11,6 +11,10 @@ namespace Tnb.WarehouseMgr.Entities.Dto /// public class CarryCodeDetailOutput { + /// + /// 物料单位 + /// + public string unit_id { get; set; } /// /// 条码编号 /// diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IBasRegionUserService.cs b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IBasRegionUserService.cs new file mode 100644 index 00000000..4f6eb634 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IBasRegionUserService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Interfaces +{ + /// + /// 区域人员设定服务接口 + /// + public interface IBasRegionUserService + { + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryLedgerService.cs b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryLedgerService.cs new file mode 100644 index 00000000..a78c80c8 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryLedgerService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Interfaces +{ + /// + /// 载具台账服务接口 + /// + public interface IWmsCarryLedgerService + { + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BasRegionUserService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BasRegionUserService.cs new file mode 100644 index 00000000..172c4134 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/BasRegionUserService.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Aspose.Cells.Drawing; +using JNPF.Common.Dtos.VisualDev; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + [OverideVisualDev(ModuleId)] + public class BasRegionUserService : IOverideVisualDevService, IBasRegionUserService, IDynamicApiController, ITransient + { + private const string ModuleId = "26169876750629"; + private readonly ISqlSugarClient _db; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private static Dictionary _dicRegion = new Dictionary(); + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public BasRegionUserService(ISqlSugarRepository repository, IRunService runService, IVisualDevService visualDevService) + { + _db = repository.AsSugarClient(); + _runService = runService; + _visualDevService = visualDevService; + OverideFuncs.CreateAsync = Create; + } + + private async Task Create(VisualDevModelDataCrInput input) + { + if (_dicRegion.Count < 1) + { + _dicRegion = await _db.Queryable().ToDictionaryAsync(x => x.id, x => x.region_name); + } + if (input.data.ContainsKey(nameof(BasRegionUser.region_id)) && input.data.ContainsKey(nameof(BasRegionUser.user_id))) + { + var regionId = input.data[nameof(BasRegionUser.region_id)].ToString(); + var userId = input.data[nameof(BasRegionUser.user_id)].ToString(); + var user = await _db.Queryable().Where(it => it.region_id == regionId && it.user_id == userId).FirstAsync(); + if (user != null) + { + throw new AppFriendlyException($"区域【{_dicRegion[regionId]}】,已存在用户【{user.user_name}】", 500); + } + } + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + await _runService.Create(templateEntity, input); + return await Task.FromResult(true); + } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs new file mode 100644 index 00000000..c8c37253 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Core.Manager; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys.Dto.VisualDevModelData; +using JNPF.VisualDev.Interfaces; +using SqlSugar; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Enums; +using Tnb.WarehouseMgr.Interfaces; +using JNPF.Common.Extension; +using JNPF.VisualDev.Entitys; +using Aspose.Cells.Drawing; +using Microsoft.AspNetCore.Mvc; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具台账服务 + /// + [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + //[OverideVisualDev(ModuleId)] + public class WmsCarryLedgerService : IOverideVisualDevService, IWmsCarryLedgerService, IDynamicApiController, ITransient + { + private const string ModuleId = "26038721525029"; + private readonly ISqlSugarClient _db; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private static Dictionary _dicCarryStatus = new(); //载具状态 + private static Dictionary _dicOutStatus = new(); //出库类型 + private static Dictionary _dicIsCheck = new() //是否检验 + { + [0] = "未检验", + [1] = "已检验", + }; + private static Dictionary _dicIsEnabled = new() + { + [0] = "启用", + [1] = "禁用", + }; + private static Dictionary _dicIsLock = new() + { + [0] = "未锁定", + [1] = "锁定", + }; + + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public WmsCarryLedgerService(ISqlSugarRepository repository, IRunService runService, IVisualDevService visualDevService) + { + _db = repository.AsSugarClient(); + _runService = runService; + _visualDevService = visualDevService; + //OverideFuncs.GetListAsync = GetList; + } + + private async Task GetList(VisualDevModelListQueryInput input) + { + if (_dicCarryStatus.Count < 1) + { + _dicCarryStatus = typeof(EnumCarryStatus).GetEnumDictionary(); + } + if (_dicOutStatus.Count < 1) + { + _dicOutStatus = typeof(EnumOutStatus).GetEnumDictionary(); + } + + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + var data = await _runService.GetListResult(templateEntity, input); + if (data?.list?.Count > 0) + { + //foreach (var item in data.list) + //{ + // if (item.ContainsKey(nameof(WmsCarryH.carry_status)) && item[nameof(WmsCarryH.carry_status)].IsNotEmptyOrNull()) + // { + // item[nameof(WmsCarryH.carry_status)] = _dicCarryStatus[item[nameof(WmsCarryH.carry_status)].ParseToInt()]; + // } + // if (item.ContainsKey(nameof(WmsCarryH.out_status)) && item[nameof(WmsCarryH.out_status)].IsNotEmptyOrNull()) + // { + // item[nameof(WmsCarryH.out_status)] = _dicOutStatus[item[nameof(WmsCarryH.out_status)].ParseToInt()]; + // } + // if (item.ContainsKey(nameof(WmsCarryH.is_lock)) && item[nameof(WmsCarryH.is_lock)].IsNotEmptyOrNull()) + // { + // item[nameof(WmsCarryH.is_lock)] = _dicIsLock[item[nameof(WmsCarryH.is_lock)].ParseToInt()]; + // } + // if (item.ContainsKey(nameof(WmsCarryH.is_check)) && item[nameof(WmsCarryH.is_check)].IsNotEmptyOrNull()) + // { + // item[nameof(WmsCarryH.is_check)] = _dicIsCheck[item[nameof(WmsCarryH.is_check)].ParseToInt()]; + // } + // if (item.ContainsKey(nameof(WmsCarryH.status)) && item[nameof(WmsCarryH.status)].IsNotEmptyOrNull()) + // { + // item[nameof(WmsCarryH.status)] = _dicIsEnabled[item[nameof(WmsCarryH.status)].ParseToInt()]; + // } + //} + } + return data; + } + + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs index a25dbeb2..1f341320 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs @@ -88,6 +88,7 @@ namespace Tnb.WarehouseMgr 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; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsFeedingService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsFeedingService.cs index 47b0d20f..8073fd6d 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsFeedingService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsFeedingService.cs @@ -41,16 +41,17 @@ namespace Tnb.WarehouseMgr { dicMaterial = await _db.Queryable().ToDictionaryAsync(x => x.id, x => x.name); } - var items = await _db.Queryable().Where(it => it.carry_id == carryId) - .Select(it => new CarryCodeDetailOutput + var items = await _db.Queryable().Where(a => a.carry_id == carryId) + .Select(a => new CarryCodeDetailOutput { - barcode = it.barcode, - code_batch = it.code_batch, - codeqty = it.codeqty, - material_code = it.material_code, - material_id = it.material_id, + barcode = a.barcode, + code_batch = a.code_batch, + codeqty = a.codeqty, + material_code = a.material_code, + material_id = a.material_id, + unit_id = a.unit_id, }) - .Mapper(it => it.material_name = dicMaterial.ContainsKey(it.material_id) ? dicMaterial[it.material_id].ToString() : "") + .Mapper(it => it.material_name = dicMaterial.ContainsKey(it.material_id) ? dicMaterial[it.material_id].ToString()! : "") .ToListAsync(); return items; }