using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Admin.NET.Core;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
using Microsoft.AspNetCore.Http;
using System.Text;
using System.Web;
using SixLabors.ImageSharp;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
namespace Admin.NET.Application
{
///
/// 入库报表
///
[ApiDescriptionSettings("入库报表", Name = "WareHouseInReportForms", Order = 100)]
[Route("api/[Controller]")]
public class WareHouseInReportFormsService : IDynamicApiController, ITransient
{
private readonly IRepository _wmsOrderRep;
private readonly IRepository _sysDictTypeRep;
private readonly IRepository _sysDictDataRep;
private readonly ISysExcelTemplateService _sysExcelTemplateService;
private readonly static object _lock = new();
private readonly IRepository _wmsOrderTypeRep;
private readonly IRepository _wmsOrderDetailsRep;
private readonly IRepository _wmsPlaceRep;
private readonly IRepository _wmsTaskRep;
private readonly IRepository _wmsTakeMaterialOrderRep;
private readonly IRepository _wmsTakeMaterialOrderDetailRep;
public WareHouseInReportFormsService(
IRepository wmsOrderRep
,IRepository sysDictTypeRep
,IRepository sysDictDataRep
,ISysExcelTemplateService sysExcelTemplateService
,IRepository wmsOrderTypeRep
,IRepository wmsOrderDetailsRep
,IRepository wmsPlaceRep
,IRepository wmsTaskRep
,IRepository wmsTakeMaterialOrderRep
,IRepository wmsTakeMaterialOrderDetailRep
)
{
_wmsOrderRep = wmsOrderRep;
_sysDictTypeRep = sysDictTypeRep;
_sysDictDataRep = sysDictDataRep;
_sysExcelTemplateService = sysExcelTemplateService;
_wmsOrderTypeRep = wmsOrderTypeRep;
_wmsOrderDetailsRep = wmsOrderDetailsRep;
_wmsPlaceRep = wmsPlaceRep;
_wmsTaskRep = wmsTaskRep;
_wmsTakeMaterialOrderDetailRep = wmsTakeMaterialOrderDetailRep;
}
///
/// 分页查询入库报表
///
///
///
[HttpGet("GetWareHouseOutReportForms")]
public async Task> GetWareHouseOutReportForms([FromQuery] GetWareHouseInReportFormsInput input)
{
//任务表关联领料表
var pageResult = new PageResult();
pageResult.PageNo = input.PageNo;
pageResult.PageSize = input.PageSize;
var result =from p in _wmsTaskRep.AsQueryable()
join d in _wmsTakeMaterialOrderDetailRep.AsQueryable() on p.OrderDetailsId equals d.Id
where p.TaskStatus == TaskStatusEnum.WANCHENG
select new GetWareHouseInReportFormsOutput
{
OID = d.OID,
Materialcode = d.Materialcode,
Materialname = d.Materialname,
Unit = d.Unit,
Qty = d.Qty,
DistributeQty = d.DistributeQty,
SingleLength = d.SingleLength,
Number = d.Number,
Batchno_SCM = d.Batchno_SCM,
Batchno_WMS = d.Batchno_WMS,
ProjectCode = d.ProjectCode,
TACode = d.TACode,
PartCode = d.PartCode,
ContainerCode = p.ContainerCode,
PlaceCode = p.SourcePlace,
CreatedTime = p.CreatedTime,
Aisle = p.Aisle,
UpdatedTime = p.UpdatedTime,
};
result = result
.Where(!string.IsNullOrEmpty(input.Materialcode), u => EF.Functions.Like(u.Materialcode, $"%{input.Materialcode.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.Materialname), u => EF.Functions.Like(u.Materialname, $"%{input.Materialname.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.Batchno_SCM), u => EF.Functions.Like(u.Batchno_SCM, $"%{input.Batchno_SCM.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.Batchno_WMS), u => EF.Functions.Like(u.Batchno_WMS, $"%{input.Batchno_WMS.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.ProjectCode), u => EF.Functions.Like(u.ProjectCode, $"%{input.ProjectCode.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.ContainerCode), u => EF.Functions.Like(u.ContainerCode, $"%{input.ContainerCode.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.PlaceCode), u => EF.Functions.Like(u.PlaceCode, $"%{input.PlaceCode.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.TACode), u => EF.Functions.Like(u.TACode, $"%{input.TACode.Trim()}%"))
.Where(!string.IsNullOrEmpty(input.PartCode), u => EF.Functions.Like(u.PartCode, $"%{input.PartCode.Trim()}%"))
.Where(input.SearchBeginTime != null && input.SearchEndTime != null, u => u.CreatedTime >= DateTime.Parse(input.SearchBeginTime.Trim()) &&
u.CreatedTime <= DateTime.Parse(input.SearchEndTime.Trim()))
.OrderByDescending(u => u.UpdatedTime);
pageResult.Rows = result
.Skip((input.PageNo - 1) * input.PageSize).Take(input.PageSize).Adapt>();
pageResult.TotalRows = result.Count();
pageResult.TotalPage = (int)Math.Ceiling(pageResult.TotalRows / (double)pageResult.PageSize);
return pageResult;
}
}
}