74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
|
|
namespace Tnb.EquipMgr
|
|
{
|
|
/// <summary>
|
|
/// 模具保养规则定义服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class ToolMoldMaintainRuleService : BaseMoldMaintainService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository) : base(repository.AsSugarClient())
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
/// <summary>
|
|
/// 根据规则Id获取匹配的模具列表
|
|
/// </summary>
|
|
/// <param name="ruleId">规则Id</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetListById([FromRoute] string ruleId)
|
|
{
|
|
var result = new List<MaintainRuleMoldListOutput>();
|
|
var list = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == ruleId).ToListAsync();
|
|
if (list?.Count > 0)
|
|
{
|
|
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();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关联模具
|
|
/// </summary>
|
|
/// <param name="input">关联模具输入参数</param>
|
|
/// <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);
|
|
/// <summary>
|
|
/// 删除模具信息
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[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);
|
|
}
|
|
}
|
|
}
|