DigitalFactory/Admin.NET/Admin.NET.Application/Service/ProductionTasks/ProductionTasksService.cs

150 lines
5.8 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 ProductionTasksService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<ProductionTasks> _rep;
public ProductionTasksService(SqlSugarRepository<ProductionTasks> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询生产任务单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<ProductionTasksOutput>> Page(ProductionTasksInput input)
{
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.OddNumber.Contains(input.SearchKey.Trim())
|| u.ProductType.Contains(input.SearchKey.Trim())
|| u.Name.Contains(input.SearchKey.Trim())
|| u.CodeNum.Contains(input.SearchKey.Trim())
|| u.Specifications.Contains(input.SearchKey.Trim())
|| u.ProductionLine.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.Name), u => u.Name.Contains(input.Name.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Specifications), u => u.Specifications.Contains(input.Specifications.Trim()))
.WhereIF(input.Batch>0, u => u.Batch == input.Batch)
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductionLine), u => u.ProductionLine.Contains(input.ProductionLine.Trim()))
.Select<ProductionTasksOutput>();
if(input.PlanStartDateRange != null && input.PlanStartDateRange.Count >0)
{
DateTime? start= input.PlanStartDateRange[0];
query = query.WhereIF(start.HasValue, u => u.PlanStartDate > start);
if (input.PlanStartDateRange.Count >1 && input.PlanStartDateRange[1].HasValue)
{
var end = input.PlanStartDateRange[1].Value.AddDays(1);
query = query.Where(u => u.PlanStartDate < end);
}
}
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.EndDateRange != null && input.EndDateRange.Count >0)
{
DateTime? start= input.EndDateRange[0];
query = query.WhereIF(start.HasValue, u => u.EndDate > start);
if (input.EndDateRange.Count >1 && input.EndDateRange[1].HasValue)
{
var end = input.EndDateRange[1].Value.AddDays(1);
query = query.Where(u => u.EndDate < 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(AddProductionTasksInput input)
{
var entity = input.Adapt<ProductionTasks>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 删除生产任务单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteProductionTasksInput 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(UpdateProductionTasksInput input)
{
var entity = input.Adapt<ProductionTasks>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取生产任务单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<ProductionTasks> Detail([FromQuery] QueryByIdProductionTasksInput 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<ProductionTasksOutput>> List()
{
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<ProductionTasksOutput>().ToListAsync();
}
}