|
|
|
@ -1,4 +1,7 @@ |
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
using MathNet.Numerics.Distributions; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 问卷调查 (服务) |
|
|
|
@ -220,23 +223,97 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins |
|
|
|
|
public async Task<ServiceResult> SubmitESSData(long id, Ghre_SurveyExtend input) |
|
|
|
|
{ |
|
|
|
|
var entity = await base.QueryById(id); |
|
|
|
|
var data = Mapper.Map(entity).ToANew<Ghre_SurveyExtend>(); |
|
|
|
|
|
|
|
|
|
data.BeginEndTime.Add(data.BeginTime); |
|
|
|
|
data.BeginEndTime.Add(data.EndTime); |
|
|
|
|
if (entity.StaffId.IsNotEmptyOrNull()) |
|
|
|
|
data.StaffIds = JsonHelper.JsonToObj<List<int>>(entity.StaffId); |
|
|
|
|
if (entity.DeptId.IsNotEmptyOrNull()) |
|
|
|
|
data.DeptIds = JsonHelper.JsonToObj<List<int>>(entity.DeptId); |
|
|
|
|
await Db.Updateable<Ghre_SurveyRecord>() |
|
|
|
|
.SetColumns(it => new Ghre_SurveyRecord() { IsEnable = 0 }) |
|
|
|
|
.Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id && x.IsEnable == 1) |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
var questions = await Db.Queryable<Ghre_SurveyQuestion>().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(); |
|
|
|
|
|
|
|
|
|
data.Questions = Mapper.Map(questions).ToANew<List<Ghre_SurveyQuestionExtend>>(); |
|
|
|
|
data.Questions.ForEach(x => |
|
|
|
|
//var recordId = SnowFlakeSingle.Instance.NextId(); |
|
|
|
|
var record = new Ghre_SurveyRecord() |
|
|
|
|
{ |
|
|
|
|
x.Options = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew<List<Ghre_SurveyOptionExtend>>(); |
|
|
|
|
}); |
|
|
|
|
//Id = recordId, |
|
|
|
|
SurveyId = id, |
|
|
|
|
StaffId = App.User.StaffId, |
|
|
|
|
Score = 0, |
|
|
|
|
AdjustScore = 0, |
|
|
|
|
SubmitDate = DateTime.Now, |
|
|
|
|
IsView = false |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var recordDetails = new List<Ghre_SurveyRecordDetail>(); |
|
|
|
|
|
|
|
|
|
var recordId = await Db.Insertable(record).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < input.Questions.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var question = input.Questions[i]; |
|
|
|
|
|
|
|
|
|
var recordDetailId = await Db.Insertable(new Ghre_SurveyRecordDetail() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
SurveyId = id, |
|
|
|
|
SurveyRecordId = recordId, |
|
|
|
|
SurveyQuestionId = question.Id, |
|
|
|
|
StaffId = App.User.StaffId, |
|
|
|
|
Score = 0 |
|
|
|
|
|
|
|
|
|
}).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
var recordOptions = new List<Ghre_SurveyRecordOption>(); |
|
|
|
|
|
|
|
|
|
switch (question.QuestionType) |
|
|
|
|
{ |
|
|
|
|
case "Multiple": |
|
|
|
|
case "MultipleScore": |
|
|
|
|
for (int j = 0; j < question.Value1.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var option1 = new Ghre_SurveyRecordOption() |
|
|
|
|
{ |
|
|
|
|
SurveyId = id, |
|
|
|
|
SurveyRecordId = recordId, |
|
|
|
|
SurveyRecordDetailId = recordDetailId, |
|
|
|
|
SurveyQuestionId = question.Id, |
|
|
|
|
//SurveyQuestionOptionId = x.Id, |
|
|
|
|
StaffId = App.User.StaffId, |
|
|
|
|
Score = 0 |
|
|
|
|
}; |
|
|
|
|
option1.SurveyQuestionOptionId = question.Options.Where(x => x.OptionNo == question.Value1[j]).FirstOrDefault()?.Id; |
|
|
|
|
option1.OptionContent = question.Value1[j]; |
|
|
|
|
await Db.Insertable(option1).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "Single": |
|
|
|
|
case "ShortAnswer": |
|
|
|
|
case "SingleScore": |
|
|
|
|
case "Rate": |
|
|
|
|
case "Scale": |
|
|
|
|
var option = new Ghre_SurveyRecordOption() |
|
|
|
|
{ |
|
|
|
|
SurveyId = id, |
|
|
|
|
SurveyRecordId = recordId, |
|
|
|
|
SurveyRecordDetailId = recordDetailId, |
|
|
|
|
SurveyQuestionId = question.Id, |
|
|
|
|
//SurveyQuestionOptionId = x.Id, |
|
|
|
|
StaffId = App.User.StaffId, |
|
|
|
|
Score = 0 |
|
|
|
|
}; |
|
|
|
|
option.SurveyQuestionOptionId = question.Options.Where(x => x.OptionNo == question.Value).FirstOrDefault()?.Id; |
|
|
|
|
option.OptionContent = question.Value; |
|
|
|
|
await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("提交成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|