1
wankeda
2025-03-07 b55d324f4b7465f9a7dc50e999346697f5cc35a2
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using AutoMapper;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
using MailKit.Search;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Stock;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using WIDESEA_TaskInfoRepository;
using OrderByType = SqlSugar.OrderByType;
 
namespace WIDESEA_TaskInfoService;
 
public class Task_HtyService : ServiceBase<Dt_Task_Hty, ITask_HtyRepository>, ITask_HtyService
{
    
    public Task_HtyService(ITask_HtyRepository BaseDal
                                    ) : base(BaseDal)
    {
        
    }
 
    /// <summary>
    /// 添加历史任务
    /// </summary>
    /// <param name="task">历史任务Model</param>
    /// <returns>成功/失败</returns>
    public bool InsertTask(Dt_Task_Hty task)
    {
        return BaseDal.InsertTask(task);
    }
    public WebResponseContent AddTaskHty(Dt_Task task)
    {
        WebResponseContent content = new WebResponseContent();
        Dt_Task_Hty task_Hty = new Dt_Task_Hty()
        {
            TaskNum = task.TaskNum,
            PalletCode = task.PalletCode,
            Roadway = task.Roadway,
            TaskType = task.TaskType,
            TaskStatus = task.TaskStatus,
            SourceAddress = task.SourceAddress,
            TargetAddress = task.TargetAddress,
            CurrentAddress = task.CurrentAddress,
            NextAddress = task.NextAddress,
            Grade = task.Grade,
            Dispatchertime = task.Dispatchertime,
            Creater =task.Creater,
            CreateDate = task.CreateDate,
            ModifyDate = DateTime.Now,
            Modifier = task.Modifier,
            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; }
    }
}