diff --git a/PerMgr/Tnb.PerMgr.Entities/Dto/ProcessChildDataInput.cs b/PerMgr/Tnb.PerMgr.Entities/Dto/ProcessChildDataInput.cs new file mode 100644 index 00000000..1e8b577e --- /dev/null +++ b/PerMgr/Tnb.PerMgr.Entities/Dto/ProcessChildDataInput.cs @@ -0,0 +1,13 @@ +namespace Tnb.PerMgr.Entities.Dto +{ + public class ProcessChildDataInput + { + + public string process_standards_id { get; set; } + /// + /// 工艺参数id + /// + public string process_param_id { get; set; } + public decimal value { get; set; } + } +} \ No newline at end of file diff --git a/PerMgr/Tnb.PerMgr.Entities/Dto/ProcessParamTypeChildrenOutput.cs b/PerMgr/Tnb.PerMgr.Entities/Dto/ProcessParamTypeChildrenOutput.cs new file mode 100644 index 00000000..1725773c --- /dev/null +++ b/PerMgr/Tnb.PerMgr.Entities/Dto/ProcessParamTypeChildrenOutput.cs @@ -0,0 +1,18 @@ +namespace Tnb.PerMgr.Entities.Dto +{ + public class ProcessParamTypeChildrenOutput + { + /// + /// 工艺标准子表id + /// + public string id { get; set; } + /// + /// 工艺参数id + /// + public string process_param_id { get; set; } + public string name { get; set; } + public decimal? value { get; set; } + public decimal upper_value { get; set; } + public decimal lower_value { get; set; } + } +} \ No newline at end of file diff --git a/PerMgr/Tnb.PerMgr.Entities/Entity/PerProcessStandardsD.cs b/PerMgr/Tnb.PerMgr.Entities/Entity/PerProcessStandardsD.cs new file mode 100644 index 00000000..bbf44f4a --- /dev/null +++ b/PerMgr/Tnb.PerMgr.Entities/Entity/PerProcessStandardsD.cs @@ -0,0 +1,42 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.PerMgr.Entities; + +/// +/// 工艺标准子表 +/// +[SugarTable("per_process_standards_d")] +public partial class PerProcessStandardsD : BaseEntity +{ + public PerProcessStandardsD() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 工艺标准主表id + /// + public string process_standards_id { get; set; } = string.Empty; + + /// + /// 工艺参数id + /// + public string process_param_id { get; set; } = string.Empty; + + /// + /// 设定值 + /// + public decimal value { get; set; } + + /// + /// 上限 + /// + public decimal? upper_value { get; set; } + + /// + /// 下限 + /// + public decimal? lower_value { get; set; } + +} \ No newline at end of file diff --git a/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessParamTypeService.cs b/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessParamTypeService.cs new file mode 100644 index 00000000..1b334363 --- /dev/null +++ b/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessParamTypeService.cs @@ -0,0 +1,28 @@ +using Tnb.PerMgr.Entities.Dto; +namespace Tnb.PerMgr.Interfaces +{ + public interface IPerProcessParamTypeService + { + /// + /// 根据设备id获取工艺参数类型和对应工艺参数 + /// + /// + /// + public Task GetProcessParamType(Dictionary dic); + + /// + /// 保存工艺参数子表 + /// + /// + /// + public Task SaveData(List input); + + + /// + /// 根据id获取修改信息 + /// + /// + /// + public Task GetProcessStandardsChildrenInfo(Dictionary dic); + } +} \ No newline at end of file diff --git a/PerMgr/Tnb.PerMgr/PerProcessParamTypeService.cs b/PerMgr/Tnb.PerMgr/PerProcessParamTypeService.cs new file mode 100644 index 00000000..efcc1955 --- /dev/null +++ b/PerMgr/Tnb.PerMgr/PerProcessParamTypeService.cs @@ -0,0 +1,131 @@ +using JNPF.Common.Core.Manager; +using JNPF.Common.Enums; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.EquipMgr.Entities; +using Tnb.PerMgr.Entities; +using Tnb.PerMgr.Entities.Dto; +using Tnb.PerMgr.Interfaces; + +namespace Tnb.PerMgr +{ + /// + /// 工艺参数类型 + /// + [ApiDescriptionSettings + (Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + public class PerProcessParamTypeService : IPerProcessParamTypeService, IDynamicApiController, ITransient + { + private readonly ISqlSugarRepository _repository; + private readonly IUserManager _userManager; + + public PerProcessParamTypeService(ISqlSugarRepository repository, IUserManager userManager) + { + _userManager = userManager; + _repository = repository; + } + + [HttpPost] + public async Task GetProcessParamType(Dictionary dic) + { + string equipId = dic["equip_id"]; + var db = _repository.AsSugarClient(); + var equipment = await db.Queryable().Where(x => x.id == equipId).SingleAsync(); + string equipTypeId = equipment?.equip_type_id; + + //List perProcessParamTypes = await _repository.GetListAsync(x => x.equip_type_id == equipTypeId); + var result = await db.Queryable() + .Where(x => x.equip_type_id == equipTypeId) + .OrderBy(x=>x.ordinal) + .Select(x => new + { + tab_id = x.id, + tab_name = x.name, + children = SqlFunc.Subqueryable() + .LeftJoin((y,z)=>y.tolerance_category_id==z.id) + .Where(y=>y.process_param_type_id==x.id) + .OrderBy((y,z)=>y.ordinal) + .ToList((y,z)=>new ProcessParamTypeChildrenOutput + { + process_param_id = y.id, + name = y.name, + upper_value = z.upper_value, + lower_value = z.lower_value + }), + }).ToListAsync(); + + + return result; + + } + + [HttpPost] + public async Task SaveData(List input) + { + var db = _repository.AsSugarClient(); + DbResult result = await db.Ado.UseTranAsync(async () => + { + + List list = new List(); + if (input != null && input.Count > 0) + { + foreach (var item in input) + { + list.Add(new PerProcessStandardsD() + { + process_standards_id = item.process_standards_id, + process_param_id = item.process_param_id, + value = item.value + }); + } + + await db.Insertable(list).ExecuteCommandAsync(); + } + + }); + if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008); + + return result.IsSuccess ? "保存成功" : result.ErrorMessage; + } + + [HttpPost] + public async Task GetProcessStandardsChildrenInfo(Dictionary dic) + { + string id = dic["id"]; + var db = _repository.AsSugarClient(); + var perProcessStandardsH = await db.Queryable().SingleAsync(x => x.id == id); + var equipment = await db.Queryable().Where(x => x.id == perProcessStandardsH.equip_id).SingleAsync(); + string equipTypeId = equipment?.equip_type_id; + + var result = await db.Queryable() + .Where(a => a.equip_type_id == equipTypeId) + .OrderBy(a=>a.ordinal) + .Select(a => new + { + tab_id = a.id, + tab_name = a.name, + children = SqlFunc.Subqueryable() + .LeftJoin((b,c)=>b.process_param_id==c.id) + .LeftJoin((b,c,d)=>c.tolerance_category_id==d.id) + .Where((b,c,d)=>c.process_param_type_id==a.id && b.process_standards_id==id) + .OrderBy((b,c,d)=>c.ordinal) + .ToList((b,c,d)=>new ProcessParamTypeChildrenOutput + { + id = b.id, + process_param_id = c.id, + name = c.name, + value = b.value, + upper_value = d.upper_value, + lower_value = d.lower_value + }), + }).ToListAsync(); + + + return result; + } + } +} \ No newline at end of file diff --git a/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj b/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj index 720e38c1..ddd2d646 100644 --- a/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj +++ b/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj @@ -7,6 +7,7 @@ + diff --git a/apihost/Tnb.API.Entry/Configurations/App.json b/apihost/Tnb.API.Entry/Configurations/App.json index 88325a5f..2610456e 100644 --- a/apihost/Tnb.API.Entry/Configurations/App.json +++ b/apihost/Tnb.API.Entry/Configurations/App.json @@ -187,5 +187,6 @@ "DoMainPc": "http://localhost:3000", // 前端PC外网能访问的地址(域名), 回调的时候拼接接口地址用 "DoMainApp": "http://localhost:8081", // 前端App外网能访问的地址(域名), 回调的时候拼接接口地址用 "AppPushUrl": "https://8e84eea8-6922-4033-8e86-67ad7442e692.bspapp.com/unipush" - } + }, + "IsStartTimeJob": true //是否开启定时任务 } \ No newline at end of file diff --git a/apihost/Tnb.API.Entry/Startup.cs b/apihost/Tnb.API.Entry/Startup.cs index f8da43b2..da09f6a4 100644 --- a/apihost/Tnb.API.Entry/Startup.cs +++ b/apihost/Tnb.API.Entry/Startup.cs @@ -109,6 +109,8 @@ public class Startup : AppStartup SnowflakeIdHelper.InitYitIdWorker(); - //serviceProvider.GetRequiredService().StartTimerJob(); + bool isStartTimeJob = App.GetConfig("IsStartTimeJob"); + if(isStartTimeJob) + serviceProvider.GetRequiredService().StartTimerJob(); } } \ No newline at end of file diff --git a/system/Tnb.Systems/System/DataBaseService.cs b/system/Tnb.Systems/System/DataBaseService.cs index 54c6977d..3d0bd55d 100644 --- a/system/Tnb.Systems/System/DataBaseService.cs +++ b/system/Tnb.Systems/System/DataBaseService.cs @@ -405,11 +405,7 @@ public class DataBaseService : IDynamicApiController, ITransient string sResult = string.Empty; foreach (var item in entities) { - sResult = _viewEngine.RunCompileFromCached(tplContent, item, builderAction: builder => - { - builder.AddUsing("System.Collections.Generic"); - builder.AddAssemblyReferenceByName("System.Collections"); - }); + sResult = _viewEngine.RunCompileFromCached(tplContent, item); var dir = Path.Combine(FileVariable.GenerateCodePath, item.nsName); Directory.CreateDirectory(dir); File.WriteAllText(Path.Combine(dir, item.clsName + ".cs"), sResult); diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index fbce46ad..37857265 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -60,13 +60,18 @@ namespace JNPF.TaskScheduler.Listener // } // } + //丢失精度补齐 例如设定10分钟执行 但是这个破框架会再9:59 时进入这个方法导致不能正常执行 + //精确到分的定时任务可以不使用本地任务 采用数据接口的方式规避掉这个问题 + int second = DateTime.Now.Second;//当前的秒数 + int offsetMinute = second > 30 ? 1 : 0; + //整除表示一个周期到了 foreach (var item in eqpSpotInsTemEquipHsByCirculate) { TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Ticks); TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(item.start_time.ToString("yyyy-MM-dd HH:mm")).Ticks); TimeSpan ts3 = ts1.Subtract(ts2).Duration(); - if (ts3.TotalMinutes * 10 / 60 % (10 * (double)item.plan_cycle)==0) + if ((ts3.TotalMinutes+offsetMinute) * 10 / 60 % (10 * (double)item.plan_cycle)==0) { tobeCreateTemplets.Add(item); } diff --git a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs index 4deb9035..14d06b18 100644 --- a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs +++ b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs @@ -284,7 +284,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie // 非多租户模式启动自启任务 if (!KeyVariable.MultiTenancy) { - //_repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(AddTimerJob); + _repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607 } } @@ -332,16 +332,17 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie /// 新增定时任务. /// /// - private async void AddTimerJob(TimeTaskEntity input) + private async void AddTimerJob(TimeTaskEntity input,bool startNow = true) { Action? action = null; ContentModel? comtentModel = input.ExecuteContent.ToObject(); input.ExecuteCycleJson = comtentModel.cron; + TaskMethodInfo? taskMethod = null; switch (input.ExecuteType) { case "3": // 查询符合条件的任务方法 - TaskMethodInfo? taskMethod = GetTaskMethods()?.Result.FirstOrDefault(m => m.id == comtentModel.localHostTaskId); + taskMethod = GetTaskMethods()?.Result.FirstOrDefault(m => m.id == comtentModel.localHostTaskId); if (taskMethod == null) break; // 创建任务对象 @@ -368,20 +369,19 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie { interval = (starTime.ParseToDateTime() - DateTime.Now).TotalMilliseconds.ParseToInt(); } - SpareTime.DoOnce(interval, action, "Once_" + input.Id); - SpareTime.Do( - () => - { - var isRun = comtentModel.endTime.IsNullOrEmpty() ? DateTime.Now >= starTime : DateTime.Now >= starTime && DateTime.Now < endTime; - if (isRun) - { - return SpareTime.GetCronNextOccurrence(comtentModel.cron); - } - else - { - return null; - } - }, + if (startNow) //modifyby zhoukeda 20230516 + { + SpareTime.DoOnce(interval, action, "Once_" + input.Id); + } + + Func nextHandle = null; + var isRun = comtentModel.endTime.IsNullOrEmpty() ? DateTime.Now >= starTime : DateTime.Now >= starTime && DateTime.Now < endTime; + if (isRun) + { + nextHandle = ()=>SpareTime.GetCronNextOccurrence(comtentModel.cron); + } + SpareTime.Do(nextHandle + , action, input.Id, comtentModel.ConnectionConfig.ToJsonString(), true, executeType: SpareTimeExecuteTypes.Parallel, cancelInNoneNextTime: false); }