|
|
|
@ -1,5 +1,4 @@ |
|
|
|
|
using AgileObjects.AgileMapper.Extensions; |
|
|
|
|
using Microsoft.IdentityModel.Tokens; |
|
|
|
|
using SqlSugar.Extensions; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
@ -228,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).ToListAsync(); |
|
|
|
|
var recordOptions = await Db.Queryable<Ghre_SurveyRecordOption>().Where(x => x.SurveyRecordId == recordId).OrderBy(x=>x.OptionContent).ToListAsync(); |
|
|
|
|
|
|
|
|
|
data.Questions.ForEach(question => |
|
|
|
|
{ |
|
|
|
@ -277,10 +276,22 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins |
|
|
|
|
{ |
|
|
|
|
var entity = await base.QueryById(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var surveyRecordId = await Db.Queryable<Ghre_SurveyRecord>() |
|
|
|
|
.Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) |
|
|
|
|
.Select(x => x.Id).FirstAsync(); |
|
|
|
|
await Db.Updateable<Ghre_SurveyRecord>() |
|
|
|
|
.SetColumns(it => new Ghre_SurveyRecord() { IsEnable = 0 }) |
|
|
|
|
.SetColumns(it => new Ghre_SurveyRecord() { IsEnable = 0 }, true) |
|
|
|
|
.Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id && x.IsEnable == 1) |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
await Db.Updateable<Ghre_SurveyRecordDetail>() |
|
|
|
|
.SetColumns(it => new Ghre_SurveyRecordDetail() { IsEnable = 0 }, true) |
|
|
|
|
.Where(x => x.SurveyRecordId == surveyRecordId) |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
await Db.Updateable<Ghre_SurveyRecordOption>() |
|
|
|
|
.SetColumns(it => new Ghre_SurveyRecordOption() { IsEnable = 0 }, true) |
|
|
|
|
.Where(x => x.SurveyRecordId == surveyRecordId) |
|
|
|
|
.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(); |
|
|
|
@ -333,7 +344,7 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins |
|
|
|
|
StaffId = App.User.StaffId, |
|
|
|
|
Score = 0 |
|
|
|
|
}; |
|
|
|
|
if (question.Value.IsNotEmptyOrNull()) |
|
|
|
|
if (question.Value1.Any()) |
|
|
|
|
{ |
|
|
|
|
var questionOption1 = question.Options.Where(x => x.OptionNo == question.Value1[j]).FirstOrDefault(); |
|
|
|
|
|
|
|
|
@ -342,8 +353,8 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins |
|
|
|
|
|
|
|
|
|
if (questionOption1.IsOther == true) |
|
|
|
|
option1.Reverse1 = questionOption1.OtherContent; |
|
|
|
|
await Db.Insertable(option1).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
} |
|
|
|
|
await Db.Insertable(option1).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
@ -489,24 +500,95 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins |
|
|
|
|
data.Questions = Mapper.Map(questions).ToANew<List<Ghre_SurveyStatisticQuestion>>(); |
|
|
|
|
data.Questions.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.Table = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew<List<Ghre_SurveyStatisticQuestionTable>>(); |
|
|
|
|
if (x.QuestionType == "Rate") |
|
|
|
|
{ |
|
|
|
|
//var totals = recordOptions.Where(a => a.SurveyQuestionId == x.Id).ToList(); |
|
|
|
|
decimal total = recordOptions.Where(a => a.SurveyQuestionId == x.Id).Count(); |
|
|
|
|
for (int i = 1; i < 6; i++) |
|
|
|
|
{ |
|
|
|
|
x.Table.Add(new Ghre_SurveyStatisticQuestionTable() |
|
|
|
|
{ |
|
|
|
|
OptionNo = i.ObjToString(), |
|
|
|
|
OptionContent = i.ObjToString(), |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
x.Table.ForEach(o => |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
decimal total = recordOptions.Where(a => a.SurveyQuestionId == x.Id).Count(); |
|
|
|
|
x.Table.ForEach(o => |
|
|
|
|
o.Count = recordOptions.Where(a => a.SurveyQuestionId == x.Id && a.OptionContent == o.OptionContent).Count(); |
|
|
|
|
if (o.Count > 0 && total > 0) |
|
|
|
|
{ |
|
|
|
|
o.Percent1 = o.Count / total; |
|
|
|
|
o.Percent1 = o.Percent1 * 100; |
|
|
|
|
o.Percent = $"{o.Percent1.TrimDecimalString(2)}%"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
o.Percent = $"0%"; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (x.QuestionType == "Scale") |
|
|
|
|
{ |
|
|
|
|
//var totals = recordOptions.Where(a => a.SurveyQuestionId == x.Id).ToList(); |
|
|
|
|
decimal total = recordOptions.Where(a => a.SurveyQuestionId == x.Id).Count(); |
|
|
|
|
for (int i = 1; i < 11; i++) |
|
|
|
|
{ |
|
|
|
|
x.Table.Add(new Ghre_SurveyStatisticQuestionTable() |
|
|
|
|
{ |
|
|
|
|
OptionNo = i.ObjToString(), |
|
|
|
|
OptionContent = i.ObjToString(), |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
o.Count = recordOptions.Where(a => a.SurveyQuestionOptionId == o.Id).Count(); |
|
|
|
|
if (o.Count > 0 && total > 0) |
|
|
|
|
x.Table.ForEach(o => |
|
|
|
|
{ |
|
|
|
|
o.Percent1 = o.Count / total; |
|
|
|
|
o.Percent1 = o.Percent1 * 100; |
|
|
|
|
o.Percent = $"{o.Percent1.RemoveZero()}%"; |
|
|
|
|
}else |
|
|
|
|
o.Percent = $"0%"; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
o.Count = recordOptions.Where(a => a.SurveyQuestionId == x.Id && a.OptionContent == o.OptionContent).Count(); |
|
|
|
|
if (o.Count > 0 && total > 0) |
|
|
|
|
{ |
|
|
|
|
o.Percent1 = o.Count / total; |
|
|
|
|
o.Percent1 = o.Percent1 * 100; |
|
|
|
|
o.Percent = $"{o.Percent1.TrimDecimalString(2)}%"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
o.Percent = $"0%"; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
x.Table = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew<List<Ghre_SurveyStatisticQuestionTable>>(); |
|
|
|
|
|
|
|
|
|
decimal total = recordOptions.Where(a => a.SurveyQuestionId == x.Id).Count(); |
|
|
|
|
x.Table.ForEach(o => |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
o.Count = recordOptions.Where(a => a.SurveyQuestionOptionId == o.Id).Count(); |
|
|
|
|
if (o.Count > 0 && total > 0) |
|
|
|
|
{ |
|
|
|
|
o.Percent1 = o.Count / total; |
|
|
|
|
o.Percent1 = o.Percent1 * 100; |
|
|
|
|
o.Percent = $"{o.Percent1.TrimDecimalString(2)}%"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
o.Percent = $"0%"; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return ServiceResult<Ghre_SurveyStatistic>.OprateSuccess("查询成功!", data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("记录成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|