This commit is contained in:
qianjiawei
2023-09-05 16:15:18 +08:00
parent 893b0bd95f
commit 36e4944e5e
6 changed files with 176 additions and 4 deletions

View File

@@ -26,6 +26,9 @@ public partial class ToolMoldMaintainPlanRelation : BaseEntity<string>
/// </summary>
public string mold_id { get; set; } = string.Empty;
public string group_id { get; set; } = string.Empty;
}

View File

@@ -39,4 +39,6 @@ public partial class ToolMoldMaintainRunRecordD : BaseEntity<string>
/// </summary>
public string? check_item_name { get; set; }
public string? mainid { get; set; }
}

View File

@@ -11,6 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\..\BasicData\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />
<ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" />
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\..\workflow\Tnb.WorkFlow\Tnb.WorkFlow.csproj" />
<ProjectReference Include="..\Tnb.EquipMgr.Interfaces\Tnb.EquipMgr.Interfaces.csproj" />

View File

@@ -2,11 +2,14 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reactive;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Aop.Api.Domain;
using Aspose.Cells.Drawing;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
@@ -14,11 +17,18 @@ using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.System;
using JNPF.TaskScheduler;
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
using JNPF.TaskScheduler.Entitys.Model;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SqlSugar;
using Tnb.BasicData;
using Tnb.BasicData.Entities;
using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto;
using Tnb.EquipMgr.Interfaces;
@@ -30,17 +40,78 @@ namespace Tnb.EquipMgr
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class ToolMoldMaintainRuleService : IToolMoldMaintainRuleService, IDynamicApiController, ITransient
[OverideVisualDev(ModuleId)]
public class ToolMoldMaintainRuleService : IOverideVisualDevService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient
{
private const string ModuleId = "26164864904981";
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
private readonly IDictionaryDataService _dictionaryDataService;
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager, IDictionaryDataService dictionaryDataService)
private readonly TimeTaskService _timeTaskService;
private readonly IVisualDevService _visualDevService;
private readonly IRunService _runService;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager, IDictionaryDataService dictionaryDataService, TimeTaskService timeTaskService, IVisualDevService visualDevService, IRunService runService)
{
_db = repository.AsSugarClient();
_userManager = userManager;
_dictionaryDataService = dictionaryDataService;
_timeTaskService = timeTaskService;
_visualDevService = visualDevService;
_runService = runService;
OverideFuncs.DeleteAsync = Delete;
OverideFuncs.CreateAsync = Create;
}
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
{
int cycle = int.Parse(input.data["cycle"].ToString()!);
var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(long.Parse(input.data["startandend_date"].ToString()!));
ToolMoldMaintainRule toolMoldMaintainRule = new ToolMoldMaintainRule();
toolMoldMaintainRule.id = SnowflakeIdHelper.NextId();
toolMoldMaintainRule.mode = input.data["mode"].ToString();
toolMoldMaintainRule.cycle = cycle;
toolMoldMaintainRule.startandend_date = startTime.ToString("yyyy-MM-dd HH:mm:ss");
await _db.Insertable(toolMoldMaintainRule).ExecuteCommandAsync();
if (toolMoldMaintainRule.mode == "27118635748885")
{
string id = toolMoldMaintainRule.id;
var comtentModel = new ContentModel();
comtentModel.cron = "0 0 9 "+ startTime.Day + "/"+ toolMoldMaintainRule.cycle + " * ?";
comtentModel.interfaceId = "";
comtentModel.interfaceName = "";
comtentModel.parameter = new List<InterfaceParameter>();
comtentModel.parameter!.Add(new InterfaceParameter() { field = "id", value = id, defaultValue = "" });
comtentModel.localHostTaskId = "MoldMaintainTask/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 = "生成模具保养任务" + id,
executeType = "3",
executeContent = comtentModel.ToJsonString(),
description = "",
sortCode = 99,
enabledMark = 1,
};
await _timeTaskService.DeleteByName(timeTaskCrInput.fullName);
await _timeTaskService.Create(timeTaskCrInput, false);
}
return await Task.FromResult(true);
}
private async Task Delete(string id)
{
var ToolMoldMaintainRule = await _db.Queryable<ToolMoldMaintainRule>().Where(p => p.id == id).FirstAsync();
var ToolMoldMaintainRuleRelations = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(p => p.rule_id == id).ToListAsync();
await _timeTaskService.DeleteByName("生成模具保养任务" + id);
await _db.Ado.BeginTranAsync();
await _db.Deleteable(ToolMoldMaintainRule).ExecuteCommandAsync();
await _db.Deleteable(ToolMoldMaintainRuleRelations).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
}
/// <summary>
/// 根据规则Id获取匹配的模具列表

View File

@@ -135,6 +135,10 @@ namespace Tnb.EquipMgr
item_name = e.name,
})
.ToListAsync();
//新增功能
var ToolMoldMaintainPlanRelation= _db.Queryable<ToolMoldMaintainPlanRelation>().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id&& !string.IsNullOrEmpty(a.group_id)).First();
if (ToolMoldMaintainPlanRelation != null)
items = items.Where(a => a.item_group_id == ToolMoldMaintainPlanRelation.group_id).ToList();
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new
{
plan_id = it.plan_id,
@@ -183,7 +187,7 @@ namespace Tnb.EquipMgr
var isOk = await _db.Updateable<ToolMolds>(mold).Where(it => it.id == input.mold_id).ExecuteCommandHasChangeAsync();
if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
var plan = await _db.Queryable<ToolMoldMaintainPlanRelation>().LeftJoin<ToolMoldMaintainPlan>((a, b) => a.maintain_plan_id == b.id)
.Where(a => a.mold_id == input.mold_id).Select((a, b) => b).FirstAsync();
.Where(a => a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).Select((a, b) => b).FirstAsync();
if (plan is not null)
{
@@ -200,6 +204,10 @@ namespace Tnb.EquipMgr
var row = await _db.Insertable(record).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
var groupids = _db.Queryable<ToolMoldMaintainPlanRelation>().Where(a => !string.IsNullOrEmpty(a.group_id) && a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).ToList().Select(p => p.group_id);
/*
var maintainInfos = await _db.Queryable<ToolMoldMaintainGroupRelation>()
.LeftJoin<ToolMoldMaintainGroup>((a, b) => a.item_group_id == b.id)
.LeftJoin<ToolMoldMaintainGroupItem>((a, b, c) => b.id == c.item_group_id)
@@ -213,12 +221,27 @@ namespace Tnb.EquipMgr
check_item_name = d.name
})
.ToListAsync();
*/
var maintainInfos = await _db.Queryable<ToolMoldMaintainGroupRelation>()
.LeftJoin<ToolMoldMaintainGroup>((a, b) => a.item_group_id == b.id)
.LeftJoin<ToolMoldMaintainGroupItem>((a, b, c) => b.id == c.item_group_id)
.LeftJoin<ToolMoldMaintainItem>((a, b, c, d) => c.item_id == d.id)
.WhereIF(groupids.Count() > 0, (a) => groupids.Contains(a.item_group_id))
.Where(a => a.mold_id == input.mold_id)
.Select((a, b, c, d) => new
{
group_id = b.id,
group_name = b.name,
check_item_id = d.id,
check_item_name = d.name
}).ToListAsync();
if (maintainInfos?.Count > 0)
{
List<ToolMoldMaintainRunRecordD> recordDs = new();
foreach (var info in maintainInfos)
{
ToolMoldMaintainRunRecordD record_d = new();
record_d.mainid = record.id;
record_d.group_id = info.group_id;
record_d.group_name = info.group_name;
record_d.check_item_id = info.check_item_id;
@@ -253,6 +276,7 @@ namespace Tnb.EquipMgr
record.mold_id = input.mold_id;
record.item_group_id = item.item_group_id;
record.item_id = item.item_id;
record.status = 1;
records.Add(record);
}
var row = await _db.Insertable(records).ExecuteCommandAsync();
@@ -283,6 +307,11 @@ namespace Tnb.EquipMgr
item_name = e.name,
})
.ToListAsync();
//新增功能
var ToolMoldMaintainPlanRelation = _db.Queryable<ToolMoldMaintainPlanRelation>().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id && !string.IsNullOrEmpty(a.group_id)).First();
if (ToolMoldMaintainPlanRelation != null)
items = items.Where(a => a.item_group_id == ToolMoldMaintainPlanRelation.group_id).ToList();
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new
{
plan_id = it.plan_id,

View File

@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF;
using JNPF.Common.Security;
using JNPF.Systems.Entitys.System;
using JNPF.TaskScheduler;
using JNPF.TaskScheduler.Entitys.Model;
using SqlSugar;
using Tnb.EquipMgr.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.QcMgr.Entities;
using Tnb.QcMgr.Entities.Entity;
namespace Tnb.TaskScheduler.Listener
{
internal class MoldMaintainTask : ISpareTimeWorker
{
private ISqlSugarRepository<ToolMoldMaintainRule> repository => App.GetService<ISqlSugarRepository<ToolMoldMaintainRule>>();
[SpareTime("0 0 0 * * ?", "生成模具保养任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)]
public async void CreateTask(SpareTimer timer, long count)
{
try
{
var timeTaskEntity = await repository.AsSugarClient().Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync();
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();
if (ToolMoldMaintainRule == null)
return;
var ToolMoldMaintainRuleRelations= await repository.AsSugarClient().Queryable<ToolMoldMaintainRuleRelation>().Where(p => p.rule_id == ToolMoldMaintainRule.id).ToListAsync();
if (ToolMoldMaintainRuleRelations.Count() > 0)
{
var now = DateTime.Now;
Random rNum = new Random();
ToolMoldMaintainPlan toolMoldMaintainPlan=new ToolMoldMaintainPlan();
toolMoldMaintainPlan.id = SnowflakeIdHelper.NextId();
toolMoldMaintainPlan.plan_code = "JHDM" + now.ToString("yyyyMMdd") + rNum.Next(1000, 9999).ToString();
toolMoldMaintainPlan.mode = ToolMoldMaintainRule.mode;
toolMoldMaintainPlan.status = "UnMaintain";
toolMoldMaintainPlan.plan_start_date = now;
toolMoldMaintainPlan.plan_end_date = now.AddDays((double)ToolMoldMaintainRule.cycle!);
List<ToolMoldMaintainPlanRelation> toolMoldMaintainPlanRelations = new List<ToolMoldMaintainPlanRelation>();
foreach (var ToolMoldMaintainRuleRelation in ToolMoldMaintainRuleRelations)
{
ToolMoldMaintainPlanRelation toolMoldMaintainPlanRelation = new ToolMoldMaintainPlanRelation();
toolMoldMaintainPlanRelation.id= SnowflakeIdHelper.NextId();
toolMoldMaintainPlanRelation.maintain_plan_id = toolMoldMaintainPlan.id;
toolMoldMaintainPlanRelation.mold_id = ToolMoldMaintainRuleRelation.mold_id;
toolMoldMaintainPlanRelation.group_id = ToolMoldMaintainRuleRelation.item_group_id;
toolMoldMaintainPlanRelations.Add(toolMoldMaintainPlanRelation);
}
await repository.AsSugarClient().Insertable(toolMoldMaintainPlanRelations).ExecuteCommandAsync();
await repository.AsSugarClient().Insertable(toolMoldMaintainPlan).ExecuteCommandAsync();
}
}
catch (Exception)
{
}
}
}
}