128 lines
4.6 KiB
C#
128 lines
4.6 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 ReportTableService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<ReportTable> _rep;
|
|
public ReportTableService(SqlSugarRepository<ReportTable> rep)
|
|
{
|
|
_rep = rep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询汇报单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
public async Task<SqlSugarPagedList<ReportTableOutput>> Page(ReportTableInput input)
|
|
{
|
|
var query = _rep.AsQueryable()
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
u.OddNumber.Contains(input.SearchKey.Trim())
|
|
|| u.ProductType.Contains(input.SearchKey.Trim())
|
|
|| u.ProductionLine.Contains(input.SearchKey.Trim())
|
|
|| u.CodeNum.Contains(input.SearchKey.Trim())
|
|
|| u.SourceNumber.Contains(input.SearchKey.Trim())
|
|
|| u.Remarks.Contains(input.SearchKey.Trim())
|
|
)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.OddNumber), u => u.OddNumber.Contains(input.OddNumber.Trim()))
|
|
.WhereIF(input.State>0, u => u.State == input.State)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductType), u => u.ProductType.Contains(input.ProductType.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductionLine), u => u.ProductionLine.Contains(input.ProductionLine.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SourceNumber), u => u.SourceNumber.Contains(input.SourceNumber.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Remarks), u => u.Remarks.Contains(input.Remarks.Trim()))
|
|
.Select<ReportTableOutput>();
|
|
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);
|
|
}
|
|
}
|
|
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(AddReportTableInput input)
|
|
{
|
|
var entity = input.Adapt<ReportTable>();
|
|
await _rep.InsertAsync(entity);
|
|
return entity.Id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除汇报单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
public async Task Delete(DeleteReportTableInput 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(UpdateReportTableInput input)
|
|
{
|
|
var entity = input.Adapt<ReportTable>();
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取汇报单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
public async Task<ReportTable> Detail([FromQuery] QueryByIdReportTableInput 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<ReportTableOutput>> List()
|
|
{
|
|
return await _rep.AsQueryable().Select<ReportTableOutput>().ToListAsync();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|