From 37454e625df68d40897112b2e8c2e3cf4d7163e3 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期三, 25 三月 2026 11:43:10 +0800
Subject: [PATCH] 1
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs | 209 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 175 insertions(+), 34 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 cc3a34a..dfb1776 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,4 +1,6 @@
锘縰sing IBigBreenService;
+using Microsoft.IdentityModel.Tokens;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -11,7 +13,9 @@
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
{
@@ -25,8 +29,10 @@
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;
+ private readonly IRepository<Dt_InboundOrder> _inboundRepository;
- 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,IRepository<Dt_InboundOrder> inboundRepository)
{
_stockInfoDetailRepository = stockInfoDetailRepository;
_outBoundOrderRepository = outBoundOrderRepository;
@@ -36,6 +42,8 @@
_taskRepository = taskRepository;
_taskHtyRepository = taskHtyRepository;
_stockInfoRepository = stockInfoRepository;
+ _materialExpirationDateRepository = materialExpirationDateRepository;
+ _inboundRepository = inboundRepository;
}
public WebResponseContent GetBigGreenData()
{
@@ -48,33 +56,41 @@
(int)OutOrderStatusEnum.鍑哄簱涓�,
(int)OutOrderStatusEnum.鏈紑濮�
};
- var unOutBound =_outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x =>targetStatus.Contains(x.OrderStatus)).Count();
+ var targetInStatus = new List<int>
+ {
+ (int)InOrderStatusEnum.鍏ュ簱涓�,
+ (int)InOrderStatusEnum.鏈紑濮�
+ };
+ var unOutBound = _outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => targetStatus.Contains(x.OrderStatus) && x.CreateDate.ToString("MM-dd") == DateTime.Now.ToString("MM-dd")).Count();
+ var unInBound = _inboundRepository.Db.Queryable<Dt_InboundOrder>().Where(x => targetInStatus.Contains(x.OrderStatus) && x.CreateDate.ToString("MM-dd") == DateTime.Now.ToString("MM-dd")).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;
+ var totalLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Select(x=>x.Id).Count();
+ var inStockLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus == (int)LocationStatusEnum.InStock).Count();
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).Count();
- var outboundCount =_taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 100 && x.TaskType < 500).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).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).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,
@@ -82,7 +98,10 @@
InboundCount = inboundCount,
OutboundCount = outboundCount,
InStockPallet = inStockPallet,
- FreeStockPallet = freeStockPallet
+ FreeStockPallet = freeStockPallet,
+ CompleteTask = completeTask,
+ NearExpirationList = nearExpirationList,
+ UnInBoundOrderCount = unInBound
};
return WebResponseContent.Instance.OK(data: bigGreenData);
}
@@ -103,33 +122,33 @@
.ToList();
// 2. 鏌ヨ姣忔棩鍑哄簱鏄庣粏锛堟寜鏃ユ湡鍒嗙粍锛�
- var dailyOutboundList = _outBoundOrderDetailRepository.Db
- .Queryable<Dt_OutboundOrderDetail>()
+ var dailyOutboundList = _outBoundOrderRepository.Db
+ .Queryable<Dt_OutboundOrder>()
.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
- })
- .ToList()
- .ToDictionary(k => k.Date, v => v.DailyOutbound); // 杞负瀛楀吀鏂逛究鍖归厤
- // 3. 鏌ヨ姣忔棩鍏ュ簱鏄庣粏锛堟寜鏃ユ湡鍒嗙粍锛�
- var dailyInboundList = _inboundOrderDetailRepository.Db
- .Queryable<Dt_InboundOrderDetail>()
- .Where(x => x.CreateDate != null // 杩囨护绌烘棩鏈�
- && 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.OrderStatus
})
.ToList()
- .ToDictionary(k => k.Date, v => v.DailyInbound); // 杞负瀛楀吀鏂逛究鍖归厤
+ .GroupBy(x => x.Date)
+ .ToDictionary(k => k.Key, g => g.Count(x => x.OrderStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)); // 杞负瀛楀吀鏂逛究鍖归厤
+
+ // 3. 鏌ヨ姣忔棩鍏ュ簱鏄庣粏锛堟寜鏃ユ湡鍒嗙粍锛�
+ var dailyInboundList = _inboundRepository.Db
+ .Queryable<Dt_InboundOrder>()
+ .Where(x => x.CreateDate >= startDate
+ && x.CreateDate < endDate.AddDays(1))
+ .Select(x => new
+ {
+ Date = x.CreateDate.ToString("MM-dd"),
+ x.OrderStatus
+ })
+ .ToList()
+ .GroupBy(x => x.Date)
+ .ToDictionary(k => k.Key, g => g.Count(x => x.OrderStatus == (int)InOrderStatusEnum.鍏ュ簱瀹屾垚)); // 杞负瀛楀吀鏂逛究鍖归厤
// 4. 鍚堝苟姣忔棩鏁版嵁锛堢‘淇�7澶╂棩鏈熷畬鏁达紝鏃犳暟鎹ˉ0锛�
var dailyInOutBoundList = all7Days.Select(date => new DailyInOutBoundDto
@@ -137,13 +156,55 @@
Date = date,
DailyOutboundQuantity = dailyOutboundList.ContainsKey(date) ? dailyOutboundList[date] : 0,
DailyInboundQuantity = dailyInboundList.ContainsKey(date) ? dailyInboundList[date] : 0,
-
+
}).ToList();
return dailyInOutBoundList;
}
-
+ public List<SimpleStatisticsDTO> SimpleStatistics()
+ {
+ var today = DateTime.Now.Date;
+ var threeDaysAgo = today.AddDays(-3);
+
+ var targetStatuses = new List<int> { (int)InOrderStatusEnum.鍏ュ簱涓�, (int)InOrderStatusEnum.鏈紑濮�,
+ (int)OutOrderStatusEnum.鏈紑濮�, (int)OutOrderStatusEnum.鍑哄簱涓� };
+ var failReturnStatuses = new List<int> {4,2};
+
+ var inboundToday = QueryInboundOrders(today, today, targetStatuses);
+ var outboundToday = QueryOutboundOrders(today, today, targetStatuses);
+ var inboundFail3Days = QueryInboundOrders(threeDaysAgo, today, failReturnStatuses, isReturnStatus: true);
+ var outboundFail3Days = QueryOutboundOrders(threeDaysAgo, today, failReturnStatuses, isReturnStatus: true);
+
+
+ return new List<SimpleStatisticsDTO> { new()
+ {
+ inboundOrders = inboundToday,
+ outboundOrders = outboundToday,
+ inboundReturnFailOrders = inboundFail3Days,
+ outboundReturnFailOrders = outboundFail3Days
+ }};
+ }
+
+
+ private List<Dt_InboundOrder> QueryInboundOrders(DateTime startDate, DateTime endDate,
+ List<int> statusList, bool isReturnStatus = false)
+ {
+ return _inboundRepository.QueryData(x =>
+ x.CreateDate.Date >= startDate &&
+ x.CreateDate.Date <= endDate &&
+ (isReturnStatus ? statusList.Contains(x.ReturnToMESStatus) : statusList.Contains(x.OrderStatus))).ToList();
+ }
+
+
+ private List<Dt_OutboundOrder> QueryOutboundOrders(DateTime startDate, DateTime endDate,
+ List<int> statusList, bool isReturnStatus = false)
+ {
+ return _outBoundOrderRepository.QueryData(x =>
+ x.CreateDate.Date >= startDate &&
+ x.CreateDate.Date <= endDate &&
+ (isReturnStatus ? statusList.Contains(x.ReturnToMESStatus) : statusList.Contains(x.OrderStatus))).ToList();
+ }
/// <summary>
/// 澶у睆/姹囨�绘暟鎹繑鍥濪TO锛堝ぇ缁挎暟鎹眹鎬伙級
@@ -167,6 +228,8 @@
/// 寰呭嚭搴撹鍗曟暟閲忥紙鍑哄簱涓�+鏈紑濮嬶級
/// </summary>
public int UnOutBoundOrderCount { get; set; }
+
+ public int UnInBoundOrderCount { get; set; }
/// <summary>
/// 绌洪棽搴撲綅鏁伴噺
@@ -196,7 +259,7 @@
/// <summary>
/// 杩�7鏃ュ噣鍏ュ簱閲忥紙鍏ュ簱-鍑哄簱锛�
/// </summary>
- public decimal totalStockChangeRate { get; set; }
+ public decimal TotalStockChangeRate { get; set; }
/// <summary>
/// 浠诲姟鍒楄〃
@@ -206,6 +269,10 @@
public int InStockPallet { get; set; }
public int FreeStockPallet { get; set; }
+
+ public List<SimpleStatisticsDTO> CompleteTask { get; set; }
+
+ public List<StockInfoDetailExtDTO> NearExpirationList { get; set; }
}
/// <summary>
@@ -230,6 +297,80 @@
}
+ public class SimpleStatisticsDTO
+ {
+ public List<Dt_InboundOrder> inboundOrders { get; set; }
+ public List<Dt_OutboundOrder> outboundOrders { get; set; }
+ public List<Dt_InboundOrder> inboundReturnFailOrders { get; set; }
+ public List<Dt_OutboundOrder> outboundReturnFailOrders { 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