dengyu 1 month ago
commit faf61ea613

@ -58,7 +58,7 @@ public interface IUserEmailService
/// 获取用户邮箱配置
/// </summary>
/// <returns></returns>
public Task<DataResult<CodeUserEmailRes>> GetUserEmailSetInfo();
public Task<DataResult<CodeUserEmailRes>> GetCurrentUserEmailAsync();
/// <summary>

@ -115,8 +115,9 @@ public class CodeUserEmailService : ServiceBase, IUserEmailService
/// <returns></returns>
public DataResult<CodeUserEmailRes> GetUserEmailInfo(string id)
{
var int64Id = long.Parse(id);
var data = TenantDb.Queryable<CodeUserEmail>()
.Where(x => x.Id == long.Parse(id) && x.Status == StatusEnum.Enable)
.Where(x => x.Id == int64Id && x.Status == StatusEnum.Enable)
.Select<CodeUserEmailRes>()
.First();
return DataResult<CodeUserEmailRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
@ -150,17 +151,18 @@ public class CodeUserEmailService : ServiceBase, IUserEmailService
/// 获取用户邮箱配置
/// </summary>
/// <returns></returns>
public async Task<DataResult<CodeUserEmailRes>> GetUserEmailSetInfo()
public async Task<DataResult<CodeUserEmailRes>> GetCurrentUserEmailAsync()
{
var userId = long.Parse(User.UserId);
var data = await TenantDb.Queryable<CodeUserEmail>()
.Where(a => a.IsCompany == false && a.CreateBy == long.Parse(User.UserId))
.Where(a => a.CreateBy == userId && !a.IsCompany)
.Select<CodeUserEmailRes>()
.FirstAsync();
if (data == null)
{
data = await TenantDb.Queryable<CodeUserEmail>()
.Where(a => a.IsCompany == true)
.Where(a => a.IsCompany)
.Select<CodeUserEmailRes>()
.FirstAsync();
}

@ -27,6 +27,7 @@ using DS.WMS.Core.Map.Interface;
using Org.BouncyCastle.Ocsp;
using DS.WMS.Core.Invoice.Dtos;
using Org.BouncyCastle.Crypto;
using DS.WMS.Core.Info.Interface;
namespace DS.WMS.Core.Op.Method
{
@ -41,6 +42,7 @@ namespace DS.WMS.Core.Op.Method
private readonly IConfigService configService;
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IMappingCarrierService _mappingCarrierService;
private readonly IClientInfoService _clientInfoService;
const string CONST_MAPPING_MODULE = "CARGOO_DATA";
@ -54,6 +56,7 @@ namespace DS.WMS.Core.Op.Method
seaComService = _serviceProvider.GetRequiredService<ISeaExportCommonService>();
configService = _serviceProvider.GetRequiredService<IConfigService>();
_mappingCarrierService = _serviceProvider.GetRequiredService<IMappingCarrierService>();
_clientInfoService = _serviceProvider.GetRequiredService<IClientInfoService>();
}
#region 发送Cargoo
@ -80,7 +83,7 @@ namespace DS.WMS.Core.Op.Method
if (bookingInfo == null)
return DataResult<CargooShipmentResultDto>.Failed("订单信息获取失败订单ID错误或数据已作废");
if (bookingInfo.ParentId != null || bookingInfo.ParentId > 0)
if (bookingInfo.ParentId != null && bookingInfo.ParentId > 0)
{
return DataResult<CargooShipmentResultDto>.Failed("当前订单不是主单不能发送");
}
@ -477,44 +480,42 @@ namespace DS.WMS.Core.Op.Method
if (IsWSLFOB)
{
var tmpList = tenantDb.Queryable<SeaExportShippingBillTemplate>()
.WhereIF(order.ShipperId.HasValue && order.ShipperId.Value > 0, x => x.Id == order.ShipperId.Value)
.WhereIF(order.ConsigneeId.HasValue && order.ConsigneeId.Value > 0, x => x.Id == order.ConsigneeId.Value)
.WhereIF(order.NotifyPartyId.HasValue && order.NotifyPartyId.Value > 0, x => x.Id == order.NotifyPartyId.Value).ToList();
//var tmpList = tenantDb.Queryable<SeaExportShippingBillTemplate>()
// .WhereIF(order.ShipperId.HasValue && order.ShipperId.Value > 0, x => x.Id == order.ShipperId.Value)
// .WhereIF(order.ConsigneeId.HasValue && order.ConsigneeId.Value > 0, x => x.Id == order.ConsigneeId.Value)
// .WhereIF(order.NotifyPartyId.HasValue && order.NotifyPartyId.Value > 0, x => x.Id == order.NotifyPartyId.Value).ToList();
if (order.ShipperId.HasValue && order.ShipperId.Value > 0)
dto.parties.Add(new CargooShipmentPartyDto
{
var currTmp = tmpList.FirstOrDefault(a => a.Id == order.ShipperId.Value);
type = "CZ",
name = "SUNNINESS LOGISTICS CO.,LTD."
});
dto.parties.Add(new CargooShipmentPartyDto
{
type = "CZ",
name = currTmp.TemplateName
});
}
//取委托客户下面所有的联系人列表
var djyCustomerInfo = _clientInfoService.GetClientInfoWithContact(new Info.Dtos.QueryClientInfo { ClientId = order.CustomerId, IsController = true }).GetAwaiter().GetResult().Data;
if (order.ConsigneeId.HasValue && order.ConsigneeId.Value > 0)
if (djyCustomerInfo == null)
{
var currTmp = tmpList.FirstOrDefault(a => a.Id == order.ConsigneeId.Value);
Logger.Log(NLog.LogLevel.Info, $"委托单位{order.CustomerName} 获取失败,委托单位不存在或已作废 bookingId={order.Id}");
dto.parties.Add(new CargooShipmentPartyDto
{
type = "CN",
name = currTmp.TemplateName
});
//委托单位{0} 获取失败,委托单位不存在或已作废
return DataResult<CargooShipmentDto>.Failed($"委托单位{order.CustomerName} 获取失败,委托单位不存在或已作废");
}
if (order.NotifyPartyId.HasValue && order.NotifyPartyId.Value > 0)
if(string.IsNullOrWhiteSpace(djyCustomerInfo.EnFullName))
return DataResult<CargooShipmentDto>.Failed($"委托单位{djyCustomerInfo.ShortName} 未维护客户英文全称");
dto.parties.Add(new CargooShipmentPartyDto
{
var currTmp = tmpList.FirstOrDefault(a => a.Id == order.NotifyPartyId.Value);
type = "CN",
name = djyCustomerInfo.EnFullName,
});
dto.parties.Add(new CargooShipmentPartyDto
{
type = "NI",
name = currTmp.TemplateName
});
}
dto.parties.Add(new CargooShipmentPartyDto
{
type = "NI",
name = djyCustomerInfo.EnFullName,
});
}
else
{
@ -831,7 +832,7 @@ namespace DS.WMS.Core.Op.Method
if (bookingInfo == null)
return DataResult<string>.Failed("订单信息获取失败订单ID错误或数据已作废");
if (bookingInfo.ParentId != null || bookingInfo.ParentId > 0)
if (bookingInfo.ParentId != null && bookingInfo.ParentId > 0)
{
return DataResult<string>.Failed("当前订单不是主单不能发送");
}

@ -123,25 +123,25 @@ namespace DS.WMS.MainApi.Controllers
});
}
/// <summary>
/// 新增客户干系人
/// </summary>
/// <param name="clientId">客户ID</param>
/// <returns></returns>
[HttpPost, Route("Create")]
public async Task<DataResult> EditAsync(long clientId)
{
var date = DateTime.Now.Date;
return await _invokeService.EditAsync(new InfoClientStakeholder
{
ClientId = clientId,
CreateBy = long.Parse(_user.UserId),
CreateByName = _user.UserName,
StartDate = date,
EndDate = date.AddMonths(4),
Status = StakeholderStatus.Uncommitted
});
}
///// <summary>
///// 新增客户干系人
///// </summary>
///// <param name="clientId">客户ID</param>
///// <returns></returns>
//[HttpPost, Route("Create")]
//public async Task<DataResult> EditAsync(long clientId)
//{
// var date = DateTime.Now.Date;
// return await _invokeService.EditAsync(new InfoClientStakeholder
// {
// ClientId = clientId,
// CreateBy = long.Parse(_user.UserId),
// CreateByName = _user.UserName,
// StartDate = date,
// EndDate = date.AddMonths(4),
// Status = StakeholderStatus.Uncommitted
// });
//}
/// <summary>
/// 更新客户干系人

@ -1,6 +1,10 @@
using System.Data.Common;
using DS.Module.Core;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core;
using DS.WMS.Core.Code.Interface;
using DS.WMS.MainApi.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
@ -12,25 +16,29 @@ namespace DS.WMS.MainApi.Controllers
/// </summary>
public class MaintenanceController : ApiController
{
readonly ISqlSugarClient sugarClient;
readonly IConfiguration config;
readonly ApiFox api;
/// <summary>
/// 初始化
/// </summary>
/// <param name="sugarClient"></param>
public MaintenanceController(ISqlSugarClient sugarClient)
/// <param name="config"></param>
public MaintenanceController(IConfiguration config)
{
this.sugarClient = sugarClient;
this.config = config;
api = new ApiFox();
}
/// <summary>
/// 运行SQL脚本
/// </summary>
/// <param name="sugarClient"></param>
/// <param name="script">SQL脚本</param>
/// <param name="dbNames">运行的数据库,为空时执行全部租户库</param>
/// <returns></returns>
[HttpPost, Route("RunScript"), AllowAnonymous]
public async Task<IActionResult> RunScriptAsync([FromForm] string script, [FromQuery] params string[] dbNames)
public async Task<IActionResult> RunScriptAsync([FromServices] ISqlSugarClient sugarClient,
[FromForm] string script, [FromQuery] params string[] dbNames)
{
bool hasError = default;
var linkList = await sugarClient.Queryable<SysTenantLink>().ToListAsync();
@ -72,5 +80,65 @@ namespace DS.WMS.MainApi.Controllers
return hasError ? StatusCode(500) : Ok();
}
/// <summary>
/// 发送自定义邮件
/// </summary>
/// <param name="userEmailService"></param>
/// <param name="user"></param>
/// <param name="model">邮件发送模型</param>
/// <returns></returns>
[HttpPost, Route("SendMail")]
public async Task<DataResult> SendMailAsync([FromServices] IUserEmailService userEmailService, [FromServices] IUser user,
[FromBody] SendMailModel model)
{
if (string.IsNullOrEmpty(config["MailConfig:ApiUrl"]))
return DataResult.Failed("请联系站点管理员配置邮件服务URL");
var userEmail = await userEmailService.GetCurrentUserEmailAsync();
if (!userEmail.Succeeded || userEmail.Data == null)
return DataResult.Failed("你尚未配置邮箱设置,请到系统设置中维护后重试此操作");
if (model.Attachments?.Length > 0)
{
for (int i = 0; i < model.Attachments.Length; i++)
{
var attachment = model.Attachments[i];
var response = await api.SendRequestAsync(HttpMethod.Get, attachment.Url);
if (!response.IsSuccessStatusCode)
return DataResult.Failed("无法从下列地址中获取文件作为附件:" + attachment.Url);
var bytes = await response.Content.ReadAsByteArrayAsync();
if (bytes == null || bytes.Length == 0)
return DataResult.Failed("下列地址中获取的文件大小为零,无法生成附件:" + attachment.Url);
attachment.Base64 = Convert.ToBase64String(bytes);
if (string.IsNullOrEmpty(attachment.FileName))
attachment.FileName = Path.GetFileName(attachment.Url);
}
}
string sendTo = string.Join(",", model.Receivers);
dynamic[] mailParams = [new
{
SendTo = sendTo,
model.Title,
Body = model.Content,
ShowName = string.IsNullOrEmpty(userEmail.Data.ShowName) ? userEmail.Data.MailAccount : userEmail.Data.ShowName,
Account = userEmail.Data.MailAccount,
userEmail.Data.Password,
Server = userEmail.Data.SmtpServer,
Port = userEmail.Data.SmtpPort,
UseSSL = userEmail.Data.SmtpSSL.GetValueOrDefault(),
Attaches = model.Attachments?.Select(x => new
{
AttachName = x.FileName,
AttachContent = x.Base64
}).ToList()
}];
var mailResult = await api.SendRequestAsync(HttpMethod.Post, config["MailConfig:ApiUrl"]!, mailParams);
return mailResult.IsSuccessStatusCode ? DataResult.Success : DataResult.Failed("发送失败,邮件服务返回状态码为错误");
}
}
}

@ -129,7 +129,7 @@ public class UserEmailController : ApiController
[Route("GetUserEmailSetInfo")]
public async Task<DataResult<CodeUserEmailRes>> GetUserEmailSetInfo()
{
var res = await _invokeService.GetUserEmailSetInfo();
var res = await _invokeService.GetCurrentUserEmailAsync();
return res;
}
}

@ -0,0 +1,49 @@
namespace DS.WMS.MainApi.Models
{
/// <summary>
/// 自定义邮件发送模型
/// </summary>
public class SendMailModel
{
/// <summary>
/// 邮件标题
/// </summary>
public string? Title { get; set; }
/// <summary>
/// 邮件正文
/// </summary>
public string? Content { get; set; }
/// <summary>
/// 邮件接收人
/// </summary>
public string[]? Receivers { get; set; }
/// <summary>
/// 附件
/// </summary>
public Attachment[]? Attachments { get; set; }
}
/// <summary>
/// 邮件附件
/// </summary>
public class Attachment
{
/// <summary>
/// 附件文件名
/// </summary>
public string? FileName { get; set; }
/// <summary>
/// 附件URL
/// </summary>
public string Url { get; set; } = string.Empty;
/// <summary>
/// 附件的BASE64字符串表示
/// </summary>
public string? Base64 { get; set; }
}
}

@ -63,5 +63,15 @@
},
"RedisInfo": {
"RedisConfig": "127.0.0.1:6379,password=,defaultDatabase=15"
},
"MailConfig": {
"ApiUrl": "http://47.104.73.97:8801/mail/send",
"DefaultSetting": {
"Account": "lyle@yyts.fun",
"Password": "15275215387jZ",
"Host": "smtp.mxhichina.com",
"Port": 465,
"UseSSL": true
}
}
}
Loading…
Cancel
Save