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 Newtonsoft.Json.Linq; using Tiobon.Core.Common; using Tiobon.Core.Model; using Newtonsoft.Json; using Tiobon.Core.Common.Helper; namespace Tiobon.Core.Services { /// /// 培训记录 (服务) /// public class Ghre_StudyRecordServices : BaseServices, IGhre_StudyRecordServices { private readonly IBaseRepository _dal; public Ghre_StudyRecordServices(ICaching caching, IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; base._caching = caching; } public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) { if (string.IsNullOrWhiteSpace(filter.orderBy)) filter.orderBy = "CreateTime1 DESC"; if (filter.pageSize == 0) filter.pageSize = 10000; var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; var sql = @$" SELECT * FROM Ghre_StudyRecord_V A"; string conditions = " WHERE 1=1 "; if (IsEnable == true) conditions += " AND IsEnable = 1"; else if (IsEnable == false) conditions += " AND IsEnable = 0"; if (!string.IsNullOrWhiteSpace(condition)) conditions += " AND " + condition; 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 (name == "Date") { var jsonParam = JsonConvert.DeserializeObject(value); conditions += $" AND (Date BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}')"; continue; } if (!string.IsNullOrWhiteSpace(value)) conditions = DealConditions(conditions, name, value); } sql += conditions; countSql += conditions; int total = await Db.Ado.GetIntAsync(countSql); sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; sql += ") A ) B ) C"; sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; var entitys = await Db.Ado.SqlQueryAsync(sql); entitys.ForEach(entity => { if (!string.IsNullOrWhiteSpace(entity.Indate)) entity.Indate = DateTimeHelper.ConvertToDayString(entity.Indate); }); return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); } #region 获取ESS查询条件 public async Task> QueryESSSearchFields(QueryBody body) { var entity = new CoursePublicSearch(); string sql = @"SELECT Langkey field, CASE {2} 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 IsEnable = 1 AND (LangKey LIKE 'GHR_Page%' OR LangKey LIKE 'GHR_Common%')"; sql = string.Format(sql, body.menuName, App.User.ID, body.langId); entity.DT_PageMutiMsg = await Db.Ado.SqlQueryAsync(sql); entity.SearchFields.Add(new CoursePublicSearchField() { label = "课程编号/名称", field = "CourseNoOrName", elementType = "Input", editable = true, required = false, multipleSelect = false, }); entity.SearchFields.Add(new CoursePublicSearchField() { label = "课程分类", field = "CourseClassId", elementType = "ApiSelect", dataSource = "CommonList_TrainingCourseClass", editable = true, required = false, multipleSelect = false, }); entity.SearchFields.Add(new CoursePublicSearchField() { label = "课程场景", field = "CourseSceneId", elementType = "ApiSelect", dataSource = "CommonList_TrainingCourseScene", editable = true, required = false, multipleSelect = false, }); entity.SearchFields.Add(new CoursePublicSearchField() { label = "课程状态", field = "CourseStatus", elementType = "ApiSelect", dataSource = "TBParaDetail_Train_CourseIsOpen", editable = true, required = false, multipleSelect = false, }); entity.SearchFields.Add(new CoursePublicSearchField() { label = "学习状态", field = "StudyStatus", elementType = "ApiSelect", dataSource = "TBParaDetail_Train_CourseIsOpen", editable = true, required = false, multipleSelect = false, }); return ServiceResult.OprateSuccess("", entity); } #endregion #region 获取我的学习 /// /// /// /// /// /// /// public async Task> QueryESS(QueryBody filter, string condition, bool? IsEnable = true) { if (string.IsNullOrWhiteSpace(filter.orderBy)) filter.orderBy = "JoinTime DESC"; if (filter.pageSize == 0) filter.pageSize = 10000; var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; var sql = @$" SELECT A.Id, A.StaffId, A.CourseSnapId, A.CourseId, A.CoverUrl, A.UseDefaultCoverImage, A.DefaultCoverImageName, A.CourseName, A.StandardHour, A.CreditPoints, A.BeginTime CourseBeginDate, A.EndTime CourseEndDate, A.ExamDate, A.ExamBeginDate, A.ExamEndDate, A.JoinTime, A.CourseClassId, A.CourseSceneId, A.CourseType FROM Ghre_StudyRecord_V A"; string conditions = $" WHERE UserId={App.User.ID} "; if (IsEnable == true) conditions += " AND IsEnable = 1"; else if (IsEnable == false) conditions += " AND IsEnable = 0"; if (!string.IsNullOrWhiteSpace(condition)) conditions += " AND " + condition; 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 (name == "CourseNoOrName") { var jsonParam = JsonConvert.DeserializeObject(value); conditions += $" AND CourseName LIKE '%{jsonParam.columnValue}%'"; continue; } if (name == "CourseClassId") { var jsonParam = JsonConvert.DeserializeObject(value); conditions += $" AND CourseClassId LIKE '%{jsonParam.columnValue}%' "; 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; case "GreaterOrEqual"://大于等于 conditions += $" AND {name} >='{jsonParam.columnValue}'"; break; case "Greater"://大于 conditions += $" AND {name} >'{jsonParam.columnValue}'"; break; case "LessOrEqual"://小于等于 conditions += $" AND {name} <='{jsonParam.columnValue}'"; break; case "Less"://小于 conditions += $" AND {name} <'{jsonParam.columnValue}'"; break; default: break; } } } sql += conditions; countSql += conditions; int total = await Db.Ado.GetIntAsync(countSql); sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; sql += ") A ) B ) C"; sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; var entitys = await Db.Ado.SqlQueryAsync(sql); return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); } #endregion } }