using Furion.DatabaseAccessor;
|
using Furion.DatabaseAccessor.Extensions;
|
using Furion.DependencyInjection;
|
using Furion.DynamicApiController;
|
using Furion.FriendlyException;
|
using iWare.Wms.Core;
|
using Mapster;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.EntityFrameworkCore;
|
using System.Linq.Dynamic.Core;
|
|
namespace iWare.Wms.Application
|
{
|
/// <summary>
|
/// 端拾器小车类型信息服务
|
/// </summary>
|
[ApiDescriptionSettings("基础信息", Name = "WmsContainerType", Order = 100)]
|
[Route("api/[Controller]")]
|
public class WmsContainerTypeService : IDynamicApiController, ITransient
|
{
|
private readonly IRepository<WmsContainerType, MasterDbContextLocator> _wmsContainerTypeRep;
|
|
|
public WmsContainerTypeService(
|
IRepository<WmsContainerType, MasterDbContextLocator> wmsContainerTypeRep
|
)
|
{
|
_wmsContainerTypeRep = wmsContainerTypeRep;
|
}
|
|
/// <summary>
|
/// 分页查询端拾器小车类型信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("page")]
|
public async Task<PageResult<WmsContainerTypeOutput>> Page([FromQuery] WmsContainerTypeSearch input)
|
{
|
var wmsContainerTypes = await _wmsContainerTypeRep.DetachedEntities
|
.Where(!string.IsNullOrEmpty(input.WareContainerTypeCode), u => u.WareContainerTypeCode == input.WareContainerTypeCode)
|
.Where(!string.IsNullOrEmpty(input.WareContainerTypeName), u => u.WareContainerTypeName == input.WareContainerTypeName)
|
.Where(!string.IsNullOrEmpty(input.LocationType), u => u.LocationType == input.LocationType)
|
.Where(input.Status != null, u => u.Status == input.Status)
|
.OrderBy(PageInputOrder.OrderBuilder<WmsContainerTypeSearch>(input))
|
.ProjectToType<WmsContainerTypeOutput>()
|
.ToADPagedListAsync(input.PageNo, input.PageSize);
|
return wmsContainerTypes;
|
}
|
|
/// <summary>
|
/// 增加端拾器小车类型信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("add")]
|
public async Task Add(AddWmsContainerTypeInput input)
|
{
|
//string str = "";
|
//for (int i = 0; i < input.LocationType.Count; i++)
|
//{
|
// str = str + input.LocationType[i] + ",";
|
//}
|
//WmsContainerType wmsContainerType = new WmsContainerType()
|
//{
|
// WareContainerTypeCode = input.WareContainerTypeCode,
|
// WareContainerTypeName = input.WareContainerTypeName,
|
// Length = input.Length,
|
// LocationType = str.Trim(','),
|
// Height = input.Height,
|
// Width = input.Width,
|
// Status = input.Status
|
//};
|
var isExist = await _wmsContainerTypeRep.AnyAsync(n => n.WareContainerTypeCode == input.WareContainerTypeCode);
|
if (isExist) throw Oops.Oh("存在的相同的类型编码!");
|
|
var wmsContainerType = input.Adapt<WmsContainerType>();
|
await _wmsContainerTypeRep.InsertAsync(wmsContainerType);
|
}
|
|
/// <summary>
|
/// 删除端拾器小车类型信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("delete")]
|
public async Task Delete(DeleteWmsContainerTypeInput input)
|
{
|
var wmsContainerType = await _wmsContainerTypeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
await _wmsContainerTypeRep.DeleteAsync(wmsContainerType);
|
}
|
|
/// <summary>
|
/// 更新端拾器小车类型信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("edit")]
|
public async Task Update([FromBody] UpdateWmsContainerTypeInput input)
|
{
|
var isExist = await _wmsContainerTypeRep.AnyAsync(n => n.WareContainerTypeCode == input.WareContainerTypeCode && n.Id != input.Id);
|
if (isExist) throw Oops.Oh("存在的相同的类型编码!");
|
//var isExist = await _wmsContainerTypeRep.AnyAsync(u => u.Id == input.Id, false);
|
//if (!isExist) throw Oops.Oh(ErrorCode.D3000);
|
//string str = "";
|
//for (int i = 0; i < input.LocationType.Count; i++)
|
//{
|
// str = str + input.LocationType[i] + ",";
|
//}
|
//WmsContainerType wmsContainerType = new WmsContainerType()
|
//{
|
// WareContainerTypeCode = input.WareContainerTypeCode,
|
// WareContainerTypeName = input.WareContainerTypeName,
|
// Length = input.Length,
|
// LocationType = str.Trim(','),
|
// Height = input.Height,
|
// Width = input.Width,
|
// Status = input.Status
|
//};
|
var wmsContainerType = input.Adapt<WmsContainerType>();
|
await _wmsContainerTypeRep.UpdateAsync(wmsContainerType, ignoreNullValues: true);
|
}
|
|
/// <summary>
|
/// 获取端拾器小车类型信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("detail")]
|
public async Task<WmsContainerTypeOutput> Get([FromQuery] QueryeWmsContainerTypeInput input)
|
{
|
return (await _wmsContainerTypeRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WmsContainerTypeOutput>();
|
}
|
|
///// <summary>
|
///// 获取端拾器小车类型信息列表
|
///// </summary>
|
///// <param name="input"></param>
|
///// <returns></returns>
|
//[HttpGet("list")]
|
//public async Task<List<WmsContainerTypeOutput>> List([FromQuery] WmsContainerTypeInput input)
|
//{
|
// return await _wmsContainerTypeRep.DetachedEntities.ProjectToType<WmsContainerTypeOutput>().ToListAsync();
|
//}
|
|
|
/// <summary>
|
/// 获取容器类型列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet("fkWmsContainerType")]
|
public async Task<dynamic> FkWmsMaterialList()
|
{
|
var list = await _wmsContainerTypeRep.DetachedEntities.ToListAsync();
|
return list.Select(e => new { Code = e.WareContainerTypeCode, Name = e.WareContainerTypeName });
|
}
|
}
|
}
|