diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs b/EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs new file mode 100644 index 00000000..7224dfc9 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs @@ -0,0 +1,25 @@ +namespace Tnb.EquipMgr +{ + /// + /// 设备生命周期 + /// + public static class EquipmentLife + { + /// + /// 启用 + /// + public const string ENABLE = "1"; + /// + /// 停用 + /// + public const string DISABLE = "2"; + /// + /// 库存 + /// + public const string STOCK = "3"; + /// + /// 报废 + /// + public const string SCRAP = "4"; + } +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs new file mode 100644 index 00000000..13a649e8 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs @@ -0,0 +1,150 @@ +using SqlSugar; +using Tnb.Common.Contracts; + +namespace Tnb.EquipMgr.Entities +{ + /// + ///设备点巡检项目 + /// + [SugarTable("eqp_spot_ins_item")] + public class EqpSpotInsItem : BaseEntity + { + public EqpSpotInsItem() + { + } + + /// + /// Desc:创建时间 + /// Default: + /// Nullable:True + /// + public DateTime? create_time { get; set; } + + /// + /// Desc:修改时间 + /// Default: + /// Nullable:True + /// + public DateTime? modify_time { get; set; } + + + /// + /// Desc:判断类型1数值2结果 + /// Default: + /// Nullable:False + /// + public string judge_type { get; set; } + + /// + /// Desc:上限值 + /// Default: + /// Nullable:True + /// + public decimal? high_value { get; set; } + + /// + /// Desc:是否包含上限值 + /// Default: + /// Nullable:True + /// + public int? high_value_is_include { get; set; } + + /// + /// Desc:下限值 + /// Default: + /// Nullable:True + /// + public decimal? low_value { get; set; } + + /// + /// Desc:是否包含下限值 + /// Default: + /// Nullable:True + /// + public int? low_value_is_include { get; set; } + + /// + /// Desc:标准值 + /// Default: + /// Nullable:True + /// + public decimal? standard_value { get; set; } + + /// + /// Desc:单位id + /// Default: + /// Nullable:False + /// + public string unit_id { get; set; } + + /// + /// Desc:排序 + /// Default: + /// Nullable:False + /// + public int ordinal { get; set; } + + /// + /// Desc:类型 1 点检 2巡检 + /// Default: + /// Nullable:False + /// + public string type { get; set; } + + /// + /// Desc:创建用户 + /// Default:NULL::character varying + /// Nullable:True + /// + public string create_id { get; set; } + + /// + /// Desc:修改用户 + /// Default:NULL::character varying + /// Nullable:True + /// + public string modify_id { get; set; } + + /// + /// Desc:编码 + /// Default:NULL::character varying + /// Nullable:True + /// + public string code { get; set; } + + /// + /// Desc:名称 + /// Default:NULL::character varying + /// Nullable:True + /// + public string name { get; set; } + + /// + /// Desc:判断内容 + /// Default:NULL::character varying + /// Nullable:True + /// + public string judge_content { get; set; } + + /// + /// Desc:点巡检方法 + /// Default:NULL::character varying + /// Nullable:True + /// + public string inspection_method { get; set; } + + /// + /// Desc:备注 + /// Default:NULL::character varying + /// Nullable:True + /// + public string remark { get; set; } + + /// + /// Desc:所属组织 + /// Default:NULL::character varying + /// Nullable:True + /// + public string org_id { get; set; } + } +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs index 7ac2a892..3e7c12bc 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs @@ -67,7 +67,7 @@ public partial class EqpSpotInsRecordD : BaseEntity /// Default: /// Nullable:True /// - public double? standard_value { get; set; } + public decimal? standard_value { get; set; } /// /// Desc:单位id @@ -131,4 +131,11 @@ public partial class EqpSpotInsRecordD : BaseEntity /// Nullable:True /// public string remark { get; set; } + + /// + /// Desc:点巡检设备模板id + /// Default:NULL::character varying + /// Nullable:True + /// + public string spot_ins_tem_equip_id {get;set;} } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs index 94a35273..cdcfec28 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs @@ -27,6 +27,7 @@ namespace Tnb.EquipMgr.Entities /// public DateTime? modify_time { get; set; } + /// /// Desc:设备id /// Default: @@ -70,18 +71,18 @@ namespace Tnb.EquipMgr.Entities public DateTime? send_date_time { get; set; } /// - /// Desc:滞后推送时间 + /// Desc:计划执行通知提前量 /// Default: /// Nullable:True /// - public DateTime? after_send_date_time { get; set; } + public int? plan_run_notice { get; set; } /// - /// Desc:是否滞后推送 + /// Desc:执行滞后推送时间 /// Default: /// Nullable:True /// - public int? is_after_send { get; set; } + public int? plan_delay { get; set; } /// /// Desc:创建用户 @@ -131,5 +132,81 @@ namespace Tnb.EquipMgr.Entities /// Nullable:True /// public string send_id { get; set; } + + /// + /// Desc:编码 + /// Default:NULL::character varying + /// Nullable:True + /// + public string code { get; set; } + + /// + /// Desc:计划执行通知提前量单位 1 小时 2 天 3 周 + /// Default:NULL::character varying + /// Nullable:True + /// + public string plan_run_notice_unit { get; set; } + + /// + /// Desc:执行滞后推送时间单位 1 小时 2 天 3 周 + /// Default:NULL::character varying + /// Nullable:True + /// + public string plan_delay_unit { get; set; } + + /// + /// Desc:复核岗位id + /// Default:NULL::character varying + /// Nullable:True + /// + public string repeat_post_info_user_id { get; set; } + + /// + /// Desc:责任岗位id + /// Default:NULL::character varying + /// Nullable:True + /// + public string send_post_info_user_id { get; set; } + + /// + /// Desc:是否复核 + /// Default:NULL::character varying + /// Nullable:True + /// + public string is_repeat { get; set; } + + /// + /// Desc:复核时间 + /// Default: + /// Nullable:True + /// + public DateTime? repeat_time {get;set;} + + /// + /// Desc:复核备注 + /// Default:NULL::character varying + /// Nullable:True + /// + public string repeat_remark {get;set;} + + /// + /// Desc:复核人id + /// Default:NULL::character varying + /// Nullable:True + /// + public string repeat_user_id {get;set;} + + /// + /// Desc:仅用于关联表字段查询用不存储数据 + /// Default:NULL::character varying + /// Nullable:True + /// + [SugarColumn(ColumnName="query_info")] + public string query_info {get;set;} + + /// + /// 附件 + /// + public string attachment { get; set; } } } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs new file mode 100644 index 00000000..7d0042e5 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs @@ -0,0 +1,33 @@ +using SqlSugar; +using Tnb.Common.Contracts; + + +namespace Tnb.EquipMgr.Entities +{ + /// + ///点巡检设备模板子表 + /// + [SugarTable("eqp_spot_ins_tem_equip_d")] + public class EqpSpotInsTemEquipD : BaseEntity + { + public EqpSpotInsTemEquipD(){ + + + } + + /// + /// Desc:设备模板id + /// Default: + /// Nullable:False + /// + public string spot_ins_tem_equip_id {get;set;} + + /// + /// Desc:点巡检项id + /// Default: + /// Nullable:False + /// + public string spot_ins_item_id {get;set;} + + } +} \ No newline at end of file diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index b124ee33..d0de1e4d 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -1,11 +1,171 @@ +using JNPF.Common.Security; +using JNPF.Logging; +using Microsoft.AspNetCore.Components; +using SqlSugar; +using Tnb.EquipMgr.Entities; + namespace JNPF.TaskScheduler.Listener { + /// + /// 生成点巡检计划 + /// public class GenerateSpotInspectionPlanTimeWorker : ISpareTimeWorker { - [SpareTime("0 45 14 * * ? *", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] + private ISqlSugarRepository _repository => App.GetService>(); + // public GenerateSpotInspectionPlanTimeWorker(ISqlSugarRepository repository) + // { + // _repository = repository; + // } + + [SpareTime("0 0 0 * * ?", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] public void GenerateSpotInspectionPlan(SpareTimer timer, long count) { - Console.WriteLine("hello world"); + Log.Information("----------------------开始生成点巡检计划----------------------"); + + try + { + List eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1"); + List eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2"); + List tobeCreateList = new List(); + List tobeCreateTemplets = new List(); + var db = _repository.AsSugarClient(); + + foreach (var item in eqpSpotInsTemEquipHsByOne) + { + if (item.start_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH:mm") == DateTime.Now.ToString("yyyy-MM-dd HH:mm")) + { + tobeCreateTemplets.Add(item); + } + } + + if (eqpSpotInsTemEquipHsByCirculate != null && eqpSpotInsTemEquipHsByCirculate.Count > 0) + { + List ids = eqpSpotInsTemEquipHsByCirculate.Select(x => x.id).ToList(); + List lastPlans = db.Queryable() + .GroupBy(a => new { a.spot_ins_tem_equip_id }) + .Where(a => ids.Contains(a.spot_ins_tem_equip_id)) + .Select(a => new SpotInsRecordLastDTO() + { + spot_ins_tem_equip_id = a.spot_ins_tem_equip_id, + create_time = SqlFunc.AggregateMax(a.create_time.Value) + }).ToList(); + + foreach (var item in eqpSpotInsTemEquipHsByCirculate) + { + var lastPlan = lastPlans.FirstOrDefault(x => x.spot_ins_tem_equip_id == item.id); + if (lastPlan == null || lastPlan.create_time == null || lastPlan.create_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH")) + { + tobeCreateTemplets.Add(item); + } + } + } + + if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0) + { + List equipments = db.Queryable().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList(); + int index = 1; + foreach (var item in tobeCreateTemplets) + { + //只有启用设备才生成计划 + if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null) + continue; + + string code = $"{DateTime.Now.ToString("yyyyMMddHH")+(index++).ToString().PadLeft(3,'0')}"; + tobeCreateList.Add(new EqpSpotInsRecordH() + { + id = SnowflakeIdHelper.NextId(), + code = code, + // equip_type_id = item.equip_type_id, + equip_id = item.equip_id, + spot_ins_tem_equip_id = item.id, + plan_run_notice = item.plan_run_notice, + plan_run_notice_unit = item.plan_run_notice_unit, + plan_delay = item.plan_delay, + plan_delay_unit = item.plan_delay_unit, + send_post_info_user_id = item.send_post_info_user_id, + is_repeat = item.is_repeat, + repeat_post_info_user_id = item.repeat_post_info_user_id, + is_send = item.is_send, + create_time = DateTime.Now, + }); + } + } + + + if (tobeCreateList != null && tobeCreateList.Count > 0) + { + List templetIDs = tobeCreateList.Select(x => x.spot_ins_tem_equip_id).ToList(); + List spotInsTemEquipDs = db.Queryable().Where(x => templetIDs.Contains(x.spot_ins_tem_equip_id)).ToList(); + List spotInsItemIDs = spotInsTemEquipDs.Select(x => x.spot_ins_item_id).ToList(); + List spotCheckItems = db.Queryable().Where(x => spotInsItemIDs.Contains(x.id)).ToList(); + + + foreach (var tobeCreatePlan in tobeCreateList) + { + List spotInsRecordDs = new List(); + List spotInsItems = spotInsTemEquipDs + .Where(x => x.spot_ins_tem_equip_id == tobeCreatePlan.spot_ins_tem_equip_id) + .Select(x => x.spot_ins_item_id).ToList(); + List tobeCreateItems = spotCheckItems.Where(x => spotInsItems.Contains(x.id)).ToList(); + foreach (var tobeCreateItem in tobeCreateItems) + { + spotInsRecordDs.Add(new EqpSpotInsRecordD() + { + id = SnowflakeIdHelper.NextId(), + spot_ins_record_id = tobeCreatePlan.id, + spot_ins_tem_equip_id = tobeCreatePlan.spot_ins_tem_equip_id, + spot_ins_item_id = tobeCreateItem.id, + code = tobeCreateItem.code, + name = tobeCreateItem.name, + judge_type = tobeCreateItem.judge_type, + low_value = tobeCreateItem.low_value, + high_value = tobeCreateItem.high_value, + low_value_is_include = tobeCreateItem.low_value_is_include, + high_value_is_include = tobeCreateItem.high_value_is_include, + standard_value = tobeCreateItem.standard_value, + unit_id = tobeCreateItem.unit_id, + inspection_method = tobeCreateItem.inspection_method, + judge_content = tobeCreateItem.judge_content, + remark = tobeCreateItem.remark + }); + } + + var dbResult = db.Ado.UseTran(() => + { + if (tobeCreateList != null && tobeCreateList.Count > 0) + { + db.Insertable(tobeCreateList).ExecuteCommand(); + } + + if (spotInsRecordDs != null && spotInsRecordDs.Count > 0) + { + db.Insertable(spotInsRecordDs).ExecuteCommand(); + } + }); + if (!dbResult.IsSuccess) + { + Log.Error(dbResult.ErrorMessage); + } + Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); + } + } + } + catch (Exception e) + { + Log.Error(e.Message); + } + + + Log.Information("----------------------结束生成点巡检计划----------------------"); + } + + /// + /// 最后一个点巡检记录 + /// + private class SpotInsRecordLastDTO + { + public string spot_ins_tem_equip_id { get; set; } + public DateTime create_time { get; set; } } } } \ No newline at end of file diff --git a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs index fb492e0f..93739262 100644 --- a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs +++ b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs @@ -324,11 +324,12 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie 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; // 创建任务对象 @@ -354,20 +355,20 @@ 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 (taskMethod.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); } diff --git a/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj b/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj index f2dfa7fb..36194190 100644 --- a/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj +++ b/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj @@ -10,8 +10,13 @@ + + + + + \ No newline at end of file