生成特种设备检验计划定时任务
This commit is contained in:
@@ -35,7 +35,7 @@ namespace JNPF.TaskScheduler.Listener
|
||||
|
||||
})
|
||||
.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)
|
||||
.ToList();
|
||||
|
||||
@@ -44,12 +44,37 @@ namespace JNPF.TaskScheduler.Listener
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
insertList.Add(new EqpSpEquipCheckRecord()
|
||||
if (item.end_time != null && item.warn_unit!=null)
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
equip_id = item.equip_id,
|
||||
status = "0"
|
||||
});
|
||||
if (item.warn_unit == "1")
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -16,6 +16,7 @@ using JNPF.Schedule;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.TaskScheduler.Entitys;
|
||||
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
|
||||
using JNPF.TaskScheduler.Entitys.Enum;
|
||||
using JNPF.TaskScheduler.Entitys.Model;
|
||||
using JNPF.TaskScheduler.Interfaces.TaskScheduler;
|
||||
using JNPF.TimeCrontab;
|
||||
@@ -412,40 +413,42 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
/// <returns></returns>
|
||||
private async Task<List<TaskMethodInfo>> GetTaskMethods()
|
||||
{
|
||||
//var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
|
||||
//if (taskMethods != null) return taskMethods;
|
||||
// var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
|
||||
// if (taskMethods != null) return taskMethods;
|
||||
|
||||
//// 获取所有本地任务方法,必须有spareTimeAttribute特性
|
||||
//taskMethods = App.EffectiveTypes
|
||||
// .Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
|
||||
// .SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
||||
// .Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) &&
|
||||
// m.GetParameters().Length == 2 &&
|
||||
// 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
|
||||
// {
|
||||
// id = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
// fullName = spareTimeAttribute.WorkerName,
|
||||
// RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
// cron = spareTimeAttribute.CronExpression,
|
||||
// DoOnce = spareTimeAttribute.DoOnce,
|
||||
// ExecuteType = spareTimeAttribute.ExecuteType,
|
||||
// Interval = (int)spareTimeAttribute.Interval / 1000,
|
||||
// StartNow = spareTimeAttribute.StartNow,
|
||||
// RequestType = RequestTypeEnum.BuiltIn,
|
||||
// Remark = spareTimeAttribute.Description,
|
||||
// TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
|
||||
// MethodName = m.Name,
|
||||
// DeclaringType = m.DeclaringType
|
||||
// };
|
||||
// })).ToList();
|
||||
//await _cacheManager.SetAsync(CommonConst.CACHEKEYTIMERJOB, taskMethods);
|
||||
//return taskMethods;
|
||||
List<TaskMethodInfo> taskMethods = null;
|
||||
|
||||
// 获取所有本地任务方法,必须有spareTimeAttribute特性
|
||||
taskMethods = App.EffectiveTypes
|
||||
.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
|
||||
.SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(m => m.GetCustomAttributes(typeof(SpareTimeAttribute), false).ToString().Contains("SpareTime") &&
|
||||
m.GetParameters().Length == 2 &&
|
||||
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
|
||||
{
|
||||
id = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
fullName = spareTimeAttribute.WorkerName,
|
||||
RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
cron = spareTimeAttribute.CronExpression,
|
||||
DoOnce = spareTimeAttribute.DoOnce,
|
||||
ExecuteType = spareTimeAttribute.ExecuteType,
|
||||
Interval = (int)spareTimeAttribute.Interval / 1000,
|
||||
StartNow = spareTimeAttribute.StartNow,
|
||||
RequestType = RequestTypeEnum.BuiltIn,
|
||||
Remark = spareTimeAttribute.Description,
|
||||
TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
|
||||
MethodName = m.Name,
|
||||
DeclaringType = m.DeclaringType
|
||||
};
|
||||
})).ToList();
|
||||
await _cacheManager.SetAsync(CommonConst.CACHEKEYTIMERJOB, taskMethods);
|
||||
return taskMethods;
|
||||
return new List<TaskMethodInfo>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user