diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs index c2d5068c..2dd40800 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_SurveyController.cs @@ -49,10 +49,11 @@ public class Ghre_SurveyController : BaseController /// 插入 /// + /// /// /// - [HttpPost("InsertData")] - public async Task> InsertData([FromBody] InsertGhre_SurveyExtend input) => await _service.InsertData(input); + [HttpPost("InsertData/{id}")] + public async Task> InsertData(long id, [FromBody] InsertGhre_SurveyExtend input) => await _service.InsertData(id, input); #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index 091bcaeb..07132dbd 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -34707,11 +34707,6 @@ 题目解析 - - - 排序 - - 备注 diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index b6c69ba1..0f44f739 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -1373,10 +1373,11 @@ status - + 插入 + diff --git a/Tiobon.Core.Api/appsettings.json b/Tiobon.Core.Api/appsettings.json index 50980a04..b81d736c 100644 --- a/Tiobon.Core.Api/appsettings.json +++ b/Tiobon.Core.Api/appsettings.json @@ -269,7 +269,7 @@ "Enabled": false }, "QuartzNetJob": { - "Enabled": true + "Enabled": false }, "Consul": { "Enabled": false diff --git a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs index 890b1bce..194970ad 100644 --- a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs +++ b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs @@ -39,7 +39,7 @@ public static class SqlSugarAop public static void DataExecuting(object oldValue, DataFilterModel entityInfo) { - if (entityInfo.EntityValue is RootEntityTkey rootEntity) + if (entityInfo.EntityValue is BasePoco rootEntity) if (rootEntity.Id == 0) rootEntity.Id = SnowFlakeSingle.Instance.NextId(); diff --git a/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs index 9831d08c..76c347d7 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_SurveyServices.cs @@ -12,5 +12,5 @@ public interface IGhre_SurveyServices : IBaseServices UpdateStatus(InsertGhre_SurveyInput input, string status); - Task> InsertData(InsertGhre_SurveyExtend insertModel); + Task> InsertData(long id, InsertGhre_SurveyExtend insertModel); } \ 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 b634b1fb..1d204bfa 100644 --- a/Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs +++ b/Tiobon.Core.Model/ViewModels/Extend/InsertGhre_SurveyExtend.cs @@ -65,11 +65,6 @@ public class InsertGhre_SurveyQuestionExtend [Display(Name = "QuestionAnalysis"), Description("题目解析"), MaxLength(2000, ErrorMessage = "题目解析 不能超过 2000 个字符")] public string QuestionAnalysis { get; set; } - /// - /// 排序 - /// - public int? SortNo { get; set; } - /// /// 备注 /// diff --git a/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs b/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs index d6857d38..f7005cb8 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_SurveyServices.cs @@ -1,4 +1,6 @@ -namespace Tiobon.Core.Services; +using MongoDB.Driver.Core.Servers; + +namespace Tiobon.Core.Services; /// /// 问卷调查 (服务) @@ -83,13 +85,57 @@ public class Ghre_SurveyServices : BaseServices> InsertData(InsertGhre_SurveyExtend insertModel) + public async Task> InsertData(long id, InsertGhre_SurveyExtend insertModel) { + var data = ServiceResult.OprateSuccess("新增成功", id); + if (id == 0) + { - var data = ServiceResult.OprateSuccess("新增成功", 0); + var insert = Mapper.Map(insertModel).ToANew(); + + id = await Add(insert); + + for (int i = 0; i < insertModel.Questions.Count; i++) + { + var question = Mapper.Map(insertModel.Questions[i]).ToANew(); + //question.Id = SnowFlakeSingle.instance.getID(); - //return ServiceResult.OprateFailed("失败!"); + question.SurveyId = id; + var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync(); + for (int j = 0; j < insertModel.Questions[i].Options.Count; j++) + { + var option = Mapper.Map(insertModel.Questions[i].Options[j]).ToANew(); + option.SurveyId = id; + option.SurveyQuestionId = questionId; + await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); + } + } + data.Data = id; + } + else + { + await Db.Deleteable().Where(x => x.SurveyId == id).ExecuteCommandAsync(); + await Db.Deleteable().Where(x => x.SurveyId == id).ExecuteCommandAsync(); + + for (int i = 0; i < insertModel.Questions.Count; i++) + { + var question = Mapper.Map(insertModel.Questions[i]).ToANew(); + //question.Id = SnowFlakeSingle.instance.getID(); + + question.SurveyId = id; + var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync(); + + for (int j = 0; j < insertModel.Questions[i].Options.Count; j++) + { + var option = Mapper.Map(insertModel.Questions[i].Options[j]).ToANew(); + option.SurveyId = id; + option.SurveyQuestionId = questionId; + await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); + } + } + data.Message = "修改成功!"; + } return data; }