diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs index dc55acb6..ec21df0d 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs @@ -112,4 +112,15 @@ public class Ghre_SurveyController : BaseController> QueryStatistic(long id) => await _service.QueryStatistic(id); #endregion + + #region 开始 + /// + /// 开始 + /// + /// + /// + [HttpPost("Start/{id}")] + public async Task Start(long id) => await _service.Start(id); + + #endregion } diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 39f01c7d..e3e8b93a 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -1441,6 +1441,13 @@ + + + 开始 + + + + 问卷调查选项(Controller) diff --git a/Tiobon.Core.Common/Helper/UtilHelper.cs b/Tiobon.Core.Common/Helper/UtilHelper.cs index c915efac..a43235ce 100644 --- a/Tiobon.Core.Common/Helper/UtilHelper.cs +++ b/Tiobon.Core.Common/Helper/UtilHelper.cs @@ -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 /// diff --git a/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs index c459936e..1f7824ee 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs @@ -23,4 +23,6 @@ public interface IGhre_SurveyServices : IBaseServices Publish(long id); Task> QueryStatistic(long id); + + Task Start(long id); } \ No newline at end of file diff --git a/Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs b/Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs index 465c2967..2ef8f33f 100644 --- a/Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs +++ b/Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs @@ -333,7 +333,7 @@ public class Ghre_SurveyStatistic /// public class Ghre_SurveyStatisticQuestion : Ghre_SurveyQuestionExtendBase { - public List Table { get; set; } + public List Table { get; set; } = new List(); } diff --git a/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs b/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs index e68ad958..46c77e2f 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs @@ -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().Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id).Select(x => x.Id).FirstAsync(); var recordDetails = await Db.Queryable().Where(x => x.SurveyRecordId == recordId).ToListAsync(); - var recordOptions = await Db.Queryable().Where(x => x.SurveyRecordId == recordId).ToListAsync(); + var recordOptions = await Db.Queryable().Where(x => x.SurveyRecordId == recordId).OrderBy(x=>x.OptionContent).ToListAsync(); data.Questions.ForEach(question => { @@ -277,10 +276,22 @@ public class Ghre_SurveyServices : BaseServices() + .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) + .Select(x => x.Id).FirstAsync(); await Db.Updateable() - .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() + .SetColumns(it => new Ghre_SurveyRecordDetail() { IsEnable = 0 }, true) + .Where(x => x.SurveyRecordId == surveyRecordId) + .ExecuteCommandAsync(); + await Db.Updateable() + .SetColumns(it => new Ghre_SurveyRecordOption() { IsEnable = 0 }, true) + .Where(x => x.SurveyRecordId == surveyRecordId) + .ExecuteCommandAsync(); var questions = await Db.Queryable().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync(); var options = await Db.Queryable().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync(); @@ -333,7 +344,7 @@ public class Ghre_SurveyServices : BaseServices x.OptionNo == question.Value1[j]).FirstOrDefault(); @@ -342,8 +353,8 @@ public class Ghre_SurveyServices : BaseServices>(); data.Questions.ForEach(x => { - x.Table = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew>(); + 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>(); + + 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.OprateSuccess("查询成功!", data); } + + public async Task Start(long id) + { + await Db.Updateable() + .SetColumns(it => new Ghre_SurveyRecord() { BeginTime = DateTime.Now }) + .Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id) + .ExecuteCommandAsync(); + + return ServiceResult.OprateSuccess("记录成功!"); + } + } diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index 39f01c7d..e3e8b93a 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -1441,6 +1441,13 @@ + + + 开始 + + + + 问卷调查选项(Controller)