From 3386c4e2a11ed345986a0b4af28e4a8630f84b41 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期二, 13 一月 2026 18:41:35 +0800
Subject: [PATCH] 重检,盘点优化
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 101 insertions(+), 16 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 3ed522c..2c3797e 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,5 +1,6 @@
锘縰sing IBigBreenService;
using Microsoft.IdentityModel.Tokens;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -14,6 +15,7 @@
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.Helper;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
namespace BigGreenService
{
@@ -27,8 +29,9 @@
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,IRepository<Dt_Task_Hty> taskHtyRepository, IRepository<Dt_StockInfo> stockInfoRepository)
+ 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;
@@ -38,6 +41,7 @@
_taskRepository = taskRepository;
_taskHtyRepository = taskHtyRepository;
_stockInfoRepository = stockInfoRepository;
+ _materialExpirationDateRepository = materialExpirationDateRepository;
}
public WebResponseContent GetBigGreenData()
{
@@ -50,27 +54,28 @@
(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 || x.LocationStatus == (int)LocationStatusEnum.Pallet).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 || x.LocationStatus == (int)LocationStatusEnum.Pallet).Count();
int totalLocation = freeLocation + inStockLocation;
decimal locationUtilizationRate = totalLocation == 0
? 0
- : Math.Round((decimal)inStockLocation / totalLocation, 4)*100;
+ : 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 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 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();
+ var nearExpirationList = GetMaterialsNearExpiration();
//鑾峰彇浣滀笟缁熻
var completeTask = SimpleStatistics();
//浠诲姟
@@ -78,7 +83,7 @@
var bigGreenData = new BigGreenDataDto
{
- TotalStockQuantity=totalStockQuantity,
+ TotalStockQuantity = totalStockQuantity,
UnOutBoundOrderCount = unOutBound,
LocationUtilizationRate = locationUtilizationRate,
DailyInOutBoundList = dailyInOutBoundList,
@@ -87,7 +92,8 @@
OutboundCount = outboundCount,
InStockPallet = inStockPallet,
FreeStockPallet = freeStockPallet,
- CompleteTask = completeTask
+ CompleteTask = completeTask,
+ NearExpirationList = nearExpirationList
};
return WebResponseContent.Instance.OK(data: bigGreenData);
}
@@ -120,13 +126,12 @@
})
.ToList()
.GroupBy(x => x.Date)
- .ToDictionary(k => k.Key , g => g.Sum(x => (decimal?)x.OverOutQuantity) ?? 0); // 杞负瀛楀吀鏂逛究鍖归厤
+ .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))
.Select(x => new
{
@@ -134,7 +139,7 @@
x.OverInQuantity
})
.ToList()
- .GroupBy(x=>x.Date)
+ .GroupBy(x => x.Date)
.ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverInQuantity) ?? 0); // 杞负瀛楀吀鏂逛究鍖归厤
// 4. 鍚堝苟姣忔棩鏁版嵁锛堢‘淇�7澶╂棩鏈熷畬鏁达紝鏃犳暟鎹ˉ0锛�
@@ -143,7 +148,7 @@
Date = date,
DailyOutboundQuantity = dailyOutboundList.ContainsKey(date) ? dailyOutboundList[date] : 0,
DailyInboundQuantity = dailyInboundList.ContainsKey(date) ? dailyInboundList[date] : 0,
-
+
}).ToList();
return dailyInOutBoundList;
@@ -159,7 +164,7 @@
(int)t.TaskType >= 100 && (int)t.TaskType <= 299 ? "鍑哄簱" :
(int)t.TaskType >= 500 && (int)t.TaskType <= 699 ? "鍏ュ簱" : "鍏朵粬"
)
- .Where(g => g.Key == "鍑哄簱" || g.Key == "鍏ュ簱")
+ .Where(g => g.Key == "鍑哄簱" || g.Key == "鍏ュ簱")
.Select(g => new SimpleStatisticsDTO
{
TaskType = g.Key,
@@ -233,6 +238,8 @@
public int FreeStockPallet { get; set; }
public List<SimpleStatisticsDTO> CompleteTask { get; set; }
+
+ public NearExpirationDTO NearExpirationList { get; set; }
}
/// <summary>
@@ -263,6 +270,84 @@
public int Count { get; set; }
}
+ public class NearExpirationDTO
+ {
+ public int DaysToExpiration { get; set; }
+ public List<Dt_StockInfoDetail> Details { get; set; }
+
+ public string LocationCode { get; set; }
+
+ public string PalletCode { get; set; }
+ }
+
+ ///<summary>
+ ///鑾峰彇杩�30澶╄杩囨湡鐨勭墿鏂�
+ /// </summary>
+ public NearExpirationDTO GetMaterialsNearExpiration()
+ {
+ // 鍒濆鍖栬繑鍥濪TO
+ var resultDTO = new NearExpirationDTO
+ {
+ Details = new List<Dt_StockInfoDetail>(),
+ LocationCode = string.Empty,
+ PalletCode = string.Empty,
+ DaysToExpiration = 0 // 鍒濆鍖栧ぉ鏁�
+ };
+
+ DateTime currentTime = DateTime.Now;
+ DateTime thirtyDaysLater = currentTime.AddDays(30);
+
+ // 绛涢��30澶╁唴杩囨湡鐨勫簱瀛樻槑缁�
+ var nearExpirationList = _stockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => (x.ValidDate.Value - x.CreateDate).TotalDays <= 30)
+ .ToList();
+
+ // 鏃犵鍚堟潯浠剁殑鏄庣粏锛岀洿鎺ヨ繑鍥�
+ if (!nearExpirationList.Any())
+ {
+ return resultDTO;
+ }
+
+
+ var firstStockId = nearExpirationList.First().StockId;
+
+ var stock = _stockInfoRepository.Db.Queryable<Dt_StockInfo>()
+ .First(x => x.Id == firstStockId);
+
+
+ if (stock == null)
+ {
+ return resultDTO;
+ }
+
+
+ resultDTO.LocationCode = stock.LocationCode;
+ resultDTO.PalletCode = stock.PalletCode;
+
+
+ int minDaysToExpiration = int.MaxValue;
+ foreach (var detail in nearExpirationList)
+ {
+
+ TimeSpan totalDaysToExpiration = detail.ValidDate.Value - detail.CreateDate;
+ double remainingDays = totalDaysToExpiration.TotalDays;
+ int daysToExpiration = (int)Math.Ceiling(Math.Max(0, remainingDays));
+
+
+ if (daysToExpiration < minDaysToExpiration)
+ {
+ minDaysToExpiration = daysToExpiration;
+ }
+
+
+ resultDTO.Details.Add(detail);
+ }
+
+
+ resultDTO.DaysToExpiration = minDaysToExpiration;
+
+ return resultDTO;
+ }
}
}
--
Gitblit v1.9.3