1
huanghongfeng
2024-12-08 885bd60ed54a0642c48c57a3d685cba24e4c763b
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/Task_HtyService.cs
@@ -1,4 +1,6 @@
using AutoMapper;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
using MailKit.Search;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
@@ -30,6 +32,7 @@
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using WIDESEA_TaskInfoRepository;
using OrderByType = SqlSugar.OrderByType;
namespace WIDESEA_TaskInfoService;
@@ -71,9 +74,60 @@
            CreateDate = task.CreateDate,
            ModifyDate = DateTime.Now,
            Modifier = task.Modifier,
            Remark = task.Remark
            Remark = task.Remark,
            PLCTo=task.PLCTo,
            PalletCodequantity=task.PalletCodequantity,
            MaterialType = task.MaterialType
        };
        BaseDal.AddData(task_Hty);
        return content;
    }
    //导出
    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<Dt_Task_Hty> entities = BaseDal.QueryData(wheres, orderbyDic);
            var stockdct = entities
                .GroupBy(x => new { x.TaskType,x.MaterialType })
                .Select(g => new Dt_Task_Htyt
                {
                    MaterialType = g.Key.MaterialType.ToString() == "0" ? "原材料" : "成品",        // è¿™é‡Œèµ‹å€¼ç»™ MaterielCode
                    TaskType= g.Key.TaskType.ToString() == "100" ? "出库" : "入库",
                    PalletCodequantity = g.Count(),
                })
                .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;
    }
    public class Dt_Task_Htyt
    {
        [ExporterHeader(DisplayName = "物料类型")]
        public string MaterialType { get; set;}
        [ExporterHeader(DisplayName = "任务类型")]
        public string TaskType { get; set; }
        [ExporterHeader(DisplayName = "数量")]
        public int PalletCodequantity { get; set; }
    }
}