优化问卷提交接口

master
xiaochanghai 2 months ago
parent ab9f6d9459
commit b4b6053926
  1. 11
      Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs
  2. 7
      Tiobon.Core.Api/Tiobon.Core.xml
  3. 22
      Tiobon.Core.Common/Helper/UtilHelper.cs
  4. 2
      Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs
  5. 2
      Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs
  6. 116
      Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs
  7. 7
      Tiobon.Core/Tiobon.Core.xml

@ -112,4 +112,15 @@ public class Ghre_SurveyController : BaseController<IGhre_SurveyServices, Ghre_S
public async Task<ServiceResult<Ghre_SurveyStatistic>> QueryStatistic(long id) => await _service.QueryStatistic(id);
#endregion
#region 开始
/// <summary>
/// 开始
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("Start/{id}")]
public async Task<ServiceResult> Start(long id) => await _service.Start(id);
#endregion
}

@ -1441,6 +1441,13 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_SurveyController.Start(System.Int64)">
<summary>
开始
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Api.Controllers.Ghre_SurveyOptionController">
<summary>
问卷调查选项(Controller)

@ -206,6 +206,28 @@ public static class UtilHelper
sResult = sResult.Substring(0, sResult.Length - 1);
return sResult;
}
public static string TrimDecimalString(this decimal? value1, int reservedDigit)
{
try
{
var value = value1.RemoveZero();
string result = string.Empty;
if (!string.IsNullOrEmpty(value))
{
Decimal tmp = Decimal.Parse(value);
if (reservedDigit == -1)
result = string.Format("{0:#0.##########}", tmp);
else
{
result = String.Format("{0:N" + reservedDigit.ToString() + "}", tmp);
result = result.Replace(",", "");
}
}
return result;
}
catch (Exception) { return null; }
}
#endregion
/// <summary>

@ -23,4 +23,6 @@ public interface IGhre_SurveyServices : IBaseServices<Ghre_Survey, Ghre_SurveyDt
Task<ServiceResult> Publish(long id);
Task<ServiceResult<Ghre_SurveyStatistic>> QueryStatistic(long id);
Task<ServiceResult> Start(long id);
}

@ -333,7 +333,7 @@ public class Ghre_SurveyStatistic
/// </summary>
public class Ghre_SurveyStatisticQuestion : Ghre_SurveyQuestionExtendBase
{
public List<Ghre_SurveyStatisticQuestionTable> Table { get; set; }
public List<Ghre_SurveyStatisticQuestionTable> Table { get; set; } = new List<Ghre_SurveyStatisticQuestionTable>();
}

@ -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("记录成功!");
}
}

@ -1441,6 +1441,13 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_SurveyController.Start(System.Int64)">
<summary>
开始
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Api.Controllers.Ghre_SurveyOptionController">
<summary>
问卷调查选项(Controller)

Loading…
Cancel
Save