优化问卷提交接口

master
Tiobon 2 months ago
parent 1919c3926e
commit 26fe977cfe
  1. 51
      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 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 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 => 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 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) .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>() await Db.Updateable<Ghre_SurveyRecord>()
.SetColumns(it => new Ghre_SurveyRecord() { IsEnable = 0 }, true) .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(); .ExecuteCommandAsync();
await Db.Updateable<Ghre_SurveyRecordDetail>() await Db.Updateable<Ghre_SurveyRecordDetail>()
.SetColumns(it => new Ghre_SurveyRecordDetail() { IsEnable = 0 }, true) .SetColumns(it => new Ghre_SurveyRecordDetail() { IsEnable = 0 }, true)
@ -297,6 +298,10 @@ 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 options = await Db.Queryable<Ghre_SurveyOption>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
//var recordId = SnowFlakeSingle.Instance.NextId(); //var recordId = SnowFlakeSingle.Instance.NextId();
if (lastRecord.IsNullOrEmpty() || (lastRecord != null && lastRecord.SubmitDate != null) || surveyRecordId == 0)
{
var record = new Ghre_SurveyRecord() var record = new Ghre_SurveyRecord()
{ {
//Id = recordId, //Id = recordId,
@ -307,10 +312,18 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
SubmitDate = DateTime.Now, SubmitDate = DateTime.Now,
IsView = false 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 recordDetails = new List<Ghre_SurveyRecordDetail>();
var recordId = await Db.Insertable(record).ExecuteReturnSnowflakeIdAsync();
for (int i = 0; i < input.Questions.Count; i++) 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, SurveyId = id,
SurveyRecordId = recordId, SurveyRecordId = surveyRecordId,
SurveyQuestionId = question.Id, SurveyQuestionId = question.Id,
StaffId = App.User.StaffId, StaffId = App.User.StaffId,
Score = 0 Score = 0
@ -337,7 +350,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var option1 = new Ghre_SurveyRecordOption() var option1 = new Ghre_SurveyRecordOption()
{ {
SurveyId = id, SurveyId = id,
SurveyRecordId = recordId, SurveyRecordId = surveyRecordId,
SurveyRecordDetailId = recordDetailId, SurveyRecordDetailId = recordDetailId,
SurveyQuestionId = question.Id, SurveyQuestionId = question.Id,
//SurveyQuestionOptionId = x.Id, //SurveyQuestionOptionId = x.Id,
@ -364,7 +377,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
var option = new Ghre_SurveyRecordOption() var option = new Ghre_SurveyRecordOption()
{ {
SurveyId = id, SurveyId = id,
SurveyRecordId = recordId, SurveyRecordId = surveyRecordId,
SurveyRecordDetailId = recordDetailId, SurveyRecordDetailId = recordDetailId,
SurveyQuestionId = question.Id, SurveyQuestionId = question.Id,
//SurveyQuestionOptionId = x.Id, //SurveyQuestionOptionId = x.Id,
@ -390,7 +403,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins
option = new Ghre_SurveyRecordOption() option = new Ghre_SurveyRecordOption()
{ {
SurveyId = id, SurveyId = id,
SurveyRecordId = recordId, SurveyRecordId = surveyRecordId,
SurveyRecordDetailId = recordDetailId, SurveyRecordDetailId = recordDetailId,
SurveyQuestionId = question.Id, SurveyQuestionId = question.Id,
//SurveyQuestionOptionId = x.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) public async Task<ServiceResult> Start(long id)
{ {
await Db.Updateable<Ghre_SurveyRecord>() //await Db.Updateable<Ghre_SurveyRecord>()
.SetColumns(it => new Ghre_SurveyRecord() { BeginTime = DateTime.Now }) // .SetColumns(it => new Ghre_SurveyRecord() { BeginTime = DateTime.Now })
.Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) // .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id)
.ExecuteCommandAsync(); // .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("记录成功!"); return ServiceResult.OprateSuccess("记录成功!");
} }
} }

Loading…
Cancel
Save