1
wankeda
2025-02-12 8326222e65f0bb258c99d93f1954d7696c4ef00d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StockService
{
    public partial class VV_StockInfoDetService : ServiceBase<VV_StockInfoDet, IVV_StockInfoDetRepository>, IVV_StockInfoDetService
    {
 
        //导出
        public override WebResponseContent Export(PageDataOptions options)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelExport";
                IExporter exporter = new ExcelExporter();
                //添加条件
                string wheres = options.ValidatePageOptions(TProperties);
                //获取排序字段
                Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(TProperties);
                List<VV_StockInfoDet> entities = BaseDal.QueryData(wheres, orderbyDic);
 
                var stockdct = entities
                .GroupBy(x => new { x.MaterielCode, x.MaterialType, x.MaterielName, x.OrderNo, x.BatchNo, x.BatchNoName })
                .Select(g => new VV_StockInfoDet
                {
                    MaterielCode = g.Key.MaterielCode,
                    MaterialType = g.Key.MaterialType.ToString()=="0"?"原材料":"成品",
                    MaterielName = g.Key.MaterielName,
                    OrderNo = g.Key.OrderNo,
                    BatchNo = g.Key.BatchNo,
                    BatchNoName = g.Key.BatchNoName,
                    StockQuantity = g.Sum(x => x.StockQuantity),
                    CreateDate = g.Min(x => x.CreateDate) // 获取每组的最早 CreateDate
                })
                .ToList();
 
 
 
                byte[] data = exporter.ExportAsByteArray(stockdct).Result;
 
                string fileName = "1.xlsx";
 
                FileHelper.WriteFile(savePath, fileName, data);
 
                content = WebResponseContent.Instance.OK(data: savePath + "\\" + fileName);
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
        }
    }
}