diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs index 50cd8a27..f301823f 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs @@ -73,4 +73,10 @@ public class Ghre_CourseController : BaseController> QueryPublic([FromBody] QueryBody body) + { + return await _service.QueryPublic(body); + } } \ No newline at end of file diff --git a/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs index 30f49c19..6949c157 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs @@ -22,5 +22,7 @@ namespace Tiobon.Core.IServices Task> QueryPublicSearchFields(QueryBody body); + Task> QueryPublic(QueryBody filter); + } } \ No newline at end of file diff --git a/Tiobon.Core.Model/ViewModels/Extend/CoursePublicSearchField.cs b/Tiobon.Core.Model/ViewModels/Extend/CoursePublicSearchField.cs index 38d86555..7661c50a 100644 --- a/Tiobon.Core.Model/ViewModels/Extend/CoursePublicSearchField.cs +++ b/Tiobon.Core.Model/ViewModels/Extend/CoursePublicSearchField.cs @@ -19,4 +19,23 @@ public class CoursePublicSearchField public int displayType { get; set; } public int width { get; set; } = 150; +} +public class CoursePublic +{ + public long Id { get; set; } + public string CoverUrl { get; set; } + public string placeholder { get; set; } + public bool? UseDefaultCoverImage { get; set; } + public string DefaultCoverImageName { get; set; } + public string CourseName { get; set; } + public int? StandardHour { get; set; } + public int? CreditPoints { get; set; } + + public string CourseBeginTIme { get; set; } + public string CourseEndTIme { get; set; } + public string ExamDate { get; set; } + public string ExamBeginDate { get; set; } + public string ExamEndDate { get; set; } + public string DisableBtn { get; set; } + public string BtnActionType { get; set; } = "Add"; } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index dc4d368d..ef816af2 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -473,4 +473,146 @@ public class Ghre_CourseServices : BaseServices.OprateSuccess("", entity); } #endregion + + #region 获取公开课 + public async Task> QueryPublic(QueryBody filter) + { + RefAsync totalCount = 0; + string sql = @"SELECT A.Id, + A.CoverUrl, + A.UseDefaultCoverImage, + A.DefaultCoverImageName, + A.CourseName, + A.StandardHour, + A.CreditPoints, + CONVERT (VARCHAR (10), ISNULL (A.UpdateTime, A.CreateTime), 120) + CourseBeginTIme, + CONVERT + (VARCHAR (10), + dateadd (month, +3, ISNULL (A.UpdateTime, A.CreateTime)), + 120) + CourseEndTIme, + NULL + ExamDate, + NULL + ExamBeginDate, + NULL + ExamEndDate, + 'false' + DisableBtn + FROM Ghre_Course A + WHERE A.IsOPen = 'true' AND A.IsEnable = 1"; + + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "CourseName ASC"; + + 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 (name == "Indate") + //{ + // var jsonParam = JsonConvert.DeserializeObject(value); + // conditions += $" AND (Indate BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}')"; + + // continue; + //} + //if (name == "Date") + //{ + // var jsonParam = JsonConvert.DeserializeObject(value); + // conditions += $" AND (Date BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}')"; + + // continue; + //} + //if (name == "CreditPoints") + //{ + // var jsonParam = JsonConvert.DeserializeObject(value); + + // switch (jsonParam.operationKey) + // { + // case "Include": + // sql += $" WHERE {name} LIKE '%{jsonParam.columnValue}%'"; + // break; + // case "NotInclude": + // sql += $" WHERE {name} NOT LIKE '%{jsonParam.columnValue}%'"; + // break; + // case "IsNull": + // sql += $" WHERE {name} IS NULL"; + // break; + // case "NotNull": + // sql += $" WHERE {name} IS NOT NULL"; + // break; + // case "Equal": + // sql += $" WHERE {name} ='{jsonParam.columnValue}'"; + // break; + // case "NotEqual": + // sql += $" WHERE {name} !='{jsonParam.columnValue}'"; + // break; + // case "GreaterOrEqual"://大于等于 + // sql += $" WHERE {name} >='{jsonParam.columnValue}'"; + // break; + // case "Greater"://大于 + // sql += $" WHERE {name} >'{jsonParam.columnValue}'"; + // break; + // case "LessOrEqual"://小于等于 + // sql += $" WHERE {name} <='{jsonParam.columnValue}'"; + // break; + // case "Less"://小于 + // sql += $" WHERE {name} <'{jsonParam.columnValue}'"; + // break; + // default: + // break; + // } + + // 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 (ids != null && ids.Any()) + // conditions += $" AND Id IN({string.Join(",", ids)})"; + + sql = string.Format(sql, conditions); + if (filter.pageSize == 0) + filter.pageSize = 10000; + var data = await Db.SqlQueryable(sql) + .OrderBy(filter.orderBy) + .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); + + return new ServicePageResult(filter.pageNum, totalCount, filter.pageSize, data); + } + #endregion } \ No newline at end of file