|
|
|
@ -4,6 +4,7 @@ using DS.WMS.Core.Info.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using MiniExcelLibs;
|
|
|
|
|
using Quartz;
|
|
|
|
|
using SqlSugar;
|
|
|
|
@ -20,6 +21,7 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
|
ISqlSugarClient? db;
|
|
|
|
|
Microsoft.Extensions.Configuration.IConfiguration config;
|
|
|
|
|
IWebHostEnvironment hostEnvironment;
|
|
|
|
|
ILogger<WSLReportJob> logger;
|
|
|
|
|
|
|
|
|
|
static WSLReportJob()
|
|
|
|
|
{
|
|
|
|
@ -35,10 +37,13 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
|
db = serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
config = serviceProvider.GetRequiredService<Microsoft.Extensions.Configuration.IConfiguration>();
|
|
|
|
|
hostEnvironment = serviceProvider.GetRequiredService<IWebHostEnvironment>();
|
|
|
|
|
logger = serviceProvider.GetRequiredService<ILogger<WSLReportJob>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation("开始生成【WSL报表服务】...");
|
|
|
|
|
|
|
|
|
|
string path = Path.Combine(hostEnvironment.WebRootPath, "templates", "WSL.xlsx");
|
|
|
|
|
FileInfo templateFile = new(path);
|
|
|
|
|
if (!templateFile.Exists)
|
|
|
|
@ -84,7 +89,7 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var list = await tenantDb.Queryable<SeaExport>().Where(x => x.SourceCode == SOURCE_CODE && SqlFunc.Between(x.ETD, startDate, endDate) && !x.Deleted)
|
|
|
|
|
.InnerJoin<InfoClient>((x, y) => x.CustomerId == y.Id)
|
|
|
|
|
.LeftJoin<InfoClient>((x, y) => x.CustomerId == y.Id)
|
|
|
|
|
.Select((x, y) => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
@ -95,33 +100,37 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var ids = list.Select(x => x.Id.ToString());
|
|
|
|
|
var ctnList = await tenantDb.Queryable<OpCtn>().Where(x => ids.Contains(x.BSNO) &&
|
|
|
|
|
!SqlFunc.IsNullOrEmpty(x.CntrNo) && !SqlFunc.IsNullOrEmpty(x.SealNo) && !x.Deleted)
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.BSNO,
|
|
|
|
|
x.TEU
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
model.List = list.GroupBy(x => new { x.CustomerId, x.EnName }).Select(x => new WSLItem
|
|
|
|
|
{
|
|
|
|
|
CustomerId = x.Key.CustomerId,
|
|
|
|
|
CustomerName = x.Key.EnName,
|
|
|
|
|
Date = model.Date,
|
|
|
|
|
YesterdayTeu = x.Where(x => x.ETD >= yesterday && x.ETD <= yesterday).Sum(x => x.TEU),
|
|
|
|
|
TodayTeu = x.Where(x => x.ETD >= today && x.ETD <= today).Sum(x => x.TEU),
|
|
|
|
|
NextMonthTEU = x.Where(x => x.ETD.Value.Year == nextMonth.Year && x.ETD.Value.Month == nextMonth.Month).Sum(x => x.TEU),
|
|
|
|
|
LastMonthTEU = x.Where(x => x.ETD.Value.Year == lastMonth.Year && x.ETD.Value.Month == lastMonth.Month).Sum(x => x.TEU),
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var item in model.List)
|
|
|
|
|
{
|
|
|
|
|
var ids2 = list.Where(x => x.CustomerId == item.CustomerId).Select(x => x.Id.ToString());
|
|
|
|
|
item.TodayTeuCTNPickup = ctnList.Where(x => ids2.Contains(x.BSNO)).Sum(x => x.TEU);
|
|
|
|
|
model.List = [];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ids = list.Select(x => x.Id.ToString());
|
|
|
|
|
var ctnList = await tenantDb.Queryable<OpCtn>().Where(x => ids.Contains(x.BSNO) &&
|
|
|
|
|
!SqlFunc.IsNullOrEmpty(x.CntrNo) && !SqlFunc.IsNullOrEmpty(x.SealNo) && !x.Deleted)
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.BSNO,
|
|
|
|
|
x.TEU
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
model.List = list.GroupBy(x => new { x.CustomerId, x.EnName }).Select(x => new WSLItem
|
|
|
|
|
{
|
|
|
|
|
CustomerId = x.Key.CustomerId,
|
|
|
|
|
CustomerName = x.Key.EnName,
|
|
|
|
|
Date = model.Date,
|
|
|
|
|
YesterdayTeu = x.Where(x => x.ETD >= yesterday && x.ETD <= yesterday).Sum(x => x.TEU),
|
|
|
|
|
TodayTeu = x.Where(x => x.ETD >= today && x.ETD <= today).Sum(x => x.TEU),
|
|
|
|
|
NextMonthTEU = x.Where(x => x.ETD.Value.Year == nextMonth.Year && x.ETD.Value.Month == nextMonth.Month).Sum(x => x.TEU),
|
|
|
|
|
LastMonthTEU = x.Where(x => x.ETD.Value.Year == lastMonth.Year && x.ETD.Value.Month == lastMonth.Month).Sum(x => x.TEU),
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var item in model.List)
|
|
|
|
|
{
|
|
|
|
|
var ids2 = list.Where(x => x.CustomerId == item.CustomerId).Select(x => x.Id.ToString());
|
|
|
|
|
item.TodayTeuCTNPickup = ctnList.Where(x => ids2.Contains(x.BSNO)).Sum(x => x.TEU);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryStream ms = new();
|
|
|
|
|
await MiniExcel.SaveAsByTemplateAsync(ms, path, model);
|
|
|
|
@ -147,8 +156,10 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
var mailResult = await api.SendRequestAsync(HttpMethod.Post, config["TaskMail:MailApiUrl"], mailParams);
|
|
|
|
|
if (!mailResult.IsSuccessStatusCode)
|
|
|
|
|
throw new ApplicationException("发送邮件失败");
|
|
|
|
|
if (mailResult.IsSuccessStatusCode)
|
|
|
|
|
logger.LogInformation("已发送【WSL报表服务】...");
|
|
|
|
|
else
|
|
|
|
|
logger.LogInformation("发送【WSL报表服务】失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|