|
|
@ -39,21 +39,27 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string path = Path.Combine(hostEnvironment.WebRootPath, "templates", "WSL.xlsx");
|
|
|
|
string path = Path.Combine(hostEnvironment.WebRootPath, "templates", "WSL.xlsx");
|
|
|
|
FileInfo templateFile = new FileInfo(path);
|
|
|
|
FileInfo templateFile = new(path);
|
|
|
|
if (!templateFile.Exists)
|
|
|
|
if (!templateFile.Exists)
|
|
|
|
throw new ApplicationException("未能在下列路径找到模板文件:" + path);
|
|
|
|
{
|
|
|
|
|
|
|
|
var ex = new ApplicationException("【WSL报表服务】未能在下列路径找到模板文件:" + path);
|
|
|
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//时间计算
|
|
|
|
|
|
|
|
var today = DateTime.Now.Date;
|
|
|
|
|
|
|
|
var yesterday = today.AddDays(-1).Date;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lastMonth = today.AddMonths(-1);
|
|
|
|
|
|
|
|
var nextMonth = today.AddMonths(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var startDate = new DateTime(lastMonth.Year, lastMonth.Month, 1);
|
|
|
|
|
|
|
|
var endDate = new DateTime(nextMonth.Year, nextMonth.Month, DateTime.DaysInMonth(nextMonth.Year, nextMonth.Month), 23, 59, 59);
|
|
|
|
|
|
|
|
|
|
|
|
db.QueryFilter.Clear();
|
|
|
|
db.QueryFilter.Clear();
|
|
|
|
var dbLinks = await db.Queryable<Module.SqlSugar.SysTenantLink>().ToListAsync();
|
|
|
|
var dbLinks = await db.Queryable<Module.SqlSugar.SysTenantLink>().ToListAsync();
|
|
|
|
SqlSugarClient? tenantDb = null;
|
|
|
|
SqlSugarClient? tenantDb = null;
|
|
|
|
var today = DateTime.Now;
|
|
|
|
|
|
|
|
var today0 = new DateTime(today.Year, today.Month, today.Day);
|
|
|
|
|
|
|
|
var yesterday0 = today0.AddDays(-1).Date;
|
|
|
|
|
|
|
|
var yesterday = new DateTime(yesterday0.Year, yesterday0.Month, yesterday0.Day, 23, 59, 59);
|
|
|
|
|
|
|
|
var lastMonth = today.AddMonths(-1);
|
|
|
|
|
|
|
|
var nextMonth = today.AddMonths(1);
|
|
|
|
|
|
|
|
var startDate = new DateTime(lastMonth.Year, lastMonth.Month, lastMonth.Day);
|
|
|
|
|
|
|
|
var endDate = new DateTime(nextMonth.Year, nextMonth.Month, nextMonth.Day, 23, 59, 59);
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var dbLink in dbLinks)
|
|
|
|
foreach (var dbLink in dbLinks)
|
|
|
@ -68,6 +74,7 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
DbType = dbLink.DbType,
|
|
|
|
DbType = dbLink.DbType,
|
|
|
|
IsAutoCloseConnection = true
|
|
|
|
IsAutoCloseConnection = true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tenantDb.QueryFilter.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
WSLModel model = new()
|
|
|
|
WSLModel model = new()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -75,7 +82,7 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
Month = today.ToString("yyyy.MM")
|
|
|
|
Month = today.ToString("yyyy.MM")
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var list = await tenantDb.Queryable<SeaExport>().Where(x => x.SourceCode == SOURCE_CODE && SqlFunc.Between(x.ETD, startDate, endDate))
|
|
|
|
var list = await tenantDb.Queryable<SeaExport>().Where(x => x.SourceCode == SOURCE_CODE && SqlFunc.Between(x.ETD, startDate, endDate) && !x.Deleted)
|
|
|
|
.Select(x => new
|
|
|
|
.Select(x => new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.Id,
|
|
|
|
x.Id,
|
|
|
@ -90,7 +97,7 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
|
|
|
|
|
|
|
|
var ids = list.Select(x => x.Id.ToString());
|
|
|
|
var ids = list.Select(x => x.Id.ToString());
|
|
|
|
var ctnList = await tenantDb.Queryable<OpCtn>().Where(x => ids.Contains(x.BSNO) &&
|
|
|
|
var ctnList = await tenantDb.Queryable<OpCtn>().Where(x => ids.Contains(x.BSNO) &&
|
|
|
|
!SqlFunc.IsNullOrEmpty(x.CntrNo) && !SqlFunc.IsNullOrEmpty(x.SealNo))
|
|
|
|
!SqlFunc.IsNullOrEmpty(x.CntrNo) && !SqlFunc.IsNullOrEmpty(x.SealNo) && !x.Deleted)
|
|
|
|
.Select(x => new
|
|
|
|
.Select(x => new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.BSNO,
|
|
|
|
x.BSNO,
|
|
|
@ -102,8 +109,8 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
CustomerId = x.Key.CustomerId,
|
|
|
|
CustomerId = x.Key.CustomerId,
|
|
|
|
CustomerName = x.Key.CustomerName,
|
|
|
|
CustomerName = x.Key.CustomerName,
|
|
|
|
Date = model.Date,
|
|
|
|
Date = model.Date,
|
|
|
|
YesterdayTeu = x.Where(x => x.ETD >= yesterday0 && x.ETD <= yesterday).Sum(x => x.TEU),
|
|
|
|
YesterdayTeu = x.Where(x => x.ETD >= yesterday && x.ETD <= yesterday).Sum(x => x.TEU),
|
|
|
|
TodayTeu = x.Where(x => x.ETD >= today0 && x.ETD <= today).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),
|
|
|
|
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),
|
|
|
|
LastMonthTEU = x.Where(x => x.ETD.Value.Year == lastMonth.Year && x.ETD.Value.Month == lastMonth.Month).Sum(x => x.TEU),
|
|
|
|
}).ToList();
|
|
|
|
}).ToList();
|
|
|
@ -114,33 +121,26 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
item.TodayTeuCTNPickup = ctnList.Where(x => ids2.Contains(x.BSNO)).Sum(x => x.TEU);
|
|
|
|
item.TodayTeuCTNPickup = ctnList.Where(x => ids2.Contains(x.BSNO)).Sum(x => x.TEU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
MemoryStream ms = new();
|
|
|
|
await MiniExcel.SaveAsByTemplateAsync(ms, path, model);
|
|
|
|
await MiniExcel.SaveAsByTemplateAsync(ms, path, model);
|
|
|
|
string base64Str = Convert.ToBase64String(ms.ToArray());
|
|
|
|
string base64Str = Convert.ToBase64String(ms.ToArray());
|
|
|
|
ms.Dispose();
|
|
|
|
ms.Dispose();
|
|
|
|
var attaches = new List<Attachment>
|
|
|
|
var attaches = new List<Attachment>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
new() { AttachName = "WSL Volume Daily Increase Report.xlsx", AttachContent = base64Str}
|
|
|
|
new() { AttachName = config["TaskMail:DefaultSetting:Title"] + ".xlsx", AttachContent = base64Str}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
dynamic[] mailParams = [new
|
|
|
|
dynamic[] mailParams = [new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SendTo = config["TaskMail:DefaultSetting:Receivers"],
|
|
|
|
SendTo = config["TaskMail:DefaultSetting:Receivers"],
|
|
|
|
Title = "WSL Volume Daily Increase Report",
|
|
|
|
CCTo = config["TaskMail:DefaultSetting:CCTo"],
|
|
|
|
Body = @"<article class='4ever-article'>
|
|
|
|
Title = config["TaskMail:DefaultSetting:Title"],
|
|
|
|
<p style='line-height: 1;'>Dear WSL Team,</p>
|
|
|
|
Body = config["TaskMail:DefaultSetting:Body"],
|
|
|
|
<p style='line-height: 1;'>Pls kindly check the daily report for your member's nomination booking: </p>
|
|
|
|
|
|
|
|
<p style='line-height: 1;'> </p>
|
|
|
|
|
|
|
|
<p style='line-height: 1;'>Thanks & Best regards</p>
|
|
|
|
|
|
|
|
<p style='line-height: 1;'>Candy SHAO 邵芳</p>
|
|
|
|
|
|
|
|
<p style='line-height: 1;'>General Manager| <strong><span style='color: #e67e23;'>SUNNINESS LOGISTICS CO.,LTD.</span></strong></p>
|
|
|
|
|
|
|
|
<p style='line-height: 1;'>TEL: +(86) (0532-80688387)1 MB./We chat: +(86)(18866622731) | QQ:2853083553|Email:candy@sunniness. net |WCA ID: 60272</p>
|
|
|
|
|
|
|
|
</article>",
|
|
|
|
|
|
|
|
Account = config["TaskMail:DefaultSetting:Account"],
|
|
|
|
Account = config["TaskMail:DefaultSetting:Account"],
|
|
|
|
Password = config["TaskMail:DefaultSetting:Password"],
|
|
|
|
Password = config["TaskMail:DefaultSetting:Password"],
|
|
|
|
Server = config["TaskMail:DefaultSetting:Host"],
|
|
|
|
Server = config["TaskMail:DefaultSetting:Host"],
|
|
|
|
Port = config["TaskMail:DefaultSetting:Port"],
|
|
|
|
Port = config["TaskMail:DefaultSetting:Port"],
|
|
|
|
UseSSL = config["TaskMail:DefaultSetting:UseSSL"],
|
|
|
|
UseSSL = config["TaskMail:DefaultSetting:UseSSL"]?.ToLowerInvariant(),
|
|
|
|
Attaches = attaches
|
|
|
|
Attaches = attaches
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
@ -149,29 +149,16 @@ namespace DS.WMS.Core.QuarztJobs
|
|
|
|
throw new ApplicationException("发送邮件失败");
|
|
|
|
throw new ApplicationException("发送邮件失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tenantDb?.Dispose();
|
|
|
|
tenantDb?.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DefaultSetting
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public long Tenant { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string? Account { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string? Password { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string? Host { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int? Port { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool UseSSL { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string? Receivers { get; set; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Attachment
|
|
|
|
class Attachment
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public string? AttachName { get; set; }
|
|
|
|
public string? AttachName { get; set; }
|
|
|
|