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; /// /// 邮件执行代码注入service /// /// public EmailExcuteCodeInjectConfigService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); } /// /// 邮件执行代码注入配置台账查询 /// /// /// public Task>> GetPageAsync(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var query = db.Queryable() .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().ToQueryPageAsync(request.PageCondition); } /// /// 保存邮件执行代码注入配置 /// /// /// public async Task> Save(EmailExcuteCodeInjectConfigDto info) { string gid = info.GID; if (string.IsNullOrWhiteSpace(info.InjectCode)) return new DataResult(ResultCode.Fail, "注入代码不能为空", MultiLanguageConst.EmailInjectCodeCanNotEmpty); if (string.IsNullOrWhiteSpace(info.InjectName)) return new DataResult(ResultCode.Fail, "注入名称不能为空", MultiLanguageConst.EmailInjectNameCanNotEmpty); if (string.IsNullOrWhiteSpace(info.InjectFullName)) return new DataResult(ResultCode.Fail, "注入代码完整路径不能为空", MultiLanguageConst.EmailInjectFullNameCanNotEmpty); DateTime nowDate = DateTime.Now; if (string.IsNullOrWhiteSpace(gid)) { var num = db.Queryable().Count(a => a.InjectCode.Equals(info.InjectCode)); if (num > 0) return new DataResult(ResultCode.Fail, "注入代码不能重复", MultiLanguageConst.EmailInjectCodeCanNotRepeat); gid = Guid.NewGuid().ToString(); var entity = info.Adapt(); entity.GID = gid; await db.Insertable(entity).ExecuteCommandAsync(); } else { var num = db.Queryable().Count(a => a.InjectCode.Equals(info.InjectCode) && a.GID != gid); if (num > 0) return new DataResult(ResultCode.Fail, "注入代码不能重复", MultiLanguageConst.EmailInjectCodeCanNotRepeat); var model = db.Queryable() .First(a => a.GID == gid); var entity = info.Adapt(); await db.Updateable(entity).ExecuteCommandAsync(); } return await GetInfo(gid); } /// /// 获取邮件执行代码注入配置详情 /// /// /// public async Task> GetInfo(string gid) { DataResult result = new DataResult(); var model = await db.Queryable().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(); result.Code = ResultCode.Success; result.Data = showModel; return result; } /// /// 删除 /// /// /// /// public async Task Delete(string[] gIds) { DataResult result = new DataResult(); var list = db.Queryable().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; } /// /// 检索所有使用此执行代码注入配置的解析配置列表 /// /// /// /// public async Task>> QueryUseParserConfigEmailList(string gid) { var result = new DataResult>(); var accountList = db.Queryable() .Where(par => par.InjectId == gid) .ToList(); var list = accountList.Select(t => t.Adapt()).OrderBy(t => t.ParserName).ToList(); result.Data = list; result.Code = ResultCode.Success; return result; } } }