优化必选修规则因员工异动导致数据不准确

master
xiaochanghai 4 weeks ago
parent fa42a08df7
commit ba5a64d9a8
  1. 16
      Tiobon.Core.Services/Ghre/Ghre_StudyRuleServices.cs

@ -1,4 +1,5 @@
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Tiobon.Core.Model.Models.RootTkey.Interface;
using static Tiobon.Core.Model.Consts; using static Tiobon.Core.Model.Consts;
namespace Tiobon.Core.Services; namespace Tiobon.Core.Services;
@ -322,7 +323,7 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul
{ {
try try
{ {
await Db.Ado.BeginTranAsync(); //await Db.Ado.BeginTranAsync();
var rule = await Db.Queryable<Ghre_StudyRule>().FirstAsync(x => x.Id == ruleId); var rule = await Db.Queryable<Ghre_StudyRule>().FirstAsync(x => x.Id == ruleId);
@ -437,12 +438,12 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul
var staff = staffs[i]; var staff = staffs[i];
var record = await Db.Queryable<Ghre_StudyRecord>() var record = await Db.Queryable<Ghre_StudyRecord>()
.Where(x => x.StudyRuleId != ruleId && x.StaffId == staff.StaffID) .Where(x => x.StudyRuleId != null && x.StaffId == staff.StaffID)
.WhereIF(!string.IsNullOrWhiteSpace(rule.Year), x => x.Year == rule.Year) .WhereIF(!string.IsNullOrWhiteSpace(rule.Year), x => x.Year == rule.Year)
.WhereIF(rule.CourseId != null, x => x.CourseId == rule.CourseId) .WhereIF(rule.CourseId != null, x => x.CourseId == rule.CourseId)
.WhereIF(rule.CourseSceneId != null, x => x.CourseSceneId == rule.CourseSceneId) .WhereIF(rule.CourseSceneId != null, x => x.CourseSceneId == rule.CourseSceneId)
//.AS("Ghre_StudyRecord_V") //.AS("Ghre_StudyRecord_V")
.FirstAsync(); .ClearFilter<IBaseDeleteFilter>().FirstAsync();
if (record is null) if (record is null)
{ {
inserts.Add(new Ghre_StudyRecord() inserts.Add(new Ghre_StudyRecord()
@ -460,7 +461,8 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul
CourseStatus = Consts.DIC_STUDY_RECORD_COURSE_STATUS_IN, CourseStatus = Consts.DIC_STUDY_RECORD_COURSE_STATUS_IN,
StudyStatus = Consts.DIC_STUDY_RECORD_STUDY_STATUS.NO_JOIN, StudyStatus = Consts.DIC_STUDY_RECORD_STUDY_STATUS.NO_JOIN,
Year = rule.Year, Year = rule.Year,
PlanId = rule.PlanId PlanId = rule.PlanId,
StudyProgress = 0
}); });
insertResults.Add(new Ghre_StudyRuleResult() insertResults.Add(new Ghre_StudyRuleResult()
{ {
@ -538,7 +540,7 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul
.ExecuteCommandAsync(); .ExecuteCommandAsync();
#endregion #endregion
await Db.Ado.CommitTranAsync(); //await Db.Ado.CommitTranAsync();
string sql = @"UPDATE A string sql = @"UPDATE A
SET A.StaffName = B.StaffName, a.StaffNo = B.StaffNo SET A.StaffName = B.StaffName, a.StaffNo = B.StaffNo
@ -548,7 +550,7 @@ public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRul
} }
catch (Exception E) catch (Exception E)
{ {
await Db.Ado.RollbackTranAsync(); //await Db.Ado.RollbackTranAsync();
await Db.Updateable<Ghre_StudyRule>().Where(x => x.Id == ruleId) await Db.Updateable<Ghre_StudyRule>().Where(x => x.Id == ruleId)
.SetColumns(it => new Ghre_StudyRule() { Result = E.Message }) .SetColumns(it => new Ghre_StudyRule() { Result = E.Message })

Loading…
Cancel
Save