模具保养计划执行模块代码提交

This commit is contained in:
DEVICE8\12494
2023-05-22 19:17:14 +08:00
parent 486d76e3d0
commit 6ee558a3e4
11 changed files with 441 additions and 180 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -12,6 +13,7 @@ using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.System;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -32,10 +34,13 @@ namespace Tnb.EquipMgr
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager)
private readonly IDictionaryDataService _dictionaryDataService;
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager, IDictionaryDataService dictionaryDataService)
{
_db = repository.AsSugarClient();
_userManager = userManager;
_dictionaryDataService = dictionaryDataService;
}
/// <summary>
/// 根据规则Id获取匹配的模具列表
@@ -78,6 +83,111 @@ namespace Tnb.EquipMgr
})
.ToListAsync();
}
[HttpGet]
public async Task<dynamic> GetMaintainInfoFromByPlanId([FromRoute] string planId)
{
dynamic info = new ExpandoObject();
var planMoldRelation = await _db.Queryable<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.id == planId);
if (planMoldRelation != null)
{
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == planMoldRelation.mold_id);
if (mold != null)
{
info.mold_code = mold.mold_code;
info.mold_name = mold.mold_name;
var moldEqpRelation = await _db.Queryable<ToolMoldsEquipment>().FirstAsync(it => it.mold_id == mold.id);
if (moldEqpRelation != null)
{
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == moldEqpRelation.equipment_id);
info.eqp_code = eqp.code;
info.eqp_name = eqp.name;
}
var itemGroupRelation = await _db.Queryable<ToolMoldMaintainGroupRelation>().FirstAsync(it => it.mold_id == mold.id);
if (itemGroupRelation != null)
{
var itemGroup = await _db.Queryable<ToolMoldMaintainGroup>().FirstAsync(it => it.id == itemGroupRelation.item_group_id);
if (itemGroup != null)
{
info.item_group_name = itemGroup.name;
}
var itemRelation = await _db.Queryable<ToolMoldMaintainGroupItem>().FirstAsync(it => it.item_group_id == itemGroupRelation.item_group_id);
if (itemRelation != null)
{
var checkItem = await _db.Queryable<ToolMoldMaintainItem>().FirstAsync(it => it.id == itemRelation.item_id);
if (checkItem != null)
{
info.item_name = checkItem.name;
}
}
}
}
}
return info;
}
/// <summary>
/// 模具保养计划执行-开始模具保养
/// </summary>
/// <param name="input">
/// {
/// plan_id:执行计划id
/// }
/// </param>
/// <returns></returns>
[HttpPost]
public async Task MaintainStart(MoldMaintainRunUpInput input)
{
try
{
await _db.Ado.BeginTranAsync();
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.MaintainStatusTypeId);
var plan = await _db.Queryable<ToolMoldMaintainPlan>().FirstAsync(it => it.id == input.plan_id);
if (plan != null)
{
plan.status = DictConst.MoldMaintainStatusDBYCode;
var row = await _db.Updateable(plan).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
ToolMoldMaintainRunRecord record = new();
record.plan_code = plan.plan_code;
record.mode = plan.mode;
record.plan_status = dic.ContainsKey(plan.plan_code) ? dic[plan.plan_code].ToString() : "";
record.designer = _userManager.RealName;
record.designer_time = DateTime.Now;
var moldPlanRelation = await _db.Queryable<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.maintain_plan_id == input.plan_id);
if (moldPlanRelation != null)
{
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == moldPlanRelation.mold_id);
record.mold_code = mold?.mold_code;
record.mold_name = mold?.mold_name;
var moldGroupRelation = await _db.Queryable<ToolMoldMaintainGroupRelation>().FirstAsync(it => it.mold_id == mold.id);
if (moldGroupRelation != null)
{
var maintainGroup = await _db.Queryable<ToolMoldMaintainGroup>().FirstAsync(it => it.id == moldGroupRelation.item_group_id);
record.group_name = maintainGroup.name;
var itemGrpRelation = await _db.Queryable<ToolMoldMaintainGroupItem>().FirstAsync(it => it.item_group_id == maintainGroup.id);
if (itemGrpRelation != null)
{
var checkItem = await _db.Queryable<ToolMoldMaintainItem>().FirstAsync(it => it.id == itemGrpRelation.item_id);
record.check_item_name = checkItem.name;
}
}
}
record.plan_start_time = DateTime.Now;
row = await _db.Insertable(record).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
await _db.Ado.CommitTranAsync();
}
}
catch (Exception ex)
{
Log.Error("开始模具保养失败", ex);
await _db.Ado.RollbackTranAsync();
throw;
}
}
/// <summary>
/// 关联模具
@@ -89,6 +199,7 @@ namespace Tnb.EquipMgr
public async Task RelevanceMold(RelevanceMoldInput input)
{
if (input == null) throw new ArgumentNullException(nameof(input));
await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id).ExecuteCommandAsync();
if (input.rowIds?.Count > 0)
{
List<ToolMoldMaintainRuleRelation> entities = new();
@@ -133,30 +244,34 @@ namespace Tnb.EquipMgr
{
await _db.Ado.BeginTranAsync();
var maintainRule = await _db.Queryable<ToolMoldMaintainRule>().FirstAsync(it => it.id == input.rule_id);
if (maintainRule is not null)
var maintainRules = await _db.Queryable<ToolMoldMaintainRule>().Where(it => input.ruleIds.Contains(it.id)).ToListAsync();
if (maintainRules?.Count > 0)
{
if (maintainRule.cycle.HasValue && maintainRule.cycle.Value > 0)
List<ToolMoldMaintainPlan> maintainPlans = new();
List<ToolMoldMaintainPlanRelation> maintainPlanRelations = new();
foreach (var maintainRule in maintainRules)
{
ToolMoldMaintainPlan maintainPlan = new();
maintainPlan.plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}";
maintainPlan.mode = maintainRule.mode;
maintainPlan.status = DictConst.UnMaintainStatusCode;
maintainPlan.plan_start_date = DateTime.Now;
maintainPlan.plan_end_date = DateTime.Now.AddDays(maintainRule.cycle.Value);
maintainPlan.create_id = _userManager.UserId;
maintainPlan.create_time = DateTime.Now;
if (maintainRule.cycle.HasValue && maintainRule.cycle.Value > 0)
{
ToolMoldMaintainPlan maintainPlan = new();
maintainPlan.plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}";
maintainPlan.mode = maintainRule.mode;
maintainPlan.status = DictConst.UnMaintainStatusCode;
maintainPlan.plan_start_date = DateTime.Now;
maintainPlan.plan_end_date = DateTime.Now.AddDays(maintainRule.cycle.Value);
maintainPlan.create_id = _userManager.UserId;
maintainPlan.create_time = DateTime.Now;
maintainPlans.Add(maintainPlan);
await _db.Insertable(maintainPlan).ExecuteCommandAsync();
ToolMoldMaintainPlanRelation maintainPlanReation = new();
maintainPlanReation.maintain_plan_id = maintainPlan.id;
maintainPlanReation.mold_id = (await _db.Queryable<ToolMoldMaintainRuleRelation>().FirstAsync(it => it.rule_id == maintainRule.id))?.mold_id!;
await _db.Insertable(maintainPlanReation).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
ToolMoldMaintainPlanRelation maintainPlanReation = new();
maintainPlanReation.maintain_plan_id = maintainPlan.id;
maintainPlanReation.mold_id = (await _db.Queryable<ToolMoldMaintainRuleRelation>().FirstAsync(it => it.rule_id == maintainRule.id))?.mold_id!;
maintainPlanRelations.Add(maintainPlanReation);
}
}
await _db.Insertable(maintainPlans).ExecuteCommandAsync();
await _db.Insertable(maintainPlanRelations).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
}
}
catch (Exception ex)