// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Application.Entity;
using Admin.NET.Application.Service.ReportCenter.WmsOtherReport.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.SemanticSemproxySearchResponse.Types;
namespace Admin.NET.Application;
///
/// 工作台服务
///
[ApiDescriptionSettings(ApplicationConst.HomePageName, Order = 100)]
public class WmsHomePageService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly SqlSugarRepository _WmsStockQuanRep;
private readonly SqlSugarRepository _WmsOrderMovementDetailsRep;
private readonly SqlSugarRepository _v_wmsOrderMovementDetailsRep;
private readonly SqlSugarRepository _BaseCustomerRep;
private readonly SqlSugarRepository _wmsMaterialRep;
private readonly SqlSugarRepository _WmsNoCreateRuleRep;
private readonly SqlSugarRepository _repSNRep;
private readonly SqlSugarRepository _repRuleDetailRep;
private readonly SqlSugarRepository _WmsOrderDeliverDetailsRep;
private readonly SqlSugarRepository _wareActionLogRep;
private readonly WmsStockQuanService _wmsStockQuanService;
private readonly SqlSugarRepository _WmsBaseBusinessTypeRep;
private readonly SqlSugarRepository _wmsPlaceRep;
private readonly SqlSugarRepository _wmsContainerRep;
private readonly SqlSugarRepository _wmsContainerPlace;
private readonly SqlSugarRepository _v_wms_stock_quanRep;
private readonly SqlSugarRepository _wmsOrderAsnRep;
private readonly SqlSugarRepository _wmsRecordReceivingDeliveryRep;
public WmsHomePageService(
SqlSugarRepository wmsRecordReceivingDeliveryRep,
SqlSugarRepository rep,
SqlSugarRepository wmsStockQuanRep,
SqlSugarRepository wmsOrderMovementDetailsRep,
SqlSugarRepository baseCustomerRep,
SqlSugarRepository WmsBaseBusinessTypeRep,
SqlSugarRepository wmsNoCreateRuleRep,
SqlSugarRepository repSNRep,
SqlSugarRepository repRuleDetailRep,
SqlSugarRepository WmsOrderDeliverDetailsRep
, SqlSugarRepository wareActionLogRep
,
WmsStockQuanService wmsStockQuanService,
SqlSugarRepository v_wmsOrderMovementDetailsRep
,
SqlSugarRepository WmsMaterial,
SqlSugarRepository WmsBaseBusinessType,
SqlSugarRepository wmsPlaceRep,
SqlSugarRepository wmsContainerRep,
SqlSugarRepository wmsContainerPlace,
SqlSugarRepository v_wms_stock_quanRep,
SqlSugarRepository wmsOrderAsnRep
)
{
_wmsRecordReceivingDeliveryRep = wmsRecordReceivingDeliveryRep;
_rep = rep;
_WmsStockQuanRep = wmsStockQuanRep;
_WmsOrderMovementDetailsRep = wmsOrderMovementDetailsRep;
_BaseCustomerRep = baseCustomerRep;
_WmsBaseBusinessTypeRep = WmsBaseBusinessTypeRep;
_WmsNoCreateRuleRep = wmsNoCreateRuleRep;
_repSNRep = repSNRep;
_repRuleDetailRep = repRuleDetailRep;
_WmsOrderDeliverDetailsRep = WmsOrderDeliverDetailsRep;
_wareActionLogRep = wareActionLogRep;
_wmsStockQuanService = wmsStockQuanService;
_wmsMaterialRep = WmsMaterial;
_WmsBaseBusinessTypeRep = WmsBaseBusinessType;
_wmsPlaceRep = wmsPlaceRep;
_wmsContainerRep = wmsContainerRep;
_wmsContainerPlace = wmsContainerPlace;
_v_wms_stock_quanRep = v_wms_stock_quanRep;
_wmsOrderAsnRep = wmsOrderAsnRep;
}
///
/// 首页出入库数据查询
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "WmsHomePageQuery")]
[Description("WmsHomePageService/WmsHomePageQuery")]
public async Task WmsHomePageQuery()
{
var returnData = new WmsHomePageOutput();
// 获取今天的日期
DateTime today = DateTime.Today;
var MovementOrderList = await _rep.AsQueryable().Where(u => u.CreateTime >= today && u.CreateTime < today.AddDays(1)).ToListAsync();
returnData.OuttingPlaceNumber = MovementOrderList.Where(u => u.OrderType == OrderTypeEnum.下架单 && u.OrderStatus == OrderStatusEnum.已完成).ToList().Count();
returnData.WarehousingNumber = MovementOrderList.Where(u => u.OrderType == OrderTypeEnum.上架单 && u.OrderStatus == OrderStatusEnum.已完成).ToList().Count();
returnData.AllOuttingNumber = MovementOrderList.Where(u => u.OrderType == OrderTypeEnum.下架单 && u.OrderStatus != OrderStatusEnum.已关闭 && u.OrderStatus != OrderStatusEnum.已取消).ToList().Count();
returnData.AllWarehousingNumber = MovementOrderList.Where(u => u.OrderType == OrderTypeEnum.上架单 && u.OrderStatus != OrderStatusEnum.已关闭 && u.OrderStatus != OrderStatusEnum.已取消).ToList().Count();
returnData.AllOrderNumber = returnData.AllOuttingNumber + returnData.AllWarehousingNumber;
return returnData;
}
///
/// 首页库位数据查询
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "WmsHomePlaceQuery")]
[Description("WmsHomePageService/WmsHomePlaceQuery")]
public async Task WmsHomePlaceQuery()
{
var returnData = new WmsHomePagePlaceInfoOutput();
var PlaceList = await _wmsPlaceRep.AsQueryable().Where(x => x.IsDelete == false && (x.IsVirtually == false || x.IsVirtually == null)).ToListAsync();
var StockQueryList = await _v_wms_stock_quanRep.AsQueryable().ToListAsync();
StockQueryList = StockQueryList.GroupBy(u => u.PlaceCode).Select(g => g.First()).ToList();//用库位号分组,去重
returnData.ContainerPlaceNumber = StockQueryList.Where(p => p.MaterialTypeCode == ApplicationConst.DefaultContinerMaterialCode).ToList().Count();
returnData.StockPlaceNumber = StockQueryList.Where(p => p.MaterialTypeCode != ApplicationConst.DefaultContinerMaterialCode).ToList().Count();
returnData.EmptyPlaceNumber = PlaceList.Count - returnData.ContainerPlaceNumber - returnData.StockPlaceNumber;
returnData.AllPlaceNumber = PlaceList.Count();
returnData.EmptyPlacePercentage = $"{Math.Round((returnData.EmptyPlaceNumber / returnData.AllPlaceNumber), 4):P}";
returnData.StockPlacePercentage = $"{Math.Round((returnData.StockPlaceNumber / returnData.AllPlaceNumber), 4):P}";
returnData.ContainerPlacePercentage = $"{Math.Round((returnData.ContainerPlaceNumber / returnData.AllPlaceNumber), 4):P}";
return returnData;
}
/////
///// 最近7天收发货推移图
/////
/////
//[HttpPost]
//[ApiDescriptionSettings(Name = "WmsTransitionDiagramQuery")]
//[Description("WmsHomePageService/WmsTransitionDiagramQuery")]
//public async Task> WmsTransitionDiagramQuery()
//{
// // 获取当前时间
// DateTime currentDate = DateTime.Now;
// //DateTime lastWeekDay = currentDate.AddDays(-(int)currentDate.DayOfWeek - 3).Date;
// //DateTime thisWeekDay = currentDate.AddDays(7 - (int)currentDate.DayOfWeek - 3).Date;
// // 计算七天前的日期
// DateTime lastWeekDay = currentDate.AddDays(-7).Date;
// // 当前日期的前一天作为结束日期
// DateTime thisWeekDay = currentDate.AddDays(+1).Date;
// var WmsTransitionDiagramList = new List();
// var NewEmptyTransitionDiagramList = new List();
// var query = await _wmsOrderAsnRep.AsQueryable().Where(u => u.CreateTime >= lastWeekDay && u.CreateTime <= thisWeekDay).ToListAsync();
// foreach (var item in query)
// {
// if (item.CreateTime == null) { NewEmptyTransitionDiagramList.Add(item); continue; }
// item.CreateTime = new DateTime(item.CreateTime?.Year ?? 1999, item.CreateTime?.Month ?? 1, item.CreateTime?.Day ?? 1);
// }
// query.RemoveAll(n => NewEmptyTransitionDiagramList.Select(x => x.Id).Contains(n.Id));
// // 使用 LINQ 的 GroupBy 方法,按照创建时间的日期分组
// var groupedData = query.GroupBy(u => u.CreateTime)
// .Select(group => new TransitionDiagramData
// {
// Date = (DateTime)group.Key,
// DataListCount = group.Count()
// }).ToList();
// if (groupedData.Count(p => p.Date >= currentDate.Date) == 0)
// {
// var todayInfo = new TransitionDiagramData()
// {
// Date = currentDate.Date,
// DataListCount = 0
// };
// groupedData.Add(todayInfo);
// }
// foreach (var item in groupedData)
// {
// var model = new WmsTransitionDiagram()
// {
// Day = item.Date.ToString("yyyy-MM-dd"),
// ReceiptNumber = item.DataListCount
// };
// WmsTransitionDiagramList.Add(model);
// }
// return WmsTransitionDiagramList;
//}
///
/// 最近7天收发货推移图
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "WmsTransitionDiagramQuery")]
[Description("WmsHomePageService/WmsTransitionDiagramQuery")]
public async Task> WmsTransitionDiagramQuery()
{
List outputlist = new List();
DateTime currentDate = DateTime.Today.AddDays(1);
DateTime firstDate = DateTime.Today.AddDays(-6);
// 查询在这一天内的出入库记录
var recordsOfDay = await _wmsRecordReceivingDeliveryRep.AsQueryable().Where(r => r.CreateTime >= firstDate && r.CreateTime <= currentDate).ToListAsync();
for (int i = 1; i < 8; i++)
{
DateTime startDate = currentDate.AddDays(-i);
DateTime endDate = startDate.Date.AddDays(1).AddTicks(-1);
// 查询在这一天内的出入库记录
var items = recordsOfDay.Where(r => r.CreateTime >= startDate && r.CreateTime <= endDate).ToList();
// 汇总出入库记录(这里假设你有合适的逻辑来汇总数据)
var summary = new WmsTransitionDiagram
{
ReceiptNumber = items.Where(x => x.InOutFlag == InOutFlagEnum.入).ToList().Sum(x => x.Quantity),
DeliveryNumber = items.Where(x => x.InOutFlag == InOutFlagEnum.出).ToList().Sum(x => x.Quantity),
Day = startDate.Date.ToString("yyyy-MM-dd")
};
outputlist.Add(summary);
}
//排序
outputlist = outputlist.OrderBy(x => x.Day).ToList();
return outputlist;
}
public class TransitionDiagramData
{
public DateTime Date { get; set; }
public decimal DataListCount { get; set; }
}
}