From 64840e4e6d97d177b8a765ba8c53888abcf86d16 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 13 一月 2026 18:48:20 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 162 insertions(+), 17 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs"
index b32da1f..f533a7f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs"
@@ -1,15 +1,21 @@
锘縰sing IBigBreenService;
+using Microsoft.IdentityModel.Tokens;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
+using WIDESEA_Core.Helper;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
namespace BigGreenService
{
@@ -20,9 +26,12 @@
private readonly IRepository<Dt_LocationInfo> _locationInfoRepository;
private readonly IRepository<Dt_OutboundOrderDetail> _outBoundOrderDetailRepository;
private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
+ private readonly IRepository<Dt_Task_Hty> _taskHtyRepository;
private readonly IRepository<Dt_Task> _taskRepository;
+ private readonly IRepository<Dt_StockInfo> _stockInfoRepository;
+ private readonly IRepository<Dt_MaterialExpirationDate> _materialExpirationDateRepository;
- public BigGreenService(IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_OutboundOrder> outBoundOrderRepository, IRepository<Dt_LocationInfo> locationInfoRepository,IRepository<Dt_OutboundOrderDetail> outBoundOrderDetailRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository,IRepository<Dt_Task> taskRepository)
+ public BigGreenService(IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_OutboundOrder> outBoundOrderRepository, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_OutboundOrderDetail> outBoundOrderDetailRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IRepository<Dt_Task_Hty> taskHtyRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_MaterialExpirationDate> materialExpirationDateRepository)
{
_stockInfoDetailRepository = stockInfoDetailRepository;
_outBoundOrderRepository = outBoundOrderRepository;
@@ -30,6 +39,9 @@
_outBoundOrderDetailRepository = outBoundOrderDetailRepository;
_inboundOrderDetailRepository = inboundOrderDetailRepository;
_taskRepository = taskRepository;
+ _taskHtyRepository = taskHtyRepository;
+ _stockInfoRepository = stockInfoRepository;
+ _materialExpirationDateRepository = materialExpirationDateRepository;
}
public WebResponseContent GetBigGreenData()
{
@@ -42,29 +54,46 @@
(int)OutOrderStatusEnum.鍑哄簱涓�,
(int)OutOrderStatusEnum.鏈紑濮�
};
- var unOutBound =_outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x =>targetStatus.Contains(x.OrderStatus)).Count();
+ var unOutBound = _outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => targetStatus.Contains(x.OrderStatus)).Count();
//璁$畻搴撲綅鍒╃敤鐜�
- var freeLocation =_locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x=>x.LocationStatus==(int)LocationStatusEnum.Free).Count();
- var inStockLocation =_locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus == (int)LocationStatusEnum.InStock).Count();
+ var freeLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus == (int)LocationStatusEnum.Free).Count();
+ var inStockLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus != (int)LocationStatusEnum.Free).Count();
int totalLocation = freeLocation + inStockLocation;
decimal locationUtilizationRate = totalLocation == 0
? 0
- : Math.Round((decimal)inStockLocation / totalLocation, 4);
+ : Math.Round((decimal)inStockLocation / totalLocation, 4) * 100;
+ //璁$畻鍏ュ簱浠诲姟鍜屽嚭搴撲换鍔″畬鎴愭暟閲�
+ var inboundCount = _taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 500 && x.TaskType < 900 && x.CreateDate.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Count();
+ var outboundCount = _taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 100 && x.TaskType < 500 && x.CreateDate.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Count();
+
+ //璁$畻鏈夎揣鏂欑鏁伴噺
+ var inStockPallet = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == (int)PalletTypeEnum.None && !string.IsNullOrEmpty(x.LocationCode)).Count();
+ //璁$畻绌虹鏁伴噺
+ var freeStockPallet = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == (int)PalletTypeEnum.Empty && !string.IsNullOrEmpty(x.LocationCode)).Count();
// 4. 鑾峰彇杩�7鏃ユ瘡鏃ュ嚭鍏ュ簱鏄庣粏锛堟牳蹇冧慨鏀癸細璋冪敤涓婇潰鐨勬柟娉曪級
var dailyInOutBoundList = Get7DaysDailyInOutBound();
+ List<StockInfoDetailExtDTO> nearExpirationList = GetMaterialsNearExpiration();
+ //鑾峰彇浣滀笟缁熻
+ var completeTask = SimpleStatistics();
//浠诲姟
List<Dt_Task> tasks = _taskRepository.QueryData();
var bigGreenData = new BigGreenDataDto
{
- TotalStockQuantity=totalStockQuantity,
+ TotalStockQuantity = totalStockQuantity,
UnOutBoundOrderCount = unOutBound,
LocationUtilizationRate = locationUtilizationRate,
DailyInOutBoundList = dailyInOutBoundList,
- TaskList = tasks
+ TaskList = tasks,
+ InboundCount = inboundCount,
+ OutboundCount = outboundCount,
+ InStockPallet = inStockPallet,
+ FreeStockPallet = freeStockPallet,
+ CompleteTask = completeTask,
+ NearExpirationList = nearExpirationList
};
return WebResponseContent.Instance.OK(data: bigGreenData);
}
@@ -89,29 +118,29 @@
.Queryable<Dt_OutboundOrderDetail>()
.Where(x => x.CreateDate >= startDate
&& x.CreateDate < endDate.AddDays(1))
- .GroupBy(x => x.CreateDate) // 鎸夋棩鏈熸牸寮忓寲鍒嗙粍
+
.Select(x => new
{
- Date = x.CreateDate.ToString( "MM-dd"),
- DailyOutbound = SqlFunc.AggregateSum((decimal?)x.OverOutQuantity) ?? 0
+ Date = x.CreateDate.ToString("MM-dd"),
+ x.OverOutQuantity
})
.ToList()
- .ToDictionary(k => k.Date, v => v.DailyOutbound); // 杞负瀛楀吀鏂逛究鍖归厤
+ .GroupBy(x => x.Date)
+ .ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverOutQuantity) ?? 0); // 杞负瀛楀吀鏂逛究鍖归厤
// 3. 鏌ヨ姣忔棩鍏ュ簱鏄庣粏锛堟寜鏃ユ湡鍒嗙粍锛�
var dailyInboundList = _inboundOrderDetailRepository.Db
.Queryable<Dt_InboundOrderDetail>()
- .Where(x => x.CreateDate != null // 杩囨护绌烘棩鏈�
- && x.CreateDate >= startDate
+ .Where(x => x.CreateDate >= startDate
&& x.CreateDate < endDate.AddDays(1))
- .GroupBy(x => x.CreateDate).Distinct() // 鎸夋棩鏈熸牸寮忓寲鍒嗙粍
.Select(x => new
{
Date = x.CreateDate.ToString("MM-dd"),
- DailyInbound = SqlFunc.AggregateSum((decimal?)x.OverInQuantity) ?? 0
+ x.OverInQuantity
})
.ToList()
- .ToDictionary(k => k.Date, v => v.DailyInbound); // 杞负瀛楀吀鏂逛究鍖归厤
+ .GroupBy(x => x.Date)
+ .ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverInQuantity) ?? 0); // 杞负瀛楀吀鏂逛究鍖归厤
// 4. 鍚堝苟姣忔棩鏁版嵁锛堢‘淇�7澶╂棩鏈熷畬鏁达紝鏃犳暟鎹ˉ0锛�
var dailyInOutBoundList = all7Days.Select(date => new DailyInOutBoundDto
@@ -119,10 +148,31 @@
Date = date,
DailyOutboundQuantity = dailyOutboundList.ContainsKey(date) ? dailyOutboundList[date] : 0,
DailyInboundQuantity = dailyInboundList.ContainsKey(date) ? dailyInboundList[date] : 0,
-
+
}).ToList();
return dailyInOutBoundList;
+ }
+
+ public List<SimpleStatisticsDTO> SimpleStatistics()
+ {
+ DateTime sevenDaysAgo = DateTime.Now.AddDays(-7);
+
+ var stats = _taskHtyRepository
+ .QueryData(x => x.TaskStatus == (int)TaskStatusEnum.Finish && x.CreateDate >= sevenDaysAgo)
+ .GroupBy(t =>
+ (int)t.TaskType >= 100 && (int)t.TaskType <= 299 ? "鍑哄簱" :
+ (int)t.TaskType >= 500 && (int)t.TaskType <= 699 ? "鍏ュ簱" : "鍏朵粬"
+ )
+ .Where(g => g.Key == "鍑哄簱" || g.Key == "鍏ュ簱")
+ .Select(g => new SimpleStatisticsDTO
+ {
+ TaskType = g.Key,
+ Count = g.Count()
+ })
+ .ToList();
+
+ return stats;
}
/// <summary>
@@ -130,6 +180,14 @@
/// </summary>
public class BigGreenDataDto
{
+ /// <summary>
+ /// 鍏ュ簱瀹屾垚鏁伴噺
+ /// </summary>
+ public int InboundCount { get; set; }
+ /// <summary>
+ /// 鍑哄簱瀹屾垚鏁伴噺
+ /// </summary>
+ public int OutboundCount { get; set; }
/// <summary>
/// 鎬诲簱瀛樻暟閲�
/// </summary>
@@ -166,9 +224,22 @@
public decimal NetStock7Days { get; set; }
/// <summary>
+ /// 杩�7鏃ュ噣鍏ュ簱閲忥紙鍏ュ簱-鍑哄簱锛�
+ /// </summary>
+ public decimal TotalStockChangeRate { get; set; }
+
+ /// <summary>
/// 浠诲姟鍒楄〃
/// </summary>
public List<Dt_Task> TaskList { get; set; } = new List<Dt_Task>();
+
+ public int InStockPallet { get; set; }
+
+ public int FreeStockPallet { get; set; }
+
+ public List<SimpleStatisticsDTO> CompleteTask { get; set; }
+
+ public List<StockInfoDetailExtDTO> NearExpirationList { get; set; }
}
/// <summary>
@@ -192,5 +263,79 @@
public decimal DailyInboundQuantity { get; set; }
}
+
+ public class SimpleStatisticsDTO
+ {
+ public string TaskType { get; set; }
+ public int Count { get; set; }
+ }
+
+
+ public class StockInfoDetailExtDTO : Dt_StockInfoDetail
+ {
+ public string LocationCode { get; set; }
+ public string PalletCode { get; set; }
+ public int DaysToExpiration { get; set; }
+ }
+
+ ///<summary>
+ ///鑾峰彇杩�30澶╄杩囨湡鐨勭墿鏂�
+ /// </summary>
+ public List<StockInfoDetailExtDTO> GetMaterialsNearExpiration()
+ {
+ List<StockInfoDetailExtDTO> resultDTO = new List<StockInfoDetailExtDTO>();
+
+ var nearExpirationList = _stockInfoDetailRepository.QueryData()
+ .Join(
+ _stockInfoRepository.QueryData(),
+ detail => detail.StockId,
+ stock => stock.Id,
+ (detail, stock) => new
+ {
+ Detail = detail,
+ LocationCode = stock.LocationCode,
+ PalletCode = stock.PalletCode
+ }
+ )
+ .Where(x => x.Detail.ValidDate.HasValue
+ && (x.Detail.ValidDate.Value - x.Detail.CreateDate).TotalDays <= 30)
+ .ToList();
+
+
+ if (!nearExpirationList.Any())
+ {
+ return resultDTO;
+ }
+
+
+ foreach (var item in nearExpirationList)
+ {
+ int daysToExpire = item.Detail.ValidDate.HasValue
+ ? Math.Max(0, (item.Detail.ValidDate.Value - item.Detail.CreateDate).Days)
+ : 0;
+
+ var extDetail = new StockInfoDetailExtDTO
+ {
+ MaterielCode = item.Detail.MaterielCode,
+ MaterielName = item.Detail.MaterielName,
+ BatchNo = item.Detail.BatchNo,
+ SupplyCode = item.Detail.SupplyCode,
+ StockQuantity = item.Detail.StockQuantity,
+ CreateDate = item.Detail.CreateDate,
+ ValidDate = item.Detail.ValidDate,
+ LocationCode = item.LocationCode,
+ PalletCode = item.PalletCode,
+ Barcode = item.Detail.Barcode,
+ DaysToExpiration = daysToExpire
+ };
+
+
+ resultDTO.Add(extDetail);
+ }
+
+ resultDTO = resultDTO.OrderBy(d => d.DaysToExpiration).ToList();
+
+ return resultDTO;
+ }
}
}
--
Gitblit v1.9.3