1
This commit is contained in:
66
taskschedule/Tnb.TaskScheduler/Listener/MoldMaintainTask.cs
Normal file
66
taskschedule/Tnb.TaskScheduler/Listener/MoldMaintainTask.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.TaskScheduler;
|
||||
using JNPF.TaskScheduler.Entitys.Model;
|
||||
using SqlSugar;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.ProductionMgr.Entities;
|
||||
using Tnb.QcMgr.Entities;
|
||||
using Tnb.QcMgr.Entities.Entity;
|
||||
|
||||
namespace Tnb.TaskScheduler.Listener
|
||||
{
|
||||
internal class MoldMaintainTask : ISpareTimeWorker
|
||||
{
|
||||
private ISqlSugarRepository<ToolMoldMaintainRule> repository => App.GetService<ISqlSugarRepository<ToolMoldMaintainRule>>();
|
||||
[SpareTime("0 0 0 * * ?", "生成模具保养任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)]
|
||||
public async void CreateTask(SpareTimer timer, long count)
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeTaskEntity = await repository.AsSugarClient().Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync();
|
||||
if (timeTaskEntity == null)
|
||||
return;
|
||||
ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
|
||||
var ToolMoldMaintainRule = await repository.AsSugarClient().Queryable<ToolMoldMaintainRule>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
|
||||
if (ToolMoldMaintainRule == null)
|
||||
return;
|
||||
var ToolMoldMaintainRuleRelations= await repository.AsSugarClient().Queryable<ToolMoldMaintainRuleRelation>().Where(p => p.rule_id == ToolMoldMaintainRule.id).ToListAsync();
|
||||
if (ToolMoldMaintainRuleRelations.Count() > 0)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
Random rNum = new Random();
|
||||
ToolMoldMaintainPlan toolMoldMaintainPlan=new ToolMoldMaintainPlan();
|
||||
toolMoldMaintainPlan.id = SnowflakeIdHelper.NextId();
|
||||
toolMoldMaintainPlan.plan_code = "JHDM" + now.ToString("yyyyMMdd") + rNum.Next(1000, 9999).ToString();
|
||||
toolMoldMaintainPlan.mode = ToolMoldMaintainRule.mode;
|
||||
toolMoldMaintainPlan.status = "UnMaintain";
|
||||
toolMoldMaintainPlan.plan_start_date = now;
|
||||
toolMoldMaintainPlan.plan_end_date = now.AddDays((double)ToolMoldMaintainRule.cycle!);
|
||||
List<ToolMoldMaintainPlanRelation> toolMoldMaintainPlanRelations = new List<ToolMoldMaintainPlanRelation>();
|
||||
foreach (var ToolMoldMaintainRuleRelation in ToolMoldMaintainRuleRelations)
|
||||
{
|
||||
ToolMoldMaintainPlanRelation toolMoldMaintainPlanRelation = new ToolMoldMaintainPlanRelation();
|
||||
toolMoldMaintainPlanRelation.id= SnowflakeIdHelper.NextId();
|
||||
toolMoldMaintainPlanRelation.maintain_plan_id = toolMoldMaintainPlan.id;
|
||||
toolMoldMaintainPlanRelation.mold_id = ToolMoldMaintainRuleRelation.mold_id;
|
||||
toolMoldMaintainPlanRelation.group_id = ToolMoldMaintainRuleRelation.item_group_id;
|
||||
toolMoldMaintainPlanRelations.Add(toolMoldMaintainPlanRelation);
|
||||
}
|
||||
await repository.AsSugarClient().Insertable(toolMoldMaintainPlanRelations).ExecuteCommandAsync();
|
||||
await repository.AsSugarClient().Insertable(toolMoldMaintainPlan).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user