优化问卷提交接口

master
Tiobon 2 months ago
parent 1919c3926e
commit 26fe977cfe
  1. 69
      Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs

@ -227,7 +227,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var recordId = await Db.Queryable<Ghre_SurveyRecord>().Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id).Select(x => x.Id).FirstAsync();
var recordDetails = await Db.Queryable<Ghre_SurveyRecordDetail>().Where(x => x.SurveyRecordId == recordId).ToListAsync();
var recordOptions = await Db.Queryable<Ghre_SurveyRecordOption>().Where(x => x.SurveyRecordId == recordId).OrderBy(x=>x.OptionContent).ToListAsync();
var recordOptions = await Db.Queryable<Ghre_SurveyRecordOption>().Where(x => x.SurveyRecordId == recordId).OrderBy(x => x.OptionContent).ToListAsync();
data.Questions.ForEach(question =>
{
@ -277,12 +277,13 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var entity = await base.QueryById(id);
var surveyRecordId = await Db.Queryable<Ghre_SurveyRecord>()
var lastRecord = await Db.Queryable<Ghre_SurveyRecord>()
.Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id)
.Select(x => x.Id).FirstAsync();
.FirstAsync();
var surveyRecordId = lastRecord?.Id;
await Db.Updateable<Ghre_SurveyRecord>()
.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<Ghre_SurveyRecordDetail>()
.SetColumns(it => new Ghre_SurveyRecordDetail() { IsEnable = 0 }, true)
@ -297,20 +298,32 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var options = await Db.Queryable<Ghre_SurveyOption>().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<Ghre_SurveyRecord>()
.SetColumns(it => new Ghre_SurveyRecord() { SubmitDate = DateTime.Now }, true)
.Where(x => x.Id == surveyRecordId)
.ExecuteCommandAsync();
}
var recordDetails = new List<Ghre_SurveyRecordDetail>();
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<Ghre_Survey, Ghre_SurveyDto, Ins
{
SurveyId = id,
SurveyRecordId = recordId,
SurveyRecordId = surveyRecordId,
SurveyQuestionId = question.Id,
StaffId = App.User.StaffId,
Score = 0
@ -337,7 +350,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var option1 = new Ghre_SurveyRecordOption()
{
SurveyId = id,
SurveyRecordId = recordId,
SurveyRecordId = surveyRecordId,
SurveyRecordDetailId = recordDetailId,
SurveyQuestionId = question.Id,
//SurveyQuestionOptionId = x.Id,
@ -364,7 +377,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var option = new Ghre_SurveyRecordOption()
{
SurveyId = id,
SurveyRecordId = recordId,
SurveyRecordId = surveyRecordId,
SurveyRecordDetailId = recordDetailId,
SurveyQuestionId = question.Id,
//SurveyQuestionOptionId = x.Id,
@ -390,7 +403,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
option = new Ghre_SurveyRecordOption()
{
SurveyId = id,
SurveyRecordId = recordId,
SurveyRecordId = surveyRecordId,
SurveyRecordDetailId = recordDetailId,
SurveyQuestionId = question.Id,
//SurveyQuestionOptionId = x.Id,
@ -582,13 +595,25 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
public async Task<ServiceResult> Start(long id)
{
await Db.Updateable<Ghre_SurveyRecord>()
.SetColumns(it => new Ghre_SurveyRecord() { BeginTime = DateTime.Now })
.Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id)
.ExecuteCommandAsync();
//await Db.Updateable<Ghre_SurveyRecord>()
// .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("记录成功!");
}
}

Loading…
Cancel
Save