diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index c5a53f4a..83062ad1 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -5,6 +5,7 @@ using System.Linq.Expressions; using AgileObjects.AgileMapper; using Microsoft.AspNetCore.Http; using Newtonsoft.Json.Linq; +using NPOI.Util; using SqlSugar; using Tiobon.Core.Common; using Tiobon.Core.Common.Caches; @@ -679,6 +680,8 @@ public class BaseServices : IBaseServ public virtual async Task> QueryFilterPage(QueryBody body) { + if (string.IsNullOrWhiteSpace(body.orderBy)) + body.orderBy = "CreateTime DESC"; var data = await BaseDal.QueryFilterPage(body); return new ServicePageResult(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, Mapper.Map(data.result.DT_TableDataT1).ToANew>()); @@ -1012,5 +1015,38 @@ public class BaseServices : IBaseServ } #endregion + public string GetQueryString(string sqlSelect, int? currentPage = null, int? pageSize = null, string sortField = null, string sortDirection = null) + { + string queryString = string.Empty; + if (string.IsNullOrEmpty(sortField)) + queryString = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY ROW_ID) NUM FROM (SELECT * FROM (" + sqlSelect + " WHERE 1=1 "; + else + { + if (!string.IsNullOrEmpty(sortDirection)) + queryString = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + sortField + " " + sortDirection + ") NUM FROM (SELECT * FROM (" + sqlSelect + " "; + else + queryString = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + sortField + " DESC) NUM FROM (SELECT * FROM (" + sqlSelect + " "; + } + queryString += ") A ) B ) C"; + if (currentPage != null && pageSize != null) + queryString += " WHERE NUM <= " + currentPage * pageSize + " AND NUM >" + (currentPage - 1) * pageSize; + return queryString; + } + + //public int GetTotalCount(string sqlSelect) + //{ + // string sql = string.Empty; + + // try + // { + // int count = Convert.ToInt32(DBHelper.ExecuteScalar(sql)); + // return count; + // } + // catch (Exception Ex) + // { + // throw; + // } + //} + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs index 1617fa15..5c3b6b2c 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs @@ -120,6 +120,8 @@ namespace Tiobon.Core.Services 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)) @@ -576,6 +578,9 @@ namespace Tiobon.Core.Services public async Task> Insert1(DefaultGhre_ExamPaperPageData insertModel) { + + ValidForm(insertModel); + await Db.Ado.BeginTranAsync(); try @@ -623,6 +628,9 @@ namespace Tiobon.Core.Services public async Task Update1(long id, DefaultGhre_ExamPaperPageData insertModel) { + + ValidForm(insertModel); + await Db.Ado.BeginTranAsync(); try @@ -707,5 +715,16 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); return ServiceResult.OprateSuccess("停用成功!"); } + + public static void ValidForm(DefaultGhre_ExamPaperPageData model) + { + if (model.baseData.PassScore == 0) + throw new Exception("及格分需大于0!"); + if (model.baseData.PassScore >= model.baseData.TotalScore) + throw new Exception("及格分需小于卷面总分!"); + + if (model.baseData.AnswerTime <= 0) + throw new Exception("答题时间需大于0!"); + } } } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 20ea091d..b1e8e6c8 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -1,6 +1,7 @@  using System.Data; using AgileObjects.AgileMapper; +using MathNet.Numerics.Distributions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SqlSugar; @@ -37,7 +38,7 @@ public class Ghre_QuestionServices : BaseServices> QueryFilterPage(QueryBody filter) + public async Task> QueryFilterPage1(QueryBody filter) { //var data1 = await BaseDal.QueryFilterPage(body); @@ -154,6 +155,69 @@ public class Ghre_QuestionServices : BaseServices(filter.pageNum, data1.result.DT_TablePageInfoT1.TotalCount, filter.pageSize, data); } + public override async Task> QueryFilterPage(QueryBody filter) + { + + RefAsync totalCount = 0; + string sql = @"SELECT * + FROM (SELECT A.*, + B.CourseName, + C.Id CourseTypeId, + C.ClassName CourseType + FROM Ghre_Question 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)) + filter.orderBy = "CreateTime DESC"; + + 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; + var data = await Db.SqlQueryable(sql) + .OrderBy(filter.orderBy) + .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); + + return new ServicePageResult(filter.pageNum, totalCount, filter.pageSize, data); + } /// ///