You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
6.2 KiB
150 lines
6.2 KiB
using static Tiobon.Core.Model.Consts;
|
|
using Tiobon.Core.Common.DB.Dapper.Extensions;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Tiobon.Core.Services;
|
|
|
|
/// <summary>
|
|
/// 培训证书规则 (服务)
|
|
/// </summary>
|
|
public class Ghre_CertificateRuleServices : BaseServices<Ghre_CertificateRule, Ghre_CertificateRuleDto, InsertGhre_CertificateRuleInput, EditGhre_CertificateRuleInput>, IGhre_CertificateRuleServices
|
|
{
|
|
private readonly IBaseRepository<Ghre_CertificateRule> _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<Ghre_CertificateRule> dal)
|
|
{
|
|
this._dal = dal;
|
|
base.BaseDal = dal;
|
|
base._caching = caching;
|
|
_ghre_CourseServices = ghre_CourseServices;
|
|
_ghre_CourseSceneServices = ghre_CourseSceneServices;
|
|
}
|
|
|
|
public override async Task<ServicePageResult<Ghre_CertificateRuleDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
|
|
{
|
|
string condition1 = string.Empty;
|
|
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<JsonParam>(value);
|
|
|
|
switch (jsonParam.operationKey)
|
|
{
|
|
case "Equal":
|
|
condition1 = $" ( CourseSceneId='{jsonParam.columnValue}' or CourseId='{jsonParam.columnValue}' )";
|
|
break;
|
|
case "NotEqual":
|
|
condition1 = $"( CourseSceneId!='{{jsonParam.columnValue}}' AND CourseId!='{{jsonParam.columnValue}}' )\";";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (condition.IsNull())
|
|
condition = condition1;
|
|
else condition += " AND " + condition1;
|
|
var data = await base.QueryFilterPage(filter, condition, IsEnable);
|
|
|
|
var courseIds = new List<long?>();
|
|
var courseSceneIds = new List<long?>();
|
|
data.result.DT_TableDataT1.ForEach(x =>
|
|
{
|
|
if (x.CourseId1.IsNotEmptyOrNull())
|
|
{
|
|
x.CourseIds = JsonHelper.JsonToObj<List<long?>>(x.CourseId1);
|
|
courseIds.AddRange(x.CourseIds);
|
|
}
|
|
else if (x.CourseId != null)
|
|
{
|
|
courseIds.Add(x.CourseId);
|
|
x.CourseIds = [x.CourseId];
|
|
}
|
|
|
|
if (x.CourseSceneId1.IsNotEmptyOrNull())
|
|
{
|
|
x.CourseSceneIds = JsonHelper.JsonToObj<List<long?>>(x.CourseSceneId1);
|
|
courseSceneIds.AddRange(x.CourseSceneIds);
|
|
}
|
|
else if (x.CourseSceneId != null)
|
|
{
|
|
courseSceneIds.Add(x.CourseSceneId);
|
|
x.CourseSceneIds = [x.CourseSceneId];
|
|
}
|
|
});
|
|
|
|
|
|
var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id));
|
|
var courseScenes = await _ghre_CourseSceneServices.Query(x => courseSceneIds.Contains(x.Id));
|
|
|
|
data.result.DT_TableDataT1.ForEach(async x =>
|
|
{
|
|
x.RuleTypeLabel = await GetParaLabel("TrainingCertificateRuleType", x.RuleType);
|
|
x.SendRuleLabel = await GetParaLabel("TrainingCertificateSendRule", x.SendRule);
|
|
|
|
string staticType = x.StaticType == "month" ? "月" : (x.StaticType == "year" ? "年" : "天");
|
|
if (x.ValidityType == "StaticDuration")
|
|
x.ValidityLabel = $"自颁发日起 【{x.StaticNum}】{staticType}内有效";
|
|
else
|
|
if (x.ValidityType == "Unlimited")
|
|
x.ValidityLabel = $"自颁发日起终生有效";
|
|
else
|
|
if (x.ValidityType == "Option")
|
|
x.ValidityLabel = $"有效期至【{x.ValidityTime.Value.ToString("yyyy-MM-dd")}】";
|
|
if (x.CourseIds != null && x.CourseIds.Any())
|
|
{
|
|
x.SceneOrCourseName = string.Join("、", courses.Where(o => x.CourseIds.Contains(o.Id)).Select(o => o.CourseName));
|
|
}
|
|
//
|
|
|
|
if (x.CourseSceneIds != null && x.CourseSceneIds.Any())
|
|
x.SceneOrCourseName = string.Join("、", courseScenes.Where(o => x.CourseSceneIds.Contains(o.Id)).Select(o => o.SceneName));
|
|
});
|
|
return data;
|
|
|
|
}
|
|
|
|
public override async Task<long> Add(InsertGhre_CertificateRuleInput entity)
|
|
{
|
|
if (entity.CourseSceneIds != null)
|
|
entity.CourseSceneId1 = JsonHelper.ObjToJson(entity.CourseSceneIds);
|
|
if (entity.CourseIds != null)
|
|
entity.CourseId1 = JsonHelper.ObjToJson(entity.CourseIds);
|
|
var result = await base.Add(entity);
|
|
|
|
return result;
|
|
}
|
|
|
|
public override async Task<bool> Update(long Id, EditGhre_CertificateRuleInput editModel)
|
|
{
|
|
if (editModel.CourseSceneIds != null)
|
|
editModel.CourseSceneId1 = JsonHelper.ObjToJson(editModel.CourseSceneIds);
|
|
if (editModel.CourseIds != null)
|
|
editModel.CourseId1 = JsonHelper.ObjToJson(editModel.CourseIds);
|
|
var result = await base.Update(Id, editModel);
|
|
return result;
|
|
}
|
|
|
|
public override async Task<ServiceFormResult<Ghre_CertificateRuleDto>> QueryForm(QueryForm body)
|
|
{
|
|
var result = await base.QueryForm(body);
|
|
string CourseId1 = result.result.DT_TableDataT1[0].CourseId1;
|
|
if (!string.IsNullOrWhiteSpace(CourseId1))
|
|
result.result.DT_TableDataT1[0].CourseIds = JsonConvert.DeserializeObject<List<long?>>(CourseId1);
|
|
string CourseSceneId1 = result.result.DT_TableDataT1[0].CourseSceneId1;
|
|
if (!string.IsNullOrWhiteSpace(CourseSceneId1))
|
|
result.result.DT_TableDataT1[0].CourseSceneIds = JsonConvert.DeserializeObject<List<long?>>(CourseSceneId1);
|
|
|
|
return result;
|
|
|
|
}
|
|
} |