@ -11,7 +11,7 @@ using AgileObjects.AgileMapper;
using Newtonsoft.Json ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Linq ;
using Newtonsoft.Json.Linq ;
using SqlSugar ;
using SqlSugar ;
using NPOI.OpenXmlFormats.Wordprocessing ;
using Tiobon.Core.Common.Helper ;
namespace Tiobon.Core.Services ;
namespace Tiobon.Core.Services ;
@ -24,10 +24,12 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
private readonly IGhre_CourseServices _ ghre_CourseServices ;
private readonly IGhre_CourseServices _ ghre_CourseServices ;
private readonly IGhre_CourseSceneServices _ ghre_CourseSceneServices ;
private readonly IGhre_CourseSceneServices _ ghre_CourseSceneServices ;
private readonly IGhra_StaffServices _ ghra_StaffSceneServices ;
private readonly IGhra_StaffServices _ ghra_StaffSceneServices ;
private readonly IGhre_ExamStaffServices _ ghre_ExamStaffServices ;
public Ghre_ExamServices ( ICaching caching ,
public Ghre_ExamServices ( ICaching caching ,
IGhre_CourseServices ghre_CourseServices ,
IGhre_CourseServices ghre_CourseServices ,
IGhre_CourseSceneServices ghre_CourseSceneServices ,
IGhre_CourseSceneServices ghre_CourseSceneServices ,
IGhra_StaffServices ghra_StaffSceneServices ,
IGhra_StaffServices ghra_StaffSceneServices ,
IGhre_ExamStaffServices ghre_ExamStaffServices ,
IBaseRepository < Ghre_Exam > dal )
IBaseRepository < Ghre_Exam > dal )
{
{
this . _d al = dal ;
this . _d al = dal ;
@ -36,6 +38,7 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
_ ghre_CourseServices = ghre_CourseServices ;
_ ghre_CourseServices = ghre_CourseServices ;
_ ghre_CourseSceneServices = ghre_CourseSceneServices ;
_ ghre_CourseSceneServices = ghre_CourseSceneServices ;
_ ghra_StaffSceneServices = ghra_StaffSceneServices ;
_ ghra_StaffSceneServices = ghra_StaffSceneServices ;
_ ghre_ExamStaffServices = ghre_ExamStaffServices ;
}
}
public async Task < dynamic > GetModuleInfo ( ModuleParam param )
public async Task < dynamic > GetModuleInfo ( ModuleParam param )
{
{
@ -186,46 +189,61 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
return result ;
return result ;
}
}
public async Task < ServicePageResult < Ghre_ExamDto > > QueryList ( QueryBody body , string status )
public async Task < dynamic > QueryList ( QueryBody body , string status )
{
{
var data = await QueryFilterPage1 ( body , status ) ;
var data = await QueryFilterPage1 ( body , status ) ;
var data1 = Mapper . Map ( data . result . DT_TableDataT1 ) . ToANew < List < Ghre_ExamDto > > ( ) ;
//var linkIds = data1.Where(x => x.LinkId != null).Select(x => x.LinkId.Value).Distinct().ToList();
dynamic return1 = new ExpandoObject ( ) ;
//var courses = await _ghre_CourseServices.Query(x => linkIds.Contains(x.Id));
dynamic result = new ExpandoObject ( ) ;
//var courseScenes = await _ghre_CourseSceneServices.Query(x => linkIds.Contains(x.Id));
dynamic DT_TablePageInfoT1 = new ExpandoObject ( ) ;
//data1.ForEach(async x =>
result . DT_TableDataT1 = data . result . DT_TableDataT1 ;
//{
DT_TablePageInfoT1 . PageNum = body . pageNum ;
// try
DT_TablePageInfoT1 . PageSize = body . pageSize ;
// {
DT_TablePageInfoT1 . TotalCount = data . result . DT_TablePageInfoT1 . TotalCount ;
// x.ScoreMethodLabel = await GetParaLabel("ScoreMethod", x.ScoreMethod);
result . DT_TablePageInfoT1 = DT_TablePageInfoT1 ;
// x.TotalScore1 = Regex.Replace(x.PassScore.ToString(), @"\.(0+)$", "") + "/" + Regex.Replace(x.TotalScore.ToString(), @"\.(0+)$", "");
dynamic CardConfig = new ExpandoObject ( ) ;
// x.SetMethodLabel = await GetParaLabel("SetMethod", x.SetMethod);
CardConfig . cardTitle = "ExamName" ;
CardConfig . cardImage = "CoverUrl" ;
// if (x.LinkType == "CourseId")
CardConfig . column1 = "AfterHowLongLabel" ;
// x.CourseName = courses.FirstOrDefault(o => o.Id == x.LinkId)?.CourseName;
CardConfig . column1Icon = "ghr-form-designer-deteSelect" ;
// else if (x.LinkType == "CourseSceneId")
CardConfig . column2 = "CourseName" ;
// x.CourseName = courseScenes.FirstOrDefault(o => o.Id == x.LinkId)?.SceneName;
CardConfig . column2Icon = "ghr-exam-paper" ;
// }
CardConfig . column3 = "ExamModeLabel" ;
// catch (Exception)
CardConfig . column3Icon = "ghr-online-exam" ;
// {
CardConfig . column4 = "OpenClassName" ;
CardConfig . column4Icon = "ghr-link-openClass" ;
// }
CardConfig . column5 = "" ;
CardConfig . column5Icon = "" ;
//});
CardConfig . column6 = "" ;
CardConfig . column6Icon = "" ;
return new ServicePageResult < Ghre_ExamDto > ( body . pageNum , data . result . DT_TablePageInfoT1 . TotalCount , body . pageSize , data1 ) ;
result . CardConfig = CardConfig ;
return1 . result = result ;
return1 . message = "查询成功!" ;
return1 . Success = true ;
return1 . code = 0 ;
return1 . type = "success" ;
return return1 ;
}
}
public async Task < ServicePageResult < Ghre_Exam > > QueryFilterPage1 ( QueryBody filter , string status = null )
public async Task < ServicePageResult < Ghre_ExamDto > > QueryFilterPage1 ( QueryBody filter , string status = null )
{
{
RefAsync < int > totalCount = 0 ;
string sql = @ "SELECT *
FROM ( SELECT A . * ,
B . CourseName ,
C . Id CourseTypeId ,
C . ClassName CourseType
FROM Ghre_Exam A
LEFT JOIN Ghre_Course B ON A . CourseId = B . Id
LEFT JOIN Ghre_CourseClass C ON B . CourseClassId = C . Id
WHERE A . IsEnable = 1 ) A ";
if ( string . IsNullOrWhiteSpace ( filter . orderBy ) )
if ( string . IsNullOrWhiteSpace ( filter . orderBy ) )
filter . orderBy = "CreateTime DESC" ;
filter . orderBy = "CreateTime DESC" ;
RefAsync < int > totalCount = 0 ;
var query = Db . Queryable < Ghre_Exam > ( ) ;
if ( ! string . IsNullOrWhiteSpace ( status ) )
query = query . Where ( x = > x . Status = = status ) ;
string conditions = "1=1" ;
string conditions = "1=1" ;
if ( filter . jsonParam ! = null )
if ( filter . jsonParam ! = null )
foreach ( JProperty jProperty in filter . jsonParam . Properties ( ) )
foreach ( JProperty jProperty in filter . jsonParam . Properties ( ) )
@ -234,6 +252,7 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
var value = jProperty . Value . ToString ( ) ;
var value = jProperty . Value . ToString ( ) ;
if ( name = = "page" | | name = = "pageSize" )
if ( name = = "page" | | name = = "pageSize" )
continue ;
continue ;
if ( ! string . IsNullOrWhiteSpace ( value ) )
if ( ! string . IsNullOrWhiteSpace ( value ) )
{
{
var jsonParam = JsonConvert . DeserializeObject < JsonParam > ( value ) ;
var jsonParam = JsonConvert . DeserializeObject < JsonParam > ( value ) ;
@ -265,12 +284,17 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
}
}
if ( filter . pageSize = = 0 )
if ( filter . pageSize = = 0 )
filter . pageSize = 1 0 0 0 0 ;
filter . pageSize = 1 0 0 0 0 ;
query = query . Where ( conditions ) ;
var data = await Db . SqlQueryable < Ghre_ExamDto > ( sql )
var list = await query
. OrderBy ( filter . orderBy )
. OrderByIF ( ! string . IsNullOrEmpty ( filter . orderBy ) , filter . orderBy )
. ToPageListAsync ( filter . pageNum , filter . pageSize , totalCount ) ;
. ToPageListAsync ( filter . pageNum , filter . pageSize , totalCount ) ;
return new ServicePageResult < Ghre_Exam > ( filter . pageNum , totalCount , filter . pageSize , list ) ;
//data.ForEach(async x =>
//{
// x.DifficultyLevelLabel = await GetParaLabel("DifficultyLevel", x.DifficultyLevel);
// x.QuestionTypeLabel = await GetParaLabel("QuestionType", x.QuestionType);
//});
return new ServicePageResult < Ghre_ExamDto > ( filter . pageNum , totalCount , filter . pageSize , data ) ;
}
}
@ -460,7 +484,22 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
if ( Id ! = 0 )
if ( Id ! = 0 )
{
{
var exam = await base . QueryById ( Id ) ;
var exam = await base . QueryById ( Id ) ;
input . pageData = Mapper . Map ( exam ) . ToANew < DefaultGhre_ExamPageData > ( ) ;
var pageData = Mapper . Map ( exam ) . ToANew < DefaultGhre_ExamPageData > ( ) ;
if ( pageData . AfterHowLong ! = 7 & & pageData . AfterHowLong ! = 1 5 & & pageData . AfterHowLong ! = 3 0 )
{
pageData . AfterHowLong1 = pageData . AfterHowLong ;
pageData . AfterHowLong = 0 ;
}
if ( pageData . DateType = = "ExamDate" ) pageData . ExamDate . Add ( pageData . BeginTime . Value . ToString ( "yyyy/MM/dd" ) ) ;
if ( pageData . DateType = = "ExamDate" ) pageData . ExamDate . Add ( pageData . EndTime . Value . ToString ( "yyyy/MM/dd" ) ) ;
input . pageData = pageData ;
var staffs = await _ ghre_ExamStaffServices . Query ( x = > x . ExamId = = Id ) ;
var ids = staffs . Select ( x = > Convert . ToInt32 ( x . StaffId ) ) . ToList ( ) ;
var staffTableData = await QueryStaff ( ids , null ) ;
pageData . staffTableData = staffTableData . Data ;
}
}
# endregion
# endregion
@ -484,8 +523,10 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
LEFT JOIN Ghra_Title C ON A . TitleID = C . TitleID
LEFT JOIN Ghra_Title C ON A . TitleID = C . TitleID
WHERE 1 = 1 AND A . IsEnable = 1 ";
WHERE 1 = 1 AND A . IsEnable = 1 ";
sql + = $"AND StaffID IN({string.Join(" , ", Ids)});" ;
if ( Ids . Any ( ) )
var list = await _ ghra_StaffSceneServices . Query ( x = > Ids . Contains ( x . StaffID ) ) ;
sql + = $"AND StaffID IN({string.Join(" , ", Ids)}) " ;
else sql + = "AND 1!=1 " ;
//var list = await _ghra_StaffSceneServices.Query(x => Ids.Contains(x.StaffID));
var data = Db . Ado . SqlQuery < StaffTableData > ( sql ) ;
var data = Db . Ado . SqlQuery < StaffTableData > ( sql ) ;
//var data = list.Select(x => new StaffTableData()
//var data = list.Select(x => new StaffTableData()
@ -498,4 +539,50 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
return ServiceResult < List < StaffTableData > > . OprateSuccess ( "查询成功!" , data ) ;
return ServiceResult < List < StaffTableData > > . OprateSuccess ( "查询成功!" , data ) ;
}
}
public async Task < ServiceResult < long > > Insert1 ( long id , DefaultGhre_ExamPageData pageData )
{
if ( pageData . DateType = = "ExamDate" )
{
pageData . BeginTime = Convert . ToDateTime ( pageData . ExamDate [ 0 ] ) ;
pageData . EndTime = Convert . ToDateTime ( pageData . ExamDate [ 1 ] ) ;
}
if ( pageData . AfterHowLong = = 0 )
pageData . AfterHowLong = pageData . AfterHowLong1 ;
if ( id = = 0 )
{
pageData . Status = "Draft" ;
var insert = Mapper . Map ( pageData ) . ToANew < InsertGhre_ExamInput > ( ) ;
id = await base . Add ( insert ) ;
var insertStaffs = pageData . staffTableData . Select ( x = > new InsertGhre_ExamStaffInput ( )
{
ExamId = id ,
StaffId = x . StaffID ,
Source = x . DataSource
} ) . ToList ( ) ;
await _ ghre_ExamStaffServices . Add ( insertStaffs ) ;
return ServiceResult < long > . OprateSuccess ( "添加成功!" , id ) ;
}
else
{
var insert = Mapper . Map ( pageData ) . ToANew < EditGhre_ExamInput > ( ) ;
await base . Update ( id , insert ) ;
await _ ghre_ExamStaffServices . Delete ( x = > x . ExamId = = id ) ;
var insertStaffs = pageData . staffTableData . Select ( x = > new InsertGhre_ExamStaffInput ( )
{
ExamId = id ,
StaffId = x . StaffID ,
Source = x . DataSource
} ) . ToList ( ) ;
await _ ghre_ExamStaffServices . Add ( insertStaffs ) ;
return ServiceResult < long > . OprateSuccess ( "修改成功!" , id ) ;
}
}
}
}