diff --git a/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs b/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs index 46c77e2f..181bb3bc 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs @@ -227,7 +227,7 @@ public class Ghre_SurveyServices : BaseServices().Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id).Select(x => x.Id).FirstAsync(); var recordDetails = await Db.Queryable().Where(x => x.SurveyRecordId == recordId).ToListAsync(); - var recordOptions = await Db.Queryable().Where(x => x.SurveyRecordId == recordId).OrderBy(x=>x.OptionContent).ToListAsync(); + var recordOptions = await Db.Queryable().Where(x => x.SurveyRecordId == recordId).OrderBy(x => x.OptionContent).ToListAsync(); data.Questions.ForEach(question => { @@ -277,12 +277,13 @@ public class Ghre_SurveyServices : BaseServices() + var lastRecord = await Db.Queryable() .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) - .Select(x => x.Id).FirstAsync(); + .FirstAsync(); + var surveyRecordId = lastRecord?.Id; await Db.Updateable() .SetColumns(it => new Ghre_SurveyRecord() { IsEnable = 0 }, true) - .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id && x.IsEnable == 1) + .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id && x.IsEnable == 1 && x.SubmitDate != null) .ExecuteCommandAsync(); await Db.Updateable() .SetColumns(it => new Ghre_SurveyRecordDetail() { IsEnable = 0 }, true) @@ -297,20 +298,32 @@ public class Ghre_SurveyServices : BaseServices().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync(); //var recordId = SnowFlakeSingle.Instance.NextId(); - var record = new Ghre_SurveyRecord() + + if (lastRecord.IsNullOrEmpty() || (lastRecord != null && lastRecord.SubmitDate != null) || surveyRecordId == 0) { - //Id = recordId, - SurveyId = id, - StaffId = App.User.StaffId, - Score = 0, - AdjustScore = 0, - SubmitDate = DateTime.Now, - IsView = false - }; + + var record = new Ghre_SurveyRecord() + { + //Id = recordId, + SurveyId = id, + StaffId = App.User.StaffId, + Score = 0, + AdjustScore = 0, + SubmitDate = DateTime.Now, + IsView = false + }; + surveyRecordId = await Db.Insertable(record).ExecuteReturnSnowflakeIdAsync(); + } + else + { + await Db.Updateable() + .SetColumns(it => new Ghre_SurveyRecord() { SubmitDate = DateTime.Now }, true) + .Where(x => x.Id == surveyRecordId) + .ExecuteCommandAsync(); + } var recordDetails = new List(); - var recordId = await Db.Insertable(record).ExecuteReturnSnowflakeIdAsync(); for (int i = 0; i < input.Questions.Count; i++) { @@ -320,7 +333,7 @@ public class Ghre_SurveyServices : BaseServices Start(long id) { - await Db.Updateable() - .SetColumns(it => new Ghre_SurveyRecord() { BeginTime = DateTime.Now }) - .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) - .ExecuteCommandAsync(); + //await Db.Updateable() + // .SetColumns(it => new Ghre_SurveyRecord() { BeginTime = DateTime.Now }) + // .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) + // .ExecuteCommandAsync(); + + var record = new Ghre_SurveyRecord() + { + SurveyId = id, + StaffId = App.User.StaffId, + Score = 0, + AdjustScore = 0, + IsView = false + }; + await Db.Insertable(record).ExecuteReturnSnowflakeIdAsync(); return ServiceResult.OprateSuccess("记录成功!"); } + + }