1
This commit is contained in:
@@ -24,72 +24,78 @@ namespace Tnb.TaskScheduler.Listener
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class QcTaskTimeWorker : ISpareTimeWorker
|
public class QcTaskTimeWorker : ISpareTimeWorker
|
||||||
{
|
{
|
||||||
private ISqlSugarClient repository => App.GetService<ISqlSugarClient>();
|
private ISqlSugarRepository<QcCheckPlanH> repository => App.GetService<ISqlSugarRepository<QcCheckPlanH>>();
|
||||||
|
|
||||||
[SpareTime("0 0 0 * * ?", "生成质检任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)]
|
[SpareTime("0 0 0 * * ?", "生成质检任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)]
|
||||||
public async void CreateTask(SpareTimer timer, long count)
|
public async void CreateTask(SpareTimer timer, long count)
|
||||||
{
|
{
|
||||||
var timeTaskEntity = await repository.Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync();
|
try
|
||||||
if (timeTaskEntity == null)
|
|
||||||
return;
|
|
||||||
ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
|
|
||||||
var PlanH = await repository.Queryable<QcCheckPlanH>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
|
|
||||||
var PlanDs = await repository.Queryable<QcCheckPlanD>().Where(p => p.mainid == PlanH.id).ToListAsync();
|
|
||||||
if (PlanH == null || PlanDs.Count == 0)
|
|
||||||
return;
|
|
||||||
var PlanMaterials = repository.Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToList();
|
|
||||||
var PlanProcesss = repository.Queryable<QcCheckPlanProcess>().Where(p => p.planid == PlanH.id).Select(p => p.processid).ToList();
|
|
||||||
var PlanWork = repository.Queryable<QcCheckPlanWork>().Where(p => p.planid == PlanH.id).Select(p => p.workid).ToList();
|
|
||||||
//物料工序工位不能同时为空
|
|
||||||
if (PlanMaterials.Count == 0 && PlanProcesss.Count == 0 && PlanWork.Count == 0)
|
|
||||||
return;
|
|
||||||
var PrdMoTasks = await repository.Queryable<PrdMoTask>()
|
|
||||||
.WhereIF(PlanMaterials.Count > 0, p => PlanMaterials.Contains(p.material_id))
|
|
||||||
.WhereIF(PlanProcesss.Count > 0, p => PlanProcesss.Contains(p.process_id))
|
|
||||||
.WhereIF(PlanWork.Count > 0, p => PlanWork.Contains(p.workstation_id))
|
|
||||||
.Where(p => p.mo_task_status == "InProgress")//进行中
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var DictionaryType = await repository.Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
|
|
||||||
var DictionaryData = await repository.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
|
|
||||||
foreach (var PrdMoTask in PrdMoTasks)
|
|
||||||
{
|
{
|
||||||
QcCheckExecH qcCheckExecH = new QcCheckExecH();
|
var timeTaskEntity = await repository.AsSugarClient().Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync();
|
||||||
qcCheckExecH.id = SnowflakeIdHelper.NextId();
|
if (timeTaskEntity == null)
|
||||||
qcCheckExecH.checktype = PlanH.checktype;
|
return;
|
||||||
qcCheckExecH.status = DictionaryData.Id;
|
ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
|
||||||
qcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
var PlanH = await repository.AsSugarClient().Queryable<QcCheckPlanH>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
|
||||||
qcCheckExecH.materialid = PrdMoTask.material_id;
|
var PlanDs = await repository.AsSugarClient().Queryable<QcCheckPlanD>().Where(p => p.mainid == PlanH.id).ToListAsync();
|
||||||
qcCheckExecH.processid = PrdMoTask.process_id;
|
if (PlanH == null || PlanDs.Count == 0)
|
||||||
qcCheckExecH.workid = PrdMoTask.workstation_id;
|
return;
|
||||||
var ExecDs = new List<QcCheckExecD>();
|
var PlanMaterials = repository.AsSugarClient().Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToList();
|
||||||
foreach (var PlanD in PlanDs)
|
var PlanProcesss = repository.AsSugarClient().Queryable<QcCheckPlanProcess>().Where(p => p.planid == PlanH.id).Select(p => p.processid).ToList();
|
||||||
|
var PlanWork = repository.AsSugarClient().Queryable<QcCheckPlanWork>().Where(p => p.planid == PlanH.id).Select(p => p.workid).ToList();
|
||||||
|
//物料工序工位不能同时为空
|
||||||
|
if (PlanMaterials.Count == 0 && PlanProcesss.Count == 0 && PlanWork.Count == 0)
|
||||||
|
return;
|
||||||
|
var PrdMoTasks = await repository.AsSugarClient().Queryable<PrdMoTask>()
|
||||||
|
.WhereIF(PlanMaterials.Count > 0, p => PlanMaterials.Contains(p.material_id))
|
||||||
|
.WhereIF(PlanProcesss.Count > 0, p => PlanProcesss.Contains(p.process_id))
|
||||||
|
.WhereIF(PlanWork.Count > 0, p => PlanWork.Contains(p.workstation_id))
|
||||||
|
.Where(p => p.mo_task_status == "InProgress")//进行中
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var DictionaryType = await repository.AsSugarClient().Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
|
||||||
|
var DictionaryData = await repository.AsSugarClient().Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
|
||||||
|
foreach (var PrdMoTask in PrdMoTasks)
|
||||||
{
|
{
|
||||||
QcCheckExecD QcCheckExecD = new QcCheckExecD();
|
QcCheckExecH qcCheckExecH = new QcCheckExecH();
|
||||||
QcCheckExecD.mainid = qcCheckExecH.id;
|
qcCheckExecH.id = SnowflakeIdHelper.NextId();
|
||||||
QcCheckExecD.extype = PlanD.extype;
|
qcCheckExecH.checktype = PlanH.checktype;
|
||||||
QcCheckExecD.excontent = PlanD.excontent;
|
qcCheckExecH.status = DictionaryData.Id;
|
||||||
QcCheckExecD.check = PlanD.check;
|
qcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
QcCheckExecD.errorcause = PlanD.errorcause;
|
qcCheckExecH.materialid = PrdMoTask.material_id;
|
||||||
QcCheckExecD.errorlevel = PlanD.errorlevel;
|
qcCheckExecH.processid = PrdMoTask.process_id;
|
||||||
QcCheckExecD.remark = PlanD.remark;
|
qcCheckExecH.workid = PrdMoTask.workstation_id;
|
||||||
QcCheckExecD.attachment = PlanD.attachment;
|
var ExecDs = new List<QcCheckExecD>();
|
||||||
QcCheckExecD.isexec = PlanD.isexec;
|
foreach (var PlanD in PlanDs)
|
||||||
QcCheckExecD.custom = PlanD.custom;
|
{
|
||||||
QcCheckExecD.typeid = PlanD.typeid;
|
QcCheckExecD QcCheckExecD = new QcCheckExecD();
|
||||||
QcCheckExecD.itemid = PlanD.itemid;
|
QcCheckExecD.mainid = qcCheckExecH.id;
|
||||||
ExecDs.Add(QcCheckExecD);
|
QcCheckExecD.extype = PlanD.extype;
|
||||||
|
QcCheckExecD.excontent = PlanD.excontent;
|
||||||
|
QcCheckExecD.check = PlanD.check;
|
||||||
|
QcCheckExecD.errorcause = PlanD.errorcause;
|
||||||
|
QcCheckExecD.errorlevel = PlanD.errorlevel;
|
||||||
|
QcCheckExecD.remark = PlanD.remark;
|
||||||
|
QcCheckExecD.attachment = PlanD.attachment;
|
||||||
|
QcCheckExecD.isexec = PlanD.isexec;
|
||||||
|
QcCheckExecD.custom = PlanD.custom;
|
||||||
|
QcCheckExecD.typeid = PlanD.typeid;
|
||||||
|
QcCheckExecD.itemid = PlanD.itemid;
|
||||||
|
ExecDs.Add(QcCheckExecD);
|
||||||
|
}
|
||||||
|
await repository.AsSugarClient().Insertable(qcCheckExecH).ExecuteCommandAsync();
|
||||||
|
await repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
//只执行一次的 修改EnabledMark字段
|
||||||
|
var InterfaceParameter = comtentModel.parameter.Where(p => p.field == "doonce").FirstOrDefault();
|
||||||
|
if (InterfaceParameter != null && bool.Parse(InterfaceParameter.value))
|
||||||
|
{
|
||||||
|
timeTaskEntity.EnabledMark = 0;
|
||||||
|
await repository.AsSugarClient().Updateable(timeTaskEntity).ExecuteCommandAsync();
|
||||||
|
SpareTime.Cancel(timeTaskEntity.Id);
|
||||||
}
|
}
|
||||||
await repository.Insertable(qcCheckExecH).ExecuteCommandAsync();
|
|
||||||
await repository.Insertable(ExecDs).ExecuteCommandAsync();
|
|
||||||
}
|
}
|
||||||
//只执行一次的 修改EnabledMark字段
|
catch (Exception)
|
||||||
var InterfaceParameter = comtentModel.parameter.Where(p => p.field == "doonce").FirstOrDefault();
|
{
|
||||||
if (InterfaceParameter != null && bool.Parse(InterfaceParameter.value))
|
|
||||||
{
|
|
||||||
timeTaskEntity.EnabledMark = 0;
|
|
||||||
await repository.Updateable(timeTaskEntity).ExecuteCommandAsync();
|
|
||||||
SpareTime.Cancel(timeTaskEntity.Id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user