119 lines
4.7 KiB
C#
119 lines
4.7 KiB
C#
using System.Linq.Expressions;
|
|
using JNPF.Common.Contracts;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
|
|
namespace Tnb.EquipMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
|
|
public class ToolMoldMaintainGroupService : BaseMoldMaintainService, IToolMoldMaintainGroupService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<ToolMoldMaintainGroup> _repository;
|
|
private readonly ISqlSugarClient _db;
|
|
public ToolMoldMaintainGroupService(ISqlSugarRepository<ToolMoldMaintainGroup> repository) : base(repository.AsSugarClient())
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
|
|
#region Get
|
|
/// <summary>
|
|
/// 根据项目组Id获取关联保养项信息
|
|
/// </summary>
|
|
/// <param name="itemGroupId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{itemGroupId}")]
|
|
public async Task<dynamic> GetMaintianItemListByGroupId(string itemGroupId)
|
|
{
|
|
var list = new List<MoldMaintainItemListOutput>();
|
|
var itemIds = await _db.Queryable<ToolMoldMaintainGroupItem>().Where(it => it.item_group_id == itemGroupId).Select(it => it.item_id).ToListAsync();
|
|
if (itemIds?.Count > 0)
|
|
{
|
|
var items = await _db.Queryable<MoldMaintenance>().Where(it => itemIds.Contains(it.id)).ToListAsync();
|
|
list = items.Adapt<List<MoldMaintainItemListOutput>>();
|
|
}
|
|
return list;
|
|
}
|
|
/// <summary>
|
|
/// 根据项目组Id获取关联模具信息
|
|
/// </summary>
|
|
/// <param name="itemGroupId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{itemGroupId}")]
|
|
public async Task<dynamic> GetMoldListByGroupId(string itemGroupId)
|
|
{
|
|
var list = new List<RelevanceMoldListOutput>();
|
|
var moldIds = await _db.Queryable<ToolMoldMaintainGroupRelation>().Where(it => it.item_group_id == itemGroupId).Select(it => it.mold_id).ToListAsync();
|
|
if (moldIds?.Count > 0)
|
|
{
|
|
var items = await _db.Queryable<ToolMolds>().Where(it => moldIds.Contains(it.id)).ToListAsync();
|
|
list = items.Adapt<List<RelevanceMoldListOutput>>();
|
|
}
|
|
return list;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Post
|
|
/// <summary>
|
|
/// 关联保养组与保养项
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task RelevanceMaintianGroupAndItem(MoldMaintainGroupItemInput input)
|
|
{
|
|
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input, nameof(ToolMoldMaintainGroupItem.item_group_id), nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关联项目组与模具
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input)
|
|
{
|
|
await Relevance<MoldMaintainGroupItemRelationInput, ToolMoldMaintainGroupRelation>(input, nameof(ToolMoldMaintainGroupRelation.item_group_id), nameof(ToolMoldMaintainGroupRelation.mold_id), it => it.item_group_id == input.id);
|
|
}
|
|
/// <summary>
|
|
/// 删除项目组与模具检查项信息
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task Delete(MoldMaintainDelInput input)
|
|
{
|
|
if (input.table_name == "item")
|
|
{
|
|
await Delete<ToolMoldMaintainGroupItem>(it => it.item_group_id == input.id && input.ids.Contains(it.item_id));
|
|
await Delete<ToolMoldMaintainItemRecord>(it => it.item_group_id == input.id && input.ids.Contains(it.item_id));
|
|
}
|
|
else
|
|
{
|
|
await Delete<ToolMoldMaintainGroupRelation>(it => it.item_group_id == input.id && input.ids.Contains(it.mold_id));
|
|
await Delete<ToolMoldMaintainItemRecord>(it => it.item_group_id == input.id && input.ids.Contains(it.mold_id));
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
private async Task Delete<T>(Expression<Func<T, bool>> deleteExp) where T : BaseEntity<string>, new()
|
|
{
|
|
await _db.Deleteable<T>().Where(deleteExp).ExecuteCommandAsync();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|