using Tiobon.Core.IServices;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Services.BASE;
using Tiobon.Core.IRepository.Base;
using Tiobon.Core.Common.Caches;
using System.Dynamic;
using Tiobon.Core.Model;
using Tiobon.Core.Common;
using AgileObjects.AgileMapper;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using SqlSugar;
namespace Tiobon.Core.Services;
///
/// 考试 (服务)
///
public class Ghre_ExamServices : BaseServices, IGhre_ExamServices
{
private readonly IBaseRepository _dal;
private readonly IGhre_CourseServices _ghre_CourseServices;
private readonly IGhre_CourseSceneServices _ghre_CourseSceneServices;
public Ghre_ExamServices(ICaching caching,
IGhre_CourseServices ghre_CourseServices,
IGhre_CourseSceneServices ghre_CourseSceneServices, IBaseRepository dal)
{
this._dal = dal;
base.BaseDal = dal;
base._caching = caching;
_ghre_CourseServices = ghre_CourseServices;
_ghre_CourseSceneServices = ghre_CourseSceneServices;
}
public async Task GetModuleInfo(ModuleParam param)
{
dynamic result = new ExpandoObject();
dynamic data = new ExpandoObject();
var Toolbar = new List();
Toolbar.Add(new Toolbar()
{
fnKey = "NewYN",
fnKeyValue = null,
fnTitle = "新增",
fnType = "table",
position = "left",
icon = "ghr-icon-add",
display = true
});
Toolbar.Add(new Toolbar()
{
fnKey = "Release",
fnKeyValue = null,
fnTitle = "发布",
fnType = "table",
position = "left",
icon = "ghr-publish",
display = true
});
var DT_Procedure = new DT_Procedure();
var sql = "select QueryProcedure, EditProcedure, IUDProcedure from Ghrs_Menu where MenuNo='{0}'";
sql = string.Format(sql, param.menuName, App.User.ID, param.langId);
var dt = Db.Ado.GetDataTable(sql);
if (dt.Rows.Count > 0)
{
DT_Procedure.QueryProcedure = dt.Rows[0]["QueryProcedure"].ToString();
DT_Procedure.EditProcedure = dt.Rows[0]["EditProcedure"].ToString();
DT_Procedure.IUDProcedure = dt.Rows[0]["IUDProcedure"].ToString();
}
sql = $@"SELECT PageSettingQueryId,
elementType,
field,
[dbo].[FLangKeyToValue] (Meky, {param.langId}, label)
label,
Meky,
multipleSelect,
dataType,
required,
palceholder,
dataSourceType,
dbo.FS_GetdataSourceBySet
(dataSource, APIDataSourceType, Ghrs_PageSettingQuery.APIDataSourceID)
dataSource,
sortable,
sortOrder,
defaultHidden,
ConfigIsShow,
filterable,
CAST(CASE WHEN width = '' THEN '100' ELSE width END AS INT) width,
align,
fixed,
editable,
searchable,
searchRequired,
searchColumnSeq,
multipleSearchValue,
maxTagCount,
selfDefine,
selectUI,
isPrimaryKey,
'false'
isSorted,
'false'
isHidden,
CASE
WHEN searchColumnSeq IS NULL OR searchColumnSeq = '' THEN 'false'
ELSE 'true'
END
isSearched,
SortNo,
-- searchCanOperator,
( select ParaDetailNo operator,
[dbo].[FLangKeyToValue](MKey,1,ParaDetailName) operatorDesc,
SqlFunction operatorIcon
from Ghrs_ParaDetail where ParaMasterId=13 and IsEnable=1
and ParaDetailNo in (select Value from dbo.Fs1_GHR30_SplitString2(searchCanOperator,','))
order by (select positon from dbo.Fs1_GHR30_SplitString2(searchCanOperator,',')
where value= ParaDetailNo)
FOR JSON Path ) searchOperator1,
''
searchColumnDefaultValue,
''
AppColumnType
FROM Ghrs_PageSettingQuery
WHERE PageNo = '{param.menuName}'
AND elementType NOT IN ('PageGroup')
AND IsEnable = 1
ORDER BY SortNo ASC";
sql = string.Format(sql, param.menuName, App.User.ID, param.langId);
var TableColumn = Db.Ado.SqlQuery(sql);
var SearchFormFields = Mapper.Map(TableColumn).ToANew>();
SearchFormFields.ForEach(x =>
{
if (!string.IsNullOrWhiteSpace(x.searchOperator1))
x.searchOperator = JsonConvert.DeserializeObject>(x.searchOperator1);
x.searchOperator1 = null;
});
#region DT_PageMutiMsg
var DT_PageMutiMsg = await _caching.GetAsync>("DT_PageMutiMsg");
if (DT_PageMutiMsg == null || (DT_PageMutiMsg != null && !DT_PageMutiMsg.Any()))
{
sql = $@"SELECT Langkey field,
CASE {param.langId}
WHEN 1 THEN isnull (Value01, LangValue)
WHEN 2 THEN isnull (Value02, LangValue)
WHEN 3 THEN isnull (Value03, LangValue)
WHEN 4 THEN isnull (Value04, LangValue)
WHEN 5 THEN isnull (Value05, LangValue)
WHEN 6 THEN isnull (Value06, LangValue)
WHEN 7 THEN isnull (Value07, LangValue)
WHEN 8 THEN isnull (Value08, LangValue)
WHEN 9 THEN isnull (Value09, LangValue)
WHEN 10 THEN isnull (Value10, LangValue)
END label
FROM Ghrs_LangKey
WHERE (LangKey LIKE 'GHR_Page%' OR LangKey LIKE 'GHR_Common%')
AND IsEnable = 1";
DT_PageMutiMsg = Db.Ado.SqlQuery(sql);
if (DT_PageMutiMsg.Any())
await _caching.SetAsync("DT_PageMutiMsg", DT_PageMutiMsg);
}
#endregion
data.Toolbar = Toolbar;
data.DT_Procedure = DT_Procedure;
data.SearchFormFields = SearchFormFields;
data.DT_PageMutiMsg = DT_PageMutiMsg;
result.Success = true;
result.Status = 200;
result.Data = data;
result.Message = "查询成功";
return result;
}
public async Task> QueryList(QueryBody body, string status)
{
var data = await QueryFilterPage1(body, status);
var data1 = Mapper.Map(data.result.DT_TableDataT1).ToANew>();
//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(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1);
}
public async Task> QueryFilterPage1(QueryBody filter, string status = null)
{
if (string.IsNullOrWhiteSpace(filter.orderBy))
filter.orderBy = "CreateTime DESC";
RefAsync totalCount = 0;
var query = Db.Queryable();
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(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(filter.pageNum, totalCount, filter.pageSize, list);
}
}