|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.DjyServiceStatus;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Core.EmailParse.Dtos;
|
|
|
|
|
using DS.WMS.Core.EmailParse.Entity;
|
|
|
|
|
using DS.WMS.Core.EmailParse.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos;
|
|
|
|
|
using Masuit.Tools.Reflection;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
using LanguageExt.ClassInstances;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.EmailParse.Method
|
|
|
|
|
{
|
|
|
|
|
public class EmailExcuteCodeInjectConfigService : IEmailExcuteCodeInjectConfigService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 邮件执行代码注入service
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public EmailExcuteCodeInjectConfigService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 邮件执行代码注入配置台账查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Task<DataResult<List<EmailExcuteCodeInjectConfigPageDto>>> GetPageAsync(PageRequest<QueryEmailExcuteCodeInjectConfigDto> request)
|
|
|
|
|
{
|
|
|
|
|
//序列化查询条件
|
|
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
var query = db.Queryable<EmailExcuteCodeInjectConfigInfo>()
|
|
|
|
|
.Filter(null, true)
|
|
|
|
|
.Where(x => x.Deleted == false)
|
|
|
|
|
.Where(whereList);
|
|
|
|
|
|
|
|
|
|
#region 查询条件
|
|
|
|
|
|
|
|
|
|
//接收时间起始
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.CreateBegin))
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
//if (!DateTime.TryParse(request.OtherQueryCondition.CreateBegin, out currDate))
|
|
|
|
|
// throw Oops.Oh($"创建日期起始日期格式错误,{request.OtherQueryCondition.CreateBegin}");
|
|
|
|
|
|
|
|
|
|
query = query.Where(t => t.CreateTime >= currDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//接收时间结束
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.CreateEnd))
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
//if (!DateTime.TryParse(request.OtherQueryCondition.CreateEnd, out currDate))
|
|
|
|
|
// throw Oops.Oh($"创建日期结束日期格式错误,{request.OtherQueryCondition.CreateEnd}");
|
|
|
|
|
|
|
|
|
|
currDate = currDate.AddDays(1);
|
|
|
|
|
|
|
|
|
|
query = query.Where(t => t.CreateTime < currDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新时间起始
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.UpdateBegin))
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
//if (!DateTime.TryParse(request.OtherQueryCondition.UpdateBegin, out currDate))
|
|
|
|
|
// throw Oops.Oh($"更新时间起始日期格式错误,{request.OtherQueryCondition.UpdateBegin}");
|
|
|
|
|
|
|
|
|
|
query = query.Where(t => t.UpdateTime >= currDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新时间结束
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.UpdateEnd))
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
//if (!DateTime.TryParse(request.OtherQueryCondition.UpdateEnd, out currDate))
|
|
|
|
|
// throw Oops.Oh($"更新时间结束日期格式错误,{request.OtherQueryCondition.UpdateEnd}");
|
|
|
|
|
|
|
|
|
|
currDate = currDate.AddDays(1);
|
|
|
|
|
|
|
|
|
|
query = query.Where(t => t.UpdateTime < currDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.InjectCode))
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(t => t.InjectCode.Contains(request.OtherQueryCondition.InjectCode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.InjectName))
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(t => t.InjectName.Contains(request.OtherQueryCondition.InjectName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.InjectFullName))
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(t => t.InjectFullName.Contains(request.OtherQueryCondition.InjectFullName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.CreateUser))
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(t => t.CreateUserName.Contains(request.OtherQueryCondition.CreateUser));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.OtherQueryCondition.UpdateUser))
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(t => t.UpdateUserName.Equals(request.OtherQueryCondition.UpdateUser));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
return query.Select<EmailExcuteCodeInjectConfigPageDto>().ToQueryPageAsync(request.PageCondition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存邮件执行代码注入配置
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<EmailExcuteCodeInjectConfigDto>> Save(EmailExcuteCodeInjectConfigDto info)
|
|
|
|
|
{
|
|
|
|
|
string gid = info.GID;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(info.InjectCode))
|
|
|
|
|
return new DataResult<EmailExcuteCodeInjectConfigDto>(ResultCode.Fail, "注入代码不能为空", MultiLanguageConst.EmailInjectCodeCanNotEmpty);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(info.InjectName))
|
|
|
|
|
return new DataResult<EmailExcuteCodeInjectConfigDto>(ResultCode.Fail, "注入名称不能为空", MultiLanguageConst.EmailInjectNameCanNotEmpty);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(info.InjectFullName))
|
|
|
|
|
return new DataResult<EmailExcuteCodeInjectConfigDto>(ResultCode.Fail, "注入代码完整路径不能为空", MultiLanguageConst.EmailInjectFullNameCanNotEmpty);
|
|
|
|
|
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(gid))
|
|
|
|
|
{
|
|
|
|
|
var num = db.Queryable<EmailExcuteCodeInjectConfigInfo>().Count(a => a.InjectCode.Equals(info.InjectCode));
|
|
|
|
|
|
|
|
|
|
if (num > 0)
|
|
|
|
|
return new DataResult<EmailExcuteCodeInjectConfigDto>(ResultCode.Fail, "注入代码不能重复", MultiLanguageConst.EmailInjectCodeCanNotRepeat);
|
|
|
|
|
|
|
|
|
|
gid = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
var entity = info.Adapt<EmailExcuteCodeInjectConfigInfo>();
|
|
|
|
|
entity.GID = gid;
|
|
|
|
|
|
|
|
|
|
await db.Insertable(entity).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var num = db.Queryable<EmailExcuteCodeInjectConfigInfo>().Count(a =>
|
|
|
|
|
a.InjectCode.Equals(info.InjectCode) && a.GID != gid);
|
|
|
|
|
|
|
|
|
|
if (num > 0)
|
|
|
|
|
return new DataResult<EmailExcuteCodeInjectConfigDto>(ResultCode.Fail, "注入代码不能重复", MultiLanguageConst.EmailInjectCodeCanNotRepeat);
|
|
|
|
|
|
|
|
|
|
var model = db.Queryable<EmailExcuteCodeInjectConfigInfo>()
|
|
|
|
|
.First(a => a.GID == gid);
|
|
|
|
|
|
|
|
|
|
var entity = info.Adapt<EmailExcuteCodeInjectConfigInfo>();
|
|
|
|
|
await db.Updateable(entity).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await GetInfo(gid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取邮件执行代码注入配置详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gid"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<EmailExcuteCodeInjectConfigDto>> GetInfo(string gid)
|
|
|
|
|
{
|
|
|
|
|
DataResult<EmailExcuteCodeInjectConfigDto> result = new DataResult<EmailExcuteCodeInjectConfigDto>();
|
|
|
|
|
|
|
|
|
|
var model = await db.Queryable<EmailExcuteCodeInjectConfigInfo>().FirstAsync(a => a.GID == gid);
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
result.Code = ResultCode.Fail;
|
|
|
|
|
result.Message = MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.EmailParserDataNotFound));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var showModel = model.Adapt<EmailExcuteCodeInjectConfigDto>();
|
|
|
|
|
|
|
|
|
|
result.Code = ResultCode.Success;
|
|
|
|
|
result.Data = showModel;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gIds"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
public async Task<DataResult> Delete(string[] gIds)
|
|
|
|
|
{
|
|
|
|
|
DataResult result = new DataResult();
|
|
|
|
|
var list = db.Queryable<EmailExcuteCodeInjectConfigInfo>().Where(a => gIds.Contains(a.GID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
result.Code = ResultCode.Fail;
|
|
|
|
|
result.Message = MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.EmailParserDataNotFound));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var record in list)
|
|
|
|
|
{
|
|
|
|
|
record.Deleted = true;
|
|
|
|
|
await db.Updateable(record).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Code = ResultCode.Success;
|
|
|
|
|
result.Message = MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.EmailOperateSuccess));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索所有使用此执行代码注入配置的解析配置列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gid"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
public async Task<DataResult<List<EmailParserConfigDto>>> QueryUseParserConfigEmailList(string gid)
|
|
|
|
|
{
|
|
|
|
|
var result = new DataResult<List<EmailParserConfigDto>>();
|
|
|
|
|
var accountList = db.Queryable<EmailParserConfigInfo>()
|
|
|
|
|
.Where(par => par.InjectId == gid)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var list = accountList.Select(t => t.Adapt<EmailParserConfigDto>()).OrderBy(t => t.ParserName).ToList();
|
|
|
|
|
|
|
|
|
|
result.Data = list;
|
|
|
|
|
result.Code = ResultCode.Success;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|