using Tiobon.Core.IServices; using Tiobon.Core.Model.Models; using Tiobon.Core.Services.BASE; using Tiobon.Core.IRepository.Base; using Tiobon.Core.Common.Caches; using Tiobon.Core.Common; using Tiobon.Core.Model; using Google.Protobuf.WellKnownTypes; using Newtonsoft.Json.Linq; using NPOI.Util.Collections; using Newtonsoft.Json; namespace Tiobon.Core.Services; /// /// 培训证书规则 (服务) /// public class Ghre_CertificateRuleServices : BaseServices, IGhre_CertificateRuleServices { private readonly IBaseRepository _dal; private readonly IGhre_CourseServices _ghre_CourseServices; private readonly IGhre_CourseSceneServices _ghre_CourseSceneServices; public Ghre_CertificateRuleServices(ICaching caching, IGhre_CourseServices ghre_CourseServices, IGhre_CourseSceneServices ghre_CourseSceneServices, IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; base._caching = caching; _ghre_CourseServices = ghre_CourseServices; _ghre_CourseSceneServices = ghre_CourseSceneServices; } public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) { if (filter.jsonParam != null) foreach (JProperty jProperty in filter.jsonParam.Properties()) { var name = jProperty.Name; var value = jProperty.Value.ToString(); if (!string.IsNullOrWhiteSpace(value) && name == "CourseName") { var jsonParam = JsonConvert.DeserializeObject(value); switch (jsonParam.operationKey) { case "Equal": condition = $" ( CourseSceneId='{jsonParam.columnValue}' or CourseId='{jsonParam.columnValue}' )"; break; case "NotEqual": condition = $"( CourseSceneId!='{{jsonParam.columnValue}}' AND CourseId!='{{jsonParam.columnValue}}' )\";"; break; default: break; } } } var data = await base.QueryFilterPage(filter, condition, IsEnable); var courseIds = data.result.DT_TableDataT1.Where(x => x.CourseSceneId != null || x.CourseId != null).Select(x => x.CourseId ?? x.CourseSceneId).Distinct().ToList(); var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id)); var courseScenes = await _ghre_CourseSceneServices.Query(x => courseIds.Contains(x.Id)); data.result.DT_TableDataT1.ForEach(async x => { x.RuleTypeLabel = await GetParaLabel("TrainingCertificateRuleType", x.RuleType); x.SendRuleLabel = await GetParaLabel("TrainingCertificateSendRule", x.SendRule); if (x.ValidityType == "StaticDuration") x.ValidityLabel = $"自颁发日起 【{x.StaticNum}】{x.StaticType}内有效"; else if (x.ValidityType == "Unlimited") x.ValidityLabel = $"自颁发日起终生有效"; else if (x.ValidityType == "Option") x.ValidityLabel = $"有效期至【{x.ValidityTime.Value.ToString("yyyy-MM-dd")}】"; if (x.CourseSceneId != null) x.SceneOrCourseName = courseScenes.FirstOrDefault(o => o.Id == x.CourseSceneId)?.SceneName; if (x.CourseId != null) x.SceneOrCourseName = courses.FirstOrDefault(o => o.Id == x.CourseId)?.CourseName; }); return data; } }