代码优化

master
xiaochanghai 1 year ago
parent ca31a8986a
commit 450c6ec1d5
  1. 608
      Model/Tiobon.Web.pdm
  2. 12
      Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs
  3. 7
      Tiobon.Core.Api/Tiobon.Core.xml
  4. 3
      Tiobon.Core.IServices/Ghre/IGhre_QuestionServices.cs
  5. 4
      Tiobon.Core.Model/Base/Ghre/Ghre_QuestionAnswer.Dto.Base.cs
  6. 4
      Tiobon.Core.Model/Models/Ghre/Ghre_QuestionAnswer.cs
  7. 5
      Tiobon.Core.Model/ViewModels/Extend/FromGhre_QuestionInput.cs
  8. 159
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs
  9. 7
      Tiobon.Core/Tiobon.Core.xml

File diff suppressed because it is too large Load Diff

@ -78,7 +78,11 @@ public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Gh
return Failed<string>("新增失败");
return data;
}
[HttpPost("InsertFrom")]
public async Task<ServiceResult<long>> InsertFrom([FromBody] FromGhre_QuestionPageData insertModel)
{
return await _service.InsertFrom(insertModel);
}
#endregion
#region 更新
@ -106,6 +110,12 @@ public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Gh
}
return await base.Put(Id, editModel);
}
[HttpPost("UpdareFrom/{Id}")]
public async Task<ServiceResult> UpdareFrom(long Id, [FromBody] FromGhre_QuestionPageData insertModel)
{
return await _service.UpdareFrom(Id, insertModel);
}
#endregion
#endregion

@ -244,6 +244,13 @@
<param name="param"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Controllers.CommonController.GetSelectAsync(System.String)">
<summary>
获取模块信息接口
</summary>
<param name="type"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Controllers.DbFirstController.#ctor(SqlSugar.ISqlSugarClient,Microsoft.AspNetCore.Hosting.IWebHostEnvironment)">
<summary>
构造函数

@ -10,5 +10,8 @@ namespace Tiobon.Core.IServices
public interface IGhre_QuestionServices :IBaseServices<Ghre_Question, Ghre_QuestionDto, InsertGhre_QuestionInput, EditGhre_QuestionInput>
{
Task<ServiceResult<FromGhre_QuestionInput>> QueryFrom(long Id);
Task<ServiceResult<long>> InsertFrom(FromGhre_QuestionPageData insertModel);
Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData insertModel);
}
}

@ -57,12 +57,12 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 图片宽度
/// </summary>
public int? ImageWidthPc { get; set; }
public string ImageWidthPc { get; set; }
/// <summary>
/// 图片宽度
/// </summary>
public int? ImageWidthApp { get; set; }
public string ImageWidthApp { get; set; }
/// <summary>
/// 排序号

@ -59,12 +59,12 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 图片宽度
/// </summary>
public int? ImageWidthPc { get; set; }
public string ImageWidthPc { get; set; }
/// <summary>
/// 图片宽度
/// </summary>
public int? ImageWidthApp { get; set; }
public string ImageWidthApp { get; set; }
/// <summary>
/// 排序号

@ -4,6 +4,7 @@ public class FromGhre_QuestionInput
{
public List<FromGhre_QuestionColumn> Column { get; set; } = new List<FromGhre_QuestionColumn>();
public FromGhre_QuestionPageData PageData { get; set; } = new FromGhre_QuestionPageData();
}
public class FromGhre_QuestionColumn
{
@ -49,6 +50,6 @@ public class FromGhre_QuestionQuestionAnswerList
public string No { get; set; }
public string label { get; set; }
public string imageUrl { get; set; }
public int? imgWidthPc { get; set; }
public int? imgWidthApp { get; set; }
public string imgWidthPc { get; set; }
public string imgWidthApp { get; set; }
}

@ -6,6 +6,13 @@ using Tiobon.Core.IRepository.Base;
using Tiobon.Core.Model;
using System.Dynamic;
using Newtonsoft.Json.Linq;
using AgileObjects.AgileMapper;
using Mysqlx.Crud;
using AgileObjects.AgileMapper.Extensions;
using System.Data;
using Tiobon.Core.Common;
using Tiobon.Core.Common.DB.Dapper;
using MySqlX.XDevAPI.Common;
namespace Tiobon.Core.Services
{
@ -41,7 +48,7 @@ namespace Tiobon.Core.Services
required = true,
multipleSelect = true,
editable = true,
dataSource = "TBParaDetail_GhrStaff_JTFS"
dataSource = "api/Common/GetSelect?type=Ghre_Course"
});
data.Column.Add(new FromGhre_QuestionColumn()
{
@ -96,6 +103,21 @@ namespace Tiobon.Core.Services
{
var question = await base.QueryById(Id);
data.PageData.questionType.ForEach(x => x.isActive = 0);
data.PageData.baseData.questionNo = question.QuestionNo;
if (!string.IsNullOrEmpty(question.CourseIds))
{
var list = question.CourseIds.Split(';');
list.ForEach(x =>
{
try
{
data.PageData.baseData.courseID.Add(long.Parse(x));
}
catch (Exception)
{
}
});
}
var questionType = data.PageData.questionType.Where(x => x.type == question.QuestionType).FirstOrDefault();
if (questionType != null)
{
@ -121,5 +143,140 @@ namespace Tiobon.Core.Services
return ServiceResult<FromGhre_QuestionInput>.OprateSuccess("查询成功!", data);
}
public async Task<ServiceResult<long>> InsertFrom(FromGhre_QuestionPageData insertModel)
{
var insert = new InsertGhre_QuestionInput();
insert.CourseId = insertModel.baseData.courseID;
insert.CourseIds = string.Join(";", insert.CourseId.Select(x => x));
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
insert.QuestionType = questionType.type;
insert.DifficultyLevel = questionType.detail.difficulty;
insert.QuestionContent = questionType.detail.content;
insert.QuestionAnalysis = questionType.detail.RemarkSz;
insert.QuestionNo = GenerateContinuousSequence(insert.QuestionType.Substring(0, 1));
var id = await base.Add(insert);
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput()
{
QuestionNo = x.No,
AnswerContent = x.label,
ImageUrl = x.imageUrl,
ImageWidthPc = x.imgWidthPc,
ImageWidthApp = x.imgWidthApp,
}).ToList();
int i = 100;
insertAnswers.ForEach(x =>
{
x.TaxisNo = i;
x.QuestionId = id;
if (questionType.detail.answer == x.QuestionNo && insert.QuestionType == "Single")
x.IsCorrect = true;
i = i + 100;
});
await _ghre_QuestionAnswerServices.Add(insertAnswers);
return ServiceResult<long>.OprateSuccess("查询成功!", id);
}
public async Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData editModel)
{
var data = await base.QueryById(Id);
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id);
var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>();
edit.CourseId = editModel.baseData.courseID;
edit.CourseIds = string.Join(";", edit.CourseId.Select(x => x));
edit.QuestionNo = "";
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
edit.QuestionType = questionType.type;
edit.DifficultyLevel = questionType.detail.difficulty;
edit.QuestionContent = questionType.detail.content;
edit.QuestionAnalysis = questionType.detail.RemarkSz;
await base.Update(Id, edit);
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput()
{
QuestionNo = x.No,
AnswerContent = x.label,
ImageUrl = x.imageUrl,
ImageWidthPc = x.imgWidthPc,
ImageWidthApp = x.imgWidthApp,
}).ToList();
int i = 100;
insertAnswers.ForEach(x =>
{
x.TaxisNo = i;
x.QuestionId = Id;
if (questionType.detail.answer == x.QuestionNo && edit.QuestionType == "Single")
x.IsCorrect = true;
i = i + 100;
});
await _ghre_QuestionAnswerServices.Add(insertAnswers);
return ServiceResult.OprateSuccess("更新成功!");
}
public static string GenerateContinuousSequence(string prefixTemp)
{
try
{
string result = string.Empty;
string tableCode = "Ghre_Question";
string columnCode = "QuestionNo";
int length = 6;
int tempLength = 5;
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();
string maxSequence = Convert.ToString(DbAccess.Instance.ExecuteScalar(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; }
}
}
}

@ -244,6 +244,13 @@
<param name="param"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Controllers.CommonController.GetSelectAsync(System.String)">
<summary>
获取模块信息接口
</summary>
<param name="type"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Controllers.DbFirstController.#ctor(SqlSugar.ISqlSugarClient,Microsoft.AspNetCore.Hosting.IWebHostEnvironment)">
<summary>
构造函数

Loading…
Cancel
Save