|
|
|
@ -1,8 +1,15 @@ |
|
|
|
|
|
|
|
|
|
using System.Data; |
|
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
|
using Tiobon.Core.IServices; |
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
@ -16,11 +23,13 @@ namespace Tiobon.Core.Services |
|
|
|
|
/// </summary> |
|
|
|
|
public class Ghre_ExamPaperServices : BaseServices<Ghre_ExamPaper, Ghre_ExamPaperDto, InsertGhre_ExamPaperInput, EditGhre_ExamPaperInput>, IGhre_ExamPaperServices |
|
|
|
|
{ |
|
|
|
|
private IGhre_ExamPaperConfigServices _ghre_ExamPaperConfigServices; |
|
|
|
|
private IGhre_ExamPaperQuestionServices _ghre_ExamPaperQuestionServices; |
|
|
|
|
private IGhre_QuestionServices _ghre_QuestionServices; |
|
|
|
|
readonly IGhrs_UserServices _ghrs_UserServices; |
|
|
|
|
private IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; |
|
|
|
|
private readonly IGhre_ExamPaperConfigServices _ghre_ExamPaperConfigServices; |
|
|
|
|
private readonly IGhre_ExamPaperQuestionServices _ghre_ExamPaperQuestionServices; |
|
|
|
|
private readonly IGhre_QuestionServices _ghre_QuestionServices; |
|
|
|
|
private readonly IGhrs_UserServices _ghrs_UserServices; |
|
|
|
|
private readonly IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; |
|
|
|
|
private readonly IGhre_CourseServices _ghre_CourseServices; |
|
|
|
|
private readonly IGhre_CourseSceneServices _ghre_CourseSceneServices; |
|
|
|
|
private readonly IBaseRepository<Ghre_ExamPaper> _dal; |
|
|
|
|
|
|
|
|
|
public Ghre_ExamPaperServices(IBaseRepository<Ghre_ExamPaper> dal, |
|
|
|
@ -28,17 +37,139 @@ namespace Tiobon.Core.Services |
|
|
|
|
IGhre_QuestionServices ghre_QuestionServices, |
|
|
|
|
IGhre_QuestionAnswerServices ghre_QuestionAnswerServices, |
|
|
|
|
IGhre_ExamPaperQuestionServices ghre_ExamPaperQuestionServices, |
|
|
|
|
IGhre_CourseServices ghre_CourseServices, |
|
|
|
|
IGhre_CourseSceneServices ghre_CourseSceneServices, |
|
|
|
|
ICaching caching, |
|
|
|
|
IGhrs_UserServices ghrs_UserServices) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
|
base.BaseDal = dal; |
|
|
|
|
base._caching = caching; |
|
|
|
|
_ghre_ExamPaperConfigServices = ghre_ExamPaperConfigServices; |
|
|
|
|
_ghre_ExamPaperQuestionServices = ghre_ExamPaperQuestionServices; |
|
|
|
|
_ghre_QuestionServices = ghre_QuestionServices; |
|
|
|
|
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices; |
|
|
|
|
_ghrs_UserServices = ghrs_UserServices; |
|
|
|
|
_ghre_CourseServices = ghre_CourseServices; |
|
|
|
|
_ghre_CourseSceneServices = ghre_CourseSceneServices; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public override async Task<ServicePageResult<Ghre_ExamPaperDto>> QueryFilterPage(QueryBody body) |
|
|
|
|
{ |
|
|
|
|
var data = await BaseDal.QueryFilterPage(body); |
|
|
|
|
var data1 = Mapper.Map(data.result.DT_TableDataT1).ToANew<List<Ghre_ExamPaperDto>>(); |
|
|
|
|
|
|
|
|
|
var linkIds = data1.Where(x => x.LinkId != null).Select(x => x.LinkId.Value).Distinct().ToList(); |
|
|
|
|
var courses = await _ghre_CourseServices.Query(x => linkIds.Contains(x.Id)); |
|
|
|
|
var courseScenes = await _ghre_CourseSceneServices.Query(x => linkIds.Contains(x.Id)); |
|
|
|
|
|
|
|
|
|
data1.ForEach(async x => |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
x.ScoreMethodLabel = await GetParaLabel("ScoreMethod", x.ScoreMethod); |
|
|
|
|
x.TotalScore1 = Regex.Replace(x.PassScore.ToString(), @"\.(0+)$", "") + "/" + Regex.Replace(x.TotalScore.ToString(), @"\.(0+)$", ""); |
|
|
|
|
x.SetMethodLabel = await GetParaLabel("SetMethod", x.SetMethod); |
|
|
|
|
|
|
|
|
|
if (x.LinkType == "CourseId") |
|
|
|
|
x.CourseName = courses.FirstOrDefault(o => o.Id == x.LinkId)?.CourseName; |
|
|
|
|
else if (x.LinkType == "CourseSceneId") |
|
|
|
|
x.CourseName = courseScenes.FirstOrDefault(o => o.Id == x.LinkId)?.SceneName; |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return new ServicePageResult<Ghre_ExamPaperDto>(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServicePageResult<Ghre_ExamPaperDto>> QueryList(QueryBody body, string status) |
|
|
|
|
{ |
|
|
|
|
var data = await QueryFilterPage1(body, status); |
|
|
|
|
var data1 = Mapper.Map(data.result.DT_TableDataT1).ToANew<List<Ghre_ExamPaperDto>>(); |
|
|
|
|
|
|
|
|
|
var linkIds = data1.Where(x => x.LinkId != null).Select(x => x.LinkId.Value).Distinct().ToList(); |
|
|
|
|
var courses = await _ghre_CourseServices.Query(x => linkIds.Contains(x.Id)); |
|
|
|
|
var courseScenes = await _ghre_CourseSceneServices.Query(x => linkIds.Contains(x.Id)); |
|
|
|
|
|
|
|
|
|
data1.ForEach(async x => |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
x.ScoreMethodLabel = await GetParaLabel("ScoreMethod", x.ScoreMethod); |
|
|
|
|
x.TotalScore1 = Regex.Replace(x.PassScore.ToString(), @"\.(0+)$", "") + "/" + Regex.Replace(x.TotalScore.ToString(), @"\.(0+)$", ""); |
|
|
|
|
x.SetMethodLabel = await GetParaLabel("SetMethod", x.SetMethod); |
|
|
|
|
|
|
|
|
|
if (x.LinkType == "CourseId") |
|
|
|
|
x.CourseName = courses.FirstOrDefault(o => o.Id == x.LinkId)?.CourseName; |
|
|
|
|
else if (x.LinkType == "CourseSceneId") |
|
|
|
|
x.CourseName = courseScenes.FirstOrDefault(o => o.Id == x.LinkId)?.SceneName; |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return new ServicePageResult<Ghre_ExamPaperDto>(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServicePageResult<Ghre_ExamPaper>> QueryFilterPage1(QueryBody filter, string status = null) |
|
|
|
|
{ |
|
|
|
|
RefAsync<int> totalCount = 0; |
|
|
|
|
var query = Db.Queryable<Ghre_ExamPaper>(); |
|
|
|
|
if (!string.IsNullOrWhiteSpace(status)) |
|
|
|
|
query = query.Where(x => x.Status == status); |
|
|
|
|
string conditions = "1=1"; |
|
|
|
|
if (filter.jsonParam != null) |
|
|
|
|
foreach (JProperty jProperty in filter.jsonParam.Properties()) |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
switch (jsonParam.operationKey) |
|
|
|
|
{ |
|
|
|
|
case "Include": |
|
|
|
|
conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; |
|
|
|
|
break; |
|
|
|
|
case "NotInclude": |
|
|
|
|
conditions += $" AND {name} NOT LIKE '%{jsonParam.columnValue}%'"; |
|
|
|
|
break; |
|
|
|
|
case "IsNull": |
|
|
|
|
conditions += $" AND {name} IS NULL"; |
|
|
|
|
break; |
|
|
|
|
case "NotNull": |
|
|
|
|
conditions += $" AND {name} IS NOT NULL"; |
|
|
|
|
break; |
|
|
|
|
case "Equal": |
|
|
|
|
conditions += $" AND {name} ='{jsonParam.columnValue}'"; |
|
|
|
|
break; |
|
|
|
|
case "NotEqual": |
|
|
|
|
conditions += $" AND {name} !='{jsonParam.columnValue}'"; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (filter.pageSize == 0) |
|
|
|
|
filter.pageSize = 10000; |
|
|
|
|
query = query.Where(conditions); |
|
|
|
|
var list = await query |
|
|
|
|
.OrderByIF(!string.IsNullOrEmpty(filter.orderBy), filter.orderBy) |
|
|
|
|
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); |
|
|
|
|
|
|
|
|
|
return new ServicePageResult<Ghre_ExamPaper>(filter.pageNum, totalCount, filter.pageSize, list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult<DefaultGhre_ExamPaperInput>> QueryDefault(long Id) |
|
|
|
|
{ |
|
|
|
@ -186,6 +317,7 @@ namespace Tiobon.Core.Services |
|
|
|
|
multipleSelect = false, |
|
|
|
|
editable = true, |
|
|
|
|
displayType=2, |
|
|
|
|
width=80, |
|
|
|
|
dataSource = "api/Common/GetSelect/DifficultyLevel?FW=DOTNETCORE" |
|
|
|
|
}, |
|
|
|
|
new DefaultGhre_ExamPaperColumn() |
|
|
|
@ -196,6 +328,7 @@ namespace Tiobon.Core.Services |
|
|
|
|
required = true, |
|
|
|
|
multipleSelect = false, |
|
|
|
|
editable = true, |
|
|
|
|
width=80, |
|
|
|
|
displayType=2 |
|
|
|
|
}, |
|
|
|
|
new DefaultGhre_ExamPaperColumn() |
|
|
|
@ -206,6 +339,7 @@ namespace Tiobon.Core.Services |
|
|
|
|
required = true, |
|
|
|
|
multipleSelect = false, |
|
|
|
|
editable = true, |
|
|
|
|
width=80, |
|
|
|
|
displayType=2 |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -252,6 +386,7 @@ namespace Tiobon.Core.Services |
|
|
|
|
required = true, |
|
|
|
|
multipleSelect = false, |
|
|
|
|
editable = true, |
|
|
|
|
width=80, |
|
|
|
|
displayType=2 |
|
|
|
|
}, |
|
|
|
|
new DefaultGhre_ExamPaperColumn() |
|
|
|
@ -262,6 +397,7 @@ namespace Tiobon.Core.Services |
|
|
|
|
required = true, |
|
|
|
|
multipleSelect = false, |
|
|
|
|
editable = true, |
|
|
|
|
width=80, |
|
|
|
|
displayType=2 |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -535,20 +671,37 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static string ConvertQuestionType(string type) |
|
|
|
|
{ |
|
|
|
|
string questionTypeName = string.Empty; |
|
|
|
|
if (type == "Single") |
|
|
|
|
questionTypeName = "单选题"; |
|
|
|
|
else if (type == "Multiple") |
|
|
|
|
questionTypeName = "多选题"; |
|
|
|
|
else if (type == "TrueOrFalse") |
|
|
|
|
questionTypeName = "判断题"; |
|
|
|
|
else if (type == "Completion") |
|
|
|
|
questionTypeName = "填空题"; |
|
|
|
|
else if (type == "ShortAnswer") |
|
|
|
|
questionTypeName = "简答题"; |
|
|
|
|
return questionTypeName; |
|
|
|
|
public async Task<ServiceResult> UpdateStatus(long[] ids, string status) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
|
|
List<Ghre_ExamPaper> entities = new List<Ghre_ExamPaper>(); |
|
|
|
|
foreach (var id in ids) |
|
|
|
|
{ |
|
|
|
|
if (id == null || !BaseDal.Any(id)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
var entity = await BaseDal.QueryById(id); |
|
|
|
|
|
|
|
|
|
BasePoco ent = entity; |
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
ent.UpdateProg = api; |
|
|
|
|
if ((status == "Released" && entity.Status == "Draft") || status == "Disabled" && entity.Status == "Released") |
|
|
|
|
{ |
|
|
|
|
entity.Status = status; |
|
|
|
|
entities.Add(entity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var result = await BaseDal.Update(entities); |
|
|
|
|
if (status == "Released") |
|
|
|
|
return ServiceResult.OprateSuccess("发布成功!"); |
|
|
|
|
else |
|
|
|
|
return ServiceResult.OprateSuccess("停用成功!"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |