This commit is contained in:
qianjiawei
2023-07-13 17:45:07 +08:00
parent 9c4b032f0f
commit 9f6dbcf268
6 changed files with 131 additions and 27 deletions

View File

@@ -8,8 +8,11 @@ using JNPF.Common.Security;
using JNPF.Systems.Entitys.System;
using JNPF.TaskScheduler;
using JNPF.TaskScheduler.Entitys;
using JNPF.TaskScheduler.Entitys.Model;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.EquipMgr.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.QcMgr.Entities;
using Tnb.QcMgr.Entities.Entity;
using TimeTaskEntity = JNPF.TaskScheduler.Entitys.TimeTaskEntity;
@@ -25,40 +28,69 @@ namespace Tnb.TaskScheduler.Listener
[SpareTime("0 0 0 * * ?", "生成质检任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)]
public async void CreateTask(SpareTimer timer, long count)
{
var timeTaskEntity = await repository.AsSugarClient().Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName).FirstAsync();
var timeTaskEntity = await repository.AsSugarClient().Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync();
if (timeTaskEntity == null)
return;
var PlanH = await repository.AsQueryable().Where(p => p.id == timeTaskEntity.Description).FirstAsync();
ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
var PlanH = await repository.AsQueryable().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 == timeTaskEntity.Description).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();
QcCheckExecH qcCheckExecH = new QcCheckExecH();
qcCheckExecH.id = SnowflakeIdHelper.NextId();
qcCheckExecH.checktype = PlanH.checktype;
qcCheckExecH.status = DictionaryData.Id;
qcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var ExecDs = new List<QcCheckExecD>();
foreach (var PlanD in PlanDs)
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;
ExecDs.Add(QcCheckExecD);
QcCheckExecH qcCheckExecH = new QcCheckExecH();
qcCheckExecH.id = SnowflakeIdHelper.NextId();
qcCheckExecH.checktype = PlanH.checktype;
qcCheckExecH.status = DictionaryData.Id;
qcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
qcCheckExecH.materialid = PrdMoTask.material_id;
qcCheckExecH.processid = PrdMoTask.process_id;
qcCheckExecH.workid = PrdMoTask.workstation_id;
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;
ExecDs.Add(QcCheckExecD);
}
await repository.AsSugarClient().Insertable(qcCheckExecH).ExecuteCommandAsync();
await repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync();
}
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);
}
}
}
}

View File

@@ -219,6 +219,25 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
SpareTime.Cancel(entity.Id);
}
/// <summary>
/// 删除.
/// </summary>
/// <param name="fullName">名称</param>
/// <returns></returns>
[HttpDelete("{fullName}")]
public async Task DeleteByName(string fullName)
{
var entitys = await _repository.AsQueryable().Where(p=>p.FullName==fullName).ToListAsync();
foreach (var entity in entitys)
{
var isOk = await _repository.AsUpdateable(entity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandHasChangeAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1002);
// 从调度器里取消
SpareTime.Cancel(entity.Id);
}
}
/// <summary>
/// 停止.
/// </summary>

View File

@@ -14,6 +14,7 @@
<ProjectReference Include="..\..\common\Tnb.Common.Core\Tnb.Common.Core.csproj" />
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
<ProjectReference Include="..\..\message\Tnb.Message\Tnb.Message.csproj" />
<ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr.Entities\Tnb.ProductionMgr.Entities.csproj" />
<ProjectReference Include="..\..\QcMgr\Tnb.QcMgr.Entities\Tnb.QcMgr.Entities.csproj" />
<ProjectReference Include="..\..\system\Tnb.Systems.Interfaces\Tnb.Systems.Interfaces.csproj" />
<ProjectReference Include="..\Tnb.TaskScheduler.Interfaces\Tnb.TaskScheduler.Interfaces.csproj" />