生成特种设备检验计划定时任务

This commit is contained in:
2023-06-01 16:17:55 +08:00
parent b8d77e72d9
commit 45b05925d7
4 changed files with 70 additions and 42 deletions

View File

@@ -72,7 +72,7 @@ public partial class EqpSpEquipCheckRecord : BaseEntity<string>
/// <summary> /// <summary>
/// 提前预警时间单位 /// 提前预警时间单位
/// </summary> /// </summary>
public int? warn_unit { get; set; } public string? warn_unit { get; set; }
/// <summary> /// <summary>
/// 有效开始时间 /// 有效开始时间

View File

@@ -37,10 +37,10 @@ namespace Tnb.EquipMgr
throw Oops.Bah("该设备已存在检验计划"); throw Oops.Bah("该设备已存在检验计划");
} }
if (entity.warn_unit == 1)//月 if (entity.warn_unit == "1")//月
{ {
entity.next_check_time = entity.end_time.Value.AddMonths(-entity.warm_time.Value); entity.next_check_time = entity.end_time.Value.AddMonths(-entity.warm_time.Value);
}else if (entity.warn_unit == 2)//天 }else if (entity.warn_unit == "2")//天
{ {
entity.next_check_time = entity.end_time.Value.AddDays(-entity.warm_time.Value); entity.next_check_time = entity.end_time.Value.AddDays(-entity.warm_time.Value);
} }

View File

@@ -35,7 +35,7 @@ namespace JNPF.TaskScheduler.Listener
}) })
.MergeTable() .MergeTable()
.LeftJoin<EqpSpEquipCheckRecord>((x,y)=>x.equip_id==y.equip_id && x.create_time==y.create_time) .LeftJoin<EqpSpEquipCheckRecord>((x,y)=>x.equip_id==y.equip_id && x.create_time.Value.ToString("yyyy-MM-dd")==y.create_time.Value.ToString("yyyy-MM-dd"))
.Select((x,y)=>y) .Select((x,y)=>y)
.ToList(); .ToList();
@@ -44,12 +44,37 @@ namespace JNPF.TaskScheduler.Listener
{ {
foreach (var item in list) foreach (var item in list)
{ {
insertList.Add(new EqpSpEquipCheckRecord() if (item.end_time != null && item.warn_unit!=null)
{ {
id = SnowflakeIdHelper.NextId(), if (item.warn_unit == "1")
equip_id = item.equip_id, {
status = "0" if (item.end_time.Value.AddMonths(-item.warm_time.Value).ToString("yyyy-MM-dd") ==
}); DateTime.Now.ToString("yyyy-MM-dd"))
{
insertList.Add(new EqpSpEquipCheckRecord()
{
id = SnowflakeIdHelper.NextId(),
equip_id = item.equip_id,
status = "0"
});
}
}else if (item.warn_unit == "2")
{
if (item.end_time.Value.AddDays(-item.warm_time.Value).ToString("yyyy-MM-dd") ==
DateTime.Now.ToString("yyyy-MM-dd"))
{
insertList.Add(new EqpSpEquipCheckRecord()
{
id = SnowflakeIdHelper.NextId(),
equip_id = item.equip_id,
status = "0"
});
}
}
}
} }
_repository.InsertRange(insertList); _repository.InsertRange(insertList);

View File

@@ -16,6 +16,7 @@ using JNPF.Schedule;
using JNPF.Systems.Interfaces.System; using JNPF.Systems.Interfaces.System;
using JNPF.TaskScheduler.Entitys; using JNPF.TaskScheduler.Entitys;
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler; using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
using JNPF.TaskScheduler.Entitys.Enum;
using JNPF.TaskScheduler.Entitys.Model; using JNPF.TaskScheduler.Entitys.Model;
using JNPF.TaskScheduler.Interfaces.TaskScheduler; using JNPF.TaskScheduler.Interfaces.TaskScheduler;
using JNPF.TimeCrontab; using JNPF.TimeCrontab;
@@ -412,40 +413,42 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
/// <returns></returns> /// <returns></returns>
private async Task<List<TaskMethodInfo>> GetTaskMethods() private async Task<List<TaskMethodInfo>> GetTaskMethods()
{ {
//var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB); // var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
//if (taskMethods != null) return taskMethods; // if (taskMethods != null) return taskMethods;
//// 获取所有本地任务方法必须有spareTimeAttribute特性 List<TaskMethodInfo> taskMethods = null;
//taskMethods = App.EffectiveTypes
// .Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u)) // 获取所有本地任务方法必须有spareTimeAttribute特性
// .SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance) taskMethods = App.EffectiveTypes
// .Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) && .Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
// m.GetParameters().Length == 2 && .SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
// m.GetParameters()[0].ParameterType == typeof(SpareTimer) && .Where(m => m.GetCustomAttributes(typeof(SpareTimeAttribute), false).ToString().Contains("SpareTime") &&
// m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void)) m.GetParameters().Length == 2 &&
// .Select(m => m.GetParameters()[0].ParameterType == typeof(SpareTimer) &&
// { m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void))
// // 默认获取第一条任务特性 .Select(m =>
// var spareTimeAttribute = m.GetCustomAttribute<SpareTimeAttribute>(); {
// return new TaskMethodInfo // 默认获取第一条任务特性
// { var spareTimeAttribute = m.GetCustomAttribute<SpareTimeAttribute>();
// id = $"{m.DeclaringType.Name}/{m.Name}", return new TaskMethodInfo
// fullName = spareTimeAttribute.WorkerName, {
// RequestUrl = $"{m.DeclaringType.Name}/{m.Name}", id = $"{m.DeclaringType.Name}/{m.Name}",
// cron = spareTimeAttribute.CronExpression, fullName = spareTimeAttribute.WorkerName,
// DoOnce = spareTimeAttribute.DoOnce, RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
// ExecuteType = spareTimeAttribute.ExecuteType, cron = spareTimeAttribute.CronExpression,
// Interval = (int)spareTimeAttribute.Interval / 1000, DoOnce = spareTimeAttribute.DoOnce,
// StartNow = spareTimeAttribute.StartNow, ExecuteType = spareTimeAttribute.ExecuteType,
// RequestType = RequestTypeEnum.BuiltIn, Interval = (int)spareTimeAttribute.Interval / 1000,
// Remark = spareTimeAttribute.Description, StartNow = spareTimeAttribute.StartNow,
// TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron, RequestType = RequestTypeEnum.BuiltIn,
// MethodName = m.Name, Remark = spareTimeAttribute.Description,
// DeclaringType = m.DeclaringType TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
// }; MethodName = m.Name,
// })).ToList(); DeclaringType = m.DeclaringType
//await _cacheManager.SetAsync(CommonConst.CACHEKEYTIMERJOB, taskMethods); };
//return taskMethods; })).ToList();
await _cacheManager.SetAsync(CommonConst.CACHEKEYTIMERJOB, taskMethods);
return taskMethods;
return new List<TaskMethodInfo>(); return new List<TaskMethodInfo>();
} }