Files
YunTongJackYunTask/Reportapi/MyCode.Project.Services/BLL/ReportExport/SalesOrderAttributeAnalysisExport.cs
2025-07-04 09:50:02 +08:00

151 lines
5.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.Practices.ObjectBuilder2;
using MyCode.Project.Domain.Message.Request.BaoDian;
using MyCode.Project.Domain.Message.Request.LxmZHMDReport;
using MyCode.Project.Domain.Message.Response.Bfy;
using MyCode.Project.Domain.Message.Response.LxmZHMDReport;
using MyCode.Project.Infrastructure;
using MyCode.Project.Infrastructure.Cache;
using MyCode.Project.Infrastructure.Common;
using MyCode.Project.Infrastructure.Constant;
using MyCode.Project.Infrastructure.Enumeration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCode.Project.Services.BLL.ReportExport
{
public class SalesOrderAttributeAnalysisExport : BaseExport
{
#region
private IReportService _reportService;
private IMyCodeCacheService _myCodeCacheService;
public SalesOrderAttributeAnalysisExport(IReportService reportService
,IMyCodeCacheService myCodeCacheService)
{
_reportService = reportService;
_myCodeCacheService = myCodeCacheService;
}
#endregion
#region Execute()
public override string Execute()
{
var pageSearch = base.GetPageSearch<SalesOrderAttributeAnalysisReq>(Condition,1000000,1);
var resultData = new ReportCalRateResp()
{
Total = 0,
Rate = 0.01m
};
var result = new Result()
{
Data = resultData,
Code = ResultCode.Success
};
if (base.ExcelFileType == (int)ExportFileType.Zip)
{
//类型为0是报表专用验证客户端是否在线
WebSocketBLL.CheckOnline(ReportId, 0);
//开始运算先发送个进度0%,表明开始
WebSocketBLL.SendSocketMsg(ReportId, JsonHelper.ToJson(result, false, true));
}
var list = _reportService.GetSalesOrderAttributeAnalysis(pageSearch, this.CurrentUser);
resultData.Total = list.DataList.Count;
var data = list.DataList;
data = data.OrderBy(t => t.ShopName).ThenBy(t => t.SalesTime).ToList();
int rows = 0;
string shopName = "";
Dictionary<string, List<SalesOrderAttributeAnalysis>> keyValuePairs = new Dictionary<string, List<SalesOrderAttributeAnalysis>>();
int num = 0;
int numX = 10000;
int numY = 1;
string fileName = "";
data.ForEach(x =>
{
if (num % numX == 0)
{
fileName = $"{num+1}_{numX* numY}";
numY++;
}
num++;
if (keyValuePairs.ContainsKey(fileName))
{
keyValuePairs[fileName].Add(x);
}
else
{
keyValuePairs.Add(fileName, new List<SalesOrderAttributeAnalysis> { x });
}
//base.AddExcelProcess(fileName, dataResult);
});
keyValuePairs.ForEach(t =>
{
var dataResult = new
{
op = t.Value
};
base.AddExcelProcess(t.Key, dataResult);
});
if (base.ExcelFileType == (int)ExportFileType.Zip)
{
resultData.Rate = 0.02m;
result.Data = resultData;
WebSocketBLL.SendSocketMsg(ReportId, JsonHelper.ToJson(result, false, true));
}
return base.Execute();
//var pageSearch = base.GetPageSearch<SalesOrderAttributeAnalysisReq>(Condition, 1);
//var list = _reportService.GetSalesOrderAttributeAnalysis(pageSearch, this.CurrentUser);
//resultData.Total = list.TotalCount;
//var fileName = $"销售订单属性分析";
//if (base.ExcelFileType == (int)ExportFileType.Zip)
//{
// resultData.Rate = 0.02m;
// result.Data = resultData;
// WebSocketBLL.SendSocketMsg(ReportId, JsonHelper.ToJson(result, false, true));
//}
//pageSearch.Page = 1;
//pageSearch.PageSize = 100;
//int maxPage = (list.TotalCount + pageSearch.PageSize - 1) / pageSearch.PageSize;
//string zipFile = "";
//string hasDownloadZipCacheKey = CacheKey.HasDownloadZipCacheKey + $@":{ReportId}";
//while (pageSearch.Page <= maxPage)
//{
// list = _reportService.GetSalesOrderAttributeAnalysis(pageSearch, this.CurrentUser);
// zipFile = base.PageListExecute<SalesOrderAttributeAnalysis>(list, pageSearch.Page, pageSearch.PageSize, list.TotalCount, fileName, hasDownloadZipCacheKey);
// pageSearch.Page++;
//}
//if (zipFile == "")
//{
// resultData.CurQty = list.TotalCount;
// resultData.Rate = 1;
// WebSocketBLL.SendSocketMsg(ReportId, JsonHelper.ToJson(result, false, true));
// //移除正在下载
// _myCodeCacheService.Delete($"{hasDownloadZipCacheKey}" + $@":{ReportId}");
//}
//return zipFile;
}
#endregion
}
}