This commit is contained in:
qianjiawei
2023-09-20 23:08:04 +08:00
parent f636b12517
commit 0f57d7d396
9 changed files with 310 additions and 72 deletions

View File

@@ -26,15 +26,16 @@ namespace Tnb.TaskScheduler.Listener
{
try
{
var TimeTasks = timeTaskService.GetTasks();
var timeTaskEntity = TimeTasks.Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).First();
var TimeTasks =await timeTaskService.GetTasks();
var timeTaskEntity = TimeTasks.Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstOrDefault();
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();
var client = repository.CopyNew();
var ToolMoldMaintainRule = await client.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();
var ToolMoldMaintainRuleRelations= await client.Queryable<ToolMoldMaintainRuleRelation>().Where(p => p.rule_id == ToolMoldMaintainRule.id).ToListAsync();
if (ToolMoldMaintainRuleRelations.Count() > 0)
{
var now = DateTime.Now;
@@ -58,8 +59,8 @@ namespace Tnb.TaskScheduler.Listener
toolMoldMaintainPlanRelation.group_id = ToolMoldMaintainRuleRelation.item_group_id;
toolMoldMaintainPlanRelations.Add(toolMoldMaintainPlanRelation);
}
await repository.AsSugarClient().Insertable(toolMoldMaintainPlanRelations).ExecuteCommandAsync();
await repository.AsSugarClient().Insertable(toolMoldMaintainPlan).ExecuteCommandAsync();
await client.Insertable(toolMoldMaintainPlanRelations).ExecuteCommandAsync();
await client.Insertable(toolMoldMaintainPlan).ExecuteCommandAsync();
}
}
catch (Exception)

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aop.Api.Domain;
using JNPF;
using JNPF.Common.Security;
using JNPF.Systems.Entitys.System;
@@ -32,71 +33,120 @@ namespace Tnb.TaskScheduler.Listener
{
try
{
var TimeTasks = timeTaskService.GetTasks();
var timeTaskEntity = TimeTasks.Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).First();
var TimeTasks =await timeTaskService.GetTasks();
var timeTaskEntity = TimeTasks.Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstOrDefault();
if (timeTaskEntity == null)
return;
ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
var PlanH = await repository.AsSugarClient().Queryable<QcCheckPlanH>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
var PlanDs = await repository.AsSugarClient().Queryable<QcCheckPlanD>().Where(p => p.mainid == PlanH.id).ToListAsync();
var client= repository.CopyNew();
var PlanH = await client.Queryable<QcCheckPlanH>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
var PlanDs = await client.Queryable<QcCheckPlanD>().Where(p => p.mainid == PlanH.id).ToListAsync();
if (PlanH == null || PlanDs.Count == 0)
return;
var PlanMaterials = repository.AsSugarClient().Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToList();
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();
var time = DateTime.Now;
foreach (var PrdMoTask in PrdMoTasks)
List<string> strs = new List<string>();
strs.Add("26589795199765");//首检
strs.Add("26589835919125");//生产检
strs.Add("26590141686549");//巡检
if (strs.Contains(PlanH.checktype))
{
var PlanMaterials = await client.Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToListAsync();
var PlanProcesss = await client.Queryable<QcCheckPlanProcess>().Where(p => p.planid == PlanH.id).Select(p => p.processid).ToListAsync();
var PlanWork = await client.Queryable<QcCheckPlanWork>().Where(p => p.planid == PlanH.id).Select(p => p.workid).ToListAsync();
//物料工序工位不能同时为空
if (PlanMaterials.Count == 0 && PlanProcesss.Count == 0 && PlanWork.Count == 0)
return;
var PrdMoTasks = await client.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();
QcCheckExecH qcCheckExecH = new QcCheckExecH();
qcCheckExecH.id = SnowflakeIdHelper.NextId();
qcCheckExecH.checktype = PlanH.checktype;
qcCheckExecH.status = DictionaryData.Id;
qcCheckExecH.tasktime = time.ToString("yyyy-MM-dd HH:mm:ss");
qcCheckExecH.materialid = PrdMoTask.material_id;
qcCheckExecH.processid = PrdMoTask.process_id;
qcCheckExecH.workid = PrdMoTask.workstation_id;
qcCheckExecH.create_time = time;
var ExecDs = new List<QcCheckExecD>();
foreach (var PlanD in PlanDs)
var DictionaryType = await client.Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
var DictionaryData = await client.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
var time = DateTime.Now;
foreach (var PrdMoTask in PrdMoTasks)
{
QcCheckExecD QcCheckExecD = new QcCheckExecD();
QcCheckExecD.mainid = qcCheckExecH.id;
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;
QcCheckExecD.create_time = time;
ExecDs.Add(QcCheckExecD);
QcCheckExecH qcCheckExecH = new QcCheckExecH();
qcCheckExecH.id = SnowflakeIdHelper.NextId();
qcCheckExecH.checktype = PlanH.checktype;
qcCheckExecH.status = DictionaryData.Id;
qcCheckExecH.tasktime = time.ToString("yyyy-MM-dd HH:mm:ss");
qcCheckExecH.materialid = PrdMoTask.material_id;
qcCheckExecH.processid = PrdMoTask.process_id;
qcCheckExecH.workid = PrdMoTask.workstation_id;
qcCheckExecH.create_time = time;
var ExecDs = new List<QcCheckExecD>();
foreach (var PlanD in PlanDs)
{
QcCheckExecD QcCheckExecD = new QcCheckExecD();
QcCheckExecD.mainid = qcCheckExecH.id;
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;
QcCheckExecD.create_time = time;
ExecDs.Add(QcCheckExecD);
}
await client.Insertable(qcCheckExecH).ExecuteCommandAsync();
await client.Insertable(ExecDs).ExecuteCommandAsync();
}
await repository.AsSugarClient().Insertable(qcCheckExecH).ExecuteCommandAsync();
await repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync();
}
else
{
var PlanMaterials = await client.Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToListAsync();
var DictionaryType = await client.Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
var DictionaryData = await client.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
var time = DateTime.Now;
foreach (var Material in PlanMaterials)
{
QcCheckExecH qcCheckExecH = new QcCheckExecH();
qcCheckExecH.id = SnowflakeIdHelper.NextId();
qcCheckExecH.checktype = PlanH.checktype;
qcCheckExecH.status = DictionaryData.Id;
qcCheckExecH.tasktime = time.ToString("yyyy-MM-dd HH:mm:ss");
qcCheckExecH.materialid = Material;
qcCheckExecH.processid = "";
qcCheckExecH.workid = "";
qcCheckExecH.create_time = time;
var ExecDs = new List<QcCheckExecD>();
foreach (var PlanD in PlanDs)
{
QcCheckExecD QcCheckExecD = new QcCheckExecD();
QcCheckExecD.mainid = qcCheckExecH.id;
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;
QcCheckExecD.create_time = time;
ExecDs.Add(QcCheckExecD);
}
await client.Insertable(qcCheckExecH).ExecuteCommandAsync();
await client.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();
await client.Updateable(timeTaskEntity).ExecuteCommandAsync();
SpareTime.Cancel(timeTaskEntity.Id);
}
}

View File

@@ -136,9 +136,9 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
#endregion
#region Post
public List<TimeTaskEntity> GetTasks()
public async Task<List<TimeTaskEntity>> GetTasks()
{
var list= _repository.AsQueryable().ToList();
var list = await _repository.CopyNew().Queryable<TimeTaskEntity>().ToListAsync();
return list;
}