cjy 4 months ago
commit e7378afbb8

@ -261,9 +261,9 @@ namespace DS.Module.Core
SeaExport = 6,
/// <summary>
/// 海运出口退
/// 海运出口退
/// </summary>
[Description("海运出口退")]
[Description("海运出口退")]
SeaExportReturn = 7
}
}

@ -5,32 +5,32 @@ namespace DS.Module.Core;
/// </summary>
public static class GenericHelper
{
/// <summary>
/// 把数组转为逗号连接的字符串
/// </summary>
/// <param name="data"></param>
/// <param name="Str"></param>
/// <returns></returns>
public static string ArrayToString(dynamic data, string Str)
{
string resStr = Str;
foreach (var item in data)
{
if (resStr != "")
{
resStr += ",";
}
///// <summary>
///// 把数组转为逗号连接的字符串
///// </summary>
///// <param name="data"></param>
///// <param name="Str"></param>
///// <returns></returns>
//public static string ArrayToString(dynamic data, string Str)
//{
// string resStr = Str;
// foreach (var item in data)
// {
// if (resStr != "")
// {
// resStr += ",";
// }
if (item is string)
{
resStr += item;
}
else
{
resStr += item.Value;
// if (item is string)
// {
// resStr += item;
// }
// else
// {
// resStr += item.Value;
}
}
return resStr;
}
// }
// }
// return resStr;
//}
}

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.Module.PrintModule
namespace DS.Module.PrintModule
{
/// <summary>
/// Json打印请求数据
@ -26,4 +20,32 @@ namespace DS.Module.PrintModule
/// </summary>
public string PrintType { get; set; } = "1";
}
/// <summary>
/// Json打印请求数据
/// </summary>
public class OpenPrintReq
{
public long TenantId { get; set; }
/// <summary>
/// 模板Id
/// </summary>
public long? TemplateId { get; set; }
/// <summary>
/// 模板代码
/// </summary>
public string? TemplateCode { get; set; }
/// <summary>
/// 查询语句SQL参数
/// </summary>
public string ParamJsonStr { get; set; } = string.Empty;
/// <summary>
/// 打印类型 1. PDF 2.EXCEL 3.WORD
/// </summary>
public string PrintType { get; set; } = "1";
}
}

@ -22,6 +22,17 @@
<EmbeddedResource Remove="Template\**" />
<None Remove="Template\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Op\MailTemplate.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Op\MailTemplate.cshtml">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Finance\Dtos\" />
<Folder Include="Finance\Entity\" />

@ -61,7 +61,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
var users = Db.Queryable<SysRoleUser>().Where(x =>
nextConditionNode.Roles.Contains(x.RoleId.ToString()))
.Select(x => x.UserId).Distinct().ToList();
makerList = GenericHelper.ArrayToString(users, makerList);
makerList = string.Join(",", users);
}
else if (nextConditionNode.AssigneeType == "user")
{

@ -47,18 +47,36 @@ public class ClientFlowTemplateService : IClientFlowTemplateService
public DataResult EditClientFlowTemplate(FlowTemplateReq req)
{
//if (req.Id == 0)
//{
// return DataResult.Failed("非法请求!",MultiLanguageConst.IllegalRequest);
//}
//else
//{
// var info = db.Queryable<FlowTemplateTenant>().Where(x => x.Id == req.Id).First();
// info = req.Adapt(info);
// db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
// return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
//}
if (req.Id == 0)
{
return DataResult.Failed("非法请求!",MultiLanguageConst.IllegalRequest);
var isExist = db.Queryable<FlowTemplateTenant>().Where(x => x.Name == req.Name).First();
if (isExist != null)
return DataResult.Failed("流程模板名称已存在!");
var data = req.Adapt<FlowTemplateTenant>();
var entity = db.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id);
}
else
{
var info = db.Queryable<FlowTemplateTenant>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
return DataResult.Successed("更新成功!");
}
}

@ -631,7 +631,7 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService
var users = Db.Queryable<SysRoleUser>().Where(x =>
wfruntime.NextNode.Roles.Contains(x.RoleId.ToString()))
.Select(x => x.UserId).Distinct().ToList();
makerList = GenericHelper.ArrayToString(users, makerList);
makerList = string.Join(",", users);
}
else if (wfruntime.NextNode.AssigneeType == "user")
{
@ -667,7 +667,7 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService
var users = Db.Queryable<SysRoleUser>().Where(x =>
nextConditionNode.Roles.Contains(x.RoleId.ToString()))
.Select(x => x.UserId).Distinct().ToList();
makerList = GenericHelper.ArrayToString(users, makerList);
makerList = string.Join(",", users);
}
else if (nextConditionNode.AssigneeType == "user")
{
@ -706,7 +706,7 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService
var users = Db.Queryable<SysRoleUser>().Where(x =>
node.Roles.Contains(x.RoleId.ToString()))
.Select(x => x.UserId).Distinct().ToList();
makerList = GenericHelper.ArrayToString(users, makerList);
makerList = string.Join(",", users);
}
else if (node.AssigneeType == "user")
{

@ -1,5 +1,4 @@
using DS.WMS.Core.Op.Entity.TaskInteraction;
using SqlSugar;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
@ -12,8 +11,6 @@ namespace DS.WMS.Core.Op.Dtos.TaskInteraction
public IServiceProvider ServiceProvider { get; internal set; }
public ISqlSugarClient TenantDb { get; internal set; }
public IDictionary<string, object?> AdditionalData { get; set; } = new Dictionary<string, object?>();
}
}

@ -0,0 +1,14 @@
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 邮件模板模型
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
public class MailTemplateModel<T>
{
/// <summary>
/// 主要数据项
/// </summary>
public T? Primary { get; internal set; }
}
}

@ -0,0 +1,20 @@
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
public class PrintResult
{
/// <summary>
/// 是否成功
/// </summary>
public bool Succeeded { get; set; }
/// <summary>
/// 返回消息
/// </summary>
public string Message { get; set; }
/// <summary>
/// 返回结果
/// </summary>
public string Data { get; set; }
}
}

@ -19,5 +19,11 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long TemplateId { get; set; }
/// <summary>
/// 附件获取接口的URL
/// </summary>
[SugarColumn(ColumnDescription = "附件获取接口的URL", Length = 255, IsNullable = false)]
public string RequestURL { get; set; } = string.Empty;
}
}

@ -44,100 +44,100 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction
[SugarColumn(ColumnDescription = "是否委托单位", DefaultValue = "0")]
public bool IsController { get; set; }
/// <summary>
/// Desc:是否报关行
/// </summary>
[SugarColumn(ColumnDescription = "是否报关行", DefaultValue = "0")]
public bool IsCustom { get; set; }
/// <summary>
/// Desc:是否代理(国外)
/// </summary>
[SugarColumn(ColumnDescription = "是否代理(国外)", DefaultValue = "0")]
public bool IsAgent { get; set; }
/// <summary>
/// Desc:是否代理(国内)
/// </summary>
[SugarColumn(ColumnDescription = "是否代理(国内)", DefaultValue = "0")]
public bool IsAgentCn { get; set; }
/// <summary>
/// Desc:是否快递公司
/// </summary>
[SugarColumn(ColumnDescription = "是否快递公司", DefaultValue = "0")]
public bool IsExpress { get; set; }
/// <summary>
/// Desc:是否航空公司
/// </summary>
[SugarColumn(ColumnDescription = "是否航空公司", DefaultValue = "0")]
public bool IsAirLines { get; set; }
/// <summary>
/// Desc:是否发货人
/// </summary>
[SugarColumn(ColumnDescription = "是否发货人", DefaultValue = "0")]
public bool IsShipper { get; set; }
/// <summary>
/// Desc:是否收货人
/// </summary>
[SugarColumn(ColumnDescription = "是否收货人", DefaultValue = "0")]
public bool IsConsignee { get; set; }
/// <summary>
/// Desc:是否通知人
/// </summary>
[SugarColumn(ColumnDescription = "是否通知人", DefaultValue = "0")]
public bool IsNotifyParty { get; set; }
/// <summary>
/// Desc:是否仓库
/// </summary>
[SugarColumn(ColumnDescription = "是否仓库", DefaultValue = "0")]
public bool IsWareHouse { get; set; }
/// <summary>
/// Desc:是否码头
/// </summary>
[SugarColumn(ColumnDescription = "是否码头", DefaultValue = "0")]
public bool IsWharf { get; set; }
/// <summary>
/// Desc:是否保险公司
/// </summary>
[SugarColumn(ColumnDescription = "是否保险公司", DefaultValue = "0")]
public bool IsInsurer { get; set; }
/// <summary>
/// Desc:是否租箱公司
/// </summary>
[SugarColumn(ColumnDescription = "是否租箱公司", DefaultValue = "0")]
public bool IsLeasing { get; set; }
/// <summary>
/// Desc:是否贸易代理
/// </summary>
[SugarColumn(ColumnDescription = "是否贸易代理", DefaultValue = "0")]
public bool IsTradingAgency { get; set; }
/// <summary>
/// Desc:是否船代
/// </summary>
[SugarColumn(ColumnDescription = "是否船代", DefaultValue = "0")]
public bool IsShipAgency { get; set; }
/// <summary>
/// Desc:是否经营单位
/// </summary>
[SugarColumn(ColumnDescription = "是否经营单位", DefaultValue = "0")]
public bool IsEnterprise { get; set; }
/// <summary>
/// Desc:是否国内发货人
/// </summary>
[SugarColumn(ColumnDescription = "是否国内发货人", DefaultValue = "0")]
public bool IsShipperCn { get; set; }
///// <summary>
///// Desc:是否报关行
///// </summary>
//[SugarColumn(ColumnDescription = "是否报关行", DefaultValue = "0")]
//public bool IsCustom { get; set; }
///// <summary>
///// Desc:是否代理(国外)
///// </summary>
//[SugarColumn(ColumnDescription = "是否代理(国外)", DefaultValue = "0")]
//public bool IsAgent { get; set; }
///// <summary>
///// Desc:是否代理(国内)
///// </summary>
//[SugarColumn(ColumnDescription = "是否代理(国内)", DefaultValue = "0")]
//public bool IsAgentCn { get; set; }
///// <summary>
///// Desc:是否快递公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否快递公司", DefaultValue = "0")]
//public bool IsExpress { get; set; }
///// <summary>
///// Desc:是否航空公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否航空公司", DefaultValue = "0")]
//public bool IsAirLines { get; set; }
///// <summary>
///// Desc:是否发货人
///// </summary>
//[SugarColumn(ColumnDescription = "是否发货人", DefaultValue = "0")]
//public bool IsShipper { get; set; }
///// <summary>
///// Desc:是否收货人
///// </summary>
//[SugarColumn(ColumnDescription = "是否收货人", DefaultValue = "0")]
//public bool IsConsignee { get; set; }
///// <summary>
///// Desc:是否通知人
///// </summary>
//[SugarColumn(ColumnDescription = "是否通知人", DefaultValue = "0")]
//public bool IsNotifyParty { get; set; }
///// <summary>
///// Desc:是否仓库
///// </summary>
//[SugarColumn(ColumnDescription = "是否仓库", DefaultValue = "0")]
//public bool IsWareHouse { get; set; }
///// <summary>
///// Desc:是否码头
///// </summary>
//[SugarColumn(ColumnDescription = "是否码头", DefaultValue = "0")]
//public bool IsWharf { get; set; }
///// <summary>
///// Desc:是否保险公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否保险公司", DefaultValue = "0")]
//public bool IsInsurer { get; set; }
///// <summary>
///// Desc:是否租箱公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否租箱公司", DefaultValue = "0")]
//public bool IsLeasing { get; set; }
///// <summary>
///// Desc:是否贸易代理
///// </summary>
//[SugarColumn(ColumnDescription = "是否贸易代理", DefaultValue = "0")]
//public bool IsTradingAgency { get; set; }
///// <summary>
///// Desc:是否船代
///// </summary>
//[SugarColumn(ColumnDescription = "是否船代", DefaultValue = "0")]
//public bool IsShipAgency { get; set; }
///// <summary>
///// Desc:是否经营单位
///// </summary>
//[SugarColumn(ColumnDescription = "是否经营单位", DefaultValue = "0")]
//public bool IsEnterprise { get; set; }
///// <summary>
///// Desc:是否国内发货人
///// </summary>
//[SugarColumn(ColumnDescription = "是否国内发货人", DefaultValue = "0")]
//public bool IsShipperCn { get; set; }
}
}

@ -13,7 +13,7 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction
/// 服务器地址
/// </summary>
[SugarColumn(ColumnDescription = "服务器地址", Length = 200, IsNullable = false)]
public string Server { get; set; } = string.Empty;
public string Host { get; set; } = string.Empty;
/// <summary>
/// 端口号

@ -0,0 +1,16 @@
@model DS.WMS.Core.Op.Dtos.TaskInteraction.MailTemplateModel<DS.WMS.Core.Op.Dtos.SeaExportRes>
@{
var item = Model.Primary;
}
<h1>测试邮件-@item.MBLNO<span style="padding: 2px"></span>@item.CustomerNo</h1>
<div>
<span>预计开船日期:@item.ETD</span>
<span>预计抵达日期:@item.ETA</span>
</div>
<hr />
<div>
<span>订单创建时间:@item.CreateTime.ToString("yyyy年MM月dd日 HH:mm:ss")</span>
</div>

@ -55,8 +55,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
var context = new ActionExecutionContext
{
TaskInfo = dataContext.Get<BusinessTask>(TaskFlowDataNameConst.BusinessTask),
ServiceProvider = ServiceProvider,
TenantDb = TenantDb
ServiceProvider = ServiceProvider
};
foreach (var key in dataContext.Keys)
{

@ -1,9 +1,21 @@
using DS.Module.Core.Extensions;
using DS.Module.Core;
using DS.Module.PrintModule;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using DS.WMS.Core.Sys.Entity;
using MailKit.Net.Smtp;
using Masuit.Tools;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using MimeKit;
using Newtonsoft.Json;
using RazorEngineCore;
using SqlSugar;
namespace DS.WMS.Core.Op.Method.TaskInteraction
{
@ -12,6 +24,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary>
public class MailActionExecutor : IActionExecutor
{
static readonly ApiFox api;
static MailActionExecutor()
{
api = new ApiFox();
}
/// <summary>
/// 发送邮件
/// </summary>
@ -19,8 +38,14 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// <returns></returns>
public async Task ExecuteAsync(ActionExecutionContext context)
{
var db = context.ServiceProvider.GetRequiredService<ISqlSugarClient>();
var saasService = context.ServiceProvider.GetRequiredService<ISaasDbService>();
var user = context.ServiceProvider.GetRequiredService<IUser>();
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var service = context.ServiceProvider.GetRequiredService<ITaskMailService>();
var logService = context.ServiceProvider.GetRequiredService<ITaskLogService>();
var seService = context.ServiceProvider.GetRequiredService<ISeaExportService>();
var mailName = context.AdditionalData["MailName"] as string;
if (mailName.IsNullOrEmpty())
@ -35,9 +60,141 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
return;
}
var result = seService.GetSeaExportInfo(context.TaskInfo.BusinessId.ToString());
if (!result.Succeeded)
{
await logService.WriteLogAsync(context.TaskInfo, $"未能获取Id={context.TaskInfo.BusinessId}的{context.TaskInfo.BusinessType.GetDescription()}数据");
return;
}
var templateModel = new MailTemplateModel<SeaExportRes> { Primary = result.Data };
IRazorEngine razorEngine = new RazorEngine();
IRazorEngineCompiledTemplate titleTemplate = razorEngine.Compile(mailConfig.Title);
IRazorEngineCompiledTemplate contentTemplate = razorEngine.Compile(mailConfig.Content);
var titleTemplate = razorEngine.Compile<RazorEngineTemplateBase<MailTemplateModel<SeaExportRes>>>(mailConfig.Title);
string title = titleTemplate.Run(x =>
{
x.Model = templateModel;
});
var contentTemplate = razorEngine.Compile<RazorEngineTemplateBase<MailTemplateModel<SeaExportRes>>>(mailConfig.Content);
string content = contentTemplate.Run(x =>
{
x.Model = templateModel;
});
var textPart = new TextPart("plain") { Text = content };
var message = new MimeMessage
{
Subject = title,
};
//设置发件人
List<long> senderIds = new List<long>();
if (mailConfig.Sender.IsSale)
{
senderIds.Add(templateModel.Primary.SaleId);
}
if (mailConfig.Sender.IsOperator)
{
senderIds.Add(templateModel.Primary.OperatorId);
}
if (mailConfig.Sender.IsCustomerService)
{
senderIds.Add(templateModel.Primary.CustomerService);
}
if (mailConfig.Sender.IsVouchingClerk)
{
senderIds.Add(templateModel.Primary.Doc);
}
var senderList = await db.Queryable<SysUser>().Where(x => senderIds.Contains(x.Id) && x.Email != null && x.Email != string.Empty)
.Select(x => new { x.UserName, x.UserEnName, x.Email }).ToListAsync();
foreach (var sender in senderList)
message.From.Add(new MailboxAddress(sender.UserName, sender.Email));
//设置收件人
List<long> receiverIds = new List<long>();
if (mailConfig.Receiver.IsCarrier)
{
receiverIds.Add(templateModel.Primary.CarrierId);
}
if (mailConfig.Receiver.IsBooking)
{
//receiverIds.Add(templateModel.Primary.CarrierId);
}
if (mailConfig.Receiver.IsYard)
{
receiverIds.Add(templateModel.Primary.YardId);
}
if (mailConfig.Receiver.IsTruck)
{
receiverIds.Add(templateModel.Primary.TruckerId);
}
if (mailConfig.Receiver.IsController)
{
receiverIds.Add(templateModel.Primary.CustomerId);
}
var receiverList = await tenantDb.Queryable<InfoClient>().Where(x => receiverIds.Contains(x.Id) && x.Email != null && x.Email != string.Empty)
.Select(x => new { x.ShortName, x.EnShortName, x.Email }).ToListAsync();
foreach (var item in receiverList)
message.To.Add(new MailboxAddress(item.ShortName, item.Email));
//需要上传附件
if (mailConfig.Attachments?.Count > 0)
{
var multipart = new Multipart("mixed");
multipart.Add(textPart);
if (api.DefaultHeaders.Contains("Authorization"))
api.DefaultHeaders.Remove("Authorization");
api.DefaultHeaders.Add("Authorization", "Bearer " + user.GetToken());
long tenantId = long.Parse(user.TenantId);
foreach (var item in mailConfig.Attachments)
{
var req = new OpenPrintReq
{
ParamJsonStr = JsonConvert.SerializeObject(new { Id = context.TaskInfo.BusinessId }),
PrintType = "1",
TemplateId = item.TemplateId,
TenantId = tenantId
};
var reqResult = await api.PostAsync<PrintResult>(item.RequestURL, req);
if (reqResult.Succeeded)
{
}
//var attachment = new MimePart("image", "gif")
//{
// Content = new MimeContent(File.OpenRead(path), ContentEncoding.Default),
// ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
// ContentTransferEncoding = ContentEncoding.Base64,
// FileName = Path.GetFileName(path)
//};
}
}
else
{
message.Body = textPart;
}
var client = new SmtpClient();
try
{
client.Connect(mailConfig.Server.Host, mailConfig.Server.Port, mailConfig.Server.UseSSL);
if (!mailConfig.Server.LoginName.IsNullOrEmpty() && !mailConfig.Server.Password.IsNullOrEmpty())
{
client.Authenticate(mailConfig.Server.LoginName, mailConfig.Server.Password);
}
client.Send(message);
client.Disconnect(true);
}
catch (Exception ex)
{
await ex.LogAsync(db);
}
finally
{
client?.Dispose();
}
}
}
}

@ -468,7 +468,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (useTransaction)
await TenantDb.Ado.CommitTranAsync();
ActionService.Value.TriggerAction(task);
//ActionService.Value.TriggerAction(task);
return DataResult<TaskBaseTypeEnum?>.Success(task.TaskStatus == TaskStatusEnum.Complete ? GetNextType(task) : null);
}
catch (Exception ex)

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NameOfLastUsedPublishProfile>D:\Code\DS\ds8-solution-pro\ds-wms-service\DS.WMS.MainApi\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>D:\Source\Repos\DS8\ds-wms-service\DS.WMS.MainApi\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
</PropertyGroup>
</Project>

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NameOfLastUsedPublishProfile>E:\MyCode\Dongsheng8\ds-wms-service\DS.WMS.OpApi\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>D:\Source\Repos\DS8\ds-wms-service\DS.WMS.OpApi\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>

Loading…
Cancel
Save