This commit is contained in:
alex
2023-09-05 17:40:44 +08:00
13 changed files with 325 additions and 10 deletions

View File

@@ -0,0 +1,23 @@
namespace Tnb.BasicData.Interfaces
{
/// <summary>
/// 二维码
/// </summary>
public interface IBasQrcodeService
{
/// <summary>
/// 根据code获取qrcode
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public Task<dynamic> GetQrcodeByCode(Dictionary<string, string> dic);
/// <summary>
/// 根据code获取工位信息
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public Task<dynamic> GetWorkStationByCode(Dictionary<string, string> dic);
}
}

View File

@@ -0,0 +1,84 @@
using JNPF.Common.Core.Manager;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.BasicData.Entities.Dto;
using Tnb.BasicData.Entitys.Dto.BasProcess;
using Tnb.BasicData.Interfaces;
using Tnb.EquipMgr.Entities;
namespace Tnb.BasicData
{
/// <summary>
/// 二维码
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
[Route("api/[area]/[controller]/[action]")]
public class BasQrcodeService : IBasQrcodeService,IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<BasMaterial> _repository;
private readonly DataBaseManager _dbManager;
private readonly IDictionaryDataService _dictionaryDataService;
public BasQrcodeService(
ISqlSugarRepository<BasMaterial> repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService)
{
_repository = repository;
_dbManager = dbManager;
_dictionaryDataService = dictionaryDataService;
}
[HttpPost]
public async Task<dynamic> GetQrcodeByCode(Dictionary<string, string> dic)
{
string code = dic.ContainsKey("code") ? dic["code"] : "";
if (string.IsNullOrEmpty(code)) return null;
var result = await _repository.AsSugarClient().Queryable<BasQrcode>()
.LeftJoin<OrganizeEntity>((a, b) => a.source_id == b.Id)
.LeftJoin<EqpEquipment>((a, b, c) => a.source_id == c.id)
.LeftJoin<ToolLocation>((a, b, c, d) => a.source_id == d.id)
.Where((a, b, c, d) => a.code == code)
.Select((a, b, c, d) => new
{
id = a.id,
source_id = a.source_id,
source_name = a.source_name,
org_code = b.EnCode,
org_name = b.FullName,
equip_code = a.code,
equip_name = c.name,
tool_location_code = d.location_code,
}).FirstAsync();
return result;
}
[HttpPost]
public async Task<dynamic> GetWorkStationByCode(Dictionary<string, string> dic)
{
string code = dic.ContainsKey("code") ? dic["code"] : "";
if (string.IsNullOrEmpty(code)) return null;
var result = await _repository.AsSugarClient().Queryable<BasQrcode>()
.LeftJoin<OrganizeEntity>((a, b) => a.source_id == b.Id)
.LeftJoin<OrganizeRelationEntity>((a,b,c)=>a.source_id==c.ObjectId && c.ObjectType=="Eqp")
.LeftJoin<OrganizeEntity>((a,b,c,d)=>c.OrganizeId==d.Id)
.Where((a, b, c) => a.code == code)
.Select((a, b, c,d) => new
{
id = a.id,
source_id = a.source_id,
source_name = a.source_name,
org_id = b.Id,
org_code = b.EnCode,
org_name = b.FullName,
org_id2 = d.Id,
org_code2 = d.EnCode,
org_name2 = d.FullName,
}).FirstAsync();
return result;
}
}
}

View File

@@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" />
<ProjectReference Include="..\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />

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

@@ -31,5 +31,9 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// 工序
/// </summary>
public string process { get; set; }
/// <summary>
/// 工位id
/// </summary>
public string stationId { get; set; }
}
}

View File

@@ -678,6 +678,13 @@ namespace Tnb.ProductionMgr
moTask.scheduled_qty = input.scheduled_qty;
moTask.unit_id = mo.unit_id;
if (!string.IsNullOrEmpty(input.eqp_id))
{
OrganizeRelationEntity organizeRelationEntity = await db.Queryable<OrganizeRelationEntity>()
.Where(x => x.ObjectId == input.eqp_id && x.ObjectType == "Eqp").FirstAsync();
moTask.workstation_id = organizeRelationEntity?.OrganizeId ?? "";
}
var moCode = mo?.mo_code;
var taskCode = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.PRDMOTASK_CODE);
moTask.mo_task_code = taskCode;
@@ -944,10 +951,19 @@ namespace Tnb.ProductionMgr
.ToListAsync();
if (subTaskList?.Count > 0)
{
List<string> workstationIds = await _db.Queryable<OrganizeEntity>().Where(x =>
x.Category == DictConst.RegionCategoryStationCode &&
x.OrganizeIdTree.Contains(input.workline_id)).Select(x=>x.Id).ToListAsync();
List<PrdMoTask> subMoTasks = new();
List<PrdTaskLog> subMoTaskLogs = new();
foreach (var item in subTaskList)
{
BasMbomProcess basMbomProcess = await _db.Queryable<BasMbomProcess>().SingleAsync(x=>x.id==item.mbom_process_id);
List<string> mbomProcessStationIds = JsonConvert.DeserializeObject<string[][]>(basMbomProcess.station).Select(x=>x[x.Length-1]).ToList();
List<string>? resultList = workstationIds.Intersect(mbomProcessStationIds).ToList();
PrdMoTask subMoTask = new();
subMoTask.mo_id = input.mo_id;
subMoTask.material_id = item.material_id;
@@ -956,6 +972,7 @@ namespace Tnb.ProductionMgr
subMoTask.bom_id = input.bom_id;
subMoTask.process_id = item.process_id;
subMoTask.mbom_process_id = item.mbom_process_id;
subMoTask.workstation_id = resultList?.FirstOrDefault() ?? "";
subMoTask.mo_task_status = DictConst.ToBeScheduledEncode;
subMoTask.workroute_id = item.route_id;
subMoTask.workline_id = input.workline_id;

View File

@@ -49,6 +49,8 @@ namespace Tnb.ProductionMgr
public async Task<dynamic> GetList(PrdPackReportQueryInput input)
{
if (input == null) throw new ArgumentNullException("input");
if (string.IsNullOrEmpty(input.stationId)) return Array.Empty<string>();
List<PackReportTreeOutput> trees = new();
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
var list = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "workline").ToListAsync();
@@ -75,13 +77,17 @@ namespace Tnb.ProductionMgr
endTimes[1] = GetDateTimeMilliseconds(input.estimated_end_date![1]);
}
var items = await _db.Queryable<PrdMoTask>().LeftJoin<BasProcess>((a, b) => a.process_id == b.id).LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
var items = await _db.Queryable<PrdMoTask>()
.LeftJoin<BasProcess>((a, b) => a.process_id == b.id)
.LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
.LeftJoin<PrdMoTask>((a,b,c,d)=>a.id==d.parent_id)
.WhereIF(!string.IsNullOrEmpty(input.mo_task_code), a => a.mo_task_code == input.mo_task_code.Trim())
// .WhereIF(start, a => a.estimated_start_date != null&& startTimes[0] <= a.estimated_start_date && startTimes[1] >= a.estimated_start_date)
// .WhereIF(end, a => a.estimated_end_date != null && endTimes[0] <= a.estimated_end_date && endTimes[1] >= a.estimated_end_date)
.WhereIF(!string.IsNullOrEmpty(input.workline), a => list.Where(p => p.EnCode.Contains(input.workline) || p.FullName.Contains(input.workline)).Select(p => p.Id).ToList().Contains(a.workline_id!))
.Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled")
.OrderByDescending(a=>a.create_time)
.Where((a,b,c,d)=>d.workstation_id==input.stationId)
.OrderByDescending(a=>a.create_time)
.Select((a, b, c) => new PrdMoTask
{
id = a.id,
@@ -122,7 +128,7 @@ namespace Tnb.ProductionMgr
}
node.plan_start_date = item.plan_start_date.HasValue ? item.plan_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
node.plan_end_date = item.plan_end_date.HasValue ? item.plan_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
await GetChild(item.id, trees, dic);
await GetChild(item.id, trees, dic,input.stationId);
trees.Add(node);
}
}
@@ -170,13 +176,13 @@ namespace Tnb.ProductionMgr
return dt;
}
private async Task GetChild(string parentId, List<PackReportTreeOutput> nodes, Dictionary<string, object> dic)
private async Task GetChild(string parentId, List<PackReportTreeOutput> nodes, Dictionary<string, object> dic,string stationId)
{
var items = await _db.Queryable<PrdMoTask>()
.LeftJoin<BasProcess>((a, b) => a.process_id == b.id)
.LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
.LeftJoin<BasMbomProcess>((a, b, c, d) => a.mbom_process_id == d.id)
.Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled")
.Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled" && a.workstation_id==stationId)
.OrderBy((a, b, c, d) => d.ordinal)
.Select((a, b, c) => new PrdMoTask
{
@@ -222,7 +228,7 @@ namespace Tnb.ProductionMgr
nodes.AddRange(nsChild);
foreach (var item in items)
{
await GetChild(item.id, nodes, dic);
await GetChild(item.id, nodes, dic,stationId);
}
}
}

View File

@@ -119,6 +119,13 @@ namespace Tnb.ProductionMgr
var db = _repository.AsSugarClient();
Dictionary<string, object> queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject<Dictionary<string, object>>(input.queryJson) : new Dictionary<string, object>();
string moTaskCode = queryJson!=null && queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : "";
string stationId = queryJson!=null && queryJson.ContainsKey("stationId") ? queryJson["stationId"].ToString() : "";
if (string.IsNullOrEmpty(stationId))
{
return Array.Empty<string>();
}
Dictionary<string, object> dic = await _dictionaryDataService.GetDicByKey(DictConst.TaskStatus);
DateTime[] planStartDateArr = null;
@@ -142,6 +149,7 @@ namespace Tnb.ProductionMgr
.WhereIF(!string.IsNullOrEmpty(moTaskCode),(a,b,c,d)=>a.mo_task_code.Contains(moTaskCode))
.WhereIF(planStartDateArr!=null, (a, b, c, d) => a.estimated_start_date>=planStartDateArr[0] && a.estimated_start_date<=planStartDateArr[1])
.WhereIF(planEndDateArr!=null, (a, b, c, d) => a.estimated_end_date>=planEndDateArr[0] && a.estimated_end_date<=planEndDateArr[1])
.Where((a,b,c,d)=>a.workstation_id==stationId)
.OrderByDescending((a, b, c, d) => a.create_time)
.Select((a, b, c, d) => new PrdTaskManageListOutput()
{

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)
{
}
}
}
}