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; }
|
}
|
}
|