using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_ITaskInfoService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_TaskInfoService;
|
|
public class Task_HtyService : ServiceBase<Dt_Task_Hty, IRepository<Dt_Task_Hty>>, ITask_HtyService
|
{
|
public Task_HtyService(IRepository<Dt_Task_Hty> BaseDal) : base(BaseDal)
|
{
|
}
|
public WebResponseContent GetInOutTypeStats()
|
{
|
// 查询所有任务数据
|
var allTasks = BaseDal.QueryData()
|
.Select(x => new
|
{
|
TaskType = (TaskTypeEnum)x.TaskType,
|
Roadway = x.Roadway,
|
x.WarehouseId
|
})
|
.ToList();
|
|
// 如果没有数据,返回空列表
|
if (allTasks == null || !allTasks.Any())
|
{
|
return WebResponseContent.Instance.OK("未找到任何任务数据", new List<object>());
|
}
|
|
// 计算各仓库的任务类型分布
|
var result = allTasks
|
.GroupBy(x => x.Roadway == "1" || x.Roadway == "2" ? 1 : 2) // Roadway "1"和"2"属于WarehouseId=1,其他属于2
|
.Select(g => new
|
{
|
WarehouseId = g.Key,
|
Stats = g.Where(t => Enum.IsDefined(typeof(TaskTypeEnum), t.TaskType))
|
.GroupBy(t => t.TaskType)
|
.Select(typeGroup => new
|
{
|
Type = typeGroup.Key.GetDescription(),
|
Count = typeGroup.Count(),
|
Percentage = (int)(Math.Round((double)typeGroup.Count() / g.Count() * 100, 2))
|
})
|
.OrderByDescending(x => x.Count)
|
.ToList(),
|
TotalCount = g.Count()
|
})
|
.ToList();
|
|
return WebResponseContent.Instance.OK("成功", result);
|
}
|
public WebResponseContent GetWarehouseOperationStatistics()
|
{
|
/// <summary>
|
/// 原料仓,总出入库任务数量,今日入库,今日出库,成品仓,总出入库数量,今日入库,今日出库,
|
/// </summary>
|
|
// 获取今天的日期(不考虑时间部分)
|
var today = DateTime.Today;
|
var tomorrow = today.AddDays(1);
|
|
// 查询所有任务数据,包含创建时间
|
var allTasks = BaseDal.QueryData()
|
.Select(x => new
|
{
|
TaskType = (TaskTypeEnum)x.TaskType,
|
Roadway = x.Roadway,
|
x.WarehouseId,
|
CreateTime = x.CreateDate
|
})
|
.ToList();
|
|
// 如果没有数据,返回默认值
|
if (allTasks == null || !allTasks.Any())
|
{
|
var emptyResult = new
|
{
|
RawMaterialWarehouse = new
|
{
|
TotalTasks = 0,
|
TodayInbound = 0,
|
TodayOutbound = 0
|
},
|
FinishedProductWarehouse = new
|
{
|
TotalTasks = 0,
|
TodayInbound = 0,
|
TodayOutbound = 0
|
},
|
Summary = new
|
{
|
TotalAllTasks = 0,
|
TotalInbound = 0,
|
TotalOutbound = 0
|
}
|
};
|
return WebResponseContent.Instance.OK("未找到任何任务数据", emptyResult);
|
}
|
|
// 定义出入库任务类型
|
var inboundTypes = new[] { TaskTypeEnum.Inbound };
|
var outboundTypes = new[] { TaskTypeEnum.Outbound };
|
|
// 过滤出有效的任务数据
|
var validTasks = allTasks.Where(t => Enum.IsDefined(typeof(TaskTypeEnum), t.TaskType)).ToList();
|
|
// 计算原料仓(WarehouseId = 1)的统计
|
var rawMaterialTasks = validTasks.Where(t =>
|
t.Roadway == "1" || t.Roadway == "2" || t.WarehouseId == 1).ToList();
|
|
var rawMaterialStats = new
|
{
|
TotalTasks = rawMaterialTasks.Count,
|
TodayInbound = rawMaterialTasks.Count(t =>
|
inboundTypes.Contains(t.TaskType) &&
|
t.CreateTime >= today && t.CreateTime < tomorrow),
|
TodayOutbound = rawMaterialTasks.Count(t =>
|
outboundTypes.Contains(t.TaskType) &&
|
t.CreateTime >= today && t.CreateTime < tomorrow)
|
};
|
|
// 计算成品仓(WarehouseId = 2)的统计
|
var finishedProductTasks = validTasks.Where(t =>
|
(t.Roadway != "1" && t.Roadway != "2") || t.WarehouseId == 2).ToList();
|
|
var finishedProductStats = new
|
{
|
TotalTasks = finishedProductTasks.Count,
|
TodayInbound = finishedProductTasks.Count(t =>
|
inboundTypes.Contains(t.TaskType) &&
|
t.CreateTime >= today && t.CreateTime < tomorrow),
|
TodayOutbound = finishedProductTasks.Count(t =>
|
outboundTypes.Contains(t.TaskType) &&
|
t.CreateTime >= today && t.CreateTime < tomorrow)
|
};
|
|
// 计算总的入库和出库数量(所有仓库,所有时间)
|
var totalInbound = validTasks.Count(t => inboundTypes.Contains(t.TaskType));
|
var totalOutbound = validTasks.Count(t => outboundTypes.Contains(t.TaskType));
|
|
// 构建返回结果
|
var result = new
|
{
|
RawMaterialWarehouse = rawMaterialStats,
|
FinishedProductWarehouse = finishedProductStats,
|
Summary = new
|
{
|
TotalAllTasks = validTasks.Count,
|
TotalInbound = totalInbound, // 总共入库数量
|
TotalOutbound = totalOutbound // 总共出库数量
|
}
|
};
|
|
return WebResponseContent.Instance.OK("成功", result);
|
}
|
public WebResponseContent GetTodayInOutStats()
|
{
|
// 获取今天和7天前的日期
|
var today = DateTime.Now.Date;
|
var sevenDaysAgo = today.AddDays(-6); // 包含今天共7天
|
|
// 查询7天内全天数据(0:00-24:00)
|
var query = BaseDal.QueryData(x =>
|
x.CreateDate >= sevenDaysAgo &&
|
x.CreateDate < today.AddDays(1) // 包含今天全天
|
);
|
|
var tasks = query.Select(x => new
|
{
|
TaskType = (TaskTypeEnum)x.TaskType,
|
CreateDate = x.CreateDate
|
}).ToList();
|
|
if (!tasks.Any())
|
{
|
return WebResponseContent.Instance.OK("未找到任何任务数据", new List<object>());
|
}
|
|
// 统计每天出入库数量
|
var dailyStats = new List<object>();
|
|
for (int i = 0; i < 7; i++)
|
{
|
var currentDate = sevenDaysAgo.AddDays(i);
|
var nextDate = currentDate.AddDays(1); // 下一天的0:00
|
|
var dayTasks = tasks.Where(t =>
|
t.CreateDate >= currentDate &&
|
t.CreateDate < nextDate
|
).ToList();
|
|
var stats = new
|
{
|
Date = currentDate.ToString("yyyy-MM-dd"),
|
InboundCount = dayTasks.Count(t => t.TaskType == TaskTypeEnum.Inbound),
|
OutboundCount = dayTasks.Count(t => t.TaskType == TaskTypeEnum.Outbound),
|
TotalCount = dayTasks.Count
|
};
|
|
dailyStats.Add(stats);
|
}
|
|
return WebResponseContent.Instance.OK("成功", dailyStats);
|
}
|
|
}
|