模具保养管理接口代码提交
This commit is contained in:
109
EquipMgr/Tnb.EquipMgr/ToolMoldMaintainGroupService.cs
Normal file
109
EquipMgr/Tnb.EquipMgr/ToolMoldMaintainGroupService.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
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.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.Common.Contracts;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Entities.Entity;
|
||||
using Tnb.EquipMgr.Interfaces;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
{
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
|
||||
public class ToolMoldMaintainGroupService : IToolMoldMaintainGroupService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarRepository<ToolMoldMaintainGroup> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ISqlSugarClient _db;
|
||||
public ToolMoldMaintainGroupService(ISqlSugarRepository<ToolMoldMaintainGroup> repository, IUserManager userManager)
|
||||
{
|
||||
_repository = repository;
|
||||
_userManager = userManager;
|
||||
_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);
|
||||
|
||||
/// <summary>
|
||||
/// 关联项目组与模具
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input) =>
|
||||
await Relevance<MoldMaintainGroupItemRelationInput, ToolMoldMaintainGroupRelation>(input);
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private async Task Relevance<TSrc, TDest>(TSrc input) where TDest : BaseEntity<string>, new()
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||
var entity = input.Adapt<TDest>();
|
||||
entity.id = SnowflakeIdHelper.NextId();
|
||||
var row = await _db.Insertable(entity).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user