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

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.QcMgr.Entities.Enums
{
public enum EnumTriggerType
{
= 1,
= 2,
= 3
}
}

View File

@@ -8,16 +8,22 @@ using System.Threading.Tasks;
using Aspose.Cells.Drawing; using Aspose.Cells.Drawing;
using JNPF.Common.Core.Manager; using JNPF.Common.Core.Manager;
using JNPF.Common.Enums; using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.DependencyInjection; using JNPF.DependencyInjection;
using JNPF.DynamicApiController; using JNPF.DynamicApiController;
using JNPF.FriendlyException; using JNPF.FriendlyException;
using JNPF.JsonSerialization; using JNPF.JsonSerialization;
using JNPF.TaskScheduler;
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
using JNPF.TaskScheduler.Entitys.Model;
using JNPF.VisualDev; using JNPF.VisualDev;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using Tnb.QcMgr.Entities; using Tnb.QcMgr.Entities;
using Tnb.QcMgr.Entities.Dto; using Tnb.QcMgr.Entities.Dto;
using Tnb.QcMgr.Entities.Entity; using Tnb.QcMgr.Entities.Entity;
using Tnb.QcMgr.Entities.Enums;
using Tnb.QcMgr.Interfaces; using Tnb.QcMgr.Interfaces;
namespace Tnb.QcMgr namespace Tnb.QcMgr
@@ -31,11 +37,12 @@ namespace Tnb.QcMgr
{ {
private readonly ISqlSugarRepository<QcCheckPlanH> _repository; private readonly ISqlSugarRepository<QcCheckPlanH> _repository;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly TimeTaskService _timeTaskService;
public QcCheckPlanService(ISqlSugarRepository<QcCheckPlanH> repository, IUserManager userManager) public QcCheckPlanService(ISqlSugarRepository<QcCheckPlanH> repository, IUserManager userManager, TimeTaskService timeTaskService)
{ {
_repository = repository; _repository = repository;
_userManager = userManager; _userManager = userManager;
_timeTaskService = timeTaskService;
} }
/// <summary> /// <summary>
@@ -190,6 +197,35 @@ namespace Tnb.QcMgr
await db.Insertable(QcCheckPlanDs).ExecuteCommandAsync(); await db.Insertable(QcCheckPlanDs).ExecuteCommandAsync();
await db.Insertable(QcCheckPlanAdd).ExecuteCommandAsync(); await db.Insertable(QcCheckPlanAdd).ExecuteCommandAsync();
await db.Ado.CommitTranAsync(); await db.Ado.CommitTranAsync();
if (QcCheckPlanAdd.triggertype == ((int)EnumTriggerType.).ToString()|| QcCheckPlanAdd.triggertype == ((int)EnumTriggerType.).ToString())
{
var comtentModel = new ContentModel();
comtentModel.cron = QcCheckPlanAdd.content!.Replace("\"", "");
comtentModel.interfaceId = "";
comtentModel.interfaceName = "";
comtentModel.parameter = new List<InterfaceParameter>();
comtentModel.parameter!.Add(new InterfaceParameter() { field = "id", value = QcCheckPlanAdd.mainid, defaultValue = "" });
if(QcCheckPlanAdd.triggertype == ((int)EnumTriggerType.).ToString())
comtentModel.parameter!.Add(new InterfaceParameter() { field = "doonce", value = true.ToString(), defaultValue = "" });
comtentModel.localHostTaskId = "QcTaskTimeWorker/CreateTask";
comtentModel.startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
comtentModel.TenantId = _userManager?.TenantId!;
comtentModel.TenantDbName = _userManager?.TenantDbName!;
comtentModel.ConnectionConfig = _userManager?.ConnectionConfig!;
comtentModel.Token = _userManager?.ToKen!;
TimeTaskCrInput timeTaskCrInput = new TimeTaskCrInput()
{
enCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
fullName = "生成质检任务" + QcCheckPlanAdd.mainid,
executeType = "3",
executeContent = comtentModel.ToJsonString(),
description = "",
sortCode = 99,
enabledMark = 1,
};
await _timeTaskService.DeleteByName(timeTaskCrInput.fullName);
await _timeTaskService.Create(timeTaskCrInput, false);
}
} }
catch (Exception) catch (Exception)
{ {

View File

@@ -8,6 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" /> <ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\Tnb.QcMgr.Interfaces\Tnb.QcMgr.Interfaces.csproj" /> <ProjectReference Include="..\Tnb.QcMgr.Interfaces\Tnb.QcMgr.Interfaces.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -8,8 +8,11 @@ using JNPF.Common.Security;
using JNPF.Systems.Entitys.System; using JNPF.Systems.Entitys.System;
using JNPF.TaskScheduler; using JNPF.TaskScheduler;
using JNPF.TaskScheduler.Entitys; using JNPF.TaskScheduler.Entitys;
using JNPF.TaskScheduler.Entitys.Model;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.QcMgr.Entities; using Tnb.QcMgr.Entities;
using Tnb.QcMgr.Entities.Entity; using Tnb.QcMgr.Entities.Entity;
using TimeTaskEntity = JNPF.TaskScheduler.Entitys.TimeTaskEntity; using TimeTaskEntity = JNPF.TaskScheduler.Entitys.TimeTaskEntity;
@@ -25,40 +28,69 @@ namespace Tnb.TaskScheduler.Listener
[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.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) if (timeTaskEntity == null)
return; 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(); var PlanDs = await repository.AsSugarClient().Queryable<QcCheckPlanD>().Where(p => p.mainid == timeTaskEntity.Description).ToListAsync();
if (PlanH == null || PlanDs.Count == 0) if (PlanH == null || PlanDs.Count == 0)
return; 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 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 DictionaryData = await repository.AsSugarClient().Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
QcCheckExecH qcCheckExecH = new QcCheckExecH(); foreach (var PrdMoTask in PrdMoTasks)
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)
{ {
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();
} }
await repository.AsSugarClient().Insertable(qcCheckExecH).ExecuteCommandAsync(); //只执行一次的 修改EnabledMark字段
await repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync(); 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); 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>
/// 停止. /// 停止.
/// </summary> /// </summary>

View File

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