From 26fe977cfe1e7118571ef3941f658dfe445c4e60 Mon Sep 17 00:00:00 2001 From: Tiobon Date: Mon, 14 Apr 2025 11:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=97=AE=E5=8D=B7=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ghre/Ghre_SurveyServices.cs | 69 +++++++++++++------ 1 file changed, 47 insertions(+), 22 deletions(-) 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("记录成功!"); } + + }