diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 26188cd7..2a055687 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -858,6 +858,7 @@ public partial class CommonServices : BaseServices>, ICommon var index = -1; switch (param.menuName) { + case "F_SurveyQuestionPool": case "F_QuestionBank": toolbar = result.JM_PageControlT1.Toolbar.Where(x => x.fnKey == "NewYN").FirstOrDefault(); if (toolbar != null) { toolbar.fnKey = "TBD1YN"; } @@ -2448,7 +2449,7 @@ public partial class CommonServices : BaseServices>, ICommon toolbar = result.JM_PageControlT1.Toolbar.Where(x => x.fnKey == "CopyYN").FirstOrDefault(); if (toolbar != null) toolbar.fnKey = "TBD4YN"; - if(param.menuName == "F_GhraStaffGroup") + if (param.menuName == "F_GhraStaffGroup") result.JM_PageControlT1.Toolbar.Add(new Toolbar() { display = true, @@ -4305,7 +4306,7 @@ public partial class CommonServices : BaseServices>, ICommon var dict1 = JsonHelper.JsonToObj(json); //dict.RequestNo = await GenerateContinuousSequence("Ghrh_HumanRequest", "RequestNo", "R"); id = await Db.Insertable(dict).ExecuteReturnSnowflakeIdAsync(); - + sql = $"SELECT ISNULL(MAX(id)+1,1) FROM Ghre_ExternalTrainApplyOrder_Boltone WHERE Id !='{id}' and len(Id) !=19"; var id1 = await Db.Ado.GetLongAsync(sql); sql = $"UPDATE Ghre_ExternalTrainApplyOrder_Boltone SET Id={id1} WHERE Id ='{id}'"; diff --git a/Tiobon.Core.Services/Ghre/Ghre_SurveyQuestionPoolServices.cs b/Tiobon.Core.Services/Ghre/Ghre_SurveyQuestionPoolServices.cs index dd406ad0..90bc60f3 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_SurveyQuestionPoolServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_SurveyQuestionPoolServices.cs @@ -215,25 +215,73 @@ public class Ghre_SurveyQuestionPoolServices : BaseServices.OprateSuccess("查询成功!", data); } - public async Task InsertFrom(InsertGhre_SurveyQuestionExtend insertModel) + public async Task InsertFrom(FromGhre_SurveyQuestionPoolPageData insertModel) { - var question = Mapper.Map(insertModel).ToANew(); + var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); - question.QuestionNo = await GenerateContinuousSequence("Q"); - var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync(); - for (int j = 0; j < insertModel.Options.Count; j++) + await Db.Ado.BeginTranAsync(); + + try { - var option = Mapper.Map(insertModel.Options[j]).ToANew(); - option.SurveyQuestionPoolId = questionId; - option.SortNo = j; - await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); - } - return ServiceResult.OprateSuccess("新增成功!"); + string questionTypeName = ConvertQuestionType(questionType.QuestionType); + + var insert = new InsertGhre_SurveyQuestionPoolInput(); + insert.BuiltIn = insertModel.baseData.BuiltIn; + + insert.QuestionType = questionType.QuestionType; + insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); + insert.QuestionContent = questionType.QuestionContent; + insert.QuestionAnalysis = questionType.QuestionAnalysis; + + var id = await base.Add(insert); + var insertAnswers = questionType.Options.Select(x => new InsertGhre_SurveyQuestionPoolOptionInput() + { + QuestionNo = x.OptionNo, + AnswerContent = x.OptionContent, + ImageUrl = x.ImageUrl, + ImageWidthPc = x.ImageWidthPc, + ImageWidthApp = x.ImageWidthApp, + }).ToList(); + int i = 100; + insertAnswers.ForEach(x => + { + x.TaxisNo = i; + x.SurveyQuestionPoolId = id; + i = i + 100; + }); + + + await _ghre_SurveyQuestionPoolOptionServicesServices.Add(insertAnswers); + //} + await Db.Ado.CommitTranAsync(); + return ServiceResult.OprateSuccess("新增成功!"); + } + catch (Exception) + { + await Db.Ado.RollbackTranAsync(); + throw; + } } + //{ + // var question = Mapper.Map(insertModel).ToANew(); + + // question.QuestionNo = await GenerateContinuousSequence("Q"); + // var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync(); - public async Task UpdateFrom(long Id, InsertGhre_SurveyQuestionExtend editModel) + // for (int j = 0; j < insertModel.Options.Count; j++) + // { + // var option = Mapper.Map(insertModel.Options[j]).ToANew(); + // option.SurveyQuestionPoolId = questionId; + // option.SortNo = j; + // await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); + // } + // return ServiceResult.OprateSuccess("新增成功!"); + + //} + + public async Task UpdateFrom(long Id, FromGhre_SurveyQuestionPoolPageData editModel) { await Db.Ado.BeginTranAsync(); @@ -244,13 +292,13 @@ public class Ghre_SurveyQuestionPoolServices : BaseServices(); await base.Update(Id, insert, null, ["QuestionNo"]); - for (int j = 0; j < editModel.Options.Count; j++) - { - var option = Mapper.Map(editModel.Options[j]).ToANew(); + //for (int j = 0; j < editModel.Options.Count; j++) + //{ + // var option = Mapper.Map(editModel.Options[j]).ToANew(); - option.SurveyQuestionId = Id; - await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); - } + // option.SurveyQuestionId = Id; + // await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); + //} await Db.Ado.CommitTranAsync(); return ServiceResult.OprateSuccess("更新成功!");