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

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>
public int? warn_unit { get; set; }
public string? warn_unit { get; set; }
/// <summary>
/// 有效开始时间

View File

@@ -37,10 +37,10 @@ namespace Tnb.EquipMgr
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);
}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);
}

View File

@@ -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);

View File

@@ -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>();
}