|
|
|
@ -1,16 +1,16 @@ |
|
|
|
|
|
|
|
|
|
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 System.Data; |
|
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
|
using System.Data; |
|
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
|
using Tiobon.Core.IServices; |
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
|
using Tiobon.Core.Services.BASE; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
@ -469,14 +469,133 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul |
|
|
|
|
public async Task StaffIn() |
|
|
|
|
{ |
|
|
|
|
var dt = Db.GetDate(); |
|
|
|
|
var staffs = await Db.Queryable<Ghra_Staff>() |
|
|
|
|
.Where(x => x.Indate != null && x.Indate.Value.Date == dt.Date) |
|
|
|
|
.Select(x => new |
|
|
|
|
var rules = await Db.Queryable<Ghre_StudyRule>().Where(x => x.TrainType != "PreWork" && x.TrainType != "Orientation").ToListAsync(); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < rules.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var rule = rules[j]; |
|
|
|
|
var ruleId = rule.Id; |
|
|
|
|
var ZoneIds = new List<int?>(); |
|
|
|
|
var DeptIds = new List<int?>(); |
|
|
|
|
var TitleIds = new List<int?>(); |
|
|
|
|
var GradeIds = new List<int?>(); |
|
|
|
|
var JobIds = new List<int?>(); |
|
|
|
|
if (!rule.ZoneId.IsNull()) |
|
|
|
|
ZoneIds = JsonHelper.JsonToObj<List<int?>>(rule.ZoneId); |
|
|
|
|
if (!rule.DeptId.IsNull()) |
|
|
|
|
DeptIds = JsonHelper.JsonToObj<List<int?>>(rule.DeptId); |
|
|
|
|
if (!rule.TitleId.IsNull()) |
|
|
|
|
TitleIds = JsonHelper.JsonToObj<List<int?>>(rule.TitleId); |
|
|
|
|
if (!rule.GradeId.IsNull()) |
|
|
|
|
GradeIds = JsonHelper.JsonToObj<List<int?>>(rule.GradeId); |
|
|
|
|
if (!rule.JobId.IsNull()) |
|
|
|
|
JobIds = JsonHelper.JsonToObj<List<int?>>(rule.JobId); |
|
|
|
|
|
|
|
|
|
var staffs = await Db.Queryable<Ghra_Staff>() |
|
|
|
|
.Where(x => x.Indate != null && x.Indate.Value.Date == dt.Date) |
|
|
|
|
.WhereIF(ZoneIds.Any(), x => ZoneIds.Contains(x.ZoneID)) |
|
|
|
|
.WhereIF(DeptIds.Any(), x => DeptIds.Contains(x.DeptID)) |
|
|
|
|
.WhereIF(TitleIds.Any(), x => TitleIds.Contains(x.TitleID)) |
|
|
|
|
.WhereIF(GradeIds.Any(), x => GradeIds.Contains(x.GradeID)) |
|
|
|
|
.WhereIF(JobIds.Any(), x => JobIds.Contains(x.JobID)) |
|
|
|
|
.Select(x => new |
|
|
|
|
{ |
|
|
|
|
x.StaffID, |
|
|
|
|
x.StaffEname, |
|
|
|
|
x.Indate, |
|
|
|
|
x.OutDate |
|
|
|
|
}) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!staffs.IsNull()) |
|
|
|
|
{ |
|
|
|
|
x.StaffID, |
|
|
|
|
x.StaffEname, |
|
|
|
|
x.Indate, |
|
|
|
|
x.OutDate |
|
|
|
|
}).ToListAsync(); |
|
|
|
|
if (staffs.Any()) |
|
|
|
|
{ |
|
|
|
|
var snap = await Db.Queryable<Ghre_CourseSnap>().FirstAsync(x => x.CourseId == rule.CourseId); |
|
|
|
|
|
|
|
|
|
var inserts = new List<Ghre_StudyRecord>(); |
|
|
|
|
var insertExamStaffs = new List<Ghre_ExamStaff>(); |
|
|
|
|
var insertResults = new List<Ghre_StudyRuleResult>(); |
|
|
|
|
|
|
|
|
|
//var exam = await Db.Queryable<Ghre_Exam>() |
|
|
|
|
// .WhereIF(rule.CourseId != null, x => x.CourseId == rule.CourseId) |
|
|
|
|
// .WhereIF(rule.CourseSceneId != null, x => x.CourseSceneId == rule.CourseSceneId) |
|
|
|
|
// .FirstAsync(x => x.Status == Consts.DicExamStatus.RELEASED); |
|
|
|
|
|
|
|
|
|
var exam = await Db.Queryable<Ghre_Exam>() |
|
|
|
|
.Where(x => x.Status == Consts.DIC_EXAM_STATUS.RELEASED |
|
|
|
|
&& ((x.DateType == Consts.DicExamDateType.EXAM_DATE |
|
|
|
|
&& x.BeginTime.Value.Date <= DateTime.Now.Date && x.EndTime.Value.Date >= DateTime.Now.Date) || x.DateType == Consts.DicExamDateType.AFTER_HOW_LONG)) |
|
|
|
|
.WhereIF(!rule.CourseId.IsNull(), x => x.CourseId == rule.CourseId) |
|
|
|
|
.WhereIF(!rule.CourseSceneId.IsNull(), x => x.CourseSceneId == rule.CourseSceneId) |
|
|
|
|
.FirstAsync(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < staffs.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var staff = staffs[i]; |
|
|
|
|
|
|
|
|
|
var record = await Db.Queryable<Ghre_StudyRecord>() |
|
|
|
|
.Where(x => x.StudyRuleId != ruleId && x.StaffId == staff.StaffID) |
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(rule.Year), x => x.Year == rule.Year) |
|
|
|
|
.WhereIF(rule.CourseId != null, x => x.CourseId == rule.CourseId) |
|
|
|
|
.WhereIF(rule.CourseSceneId != null, x => x.CourseSceneId == rule.CourseSceneId) |
|
|
|
|
//.AS("Ghre_StudyRecord_V") |
|
|
|
|
.FirstAsync(); |
|
|
|
|
if (record is null) |
|
|
|
|
{ |
|
|
|
|
inserts.Add(new Ghre_StudyRecord() |
|
|
|
|
{ |
|
|
|
|
StaffId = staff.StaffID, |
|
|
|
|
ExamId = exam?.Id, |
|
|
|
|
CourseSnapId = snap?.Id, |
|
|
|
|
CourseId = rule.CourseId, |
|
|
|
|
CourseSceneId = rule.CourseSceneId, |
|
|
|
|
StudyRuleId = ruleId, |
|
|
|
|
JoinTime = dt, |
|
|
|
|
CourseBeginTime = dt.Date, |
|
|
|
|
CourseEndTime = dt.Date.AddMonths((rule.DeadlineMonth ?? snap?.ValidityPeriod) ?? 1), |
|
|
|
|
CourseType = rule.RuleType, |
|
|
|
|
CourseStatus = Consts.DIC_STUDY_RECORD_COURSE_STATUS_IN, |
|
|
|
|
StudyStatus = Consts.DIC_STUDY_RECORD_STUDY_STATUS.NO_JOIN, |
|
|
|
|
Year = rule.Year |
|
|
|
|
}); |
|
|
|
|
insertResults.Add(new Ghre_StudyRuleResult() |
|
|
|
|
{ |
|
|
|
|
StaffId = staff.StaffID, |
|
|
|
|
StudyRuleId = ruleId, |
|
|
|
|
Status = "SUCCESS", |
|
|
|
|
RemarkSz = "生成成功" |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (exam != null) |
|
|
|
|
if (!await Db.Queryable<Ghre_ExamStaff>().AnyAsync(x => x.ExamId == exam.Id && x.StaffId == staff.StaffID)) |
|
|
|
|
insertExamStaffs.Add(new Ghre_ExamStaff() |
|
|
|
|
{ |
|
|
|
|
ExamId = exam.Id, |
|
|
|
|
StudyRuleId = ruleId, |
|
|
|
|
StaffId = staff.StaffID, |
|
|
|
|
Source = "StudyRule" + rule.RuleType |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else insertResults.Add(new Ghre_StudyRuleResult() |
|
|
|
|
{ |
|
|
|
|
StaffId = staff.StaffID, |
|
|
|
|
StudyRuleId = ruleId, |
|
|
|
|
Status = "FAIL", |
|
|
|
|
RemarkSz = "生成失败,该课程学习记录已被其他规则生成!" |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (inserts.Any()) |
|
|
|
|
await Db.Insertable(inserts).ExecuteReturnSnowflakeIdListAsync(); |
|
|
|
|
if (insertResults.Any()) |
|
|
|
|
await Db.Insertable(insertResults).ExecuteReturnSnowflakeIdListAsync(); |
|
|
|
|
|
|
|
|
|
if (insertExamStaffs.Any()) |
|
|
|
|
await Db.Insertable(insertExamStaffs).ExecuteReturnSnowflakeIdListAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |