新增学习完成证书发放

master
xiaochanghai 1 month ago
parent e7210e087d
commit c17495bd41
  1. 8567
      Model/Tiobon.Web.pdm
  2. 261
      Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs
  3. 1
      Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs

File diff suppressed because it is too large Load Diff

@ -1604,7 +1604,7 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
.Where(x =>
x.ExamDate != null &&
x.ExamDate.Value.Date == now.Date &&
x.IsPass == true &&
//x.IsPass == true &&
(x.IsIssueCertificate == null || x.IsIssueCertificate == false))
.ToListAsync();
_logger.LogInformation($"【发放证书】查询到{records.Count}条考试数据");
@ -1612,86 +1612,27 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
var rules = new List<Ghre_CertificateRule>();
if (records.Any())
{
var certificates = new List<Ghre_Certificate>();
rules = await Db.Queryable<Ghre_CertificateRule>().Where(x => x.SendRule == "ExamPass").ToListAsync();
for (int i = 0; i < records.Count; i++)
{
var record = records[i];
if (record.CourseId.IsNotEmptyOrNull())
{
var rules1 = rules.Where(x => x.CourseId1 != null && x.CourseId1.Contains(record.CourseId.ObjToString())).ToList();
await IssueCourseCertificate(record.StaffId, null, record.Id, record.CourseId, record.CourseSceneId);
for (int j = 0; j < rules1.Count; j++)
{
var rule = rules1[j];
var courseIds = JsonHelper.JsonToObj<List<long>>(rule.CourseId1);
courseIds = courseIds.Distinct().ToList();
if (courseIds.Any())
if (record.CourseSceneId != null)
{
var courses = await Db.Queryable<Ghre_Course>()
.Where(x => x.CourseSceneIds != null && x.CourseSceneIds.Contains(record.CourseSceneId.ObjToString()))
.ToListAsync();
if (courses.Any())
for (int j = 0; j < courses.Count; j++)
{
if (courseIds.Count() ==
await Db.Queryable<Ghre_ExamRecord>()
.Where(x =>
x.ValidBeginTime != null &&
x.ValidEndTime != null &&
x.ValidBeginTime <= now &&
x.ValidEndTime >= now &&
x.StaffId == record.StaffId &&
x.CourseId != null &&
x.IsPass == true &&
courseIds.Contains(x.CourseId.Value)).CountAsync())
{
string ValidityPeriod = string.Empty;
DateTime? ValidityPeriodTime = null;
if (rule.ValidityType == "StaticDuration" && rule.StaticNum != null)
{
ValidityPeriodTime = now.AddDays(rule.StaticNum.Value);
ValidityPeriod = DateTimeHelper.ConvertToOnlySecondString(ValidityPeriodTime);
}
else if (rule.ValidityType == "Option" && rule.ValidityTime != null)
{
ValidityPeriodTime = rule.ValidityTime;
ValidityPeriod = DateTimeHelper.ConvertToSecondString(ValidityPeriodTime);
}
else if (rule.ValidityType == "Unlimited")
{
ValidityPeriodTime = DateTime.MaxValue;
ValidityPeriod = "长期";
}
//发放证书
certificates.Add(new Ghre_Certificate()
{
CertificateRuleId = rule.Id,
StaffId = record.StaffId,
CourseId = record.CourseId,
AwardDate = now,
ValidityPeriod = ValidityPeriod,
ValidityPeriodTime = ValidityPeriodTime,
Reverse1 = "考试通过发放"
});
}
await IssueCourseCertificate(record.StaffId, null, record.Id, courses[j].Id, null);
}
}
}
else if (record.CourseSceneId.IsNotEmptyOrNull())
{
}
record.IsIssueCertificate = true;
}
await Db.Insertable(certificates).ExecuteReturnSnowflakeIdListAsync();
await Db.Updateable(records)
.UpdateColumns(it => new { it.IsIssueCertificate }, true)
.ExecuteCommandAsync();
}
if (await Db.Queryable<Ghre_CertificateRule>().Where(x => x.SendRule == "CourseFinish").AnyAsync()
&& await Db.Queryable<Ghre_StudyRecord>()
if (await Db.Queryable<Ghre_StudyRecord>()
.Where(x =>
x.StudyStatus == "HasFinish" &&
(x.IsIssueCertificate == null || x.IsIssueCertificate == false))
@ -1704,87 +1645,127 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
(x.IsIssueCertificate == null || x.IsIssueCertificate == false))
.ToListAsync();
rules = await Db.Queryable<Ghre_CertificateRule>().Where(x => x.SendRule == "CourseFinish").ToListAsync();
var certificates = new List<Ghre_Certificate>();
_logger.LogInformation($"【发放证书】查询到{studyRecords.Count}条待发放学习数据!");
for (int i = 0; i < studyRecords.Count; i++)
{
var record = studyRecords[i];
if (record.CourseId.IsNotEmptyOrNull())
{
var rules1 = rules.Where(x => x.CourseId1 != null && x.CourseId1.Contains(record.CourseId.ObjToString())).ToList();
await IssueCourseCertificate(studyRecords[i].StaffId, studyRecords[i].Id, null, studyRecords[i].CourseId, studyRecords[i].CourseSceneId);
for (int j = 0; j < rules1.Count; j++)
{
var rule = rules1[j];
var courseIds = JsonHelper.JsonToObj<List<long>>(rule.CourseId1);
courseIds = courseIds.Distinct().ToList();
if (courseIds.Any())
if (studyRecords[i].CourseSceneId != null)
{
var courses = await Db.Queryable<Ghre_Course>()
.Where(x => x.CourseSceneIds != null && x.CourseSceneIds.Contains(studyRecords[i].CourseSceneId.ObjToString()))
.ToListAsync();
if (courses.Any())
for (int j = 0; j < courses.Count; j++)
{
if (courseIds.Count() ==
await Db.Queryable<Ghre_ExamRecord>()
.Where(x =>
x.ValidBeginTime != null &&
x.ValidEndTime != null &&
x.ValidBeginTime <= now &&
x.ValidEndTime >= now &&
x.StaffId == record.StaffId &&
x.CourseId != null &&
x.IsPass == true &&
courseIds.Contains(x.CourseId.Value)).CountAsync())
{
string ValidityPeriod = string.Empty;
DateTime? ValidityPeriodTime = null;
if (rule.ValidityType == "StaticDuration" && rule.StaticNum != null)
{
ValidityPeriodTime = now.AddDays(rule.StaticNum.Value);
ValidityPeriod = DateTimeHelper.ConvertToOnlySecondString(ValidityPeriodTime);
}
else if (rule.ValidityType == "Option" && rule.ValidityTime != null)
{
ValidityPeriodTime = rule.ValidityTime;
ValidityPeriod = DateTimeHelper.ConvertToSecondString(ValidityPeriodTime);
}
else if (rule.ValidityType == "Unlimited")
{
ValidityPeriodTime = DateTime.MaxValue;
ValidityPeriod = "长期";
}
//发放证书
certificates.Add(new Ghre_Certificate()
{
CertificateRuleId = rule.Id,
StaffId = record.StaffId,
CourseId = record.CourseId,
AwardDate = now,
ValidityPeriod = ValidityPeriod,
ValidityPeriodTime = ValidityPeriodTime,
Reverse1 = "考试通过发放"
});
}
await IssueCourseCertificate(studyRecords[i].StaffId, studyRecords[i].Id, null, courses[j].Id, null);
}
}
}
else if (record.CourseSceneId.IsNotEmptyOrNull())
{
}
_logger.LogInformation($"【发放证书】学习数据处理完成!");
}
record.IsIssueCertificate = true;
}
else
_logger.LogInformation($"【发放证书】未查询到待发放学习数据!");
return ServiceResult.OprateSuccess("发放成功!");
}
/// <summary>
/// 处理证书数据
/// </summary>
/// <param name="staffId">员工ID</param>
/// <param name="studyRecordId">学习记录ID</param>
/// <param name="examRecordId">考试记录ID</param>
/// <param name="courseId">课程ID</param>
/// <param name="courseSceneId">课程场景ID</param>
/// <returns></returns>
private async Task IssueCourseCertificate(int? staffId, long? studyRecordId = null, long? examRecordId = null, long? courseId = null, long? courseSceneId = null)
{
var now = DateTime.Now;
var rules = await Db.Queryable<Ghre_CertificateRule>()
.WhereIF(studyRecordId != null, x => x.SendRule == "CourseFinish")
.WhereIF(examRecordId != null, x => (x.SendRule == "ExamPass" || x.SendRule == "ExamScore"))
.WhereIF(courseId != null, x => x.CourseId1 != null && x.CourseId1.Contains(courseId.ObjToString()))
.WhereIF(courseSceneId != null, x => x.CourseSceneId1 != null && x.CourseSceneId1.Contains(courseSceneId.ObjToString()))
.WhereIF(courseId != null && courseSceneId != null, x => x.Id == 0)
.WhereIF(studyRecordId != null && examRecordId != null, x => x.Id == 0)
.ToListAsync();
for (int j = 0; j < rules.Count; j++)
{
var rule = rules[j];
if (examRecordId != null)
{
if (rule.SendRule == "ExamPass" && !await Db.Queryable<Ghre_ExamRecord>()
.Where(x => x.Id == examRecordId.Value && x.IsPass == true).AnyAsync())
continue;
if (rule.SendRule == "ExamScore" && !await Db.Queryable<Ghre_ExamRecord>()
.Where(x => x.Id == examRecordId.Value
&& x.Score >= rule.ScoreMin
&& x.Score <= rule.ScoreMax
).AnyAsync())
continue;
}
string ValidityPeriod = string.Empty;
DateTime? ValidityPeriodTime = null;
await Db.Insertable(certificates).ExecuteReturnSnowflakeIdListAsync();
await Db.Updateable(records)
.UpdateColumns(it => new { it.IsIssueCertificate }, true)
.ExecuteCommandAsync();
if (rule.ValidityType == "StaticDuration" && rule.StaticNum != null)
{
if (rule.StaticType == "year")
ValidityPeriodTime = now.AddYears(rule.StaticNum.Value);
else if (rule.StaticType == "day")
ValidityPeriodTime = now.AddDays(rule.StaticNum.Value);
else if (rule.StaticType == "month")
ValidityPeriodTime = now.AddMonths(rule.StaticNum.Value);
ValidityPeriod = DateTimeHelper.ConvertToSecondString(ValidityPeriodTime);
}
else if (rule.ValidityType == "Option" && rule.ValidityTime != null)
{
ValidityPeriodTime = rule.ValidityTime;
ValidityPeriod = DateTimeHelper.ConvertToSecondString(ValidityPeriodTime);
}
else if (rule.ValidityType == "Unlimited")
{
ValidityPeriodTime = DateTime.MaxValue;
ValidityPeriod = "长期";
}
var certificate = new Ghre_Certificate()
{
CertificateRuleId = rule.Id,
StaffId = staffId,
CourseId = courseId,
AwardDate = now,
ValidityPeriod = ValidityPeriod,
ValidityPeriodTime = ValidityPeriodTime,
Reverse1 = studyRecordId != null ? $"学习完成发放:{studyRecordId}" : $"考试完成发放:{studyRecordId}"
};
await Db.Insertable(certificate).ExecuteReturnSnowflakeIdAsync();
}
return ServiceResult.OprateSuccess("发放成功!");
if (studyRecordId != null)
await Db.Updateable<Ghre_StudyRecord>()
.SetColumns(it => new Ghre_StudyRecord() { IsIssueCertificate = true }, true)
.Where(x => x.Id == studyRecordId)
.ExecuteCommandAsync();
if (examRecordId != null)
await Db.Updateable<Ghre_ExamRecord>()
.SetColumns(it => new Ghre_ExamRecord() { IsIssueCertificate = true }, true)
.Where(x => x.Id == examRecordId)
.ExecuteCommandAsync();
}
#endregion

@ -1824,6 +1824,7 @@ WHERE A.Id = '{id}'";
#endregion
#region 记录学习时长
[UseTran]
public async Task<ServiceResult> RecordDuration(long studyRecordId, decimal? duration, long attachmentId)
{
//var sql = $"UPDATE Ghre_StudyRecord SET StudyDuration = ISNULL(StudyDuration, 0)+{duration} WHERE Id='{studyRecordId}' AND StaffId='{staffId}'";

Loading…
Cancel
Save