huanghongfeng
3 天以前 1d8897348d578648421b024d0dc5ff3d626e05f9
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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.Attributes;
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 bool CrueeTaskHty(string TargetAddress)
    {
        Dt_Task_Hty task_Hty = BaseDal.QueryData(x => x.TargetAddress == TargetAddress).OrderByDescending(x => x.CreateDate).FirstOrDefault(); 
        if (task_Hty == null) return false;
 
        if(task_Hty.TaskType== TaskTypeEnum.Inbound.ObjToInt() || task_Hty.TaskType == TaskTypeEnum.Relocation.ObjToInt() || task_Hty.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) return true;
 
        return false;
    }
 
    //导出
    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;*/
 
            var stockdct = entities
     .Select(g => new Dt_Task_Htykt
     {
         TaskNum = g.TaskNum,
         PalletCode = g.PalletCode,
         Roadway = g.Roadway,
         TaskType = g.TaskType.ToString() == "100" ? "出库" : g.TaskType.ToString() == "104" ? "出空托" : g.TaskType.ToString() == "200" ? "入库" : "移库",
         TaskStatus = g.TaskStatus.ToString()=="290"?"入库完成":"出库完成", // 或者可以根据具体状态码转换
         SourceAddress = g.SourceAddress,
         TargetAddress = g.TargetAddress,
         Remark = g.Remark,
         Creater = g.Creater,
         CreateDate = g.CreateDate,
         Modifier = g.Modifier,
         ModifyDate = g.ModifyDate,
         MaterialType = g.MaterialType.ToString() == "0" ? "原材料" : "成品",
         PalletCodequantity = g.PalletCodequantity.ToString(), // 转换为字符串
         PLCTo = g.PLCTo.ToString(), // 或者可以根据具体值转换
         OperateType = g.OperateType.ToString()
     })
     .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; }
    }
 
 
    public class Dt_Task_Htykt
    {
        [ExporterHeader(DisplayName = "任务号")]
        public int TaskNum { get; set; }
 
        [ExporterHeader(DisplayName = "托盘编号")]
        public string PalletCode { get; set; }
 
        [ExporterHeader(DisplayName = "巷道号")]
        public string Roadway { get; set; }
 
        [ExporterHeader(DisplayName = "任务类型")]
        public string TaskType { get; set; }
 
        [ExporterHeader(DisplayName = "任务状态")]
        public string TaskStatus { get; set; }
 
        [ExporterHeader(DisplayName = "起始地址")]
        public string SourceAddress { get; set; }
 
        [ExporterHeader(DisplayName = "目标地址")]
        public string TargetAddress { get; set; }
 
        [ExporterHeader(DisplayName = "备注")]
        public string Remark { get; set; }
 
        [ExporterHeader(DisplayName = "创建人")]
        public string Creater { get; set; }
 
        [ExporterHeader(DisplayName = "创建时间")]
        public DateTime CreateDate { get; set; }
 
        [ExporterHeader(DisplayName = "修改人")]
        public string Modifier { get; set; }
 
        [ExporterHeader(DisplayName = "修改日期")]
        public DateTime? ModifyDate { get; set; }
 
        [ExporterHeader(DisplayName = "物料类型")]
        public string MaterialType { get; set; }
 
        [ExporterHeader(DisplayName = "托盘数量")]
        public string PalletCodequantity { get; set; }
 
        [ExporterHeader(DisplayName = "原材料去向")]
        public string PLCTo { get; set; }
 
        [ExporterHeader(DisplayName = "完成情况")]
        public string OperateType { get; set; }
    }
}