diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs index 4eee3d51..4902af95 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs @@ -25,6 +25,19 @@ public class Ghre_ExamPaperController : BaseController + /// 新增 + /// + /// + /// + [HttpPost("Insert1")] + public async Task> Insert1([FromBody] DefaultGhre_ExamPaperPageData insert) + { + return await _service.Insert1(insert); + } #endregion #region 新增配置数据 @@ -35,7 +48,7 @@ public class Ghre_ExamPaperController : BaseController /// [HttpPost("InsertConfig")] - public async Task> InsertConfig(InsertGhre_ExamPaperConfigInput insert) + public async Task> InsertConfig([FromBody] InsertGhre_ExamPaperConfigInput insert) { return await _service.InsertConfig(insert); } diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index 4d784471..e3ab44f5 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -3782,6 +3782,16 @@ 课程名称 + + + 难易程度 + + + + + 题目类型 + + 题目答案(Dto.View) diff --git a/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs index 7ed86c4d..06bd59d9 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs @@ -1,4 +1,5 @@ -using Tiobon.Core.IServices.BASE; +using Microsoft.AspNetCore.Mvc; +using Tiobon.Core.IServices.BASE; using Tiobon.Core.Model; using Tiobon.Core.Model.Models; @@ -12,5 +13,6 @@ namespace Tiobon.Core.IServices Task> QueryDefault(long Id); Task> InsertConfig(InsertGhre_ExamPaperConfigInput insert); + Task> Insert1([FromBody] DefaultGhre_ExamPaperPageData insert); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/Base/Ghre/Ghre_ExamPaper.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghre/Ghre_ExamPaper.Dto.Base.cs index 6c9a954b..4e02dbbb 100644 --- a/Tiobon.Core.Model/Base/Ghre/Ghre_ExamPaper.Dto.Base.cs +++ b/Tiobon.Core.Model/Base/Ghre/Ghre_ExamPaper.Dto.Base.cs @@ -13,7 +13,7 @@ *│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │ *│ 作者:SimonHsiao │ *└──────────────────────────────────┘ -*/ +*/ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -76,7 +76,7 @@ namespace Tiobon.Core.Model.Models /// /// 关联ID /// - + public long? LinkId { get; set; } /// /// 关联次数 /// diff --git a/Tiobon.Core.Model/ViewModels/Extend/DefaultGhre_ExamPaperInput.cs b/Tiobon.Core.Model/ViewModels/Extend/DefaultGhre_ExamPaperInput.cs index 2c647c16..bee0399c 100644 --- a/Tiobon.Core.Model/ViewModels/Extend/DefaultGhre_ExamPaperInput.cs +++ b/Tiobon.Core.Model/ViewModels/Extend/DefaultGhre_ExamPaperInput.cs @@ -28,13 +28,17 @@ public class DefaultGhre_ExamPaperColumn public class DefaultGhre_ExamPaperPageData { - public dynamic baseData { get; set; } = new ExpandoObject(); + public DefaultGhre_ExamPaperBaseData baseData { get; set; } = new DefaultGhre_ExamPaperBaseData(); public DefaultGhre_ExamPaperStyleInfo styleInfo { get; set; } = new DefaultGhre_ExamPaperStyleInfo(); public string examPaperSetType { get; set; } public List examPaperSetData { get; set; } = new List { }; public List previewList { get; set; } = new List { }; } - +public class DefaultGhre_ExamPaperBaseData: Ghre_ExamPaperBase +{ + public long? CourseId { get; set; } + public long? CourseSceneId { get; set; } +} public class DefaultGhre_ExamPaperStyleInfo { public string coverImage { get; set; } diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index aa388ecf..5cb56d29 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -1010,5 +1010,75 @@ public class BaseServices : IBaseServ } #endregion + #region 自动编号 + /// + /// 自动编号 + /// + /// 表名 + /// 栏位名 + /// 前缀 + /// + public async Task GenerateContinuousSequence(string tableCode, string columnCode, string prefixTemp) + { + try + { + string result = string.Empty; + int length = 7; + int tempLength = 6; + int sequence; + + #region 查询 + DbSelect dbSelect = new DbSelect(tableCode + " A", "A", null); + dbSelect.IsInitDefaultValue = false; + + if (!string.IsNullOrEmpty(prefixTemp)) + dbSelect.Select("MAX(SUBSTRING(A." + columnCode + "," + (prefixTemp.Length + 1).ToString() + "," + tempLength.ToString() + "))"); + else + dbSelect.Select("MAX(A." + columnCode + ")"); + //} + //dbSelect.Select("MAX(CONVERT(DECIMAL,SUBSTRING(A.ISSUE_NO," + (prefix.Length + dateString.Length + 1).ToString() + "," + tempLength.ToString() + ")))"); + if (!string.IsNullOrEmpty(prefixTemp)) + dbSelect.Where("SUBSTRING(A." + columnCode + ",1," + (prefixTemp.Length).ToString() + ")", " = ", prefixTemp); + dbSelect.Where("LEN(A." + columnCode + ")", "=", length); + string sql = dbSelect.GetSql(); + //await Db.Ado.GetScalarAsync(sql) + string maxSequence = Convert.ToString(await Db.Ado.GetScalarAsync(sql)); + #endregion + //tempLength = tempLength - dateString.Length; + if (string.IsNullOrEmpty(maxSequence)) + result = prefixTemp + Convert.ToString(1).PadLeft(tempLength, '0'); + else + { + if (!string.IsNullOrEmpty(prefixTemp)) + { + if (int.TryParse(maxSequence, out sequence)) + { + sequence += 1; + if (sequence.ToString().Length > tempLength) + throw new Exception("自动生成字串长度已经超过设定长度!"); + } + else + throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); + result = prefixTemp + sequence.ToString().PadLeft(tempLength, '0'); + } + else + { + if (int.TryParse(maxSequence, out sequence)) + { + sequence += 1; + if (sequence.ToString().Length > length) + throw new Exception("自动生成字串长度已经超过设定长度!"); + } + else + throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); + result = sequence.ToString().PadLeft(length, '0'); + } + } + return result; + } + catch (Exception) { throw; } + } + #endregion + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs index e1c32bb9..50bb9d8c 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs @@ -1,7 +1,9 @@  +using System.Data; using System.Dynamic; using AgileObjects.AgileMapper; using SqlSugar; +using Tiobon.Core.Common; using Tiobon.Core.Common.DB.Dapper.Extensions; using Tiobon.Core.IRepository.Base; using Tiobon.Core.IServices; @@ -266,7 +268,7 @@ namespace Tiobon.Core.Services #region pageData if (Id == 0) { - dynamic baseData = new ExpandoObject(); + var baseData = new DefaultGhre_ExamPaperBaseData(); baseData.PaperNo = null; baseData.PaperName = null; baseData.AnswerTime = null; @@ -286,7 +288,7 @@ namespace Tiobon.Core.Services { var exampaper = await base.QueryById(Id); - dynamic baseData = new ExpandoObject(); + var baseData = new DefaultGhre_ExamPaperBaseData(); baseData.PaperNo = exampaper.PaperNo; baseData.PaperName = exampaper.PaperName; baseData.AnswerTime = exampaper.AnswerTime; @@ -362,18 +364,19 @@ namespace Tiobon.Core.Services public async Task> InsertConfig(InsertGhre_ExamPaperConfigInput insert) { var input = new InsertExamPaperConfigInput(); + long parentId = SnowFlakeSingle.instance.getID(); input.tableData = Mapper.Map(insert).ToANew(); - + input.tableData.Id = parentId; string sql = $@"SELECT TOP {insert.Quantity} *,NEWID() AS GuidValue FROM Ghre_Question WHERE IsEnable=1"; if (!string.IsNullOrWhiteSpace(insert.DifficultyLevel)) sql += $" AND DifficultyLevel='{insert.DifficultyLevel}'"; if (!string.IsNullOrWhiteSpace(insert.QuestionType)) sql += $" AND QuestionType='{insert.QuestionType}'"; if (insert.CourseId != null) - sql += $" AND CourseId='{insert.DifficultyLevel}'"; + sql += $" AND CourseId='{insert.CourseId}'"; + sql += $" ORDER BY GuidValue ASC"; var questions = await Db.Ado.SqlQueryAsync(sql); - long parentId = SnowFlakeSingle.instance.getID(); var previews = questions.Select(x => new DefaultGhre_ExamPaperPreview() { @@ -395,6 +398,7 @@ namespace Tiobon.Core.Services difficulty = o.DifficultyLevel, RemarkSz = o.QuestionAnalysis, content = o.QuestionContent, + }).ToList(); detail.ForEach(y => { @@ -416,5 +420,49 @@ namespace Tiobon.Core.Services return ServiceResult.OprateSuccess("查询成功!", input); } + + public async Task> Insert1(DefaultGhre_ExamPaperPageData insertModel) + { + await Db.Ado.BeginTranAsync(); + + try + { + var insert = new InsertGhre_ExamPaperInput(); + + insert = Mapper.Map(insertModel.baseData).ToANew(); + insert.PaperNo = await GenerateContinuousSequence("Ghre_ExamPaper", "P", "PaperNo"); + insert.LinkId = insertModel.baseData.LinkType == "CourseId" ? insertModel.baseData.CourseId : insertModel.baseData.CourseSceneId; + insert.CoverUrl = insertModel.styleInfo.coverImage; + insert.Style = insertModel.styleInfo.paperStyle; + insert.ScoreMethod = insertModel.examPaperSetType; + + var id = await Add(insert); + var configs = Mapper.Map(insertModel.examPaperSetData).ToANew>(); + configs.ForEach(x => x.ExamPaperId = id); + var insertConfigs = Db.Insertable(configs); + + string sql = insertConfigs.ToSqlString(); + long row = await Db.Ado.ExecuteCommandAsync(sql); + + var questions = insertModel.previewList + .Select(x => + new InsertGhre_ExamPaperQuestionInput + { + ExamPaperId = id, + QuestionId = x.QuestionId, + ConfigId = x.parentId, + }).ToList(); + await _ghre_ExamPaperQuestionServices.Add(questions); + + await Db.Ado.CommitTranAsync(); + return ServiceResult.OprateSuccess("保存成功!", id); + } + catch (Exception) + { + await Db.Ado.RollbackTranAsync(); + throw; + } + + } } } \ No newline at end of file diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index ea731fa5..43addf3c 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -655,6 +655,13 @@ + + + 新增 + + + + 新增配置数据