|
|
@ -11,6 +11,9 @@ using Newtonsoft.Json; |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
using Org.BouncyCastle.Crypto; |
|
|
|
using Org.BouncyCastle.Crypto; |
|
|
|
using SqlSugar; |
|
|
|
using SqlSugar; |
|
|
|
|
|
|
|
using MathNet.Numerics.Distributions; |
|
|
|
|
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
|
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
|
|
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
|
@ -166,6 +169,7 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul |
|
|
|
WHERE A.StaffName IS NULL";
|
|
|
|
WHERE A.StaffName IS NULL";
|
|
|
|
await Db.Ado.ExecuteCommandAsync(sql); |
|
|
|
await Db.Ado.ExecuteCommandAsync(sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Task.Factory.StartNew(async () => await GenerateStaffStudyRecord(Db, Id)); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -191,21 +195,112 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul |
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> GenerateStaffStudyRecord(ISqlSugarClient Db, long ruleId) |
|
|
|
public async Task<bool> GenerateStaffStudyRecord(ISqlSugarClient Db, long ruleId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var rule = await Db.Queryable<Ghre_StudyRule>().FirstAsync(x => x.Id == ruleId); |
|
|
|
try |
|
|
|
var ruleStaffs = await Db.Queryable<Ghre_StudyRuleStaff>().Where(x => x.StudyRuleId == ruleId).ToListAsync(); |
|
|
|
{ |
|
|
|
|
|
|
|
await Db.Ado.BeginTranAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rule = await Db.Queryable<Ghre_StudyRule>().FirstAsync(x => x.Id == ruleId); |
|
|
|
|
|
|
|
var ruleStaffs = await Db.Queryable<Ghre_StudyRuleStaff>().Where(x => x.StudyRuleId == ruleId).ToListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Db.Updateable<Ghre_StudyRuleResult>().Where(x => x.StudyRuleId == ruleId && x.IsEnable == 1) |
|
|
|
|
|
|
|
.SetColumns(it => new Ghre_StudyRuleResult() { IsEnable = 0 })//类只能在表达示里面不能提取 |
|
|
|
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ruleStaffIds = ruleStaffs.Select(x => x.StaffId).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var staffs = await Db.Queryable<Ghra_Staff>() |
|
|
|
|
|
|
|
.WhereIF(rule.ZoneId != null, x => x.ZoneID == rule.ZoneId) |
|
|
|
|
|
|
|
.WhereIF(rule.DeptId != null, x => x.DeptID == rule.DeptId) |
|
|
|
|
|
|
|
.WhereIF(rule.TitleId != null, x => x.TitleID == rule.TitleId) |
|
|
|
|
|
|
|
.WhereIF(rule.GradeId != null, x => x.GradeID == rule.GradeId) |
|
|
|
|
|
|
|
.WhereIF(rule.JobId != null, x => x.JobID == rule.JobId) |
|
|
|
|
|
|
|
.WhereIF(ruleStaffIds != null && ruleStaffIds.Any(), x => ruleStaffIds.Contains(x.StaffID)) |
|
|
|
|
|
|
|
.WhereIF(rule.GradeId != null, x => x.GradeID == rule.GradeId) |
|
|
|
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (staffs != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DateTime courseTime = Db.GetDate(); |
|
|
|
|
|
|
|
var snap = await Db.Queryable<Ghre_CourseSnap>().FirstAsync(x => x.CourseId == rule.CourseId); |
|
|
|
|
|
|
|
if (staffs.Any()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var inserts = new List<Ghre_StudyRecord>(); |
|
|
|
|
|
|
|
var insertResults = new List<Ghre_StudyRuleResult>(); |
|
|
|
|
|
|
|
await Db.Deleteable<Ghre_StudyRecord>().Where(x => x.StudyRuleId == ruleId && x.BeginTime == null).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
.FirstAsync(); |
|
|
|
|
|
|
|
if (record is null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
inserts.Add(new Ghre_StudyRecord() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StaffId = staff.StaffID, |
|
|
|
|
|
|
|
CourseSnapId = snap.Id, |
|
|
|
|
|
|
|
CourseId = rule.CourseId, |
|
|
|
|
|
|
|
StudyRuleId = ruleId, |
|
|
|
|
|
|
|
JoinTime = courseTime, |
|
|
|
|
|
|
|
CourseBeginTime = courseTime, |
|
|
|
|
|
|
|
CourseEndTime = courseTime.AddMonths(rule.DeadlineMonth ?? 3), |
|
|
|
|
|
|
|
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 = "生成成功" |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else insertResults.Add(new Ghre_StudyRuleResult() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StaffId = staff.StaffID, |
|
|
|
|
|
|
|
StudyRuleId = ruleId, |
|
|
|
|
|
|
|
Status = "FAIL", |
|
|
|
|
|
|
|
RemarkSz = "生成失败,该课程学习记录已被其他规则生成!" |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ruleStaffIds = ruleStaffs.Select(x => x.StaffId).ToList(); |
|
|
|
if (inserts.Any()) |
|
|
|
|
|
|
|
await Db.Insertable(inserts).ExecuteReturnSnowflakeIdListAsync(); |
|
|
|
|
|
|
|
if (insertResults.Any()) |
|
|
|
|
|
|
|
await Db.Insertable(insertResults).ExecuteReturnSnowflakeIdListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
var staffs = await Db.Queryable<Ghra_Staff>() |
|
|
|
rule.RemarkSz = "数据生成成功"; |
|
|
|
.WhereIF(rule.ZoneId != null, x => x.ZoneID == rule.ZoneId) |
|
|
|
|
|
|
|
.WhereIF(rule.DeptId != null, x => x.DeptID == rule.DeptId) |
|
|
|
|
|
|
|
.WhereIF(rule.TitleId != null, x => x.TitleID == rule.TitleId) |
|
|
|
|
|
|
|
.WhereIF(rule.GradeId != null, x => x.GradeID == rule.GradeId) |
|
|
|
|
|
|
|
.WhereIF(rule.JobId != null, x => x.JobID == rule.JobId) |
|
|
|
|
|
|
|
.WhereIF(ruleStaffIds != null && ruleStaffIds.Any(), x => ruleStaffIds.Contains(x.StaffID)) |
|
|
|
|
|
|
|
.WhereIF(rule.GradeId != null, x => x.GradeID == rule.GradeId) |
|
|
|
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
rule.RemarkSz = "未匹配到相关关人员数据!"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await Db.Updateable<Ghre_StudyRule>().Where(x => x.Id == ruleId) |
|
|
|
|
|
|
|
.SetColumns(it => new Ghre_StudyRule() { RemarkSz = rule.RemarkSz })//类只能在表达示里面不能提取 |
|
|
|
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Db.Ado.CommitTranAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string sql = @"UPDATE A
|
|
|
|
|
|
|
|
SET A.StaffName = B.StaffName, a.StaffNo = B.StaffNo |
|
|
|
|
|
|
|
FROM Ghre_StudyRuleResult A LEFT JOIN Ghra_Staff B ON A.StaffId = B.StaffID |
|
|
|
|
|
|
|
WHERE A.StaffName IS NULL";
|
|
|
|
|
|
|
|
await Db.Ado.ExecuteCommandAsync(sql); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
await Db.Ado.RollbackTranAsync(); |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |