巡检
This commit is contained in:
@@ -241,4 +241,8 @@ public partial class PrdMoTask : BaseEntity<string>
|
||||
/// </summary>
|
||||
public string nightshiftafter_worker_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务key
|
||||
/// </summary>
|
||||
public string timer_key { get; set; }
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Tnb.ProductionMgr.Helpers
|
||||
// 初始化代码,如果有必要的话
|
||||
}
|
||||
|
||||
public void StartTimer(TimerCallback timerCallback,object data,TimeSpan dueTime, TimeSpan period)
|
||||
public void StartTimer(TimerCallback timerCallback,object data,TimeSpan dueTime, TimeSpan period,bool autoClode = true)
|
||||
{
|
||||
Timer timer;
|
||||
lock (_lockObject)
|
||||
@@ -36,16 +36,19 @@ namespace Tnb.ProductionMgr.Helpers
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
dic.Add("key",timestamp);
|
||||
dic.Add("value",data);
|
||||
timerCallback += DisposeTimer;
|
||||
if (autoClode)
|
||||
{
|
||||
timerCallback += DisposeTimer;
|
||||
}
|
||||
timer = new Timer(timerCallback, dic, dueTime, period);
|
||||
_timers.Add(timestamp,timer);
|
||||
}
|
||||
}
|
||||
|
||||
private void DisposeTimer(object args)
|
||||
public void DisposeTimer(object args)
|
||||
{
|
||||
Dictionary<string, object> dic = (Dictionary<string, object>)args;
|
||||
string key = dic["key"].ToString();
|
||||
string key = dic["key"]!=null ? dic["key"].ToString() : "";
|
||||
if (_timers.ContainsKey(key))
|
||||
{
|
||||
_timers[dic["key"].ToString()].Dispose();
|
||||
@@ -53,5 +56,6 @@ namespace Tnb.ProductionMgr.Helpers
|
||||
_timers.Remove(dic["key"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1247,6 +1247,23 @@ namespace Tnb.ProductionMgr
|
||||
await _qcCheckPlanService.CreateTask(entity);
|
||||
}
|
||||
}
|
||||
|
||||
if (behavior == PrdTaskBehavior.Start)
|
||||
{
|
||||
TimerPoolHelper.GetInstance().StartTimer(TimeCallback2,prdTaskList.Where(p => p.mo_task_status == "Pause" || p.mo_task_status == "ToBeStarted").ToList(),TimeSpan.FromHours(2),Timeout.InfiniteTimeSpan,false);
|
||||
}
|
||||
|
||||
if (behavior == PrdTaskBehavior.Pause)
|
||||
{
|
||||
foreach (PrdMoTask? task in prdTaskList.Where(p => p.mo_task_status == "ToBeStarted").ToList())
|
||||
{
|
||||
TimerPoolHelper.GetInstance().DisposeTimer(new Dictionary<string,string>()
|
||||
{
|
||||
["key"] = task.timer_key
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
foreach (PrdMoTask item in prdTaskList)
|
||||
@@ -1589,8 +1606,14 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
Dictionary<string, object> dic = (Dictionary<string, object>)args;
|
||||
List<PrdMoTask> prdTaskList = (List<PrdMoTask>)(dic["value"]);
|
||||
await _db.Ado.BeginTranAsync();
|
||||
foreach (PrdMoTask? task in prdTaskList)
|
||||
{
|
||||
ToolMolds toolMolds = await _db.Queryable<ToolMolds>().SingleAsync(x=>x.id==task.mold_id);
|
||||
await _db.Updateable<PrdMoTask>()
|
||||
.SetColumns(x => x.timer_key == dic["key"])
|
||||
.Where(x => x.id == task.id)
|
||||
.ExecuteCommandAsync();
|
||||
TriggerPlanEntity entity = new()
|
||||
{
|
||||
materialid = task.material_id,
|
||||
@@ -1598,7 +1621,44 @@ namespace Tnb.ProductionMgr
|
||||
workid = task.workstation_id,
|
||||
triggerevent = EnumTriggerEvent.开工首件检,
|
||||
mo_task_code = task.mo_task_code,
|
||||
check_type = WmsWareHouseConst.FULLREVIEW_CODE
|
||||
newpronum = toolMolds?.mold_cavity
|
||||
// check_type = WmsWareHouseConst.FULLREVIEW_CODE
|
||||
};
|
||||
await _qcCheckPlanService.CreateTask(entity);
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
Console.WriteLine("质检任务生成成功");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
Log.Error("质检任务生成失败:"+e.Message,e);
|
||||
}
|
||||
}
|
||||
|
||||
public async void TimeCallback2(object args)
|
||||
{
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> dic = (Dictionary<string, object>)args;
|
||||
List<PrdMoTask> prdTaskList = (List<PrdMoTask>)(dic["value"]);
|
||||
foreach (PrdMoTask? task in prdTaskList)
|
||||
{
|
||||
ToolMolds toolMolds = await _db.Queryable<ToolMolds>().SingleAsync(x=>x.id==task.mold_id);
|
||||
await _db.Updateable<PrdMoTask>()
|
||||
.SetColumns(x => x.timer_key == dic["key"])
|
||||
.Where(x => x.id == task.id)
|
||||
.ExecuteCommandAsync();
|
||||
TriggerPlanEntity entity = new()
|
||||
{
|
||||
materialid = task.material_id,
|
||||
processid = task.process_id,
|
||||
workid = task.workstation_id,
|
||||
triggerevent = EnumTriggerEvent.巡检,
|
||||
mo_task_code = task.mo_task_code,
|
||||
newpronum = toolMolds?.mold_cavity
|
||||
// check_type = WmsWareHouseConst.FULLREVIEW_CODE
|
||||
};
|
||||
await _qcCheckPlanService.CreateTask(entity);
|
||||
}
|
||||
@@ -1860,6 +1920,11 @@ namespace Tnb.ProductionMgr
|
||||
.Where(x => x.id == prdMoTask.id)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
TimerPoolHelper.GetInstance().DisposeTimer(new Dictionary<string,string>()
|
||||
{
|
||||
["key"] = prdMoTask.timer_key
|
||||
});
|
||||
ToolMolds toolMolds = await db.Queryable<ToolMolds>().SingleAsync(x=>x.id==prdMoTask.mold_id);
|
||||
TriggerPlanEntity entity = new()
|
||||
{
|
||||
materialid = prdMoTask.material_id,
|
||||
@@ -1871,6 +1936,7 @@ namespace Tnb.ProductionMgr
|
||||
report_id = report.id,
|
||||
batch = report.batch,
|
||||
plan_check_type = WmsWareHouseConst.MOJIAN_ID,
|
||||
newpronum = toolMolds?.mold_cavity,
|
||||
};
|
||||
await _qcCheckPlanService.CreateTask(entity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user