代码优化

master
xiaochanghai 1 year ago
parent 450c6ec1d5
commit 8d9350b1d3
  1. 13
      Model/Tiobon.Web.pdm
  2. 7
      Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs
  3. 13
      Tiobon.Core.Api/Tiobon.Core.Model.xml
  4. 2
      Tiobon.Core.IServices/Ghre/IGhre_QuestionServices.cs
  5. 6
      Tiobon.Core.Model/Base/Ghre/Ghre_Question.Dto.Base.cs
  6. 2
      Tiobon.Core.Model/Edit/Ghre/Ghre_Question.Dto.EditInput.cs
  7. 2
      Tiobon.Core.Model/Insert/Ghre/Ghre_Question.Dto.InsertInput.cs
  8. 6
      Tiobon.Core.Model/Models/Ghre/Ghre_Question.cs
  9. 12
      Tiobon.Core.Model/View/Ghre/Ghre_Question.Dto.View.cs
  10. 2
      Tiobon.Core.Model/ViewModels/Extend/FromGhre_QuestionInput.cs
  11. 2
      Tiobon.Core.Repository/BASE/BaseRepository.cs
  12. 2
      Tiobon.Core.Services/BASE/BaseServices.cs
  13. 19
      Tiobon.Core.Services/CommonServices.cs
  14. 230
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs
  15. 13
      Tiobon.Core/Tiobon.Core.Model.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{C294868A-C3F3-41AD-98CC-78B6D4E0CC40}" Label="" LastModificationDate="1715148812" Name="一优开发平台" Objects="6473" Symbols="275" Target="Microsoft SQL Server 2008" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="15.0.0.2613"?>
<?PowerDesigner AppLocale="UTF16" ID="{C294868A-C3F3-41AD-98CC-78B6D4E0CC40}" Label="" LastModificationDate="1715153446" Name="一优开发平台" Objects="6473" Symbols="275" Target="Microsoft SQL Server 2008" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="15.0.0.2613"?>
<!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
@ -105645,15 +105645,14 @@ LABL 0 Arial Unicode MS,8,N</a:FontList>
</o:Column>
<o:Column Id="o6334">
<a:ObjectID>127BDA02-D77D-4EF6-8050-FD6F1C8003FE</a:ObjectID>
<a:Name>课程Ids</a:Name>
<a:Code>CourseIds</a:Code>
<a:Name>课程Id</a:Name>
<a:Code>CourseId</a:Code>
<a:CreationDate>1713840012</a:CreationDate>
<a:Creator>Administrator</a:Creator>
<a:ModificationDate>1713840195</a:ModificationDate>
<a:ModificationDate>1715153446</a:ModificationDate>
<a:Modifier>Administrator</a:Modifier>
<a:Comment>课程Ids</a:Comment>
<a:DataType>nvarchar(2000)</a:DataType>
<a:Length>2000</a:Length>
<a:Comment>课程Id</a:Comment>
<a:DataType>bigint</a:DataType>
</o:Column>
<o:Column Id="o6335">
<a:ObjectID>2A7151E4-7A47-4EC7-926D-46F18A4EB848</a:ObjectID>

@ -1,4 +1,6 @@
using System.Dynamic;
using System.Drawing;
using System.Dynamic;
using Mysqlx.Crud;
namespace Tiobon.Core.Api.Controllers;
@ -56,7 +58,6 @@ public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Gh
[HttpPost("Insert")]
public override async Task<ServiceResult<string>> Insert([FromBody] InsertGhre_QuestionInput insertModel)
{
insertModel.CourseIds = string.Join(";", insertModel.CourseId.Select(x => x));
var id = await _service.Add(insertModel);
var answers = insertModel.Answers;
if (answers.Any())
@ -79,7 +80,7 @@ public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Gh
return data;
}
[HttpPost("InsertFrom")]
public async Task<ServiceResult<long>> InsertFrom([FromBody] FromGhre_QuestionPageData insertModel)
public async Task<ServiceResult> InsertFrom([FromBody] FromGhre_QuestionPageData insertModel)
{
return await _service.InsertFrom(insertModel);
}

@ -716,9 +716,9 @@
题目 (Dto.Base)
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionBase.CourseIds">
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionBase.CourseId">
<summary>
课程Ids
课程Id
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionBase.QuestionNo">
@ -2089,9 +2089,9 @@
题目 (Model)
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_Question.CourseIds">
<member name="P:Tiobon.Core.Model.Models.Ghre_Question.CourseId">
<summary>
课程Ids
课程Id
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_Question.QuestionNo">
@ -3332,6 +3332,11 @@
答案
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionDto.CourseName">
<summary>
课程名称
</summary>
</member>
<member name="T:Tiobon.Core.Model.Models.Ghre_QuestionAnswerDto">
<summary>
题目答案(Dto.View)

@ -10,7 +10,7 @@ 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> InsertFrom(FromGhre_QuestionPageData insertModel);
Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData insertModel);
}

@ -27,10 +27,10 @@ namespace Tiobon.Core.Model.Models
{
/// <summary>
/// 课程Ids
/// 课程Id
/// </summary>
[Display(Name = "CourseIds"), Description("课程Ids"), MaxLength(2000, ErrorMessage = "课程Ids 不能超过 2000 个字符")]
public string CourseIds { get; set; }
[Display(Name = "CourseIds"), Description("课程Id")]
public long? CourseId { get; set; }
/// <summary>
/// 题目编号

@ -29,7 +29,5 @@ namespace Tiobon.Core.Model.Models
/// 答案
/// </summary>
public List<InsertGhre_QuestionAnswerInput> Answers { get; set; }
public List<long> CourseId { get; set; }
}
}

@ -29,6 +29,4 @@ public class InsertGhre_QuestionInput : Ghre_QuestionBase
/// </summary>
public List<InsertGhre_QuestionAnswerInput> Answers { get; set; }
public List<long> CourseId { get; set; }
}

@ -29,10 +29,10 @@ namespace Tiobon.Core.Model.Models
{
/// <summary>
/// 课程Ids
/// 课程Id
/// </summary>
[Display(Name = "CourseIds"), Description("课程Ids"), MaxLength(2000, ErrorMessage = "课程Ids 不能超过 2000 个字符")]
public string CourseIds { get; set; }
[Display(Name = "CourseIds"), Description("课程Id")]
public long? CourseId { get; set; }
/// <summary>
/// 题目编号

@ -15,6 +15,9 @@
*
*/
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace Tiobon.Core.Model.Models
{
@ -28,5 +31,14 @@ namespace Tiobon.Core.Model.Models
/// 答案
/// </summary>
public List<Ghre_QuestionAnswer> Answers { get; set; }
/// <summary>
/// 课程名称
/// </summary>
[Display(Name = "CourseName"), Description("课程名称")]
public string CourseName { get; set; }
public string CourseType { get; set; }
}
}

@ -25,7 +25,7 @@ public class FromGhre_QuestionPageData
}
public class FromGhre_QuestionBaseData
{
public List<long> courseID { get; set; } = new List<long> { };
public List<long?> courseID { get; set; } = new List<long?> { };
public string questionNo { get; set; }
}

@ -478,6 +478,8 @@ namespace Tiobon.Core.Repository.Base
{
var name = jProperty.Name;
var value = jProperty.Value.ToString();
if (name == "page" || name == "pageSize")
continue;
if (!string.IsNullOrWhiteSpace(value))
{
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value);

@ -784,7 +784,7 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds);
}
public async Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody body)
public virtual async Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody body)
{
var data = await BaseDal.QueryFilterPage(body);

@ -257,14 +257,7 @@ public partial class CommonServices : BaseServices<RootEntityTkey<int>>, ICommon
'GHR_Common_000045' fnTitle,
'table',
'left',
'ghr-data-sort'
UNION ALL
SELECT NULL fnKeySeq,
'Muti' fnKey,
'GHR_Common_000062' fnTitle,
'row',
'left',
'ghr-icon-global') A
'ghr-data-sort') A
WHERE fnKey NOT IN
(SELECT b.field
FROM Ghrs_UserPageSettingQueryColumn a, Ghrs_PageSettingQuery b
@ -815,7 +808,7 @@ public partial class CommonServices : BaseServices<RootEntityTkey<int>>, ICommon
iif(ISJSON(searchColumnDefaultValue)=1,JSON_QUERY(searchColumnDefaultValue),null) searchColumnDefaultValue ,
AppColumnType
from [dbo].[#TmpInitPageSettingQuery]
order by sortno";
order by sortno asc";
sql = string.Format(sql, param.menuName, App.User.ID, param.langId);
var TableColumn = Db.Ado.SqlQuery<TableColumn1>(sql);
result.JM_TableColumnT1.TableColumn = Mapper.Map(TableColumn).ToANew<List<TableColumn>>();
@ -1060,11 +1053,6 @@ public partial class CommonServices : BaseServices<RootEntityTkey<int>>, ICommon
new JProperty("label","课程编号"),
];
TableColumn.Add(searchItem);
searchItem = [
new JProperty("field","label1"),
new JProperty("label1","课程名称"),
];
TableColumn.Add(searchItem);
string sql = "SELECT Id, CourseNo, CourseName FROM Ghre_Course";
DataTable dt = await Db.Ado.GetDataTableAsync(sql);
@ -1073,8 +1061,7 @@ public partial class CommonServices : BaseServices<RootEntityTkey<int>>, ICommon
{
JObject item = [
new JProperty("value",long.Parse(dt.Rows[i]["Id"].ToString())),
new JProperty("label",dt.Rows[i]["CourseNo"].ToString()),
new JProperty("label1",dt.Rows[i]["CourseName"].ToString())
new JProperty("label",dt.Rows[i]["CourseNo"].ToString()+"-"+dt.Rows[i]["CourseName"].ToString())
];
DT_TableDataT1.Add(item);
}

@ -13,6 +13,7 @@ using System.Data;
using Tiobon.Core.Common;
using Tiobon.Core.Common.DB.Dapper;
using MySqlX.XDevAPI.Common;
using System.Collections.Generic;
namespace Tiobon.Core.Services
{
@ -23,11 +24,61 @@ namespace Tiobon.Core.Services
{
private readonly IBaseRepository<Ghre_Question> _dal;
private IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices;
public Ghre_QuestionServices(IBaseRepository<Ghre_Question> dal, IGhre_QuestionAnswerServices ghre_QuestionAnswerServices)
private IGhre_CourseServices _ghre_CourseServices;
private IGhre_CourseClassServices _ghre_CourseClassServices;
public Ghre_QuestionServices(IBaseRepository<Ghre_Question> dal,
IGhre_QuestionAnswerServices ghre_QuestionAnswerServices,
IGhre_CourseServices ghre_CourseServices,
IGhre_CourseClassServices ghre_CourseClassServices)
{
this._dal = dal;
base.BaseDal = dal;
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices;
_ghre_CourseServices = ghre_CourseServices;
_ghre_CourseClassServices = ghre_CourseClassServices;
}
public override async Task<ServicePageResult<Ghre_QuestionDto>> QueryFilterPage(QueryBody body)
{
var data1 = await BaseDal.QueryFilterPage(body);
var data = Mapper.Map(data1.result.DT_TableDataT1).ToANew<List<Ghre_QuestionDto>>();
var courseIds = data.Where(x => x.CourseId != null).Select(x => x.CourseId).ToList();
var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id));
var classs = await _ghre_CourseClassServices.Query();
data.ForEach(x =>
{
if (x.DifficultyLevel == "Easy")
x.DifficultyLevel = "简单";
else if (x.DifficultyLevel == "Normal")
x.DifficultyLevel = "普通";
else if (x.DifficultyLevel == "Hard")
x.DifficultyLevel = "困难";
if (x.QuestionType == "Single")
x.QuestionType = "单选题";
else if (x.QuestionType == "Multiple")
x.QuestionType = "多选题";
else if (x.QuestionType == "TrueOrFalse")
x.QuestionType = "判断题";
else if (x.QuestionType == "Completion")
x.QuestionType = "填空题";
else if (x.QuestionType == "ShortAnswer")
x.QuestionType = "简答题";
if (x.CourseId != null)
{
var course = courses.Where(a => a.Id == x.CourseId).FirstOrDefault();
x.CourseName = course?.CourseName;
var courseClass = classs.Where(a => a.Id == course.CourseClassId).FirstOrDefault();
x.CourseType = courseClass.ClassName;
}
});
return new ServicePageResult<Ghre_QuestionDto>(body.pageNum, data1.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data);
}
/// <summary>
@ -65,25 +116,68 @@ namespace Tiobon.Core.Services
#endregion
#region PageData
var answerList = new List<FromGhre_QuestionQuestionAnswerList>
{
new FromGhre_QuestionQuestionAnswerList()
{
No = "A",
},
new FromGhre_QuestionQuestionAnswerList()
{
No = "B",
},
new FromGhre_QuestionQuestionAnswerList()
{
No = "C",
},
new FromGhre_QuestionQuestionAnswerList()
{
No = "D",
}
};
var answerList1 = new List<FromGhre_QuestionQuestionAnswerList>
{
new FromGhre_QuestionQuestionAnswerList()
{
No = "A",
},
new FromGhre_QuestionQuestionAnswerList()
{
No = "B",
}
};
data.PageData.questionType = new List<FromGhre_QuestionQuestionType>
{
new FromGhre_QuestionQuestionType()
{
label = "单选题",
type = "Single",
isActive = 1
isActive = 1,
detail= new FromGhre_QuestionQuestionTypeDetail()
{
answerList=answerList
}
},
new FromGhre_QuestionQuestionType()
{
label = "多选题",
type = "Multiple",
isActive = 0,
detail= new FromGhre_QuestionQuestionTypeDetail()
{
answerList=answerList
}
},
new FromGhre_QuestionQuestionType()
{
label = "判断题",
type = "TrueOrFalse",
isActive = 0,
detail= new FromGhre_QuestionQuestionTypeDetail()
{
answerList=answerList1
}
},
new FromGhre_QuestionQuestionType()
{
@ -104,20 +198,8 @@ 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)
{
}
});
}
data.PageData.baseData.courseID.Add(question.CourseId);
var questionType = data.PageData.questionType.Where(x => x.type == question.QuestionType).FirstOrDefault();
if (questionType != null)
{
@ -144,13 +226,42 @@ namespace Tiobon.Core.Services
return ServiceResult<FromGhre_QuestionInput>.OprateSuccess("查询成功!", data);
}
public async Task<ServiceResult<long>> InsertFrom(FromGhre_QuestionPageData insertModel)
public async Task<ServiceResult> InsertFrom(FromGhre_QuestionPageData insertModel)
{
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
string questionTypeName = string.Empty;
if (questionType.type == "Single")
questionTypeName = "单选题";
else if (questionType.type == "Multiple")
questionTypeName = "多选题";
else if (questionType.type == "TrueOrFalse")
questionTypeName = "判断题";
else if (questionType.type == "Completion")
questionTypeName = "填空题";
else if (questionType.type == "ShortAnswer")
questionTypeName = "简答题";
#region 判断是否重复
for (int j = 0; j < insertModel.baseData.courseID.Count; j++)
{
var courseID = insertModel.baseData.courseID[j];
string sql = "SELECT * FROM Ghre_Question where QuestionType='{0}' and CourseId='{1}' and QuestionContent ='{2}'";
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content);
DataTable dt = Db.Ado.GetDataTable(sql);
if (dt.Rows.Count > 0)
{
var course = await _ghre_CourseServices.QueryById(courseID);
throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】");
}
}
#endregion
for (int j = 0; j < insertModel.baseData.courseID.Count; j++)
{
var courseID = insertModel.baseData.courseID[j];
var insert = new InsertGhre_QuestionInput();
insert.CourseId = insertModel.baseData.courseID;
insert.CourseIds = string.Join(";", insert.CourseId.Select(x => x));
insert.CourseId = courseID;
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
insert.QuestionType = questionType.type;
insert.DifficultyLevel = questionType.detail.difficulty;
insert.QuestionContent = questionType.detail.content;
@ -177,19 +288,46 @@ namespace Tiobon.Core.Services
i = i + 100;
});
await _ghre_QuestionAnswerServices.Add(insertAnswers);
return ServiceResult<long>.OprateSuccess("查询成功!", id);
}
return ServiceResult.OprateSuccess("新增成功!");
}
public async Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData editModel)
{
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
string questionTypeName = string.Empty;
if (questionType.type == "Single")
questionTypeName = "单选题";
else if (questionType.type == "Multiple")
questionTypeName = "多选题";
else if (questionType.type == "TrueOrFalse")
questionTypeName = "判断题";
else if (questionType.type == "Completion")
questionTypeName = "填空题";
else if (questionType.type == "ShortAnswer")
questionTypeName = "简答题";
#region 判断是否重复
for (int j = 0; j < editModel.baseData.courseID.Count; j++)
{
var courseID = editModel.baseData.courseID[j];
string sql = "SELECT * FROM Ghre_Question where QuestionType='{0}' and CourseId='{1}' and QuestionContent ='{2}' AND Id !='{3}'";
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content, Id);
DataTable dt = Db.Ado.GetDataTable(sql);
if (dt.Rows.Count > 0)
{
var course = await _ghre_CourseServices.QueryById(courseID);
throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】");
}
}
#endregion
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 = "";
edit.CourseId = editModel.baseData.courseID[0];
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
edit.QuestionType = questionType.type;
edit.DifficultyLevel = questionType.detail.difficulty;
edit.QuestionContent = questionType.detail.content;
@ -214,6 +352,44 @@ namespace Tiobon.Core.Services
i = i + 100;
});
await _ghre_QuestionAnswerServices.Add(insertAnswers);
for (int j = 0; j < editModel.baseData.courseID.Count; j++)
{
if (j == 0)
continue;
var courseID = editModel.baseData.courseID[j];
var insert = new InsertGhre_QuestionInput();
insert.CourseId = courseID;
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);
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();
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.OprateSuccess("更新成功!");
}
@ -224,8 +400,8 @@ namespace Tiobon.Core.Services
string result = string.Empty;
string tableCode = "Ghre_Question";
string columnCode = "QuestionNo";
int length = 6;
int tempLength = 5;
int length = 7;
int tempLength = 6;
int sequence;
#region 查询

@ -716,9 +716,9 @@
题目 (Dto.Base)
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionBase.CourseIds">
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionBase.CourseId">
<summary>
课程Ids
课程Id
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionBase.QuestionNo">
@ -2089,9 +2089,9 @@
题目 (Model)
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_Question.CourseIds">
<member name="P:Tiobon.Core.Model.Models.Ghre_Question.CourseId">
<summary>
课程Ids
课程Id
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_Question.QuestionNo">
@ -3332,6 +3332,11 @@
答案
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_QuestionDto.CourseName">
<summary>
课程名称
</summary>
</member>
<member name="T:Tiobon.Core.Model.Models.Ghre_QuestionAnswerDto">
<summary>
题目答案(Dto.View)

Loading…
Cancel
Save