Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
15
QcMgr/Tnb.QcMgr.Entities/Enums/EnumTriggerType.cs
Normal file
15
QcMgr/Tnb.QcMgr.Entities/Enums/EnumTriggerType.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,22 @@ using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.JsonSerialization;
|
||||
using JNPF.TaskScheduler;
|
||||
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
|
||||
using JNPF.TaskScheduler.Entitys.Model;
|
||||
using JNPF.VisualDev;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using Tnb.QcMgr.Entities;
|
||||
using Tnb.QcMgr.Entities.Dto;
|
||||
using Tnb.QcMgr.Entities.Entity;
|
||||
using Tnb.QcMgr.Entities.Enums;
|
||||
using Tnb.QcMgr.Interfaces;
|
||||
|
||||
namespace Tnb.QcMgr
|
||||
@@ -31,11 +37,12 @@ namespace Tnb.QcMgr
|
||||
{
|
||||
private readonly ISqlSugarRepository<QcCheckPlanH> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public QcCheckPlanService(ISqlSugarRepository<QcCheckPlanH> repository, IUserManager userManager)
|
||||
private readonly TimeTaskService _timeTaskService;
|
||||
public QcCheckPlanService(ISqlSugarRepository<QcCheckPlanH> repository, IUserManager userManager, TimeTaskService timeTaskService)
|
||||
{
|
||||
_repository = repository;
|
||||
_userManager = userManager;
|
||||
_timeTaskService = timeTaskService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -190,6 +197,35 @@ namespace Tnb.QcMgr
|
||||
await db.Insertable(QcCheckPlanDs).ExecuteCommandAsync();
|
||||
await db.Insertable(QcCheckPlanAdd).ExecuteCommandAsync();
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
|
||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
|
||||
<ProjectReference Include="..\Tnb.QcMgr.Interfaces\Tnb.QcMgr.Interfaces.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user