From 36e4944e5e5bbfbc91b582f50f0af023ae172df8 Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Tue, 5 Sep 2023 16:15:18 +0800 Subject: [PATCH 1/2] 1 --- .../Entity/ToolMoldMaintainPlanRelation.cs | 3 + .../Entity/ToolMoldMaintainRunRecordD.cs | 2 + EquipMgr/Tnb.EquipMgr/Tnb.EquipMgr.csproj | 1 + .../ToolMoldMaintainRuleService.cs | 77 ++++++++++++++++++- .../ToolMoldMaintainRunService.cs | 31 +++++++- .../Listener/MoldMaintainTask.cs | 66 ++++++++++++++++ 6 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 taskschedule/Tnb.TaskScheduler/Listener/MoldMaintainTask.cs diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs index 7218b75f..4a0ec1b5 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs @@ -26,6 +26,9 @@ public partial class ToolMoldMaintainPlanRelation : BaseEntity /// public string mold_id { get; set; } = string.Empty; + public string group_id { get; set; } = string.Empty; + + } diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecordD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecordD.cs index 04a23a42..20f684dc 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecordD.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecordD.cs @@ -39,4 +39,6 @@ public partial class ToolMoldMaintainRunRecordD : BaseEntity /// public string? check_item_name { get; set; } + public string? mainid { get; set; } + } diff --git a/EquipMgr/Tnb.EquipMgr/Tnb.EquipMgr.csproj b/EquipMgr/Tnb.EquipMgr/Tnb.EquipMgr.csproj index 94325618..ad5c6e86 100644 --- a/EquipMgr/Tnb.EquipMgr/Tnb.EquipMgr.csproj +++ b/EquipMgr/Tnb.EquipMgr/Tnb.EquipMgr.csproj @@ -11,6 +11,7 @@ + diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs index c39705c9..9490814b 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs @@ -2,11 +2,14 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; +using System.Reactive; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Aop.Api.Domain; using Aspose.Cells.Drawing; using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Security; using JNPF.DependencyInjection; @@ -14,11 +17,18 @@ using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Interfaces.System; +using JNPF.TaskScheduler; +using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler; +using JNPF.TaskScheduler.Entitys.Model; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.CodeAnalysis.CSharp.Syntax; using SqlSugar; using Tnb.BasicData; +using Tnb.BasicData.Entities; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Interfaces; @@ -30,17 +40,78 @@ namespace Tnb.EquipMgr /// [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] - public class ToolMoldMaintainRuleService : IToolMoldMaintainRuleService, IDynamicApiController, ITransient + [OverideVisualDev(ModuleId)] + public class ToolMoldMaintainRuleService : IOverideVisualDevService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient { + + private const string ModuleId = "26164864904981"; private readonly ISqlSugarClient _db; private readonly IUserManager _userManager; private readonly IDictionaryDataService _dictionaryDataService; - - public ToolMoldMaintainRuleService(ISqlSugarRepository repository, IUserManager userManager, IDictionaryDataService dictionaryDataService) + private readonly TimeTaskService _timeTaskService; + private readonly IVisualDevService _visualDevService; + private readonly IRunService _runService; + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public ToolMoldMaintainRuleService(ISqlSugarRepository repository, IUserManager userManager, IDictionaryDataService dictionaryDataService, TimeTaskService timeTaskService, IVisualDevService visualDevService, IRunService runService) { _db = repository.AsSugarClient(); _userManager = userManager; _dictionaryDataService = dictionaryDataService; + _timeTaskService = timeTaskService; + _visualDevService = visualDevService; + _runService = runService; + OverideFuncs.DeleteAsync = Delete; + OverideFuncs.CreateAsync = Create; + } + private async Task Create(VisualDevModelDataCrInput input) + { + int cycle = int.Parse(input.data["cycle"].ToString()!); + var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(long.Parse(input.data["startandend_date"].ToString()!)); + ToolMoldMaintainRule toolMoldMaintainRule = new ToolMoldMaintainRule(); + toolMoldMaintainRule.id = SnowflakeIdHelper.NextId(); + toolMoldMaintainRule.mode = input.data["mode"].ToString(); + toolMoldMaintainRule.cycle = cycle; + toolMoldMaintainRule.startandend_date = startTime.ToString("yyyy-MM-dd HH:mm:ss"); + await _db.Insertable(toolMoldMaintainRule).ExecuteCommandAsync(); + if (toolMoldMaintainRule.mode == "27118635748885") + { + string id = toolMoldMaintainRule.id; + var comtentModel = new ContentModel(); + comtentModel.cron = "0 0 9 "+ startTime.Day + "/"+ toolMoldMaintainRule.cycle + " * ?"; + comtentModel.interfaceId = ""; + comtentModel.interfaceName = ""; + comtentModel.parameter = new List(); + comtentModel.parameter!.Add(new InterfaceParameter() { field = "id", value = id, defaultValue = "" }); + comtentModel.localHostTaskId = "MoldMaintainTask/CreateTask"; + comtentModel.startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + comtentModel.TenantId = _userManager?.TenantId!; + comtentModel.TenantDbName = _userManager?.TenantDbName!; + comtentModel.ConnectionConfig = _userManager?.ConnectionConfig!; + comtentModel.Token = _userManager?.ToKen!; + TimeTaskCrInput timeTaskCrInput = new TimeTaskCrInput() + { + enCode = DateTime.Now.ToString("yyyyMMddHHmmss"), + fullName = "生成模具保养任务" + id, + executeType = "3", + executeContent = comtentModel.ToJsonString(), + description = "", + sortCode = 99, + enabledMark = 1, + }; + await _timeTaskService.DeleteByName(timeTaskCrInput.fullName); + await _timeTaskService.Create(timeTaskCrInput, false); + } + return await Task.FromResult(true); + } + private async Task Delete(string id) + { + var ToolMoldMaintainRule = await _db.Queryable().Where(p => p.id == id).FirstAsync(); + var ToolMoldMaintainRuleRelations = await _db.Queryable().Where(p => p.rule_id == id).ToListAsync(); + await _timeTaskService.DeleteByName("生成模具保养任务" + id); + await _db.Ado.BeginTranAsync(); + await _db.Deleteable(ToolMoldMaintainRule).ExecuteCommandAsync(); + await _db.Deleteable(ToolMoldMaintainRuleRelations).ExecuteCommandAsync(); + await _db.Ado.CommitTranAsync(); } /// /// 根据规则Id获取匹配的模具列表 diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs index f9b3691d..72038c0d 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs @@ -135,6 +135,10 @@ namespace Tnb.EquipMgr item_name = e.name, }) .ToListAsync(); + //新增功能 + var ToolMoldMaintainPlanRelation= _db.Queryable().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id&& !string.IsNullOrEmpty(a.group_id)).First(); + if (ToolMoldMaintainPlanRelation != null) + items = items.Where(a => a.item_group_id == ToolMoldMaintainPlanRelation.group_id).ToList(); 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, @@ -183,7 +187,7 @@ namespace Tnb.EquipMgr var isOk = await _db.Updateable(mold).Where(it => it.id == input.mold_id).ExecuteCommandHasChangeAsync(); if (!isOk) throw Oops.Oh(ErrorCode.COM1001); var plan = await _db.Queryable().LeftJoin((a, b) => a.maintain_plan_id == b.id) - .Where(a => a.mold_id == input.mold_id).Select((a, b) => b).FirstAsync(); + .Where(a => a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).Select((a, b) => b).FirstAsync(); if (plan is not null) { @@ -200,6 +204,10 @@ namespace Tnb.EquipMgr var row = await _db.Insertable(record).ExecuteCommandAsync(); if (row < 1) throw Oops.Oh(ErrorCode.COM1001); + + var groupids = _db.Queryable().Where(a => !string.IsNullOrEmpty(a.group_id) && a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).ToList().Select(p => p.group_id); + + /* var maintainInfos = await _db.Queryable() .LeftJoin((a, b) => a.item_group_id == b.id) .LeftJoin((a, b, c) => b.id == c.item_group_id) @@ -213,12 +221,27 @@ namespace Tnb.EquipMgr check_item_name = d.name }) .ToListAsync(); + */ + var maintainInfos = await _db.Queryable() + .LeftJoin((a, b) => a.item_group_id == b.id) + .LeftJoin((a, b, c) => b.id == c.item_group_id) + .LeftJoin((a, b, c, d) => c.item_id == d.id) + .WhereIF(groupids.Count() > 0, (a) => groupids.Contains(a.item_group_id)) + .Where(a => a.mold_id == input.mold_id) + .Select((a, b, c, d) => new + { + group_id = b.id, + group_name = b.name, + check_item_id = d.id, + check_item_name = d.name + }).ToListAsync(); if (maintainInfos?.Count > 0) { List recordDs = new(); foreach (var info in maintainInfos) { ToolMoldMaintainRunRecordD record_d = new(); + record_d.mainid = record.id; record_d.group_id = info.group_id; record_d.group_name = info.group_name; record_d.check_item_id = info.check_item_id; @@ -253,6 +276,7 @@ namespace Tnb.EquipMgr record.mold_id = input.mold_id; record.item_group_id = item.item_group_id; record.item_id = item.item_id; + record.status = 1; records.Add(record); } var row = await _db.Insertable(records).ExecuteCommandAsync(); @@ -283,6 +307,11 @@ namespace Tnb.EquipMgr item_name = e.name, }) .ToListAsync(); + //新增功能 + var ToolMoldMaintainPlanRelation = _db.Queryable().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id && !string.IsNullOrEmpty(a.group_id)).First(); + if (ToolMoldMaintainPlanRelation != null) + items = items.Where(a => a.item_group_id == ToolMoldMaintainPlanRelation.group_id).ToList(); + 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, diff --git a/taskschedule/Tnb.TaskScheduler/Listener/MoldMaintainTask.cs b/taskschedule/Tnb.TaskScheduler/Listener/MoldMaintainTask.cs new file mode 100644 index 00000000..6bcbd9ff --- /dev/null +++ b/taskschedule/Tnb.TaskScheduler/Listener/MoldMaintainTask.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF; +using JNPF.Common.Security; +using JNPF.Systems.Entitys.System; +using JNPF.TaskScheduler; +using JNPF.TaskScheduler.Entitys.Model; +using SqlSugar; +using Tnb.EquipMgr.Entities; +using Tnb.ProductionMgr.Entities; +using Tnb.QcMgr.Entities; +using Tnb.QcMgr.Entities.Entity; + +namespace Tnb.TaskScheduler.Listener +{ + internal class MoldMaintainTask : ISpareTimeWorker + { + private ISqlSugarRepository repository => App.GetService>(); + [SpareTime("0 0 0 * * ?", "生成模具保养任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)] + public async void CreateTask(SpareTimer timer, long count) + { + try + { + var timeTaskEntity = await repository.AsSugarClient().Queryable().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync(); + if (timeTaskEntity == null) + return; + ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject(); + var ToolMoldMaintainRule = await repository.AsSugarClient().Queryable().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync(); + if (ToolMoldMaintainRule == null) + return; + var ToolMoldMaintainRuleRelations= await repository.AsSugarClient().Queryable().Where(p => p.rule_id == ToolMoldMaintainRule.id).ToListAsync(); + if (ToolMoldMaintainRuleRelations.Count() > 0) + { + var now = DateTime.Now; + Random rNum = new Random(); + ToolMoldMaintainPlan toolMoldMaintainPlan=new ToolMoldMaintainPlan(); + toolMoldMaintainPlan.id = SnowflakeIdHelper.NextId(); + toolMoldMaintainPlan.plan_code = "JHDM" + now.ToString("yyyyMMdd") + rNum.Next(1000, 9999).ToString(); + toolMoldMaintainPlan.mode = ToolMoldMaintainRule.mode; + toolMoldMaintainPlan.status = "UnMaintain"; + toolMoldMaintainPlan.plan_start_date = now; + toolMoldMaintainPlan.plan_end_date = now.AddDays((double)ToolMoldMaintainRule.cycle!); + List toolMoldMaintainPlanRelations = new List(); + foreach (var ToolMoldMaintainRuleRelation in ToolMoldMaintainRuleRelations) + { + ToolMoldMaintainPlanRelation toolMoldMaintainPlanRelation = new ToolMoldMaintainPlanRelation(); + toolMoldMaintainPlanRelation.id= SnowflakeIdHelper.NextId(); + toolMoldMaintainPlanRelation.maintain_plan_id = toolMoldMaintainPlan.id; + toolMoldMaintainPlanRelation.mold_id = ToolMoldMaintainRuleRelation.mold_id; + toolMoldMaintainPlanRelation.group_id = ToolMoldMaintainRuleRelation.item_group_id; + toolMoldMaintainPlanRelations.Add(toolMoldMaintainPlanRelation); + } + await repository.AsSugarClient().Insertable(toolMoldMaintainPlanRelations).ExecuteCommandAsync(); + await repository.AsSugarClient().Insertable(toolMoldMaintainPlan).ExecuteCommandAsync(); + } + } + catch (Exception) + { + } + + } + } +} From d0af0552a36ba502385c0c04b15e6963595f0029 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Tue, 5 Sep 2023 16:36:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8E=92=E4=BA=A7=E8=87=B3=E5=B7=A5?= =?UTF-8?q?=E4=BD=8D=20pc=E7=AB=AF=E6=B3=A8=E5=A1=91=E6=8C=A4=E5=87=BA?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=AE=A1=E7=90=86=20=E7=BB=84=E8=A3=85?= =?UTF-8?q?=E5=8C=85=E8=A3=85=E4=BB=BB=E5=8A=A1=E7=AE=A1=E7=90=86=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B7=A5=E4=BD=8D=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IBasQrcodeService.cs | 23 +++++ BasicData/Tnb.BasicData/BasQrcodeService.cs | 84 +++++++++++++++++++ BasicData/Tnb.BasicData/Tnb.BasicData.csproj | 1 + .../Dto/PrdManage/PrdPackReportQueryInput.cs | 4 + .../Tnb.ProductionMgr/PrdMoTaskService.cs | 17 ++++ .../Tnb.ProductionMgr/PrdPackReportService.cs | 18 ++-- .../Tnb.ProductionMgr/PrdTaskManageService.cs | 8 ++ 7 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 BasicData/Tnb.BasicData.Interfaces/IBasQrcodeService.cs create mode 100644 BasicData/Tnb.BasicData/BasQrcodeService.cs diff --git a/BasicData/Tnb.BasicData.Interfaces/IBasQrcodeService.cs b/BasicData/Tnb.BasicData.Interfaces/IBasQrcodeService.cs new file mode 100644 index 00000000..d47f3649 --- /dev/null +++ b/BasicData/Tnb.BasicData.Interfaces/IBasQrcodeService.cs @@ -0,0 +1,23 @@ +namespace Tnb.BasicData.Interfaces +{ + + /// + /// 二维码 + /// + public interface IBasQrcodeService + { + /// + /// 根据code获取qrcode + /// + /// + /// + public Task GetQrcodeByCode(Dictionary dic); + + /// + /// 根据code获取工位信息 + /// + /// + /// + public Task GetWorkStationByCode(Dictionary dic); + } +} \ No newline at end of file diff --git a/BasicData/Tnb.BasicData/BasQrcodeService.cs b/BasicData/Tnb.BasicData/BasQrcodeService.cs new file mode 100644 index 00000000..0c51d040 --- /dev/null +++ b/BasicData/Tnb.BasicData/BasQrcodeService.cs @@ -0,0 +1,84 @@ +using JNPF.Common.Core.Manager; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Interfaces.System; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.BasicData.Entities.Dto; +using Tnb.BasicData.Entitys.Dto.BasProcess; +using Tnb.BasicData.Interfaces; +using Tnb.EquipMgr.Entities; + +namespace Tnb.BasicData +{ + /// + /// 二维码 + /// + [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)] + [Route("api/[area]/[controller]/[action]")] + public class BasQrcodeService : IBasQrcodeService,IDynamicApiController, ITransient + { + private readonly ISqlSugarRepository _repository; + private readonly DataBaseManager _dbManager; + private readonly IDictionaryDataService _dictionaryDataService; + + public BasQrcodeService( + ISqlSugarRepository repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService) + { + _repository = repository; + _dbManager = dbManager; + _dictionaryDataService = dictionaryDataService; + } + + [HttpPost] + public async Task GetQrcodeByCode(Dictionary dic) + { + string code = dic.ContainsKey("code") ? dic["code"] : ""; + if (string.IsNullOrEmpty(code)) return null; + var result = await _repository.AsSugarClient().Queryable() + .LeftJoin((a, b) => a.source_id == b.Id) + .LeftJoin((a, b, c) => a.source_id == c.id) + .LeftJoin((a, b, c, d) => a.source_id == d.id) + .Where((a, b, c, d) => a.code == code) + .Select((a, b, c, d) => new + { + id = a.id, + source_id = a.source_id, + source_name = a.source_name, + org_code = b.EnCode, + org_name = b.FullName, + equip_code = a.code, + equip_name = c.name, + tool_location_code = d.location_code, + }).FirstAsync(); + return result; + } + + [HttpPost] + public async Task GetWorkStationByCode(Dictionary dic) + { + string code = dic.ContainsKey("code") ? dic["code"] : ""; + if (string.IsNullOrEmpty(code)) return null; + var result = await _repository.AsSugarClient().Queryable() + .LeftJoin((a, b) => a.source_id == b.Id) + .LeftJoin((a,b,c)=>a.source_id==c.ObjectId && c.ObjectType=="Eqp") + .LeftJoin((a,b,c,d)=>c.OrganizeId==d.Id) + .Where((a, b, c) => a.code == code) + .Select((a, b, c,d) => new + { + id = a.id, + source_id = a.source_id, + source_name = a.source_name, + org_id = b.Id, + org_code = b.EnCode, + org_name = b.FullName, + org_id2 = d.Id, + org_code2 = d.EnCode, + org_name2 = d.FullName, + }).FirstAsync(); + return result; + } + } +} \ No newline at end of file diff --git a/BasicData/Tnb.BasicData/Tnb.BasicData.csproj b/BasicData/Tnb.BasicData/Tnb.BasicData.csproj index 5ce642a8..b53e3d81 100644 --- a/BasicData/Tnb.BasicData/Tnb.BasicData.csproj +++ b/BasicData/Tnb.BasicData/Tnb.BasicData.csproj @@ -9,6 +9,7 @@ + diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs index 99c5bcb4..736f3fe4 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs @@ -31,5 +31,9 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// 工序 /// public string process { get; set; } + /// + /// 工位id + /// + public string stationId { get; set; } } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 0158bfca..dca6214a 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -678,6 +678,13 @@ namespace Tnb.ProductionMgr moTask.scheduled_qty = input.scheduled_qty; moTask.unit_id = mo.unit_id; + if (!string.IsNullOrEmpty(input.eqp_id)) + { + OrganizeRelationEntity organizeRelationEntity = await db.Queryable() + .Where(x => x.ObjectId == input.eqp_id && x.ObjectType == "Eqp").FirstAsync(); + moTask.workstation_id = organizeRelationEntity?.OrganizeId ?? ""; + } + var moCode = mo?.mo_code; var taskCode = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.PRDMOTASK_CODE); moTask.mo_task_code = taskCode; @@ -944,10 +951,19 @@ namespace Tnb.ProductionMgr .ToListAsync(); if (subTaskList?.Count > 0) { + List workstationIds = await _db.Queryable().Where(x => + x.Category == DictConst.RegionCategoryStationCode && + x.OrganizeIdTree.Contains(input.workline_id)).Select(x=>x.Id).ToListAsync(); + + List subMoTasks = new(); List subMoTaskLogs = new(); foreach (var item in subTaskList) { + BasMbomProcess basMbomProcess = await _db.Queryable().SingleAsync(x=>x.id==item.mbom_process_id); + List mbomProcessStationIds = JsonConvert.DeserializeObject(basMbomProcess.station).Select(x=>x[x.Length-1]).ToList(); + List? resultList = workstationIds.Intersect(mbomProcessStationIds).ToList(); + PrdMoTask subMoTask = new(); subMoTask.mo_id = input.mo_id; subMoTask.material_id = item.material_id; @@ -956,6 +972,7 @@ namespace Tnb.ProductionMgr subMoTask.bom_id = input.bom_id; subMoTask.process_id = item.process_id; subMoTask.mbom_process_id = item.mbom_process_id; + subMoTask.workstation_id = resultList?.FirstOrDefault() ?? ""; subMoTask.mo_task_status = DictConst.ToBeScheduledEncode; subMoTask.workroute_id = item.route_id; subMoTask.workline_id = input.workline_id; diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs index 62cf4e1d..91ccecbf 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs @@ -49,6 +49,8 @@ namespace Tnb.ProductionMgr public async Task GetList(PrdPackReportQueryInput input) { if (input == null) throw new ArgumentNullException("input"); + if (string.IsNullOrEmpty(input.stationId)) return Array.Empty(); + List trees = new(); var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); var list = await _db.Queryable().Where(it => it.Category == "workline").ToListAsync(); @@ -75,13 +77,17 @@ namespace Tnb.ProductionMgr endTimes[1] = GetDateTimeMilliseconds(input.estimated_end_date![1]); } - var items = await _db.Queryable().LeftJoin((a, b) => a.process_id == b.id).LeftJoin((a, b, c) => a.mo_id == c.id) + var items = await _db.Queryable() + .LeftJoin((a, b) => a.process_id == b.id) + .LeftJoin((a, b, c) => a.mo_id == c.id) + .LeftJoin((a,b,c,d)=>a.id==d.parent_id) .WhereIF(!string.IsNullOrEmpty(input.mo_task_code), a => a.mo_task_code == input.mo_task_code.Trim()) // .WhereIF(start, a => a.estimated_start_date != null&& startTimes[0] <= a.estimated_start_date && startTimes[1] >= a.estimated_start_date) // .WhereIF(end, a => a.estimated_end_date != null && endTimes[0] <= a.estimated_end_date && endTimes[1] >= a.estimated_end_date) .WhereIF(!string.IsNullOrEmpty(input.workline), a => list.Where(p => p.EnCode.Contains(input.workline) || p.FullName.Contains(input.workline)).Select(p => p.Id).ToList().Contains(a.workline_id!)) .Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled") - .OrderByDescending(a=>a.create_time) + .Where((a,b,c,d)=>d.workstation_id==input.stationId) + .OrderByDescending(a=>a.create_time) .Select((a, b, c) => new PrdMoTask { id = a.id, @@ -122,7 +128,7 @@ namespace Tnb.ProductionMgr } node.plan_start_date = item.plan_start_date.HasValue ? item.plan_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; node.plan_end_date = item.plan_end_date.HasValue ? item.plan_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; - await GetChild(item.id, trees, dic); + await GetChild(item.id, trees, dic,input.stationId); trees.Add(node); } } @@ -170,13 +176,13 @@ namespace Tnb.ProductionMgr return dt; } - private async Task GetChild(string parentId, List nodes, Dictionary dic) + private async Task GetChild(string parentId, List nodes, Dictionary dic,string stationId) { var items = await _db.Queryable() .LeftJoin((a, b) => a.process_id == b.id) .LeftJoin((a, b, c) => a.mo_id == c.id) .LeftJoin((a, b, c, d) => a.mbom_process_id == d.id) - .Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled") + .Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled" && a.workstation_id==stationId) .OrderBy((a, b, c, d) => d.ordinal) .Select((a, b, c) => new PrdMoTask { @@ -222,7 +228,7 @@ namespace Tnb.ProductionMgr nodes.AddRange(nsChild); foreach (var item in items) { - await GetChild(item.id, nodes, dic); + await GetChild(item.id, nodes, dic,stationId); } } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs index d3903b74..341427ce 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs @@ -119,6 +119,13 @@ namespace Tnb.ProductionMgr var db = _repository.AsSugarClient(); Dictionary queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject>(input.queryJson) : new Dictionary(); string moTaskCode = queryJson!=null && queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : ""; + string stationId = queryJson!=null && queryJson.ContainsKey("stationId") ? queryJson["stationId"].ToString() : ""; + + if (string.IsNullOrEmpty(stationId)) + { + return Array.Empty(); + } + Dictionary dic = await _dictionaryDataService.GetDicByKey(DictConst.TaskStatus); DateTime[] planStartDateArr = null; @@ -142,6 +149,7 @@ namespace Tnb.ProductionMgr .WhereIF(!string.IsNullOrEmpty(moTaskCode),(a,b,c,d)=>a.mo_task_code.Contains(moTaskCode)) .WhereIF(planStartDateArr!=null, (a, b, c, d) => a.estimated_start_date>=planStartDateArr[0] && a.estimated_start_date<=planStartDateArr[1]) .WhereIF(planEndDateArr!=null, (a, b, c, d) => a.estimated_end_date>=planEndDateArr[0] && a.estimated_end_date<=planEndDateArr[1]) + .Where((a,b,c,d)=>a.workstation_id==stationId) .OrderByDescending((a, b, c, d) => a.create_time) .Select((a, b, c, d) => new PrdTaskManageListOutput() {