1
This commit is contained in:
@@ -3,17 +3,23 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aop.Api.Domain;
|
||||
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.Logging;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Entities.Entity;
|
||||
using Tnb.EquipMgr.Interfaces;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
@@ -23,12 +29,14 @@ namespace Tnb.EquipMgr
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class ToolMoldMaintainRuleService : BaseMoldMaintainService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
||||
public class ToolMoldMaintainRuleService : IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository) : base(repository.AsSugarClient())
|
||||
private readonly IUserManager _userManager;
|
||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据规则Id获取匹配的模具列表
|
||||
@@ -44,10 +52,33 @@ namespace Tnb.EquipMgr
|
||||
{
|
||||
var ids = list.Select(it => it.mold_id).ToList();
|
||||
result = await _db.Queryable<ToolMolds>().Where(it => ids.Contains(it.id))
|
||||
.Select(it => new MaintainRuleMoldListOutput { mold_id = it.id }, true).ToListAsync();
|
||||
.Select(it => new MaintainRuleMoldListOutput { mold_id = it.id, item_group_id = list.First().item_group_id }, true)
|
||||
.Mapper
|
||||
(
|
||||
it => it.item_group_name = _db.Queryable<ToolMoldMaintainGroup>().First(x => x.id == list.First().item_group_id).name!
|
||||
)
|
||||
.ToListAsync();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取模具选择列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetMoldRuleSelectorList()
|
||||
{
|
||||
return await _db.Queryable<ToolMolds>().Select(it => new MoldRuleSelectorListOutput
|
||||
{
|
||||
mold_id = it.id,
|
||||
}, true)
|
||||
.Mapper(it =>
|
||||
{
|
||||
var itemGroupIds = _db.Queryable<ToolMoldMaintainGroupRelation>().Where(x => x.mold_id == it.mold_id).Select(x => x.item_group_id).Distinct().ToList();
|
||||
it.groupItems = _db.Queryable<ToolMoldMaintainGroup>().Where(x => itemGroupIds.Contains(x.id)).Select(x => new MaintainItemGroupItem { item_group_id = x.id, name = x.name }).ToList();
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关联模具
|
||||
@@ -56,8 +87,26 @@ namespace Tnb.EquipMgr
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
[HttpPost]
|
||||
public async Task RelevanceMold(RelevanceMoldInput input) =>
|
||||
await Relevance<RelevanceMoldInput, ToolMoldMaintainRuleRelation>(input, nameof(ToolMoldMaintainRuleRelation.rule_id), nameof(ToolMoldMaintainRuleRelation.mold_id), it => it.rule_id == input.rule_id);
|
||||
public async Task RelevanceMold(RelevanceMoldInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||
if (input.rowIds?.Count > 0)
|
||||
{
|
||||
List<ToolMoldMaintainRuleRelation> entities = new();
|
||||
foreach (var item in input.rowIds)
|
||||
{
|
||||
ToolMoldMaintainRuleRelation entity = new();
|
||||
entity.id = SnowflakeIdHelper.NextId();
|
||||
entity.rule_id = input.rule_id;
|
||||
entity.mold_id = item.mold_id;
|
||||
entity.item_group_id = item.group_id;
|
||||
|
||||
entities.Add(entity);
|
||||
}
|
||||
var row = await _db.Insertable(entities).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除模具信息
|
||||
/// </summary>
|
||||
@@ -66,8 +115,56 @@ namespace Tnb.EquipMgr
|
||||
[HttpPost]
|
||||
public async Task DeleteMoldRelevance(RelevanceMoldInput input)
|
||||
{
|
||||
var row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
|
||||
if (input.ids?.Count > 0)
|
||||
{
|
||||
var row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 生成模具保养计划
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task GenMaintainPlan(MaintainPlanCrInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
var maintainRule = await _db.Queryable<ToolMoldMaintainRule>().FirstAsync(it => it.id == input.rule_id);
|
||||
if (maintainRule is not null)
|
||||
{
|
||||
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;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("生成保养计划失败", ex);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user