145 lines
5.7 KiB
C#
145 lines
5.7 KiB
C#
|
using Admin.NET.Core.Service;
|
|||
|
using Admin.NET.Application.Const;
|
|||
|
using Admin.NET.Application.Entity;
|
|||
|
using Microsoft.AspNetCore.Http;
|
|||
|
namespace Admin.NET.Application;
|
|||
|
/// <summary>
|
|||
|
/// 发货通知单服务
|
|||
|
/// </summary>
|
|||
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
|||
|
public class InvoiceService : IDynamicApiController, ITransient
|
|||
|
{
|
|||
|
private readonly SqlSugarRepository<Invoice> _rep;
|
|||
|
public InvoiceService(SqlSugarRepository<Invoice> rep)
|
|||
|
{
|
|||
|
_rep = rep;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页查询发货通知单
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Page")]
|
|||
|
public async Task<SqlSugarPagedList<InvoiceOutput>> Page(InvoiceInput input)
|
|||
|
{
|
|||
|
var query = _rep.AsQueryable()
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|||
|
u.CodeNum.Contains(input.SearchKey.Trim())
|
|||
|
|| u.BusinessType.Contains(input.SearchKey.Trim())
|
|||
|
|| u.Custom.Contains(input.SearchKey.Trim())
|
|||
|
|| u.Warehouse.Contains(input.SearchKey.Trim())
|
|||
|
|| u.Department.Contains(input.SearchKey.Trim())
|
|||
|
|| u.CarNumber.Contains(input.SearchKey.Trim())
|
|||
|
|| u.ParkingSpace.Contains(input.SearchKey.Trim())
|
|||
|
|| u.Salesman.Contains(input.SearchKey.Trim())
|
|||
|
|| u.Consignee.Contains(input.SearchKey.Trim())
|
|||
|
|| u.DeliveryAddress.Contains(input.SearchKey.Trim())
|
|||
|
)
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BusinessType), u => u.BusinessType.Contains(input.BusinessType.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Custom), u => u.Custom.Contains(input.Custom.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Warehouse), u => u.Warehouse.Contains(input.Warehouse.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Department), u => u.Department.Contains(input.Department.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CarNumber), u => u.CarNumber.Contains(input.CarNumber.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ParkingSpace), u => u.ParkingSpace.Contains(input.ParkingSpace.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Salesman), u => u.Salesman.Contains(input.Salesman.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Consignee), u => u.Consignee.Contains(input.Consignee.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DeliveryAddress), u => u.DeliveryAddress.Contains(input.DeliveryAddress.Trim()))
|
|||
|
.Select<InvoiceOutput>();
|
|||
|
if(input.StartDateRange != null && input.StartDateRange.Count >0)
|
|||
|
{
|
|||
|
DateTime? start= input.StartDateRange[0];
|
|||
|
query = query.WhereIF(start.HasValue, u => u.StartDate > start);
|
|||
|
if (input.StartDateRange.Count >1 && input.StartDateRange[1].HasValue)
|
|||
|
{
|
|||
|
var end = input.StartDateRange[1].Value.AddDays(1);
|
|||
|
query = query.Where(u => u.StartDate < end);
|
|||
|
}
|
|||
|
}
|
|||
|
if(input.DeliveryDateRange != null && input.DeliveryDateRange.Count >0)
|
|||
|
{
|
|||
|
DateTime? start= input.DeliveryDateRange[0];
|
|||
|
query = query.WhereIF(start.HasValue, u => u.DeliveryDate > start);
|
|||
|
if (input.DeliveryDateRange.Count >1 && input.DeliveryDateRange[1].HasValue)
|
|||
|
{
|
|||
|
var end = input.DeliveryDateRange[1].Value.AddDays(1);
|
|||
|
query = query.Where(u => u.DeliveryDate < end);
|
|||
|
}
|
|||
|
}
|
|||
|
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 增加发货通知单
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Add")]
|
|||
|
public async Task<long> Add(AddInvoiceInput input)
|
|||
|
{
|
|||
|
var entity = input.Adapt<Invoice>();
|
|||
|
await _rep.InsertAsync(entity);
|
|||
|
return entity.Id;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除发货通知单
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Delete")]
|
|||
|
public async Task Delete(DeleteInvoiceInput input)
|
|||
|
{
|
|||
|
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
|||
|
await _rep.FakeDeleteAsync(entity); //假删除
|
|||
|
//await _rep.DeleteAsync(entity); //真删除
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 更新发货通知单
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Update")]
|
|||
|
public async Task Update(UpdateInvoiceInput input)
|
|||
|
{
|
|||
|
var entity = input.Adapt<Invoice>();
|
|||
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取发货通知单
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ApiDescriptionSettings(Name = "Detail")]
|
|||
|
public async Task<Invoice> Detail([FromQuery] QueryByIdInvoiceInput input)
|
|||
|
{
|
|||
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取发货通知单列表
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ApiDescriptionSettings(Name = "List")]
|
|||
|
public async Task<List<InvoiceOutput>> List()
|
|||
|
{
|
|||
|
return await _rep.AsQueryable().Select<InvoiceOutput>().ToListAsync();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|