新增 试卷结合保存数据接口

master
xiaochanghai 1 year ago
parent f6ace28012
commit 199dfabb92
  1. 15
      Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs
  2. 10
      Tiobon.Core.Api/Tiobon.Core.Model.xml
  3. 4
      Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs
  4. 2
      Tiobon.Core.Model/Base/Ghre/Ghre_ExamPaper.Dto.Base.cs
  5. 8
      Tiobon.Core.Model/ViewModels/Extend/DefaultGhre_ExamPaperInput.cs
  6. 70
      Tiobon.Core.Services/BASE/BaseServices.cs
  7. 58
      Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs
  8. 7
      Tiobon.Core/Tiobon.Core.xml

@ -26,6 +26,19 @@ public class Ghre_ExamPaperController : BaseController<IGhre_ExamPaperServices,
return await _service.QueryDefault(Id);
}
#endregion
#region 新增
/// <summary>
/// 新增
/// </summary>
/// <param name="insert"></param>
/// <returns></returns>
[HttpPost("Insert1")]
public async Task<ServiceResult<long>> Insert1([FromBody] DefaultGhre_ExamPaperPageData insert)
{
return await _service.Insert1(insert);
}
#endregion
#region 新增配置数据
@ -35,7 +48,7 @@ public class Ghre_ExamPaperController : BaseController<IGhre_ExamPaperServices,
/// <param name="insert"></param>
/// <returns></returns>
[HttpPost("InsertConfig")]
public async Task<ServiceResult<InsertExamPaperConfigInput>> InsertConfig(InsertGhre_ExamPaperConfigInput insert)
public async Task<ServiceResult<InsertExamPaperConfigInput>> InsertConfig([FromBody] InsertGhre_ExamPaperConfigInput insert)
{
return await _service.InsertConfig(insert);
}

@ -3782,6 +3782,16 @@
课程名称
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionDto.DifficultyLevelLabel">
<summary>
难易程度
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionDto.QuestionTypeLabel">
<summary>
题目类型
</summary>
</member>
<member name="T:Tiobon.Core.Model.Models.Ghre_QuestionAnswerDto">
<summary>
题目答案(Dto.View)

@ -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<ServiceResult<DefaultGhre_ExamPaperInput>> QueryDefault(long Id);
Task<ServiceResult<InsertExamPaperConfigInput>> InsertConfig(InsertGhre_ExamPaperConfigInput insert);
Task<ServiceResult<long>> Insert1([FromBody] DefaultGhre_ExamPaperPageData insert);
}
}

@ -76,7 +76,7 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 关联ID
/// </summary>
public long? LinkId { get; set; }
/// <summary>
/// 关联次数
/// </summary>

@ -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<Ghre_ExamPaperConfig> examPaperSetData { get; set; } = new List<Ghre_ExamPaperConfig> { };
public List<DefaultGhre_ExamPaperPreview> previewList { get; set; } = new List<DefaultGhre_ExamPaperPreview> { };
}
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; }

@ -1010,5 +1010,75 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
}
#endregion
#region 自动编号
/// <summary>
/// 自动编号
/// </summary>
/// <param name="tableCode">表名</param>
/// <param name="columnCode">栏位名</param>
/// <param name="prefixTemp">前缀</param>
/// <returns></returns>
public async Task<string> 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
}

@ -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<ServiceResult<InsertExamPaperConfigInput>> InsertConfig(InsertGhre_ExamPaperConfigInput insert)
{
var input = new InsertExamPaperConfigInput();
long parentId = SnowFlakeSingle.instance.getID();
input.tableData = Mapper.Map(insert).ToANew<Ghre_ExamPaperConfig>();
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<Ghre_Question>(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<InsertExamPaperConfigInput>.OprateSuccess("查询成功!", input);
}
public async Task<ServiceResult<long>> Insert1(DefaultGhre_ExamPaperPageData insertModel)
{
await Db.Ado.BeginTranAsync();
try
{
var insert = new InsertGhre_ExamPaperInput();
insert = Mapper.Map(insertModel.baseData).ToANew<InsertGhre_ExamPaperInput>();
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<List<Ghre_ExamPaperConfig>>();
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<long>.OprateSuccess("保存成功!", id);
}
catch (Exception)
{
await Db.Ado.RollbackTranAsync();
throw;
}
}
}
}

@ -655,6 +655,13 @@
<param name="Id"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_ExamPaperController.Insert1(Tiobon.Core.Model.DefaultGhre_ExamPaperPageData)">
<summary>
新增
</summary>
<param name="insert"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_ExamPaperController.InsertConfig(Tiobon.Core.Model.Models.InsertGhre_ExamPaperConfigInput)">
<summary>
新增配置数据

Loading…
Cancel
Save