From b095c75267297527116cda105669015babc01972 Mon Sep 17 00:00:00 2001
From: chenyong <chenyong@hnkhzn.com>
Date: 星期三, 10 十二月 2025 13:47:27 +0800
Subject: [PATCH] 1
---
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs | 73 ++++++++++++++++++++++++++++++++++++
1 files changed, 72 insertions(+), 1 deletions(-)
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
index dd6432e..5757f64 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
@@ -1,4 +1,6 @@
锘縰sing AngleSharp.Dom;
+using Magicodes.ExporterAndImporter.Core;
+using Magicodes.ExporterAndImporter.Excel;
using Mapster;
using Masuit.Tools;
using SqlSugar;
@@ -10,6 +12,8 @@
using WIDESEA_Cache;
using WIDESEA_Common;
using WIDESEA_Core;
+using WIDESEA_IStorageBasicService;
+using WIDESEA_Model.Models.BasicModel;
namespace WIDESEA_StorageBasicService;
@@ -18,10 +22,12 @@
private readonly ISimpleCacheService _simpleCacheService;
private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
- public StockInfoService(IStockInfoRepository BaseDal, ISimpleCacheService simpleCacheService, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository) : base(BaseDal)
+ private readonly IStockInfoDetailRepository _IStockInfoDetailRepository;
+ public StockInfoService(IStockInfoRepository BaseDal, ISimpleCacheService simpleCacheService, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, IStockInfoDetailRepository stockInfoDetailService) : base(BaseDal)
{
_simpleCacheService = simpleCacheService;
_locationStatusChangeRecordRepository = locationStatusChangeRecordRepository;
+ _IStockInfoDetailRepository = stockInfoDetailService;
}
/// <summary>
@@ -151,6 +157,71 @@
.ToDictionary(x => x.Key, x => x.Count());
return result;
}
+ public override WebResponseContent Export(PageDataOptions options)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ // 1. 鏋勫缓涓昏〃鏌ヨ鏉′欢鍜屾帓搴�
+ string wheres = ValidatePageOptions(options);
+ Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
+
+ // 2. 鏌ヨ涓昏〃鏁版嵁
+ List<DtStockInfo> mainList = BaseDal.QueryData(wheres, orderbyDic);
+ if (!mainList.Any())
+ {
+ return WebResponseContent.Instance.OK("鏃犳暟鎹彲瀵煎嚭");
+ }
+
+ // 3. 鎵归噺鏌ヨ瀛愯〃鏁版嵁锛堥�氳繃涓昏〃Id鍏宠仈锛�
+ var mainIds = mainList.Select(m => m.Id).Distinct().ToList();
+ List<DtStockInfoDetail> detailList = _IStockInfoDetailRepository.Db
+ .Queryable<DtStockInfoDetail>()
+ .Where(d => mainIds.Contains(d.StockId))
+ .ToList();
+
+ // 4. 鍏宠仈涓昏〃鍜屽瓙琛ㄦ暟鎹紙鍙彇瀛愯〃绗竴鏉★級
+ var exportData = new List<PalletWithDetailExportModel>();
+ foreach (var main in mainList)
+ {
+ // 鍙彇褰撳墠涓昏〃鏁版嵁鍏宠仈鐨勫瓙琛ㄧ涓�鏉★紙鍙�氳繃OrderBy鎸囧畾鎺掑簭锛岀‘淇濆彇鍒版兂瑕佺殑绗竴鏉★級
+ var firstDetail = detailList
+ .Where(d => d.StockId == main.Id)
+ .OrderBy(d => d.Id) // 鍙�夛細鎸夊瓙琛↖d鎺掑簭锛岀‘淇濈粨鏋滅ǔ瀹氾紙鍙浛鎹负鍏朵粬瀛楁锛�
+ .FirstOrDefault();
+
+ var exportModel = new PalletWithDetailExportModel
+ {
+ Id = main.Id,
+ PalletCode = main.PalletCode,
+ LocationCode = main.LocationCode,
+ IsFull = main.IsFull,
+ Remark = main.Remark,
+ Creater = main.Creater,
+ CreateDate = main.CreateDate,
+ OutboundTime = (DateTime)main.OutboundTime,
+ // 鏈夊瓙琛ㄦ暟鎹垯鍙栫涓�鏉$殑鐗╂枡缂栫爜锛屾棤鍒欎负绌�
+ MaterielCode = firstDetail?.MaterielCode ?? ""
+ };
+ exportData.Add(exportModel);
+ }
+
+ // 5. 瀵煎嚭鏁版嵁锛堥�昏緫涓嶅彉锛�
+ string savePath = AppDomain.CurrentDomain.BaseDirectory + "ExcelExport";
+ IExporter exporter = new ExcelExporter();
+ byte[] data = exporter.ExportAsByteArray(exportData).Result;
+
+ string fileName = "鎵樼洏鍙婄墿鏂欑紪鐮佹暟鎹�.xlsx";
+ FileHelper.WriteFile(savePath, fileName, data);
+
+ content = WebResponseContent.Instance.OK(data: Path.Combine(savePath, fileName));
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error(ex.Message);
+ }
+ return content;
+ }
//public override WebResponseContent UpdateData(DtStockInfo entity)
//{
--
Gitblit v1.9.3