91 lines
3.8 KiB
C#
91 lines
3.8 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Entitys.System;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
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 EqpEquipSparePartsService : IEqpEquipSparePartsService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<EqpEquipSpareParts> _repository;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public EqpEquipSparePartsService(ISqlSugarRepository<EqpEquipSpareParts> repository, IUserManager userManager)
|
|
{
|
|
_userManager = userManager;
|
|
_repository = repository;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task AddEquipSpareParts(EquipSparePartsInput input)
|
|
{
|
|
List<EqpEquipSpareParts> oldList = await _repository.GetListAsync(x => x.equip_id == input.equip_id);
|
|
List<EqpEquipSpareParts> list = new();
|
|
string orgId = _userManager?.GetUserInfo().Result.organizeId ?? "";
|
|
if (input != null && input.spare_parts_ids != null)
|
|
{
|
|
foreach (string spare_parts_id in input.spare_parts_ids)
|
|
{
|
|
if (oldList.Any(x => x.spare_parts_id == spare_parts_id))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
list.Add(new EqpEquipSpareParts()
|
|
{
|
|
id = SnowflakeIdHelper.NextId(),
|
|
equip_id = input.equip_id,
|
|
spare_parts_id = spare_parts_id,
|
|
create_id = _userManager?.UserId ?? "",
|
|
create_time = DateTime.Now,
|
|
org_id = orgId,
|
|
});
|
|
}
|
|
}
|
|
|
|
_ = await _repository.InsertRangeAsync(list);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetEquipSparePartsList(EquipQueryInput input)
|
|
{
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
Dictionary<string, string>? queryJson = new();
|
|
if (!string.IsNullOrEmpty(input.queryJson))
|
|
{
|
|
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
|
|
}
|
|
SqlSugarPagedList<EquipSparePartsQueryOutput> result = await db.Queryable<EqpEquipSpareParts>()
|
|
.LeftJoin<EqpSpareParts>((a, b) => a.spare_parts_id == b.id)
|
|
.LeftJoin<DictionaryTypeEntity>((a, b, c) => c.EnCode == Tnb.BasicData.DictConst.SparePartsType && c.DeleteMark == null)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, d) => d.DictionaryTypeId == c.Id && b.type_id == d.EnCode)
|
|
.Where((a, b, c, d) => a.equip_id == input.equip_id)
|
|
.WhereIF(queryJson != null && queryJson.ContainsKey("code"), (a, b, c, d) => b.code.Contains(queryJson!["code"]))
|
|
.WhereIF(queryJson != null && queryJson.ContainsKey("name"), (a, b, c, d) => b.name.Contains(queryJson!["name"]))
|
|
.Select((a, b, c, d) => new EquipSparePartsQueryOutput
|
|
{
|
|
id = a.id,
|
|
type_code = d.EnCode,
|
|
type_name = d.FullName,
|
|
code = b.code,
|
|
name = b.name,
|
|
specification = b.specification
|
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
return PageResult<EquipSparePartsQueryOutput>.SqlSugarPageResult(result);
|
|
}
|
|
}
|
|
} |