diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 34d8c3ac..3ad4ccfb 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -189,7 +189,7 @@ public class BaseServices : IBaseServ sql = @$"SELECT field fnKey, [dbo].[FLangKeyToValue] (mkey, {body.langId}, label) fnTitle, icon FROM Ghrs_PageSettingEdit WHERE IsEnable = 1 AND pageNo = '{body.menuName}' AND elementType = 'FnKey'"; - var toolbars = await Db.Ado.SqlQueryAsync(sql); + var toolbars = await Db.Ado.SqlQueryAsync(sql); JM_PageFormActionsT1.Toolbar = toolbars; #endregion @@ -1382,6 +1382,10 @@ public class BaseServices : IBaseServ } return conditions; } + public string DealConditions1(string conditions, string name, string value) + { + return DealConditions(conditions, "A." + name, value); + } #endregion public string GetQueryString(string sqlSelect, int? currentPage = null, int? pageSize = null, string sortField = null, string sortDirection = null) diff --git a/Tiobon.Core.Services/Ghre/Ghre_TeacherChangeServices.cs b/Tiobon.Core.Services/Ghre/Ghre_TeacherChangeServices.cs index 39d4b419..cc4ddb23 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_TeacherChangeServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_TeacherChangeServices.cs @@ -11,6 +11,9 @@ using Tiobon.Core.Common; using Tiobon.Core.Model; using AgileObjects.AgileMapper; using Tiobon.Core.Common.Helper; +using Newtonsoft.Json.Linq; +using MathNet.Numerics.Distributions; +using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Tiobon.Core.Services; @@ -39,17 +42,63 @@ public class Ghre_TeacherChangeServices : BaseServices> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) { - var result = await base.QueryFilterPage(filter, condition, IsEnable); - var data = result.result.DT_TableDataT1; + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "CreateTime1 DESC"; + + if (filter.pageSize == 0) + filter.pageSize = 10000; + + var sql = @$"SELECT * FROM (SELECT A.*, + ISNULL ((SELECT CASE WHEN {filter.langId} = 1 THEN UserName ELSE UserEname END + FROM Ghrs_User B + WHERE B.UserId = A.CreateBy), + '') CreateDataInfo, + ISNULL ((SELECT CASE WHEN {filter.langId} = 1 THEN UserName ELSE UserEname END + FROM Ghrs_User B + WHERE B.UserId = A.UpdateBy), + '') UpdateDataInfo, + ISNULL (A.UpdateTime, A.CreateTime) CreateTime1, + ISNULL (C.SchoolName, D.DeptName) DeptOrSchoolName + FROM Ghre_TeacherChange A + LEFT JOIN Ghre_Teacher B ON A.TeacherId = B.Id + LEFT JOIN Ghre_School C ON B.SchoolId = C.Id + LEFT JOIN Ghro_Dept D ON B.DeptID = D.DeptID) A"; + + 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)) + conditions = DealConditions(condition, name, value); + } + + if (IsEnable == true) + sql += " WHERE IsEnable = 1"; + else if (IsEnable == false) + sql += " WHERE IsEnable = 0"; + + if (!string.IsNullOrWhiteSpace(condition)) + conditions += " AND " + condition; + + int total = 0; + var data = Db.SqlQueryable(sql) + .Where(conditions) + .OrderBy(filter.orderBy) + .ToPageList(filter.pageNum, filter.pageSize, ref total); var teacherIds = data.Where(x => x.TeacherId != null).Select(x => x.TeacherId).Distinct().ToList(); var teachers = await Db.Queryable().Where(x => teacherIds.Contains(x.Id)).Select(x => new { x.Id, x.SchoolId, x.DeptID, x.TeacherType, TeacherName = x.TeacherName + " (" + x.TeacherNo + ")" }).ToListAsync(); - var schoolIds = teachers.Where(x => x.SchoolId != null).Select(x => x.SchoolId.Value).Distinct().ToList(); - var deptIDs = teachers.Where(x => x.DeptID != null).Select(x => x.DeptID).Distinct().ToList(); + //var schoolIds = teachers.Where(x => x.SchoolId != null).Select(x => x.SchoolId.Value).Distinct().ToList(); + //var deptIDs = teachers.Where(x => x.DeptID != null).Select(x => x.DeptID).Distinct().ToList(); - var depts = await Db.Queryable().Where(x => deptIDs.Contains(x.DeptID)).Select(x => new { x.DeptID, x.DeptName }).ToListAsync(); - var schools = await Db.Queryable().Where(x => schoolIds.Contains(x.Id)).Select(x => new { x.Id, x.SchoolName }).ToListAsync(); + //var depts = await Db.Queryable().Where(x => deptIDs.Contains(x.DeptID)).Select(x => new { x.DeptID, x.DeptName }).ToListAsync(); + //var schools = await Db.Queryable().Where(x => schoolIds.Contains(x.Id)).Select(x => new { x.Id, x.SchoolName }).ToListAsync(); data.ForEach(async x => { @@ -59,14 +108,13 @@ public class Ghre_TeacherChangeServices : BaseServices o.Id == teacher?.SchoolId)?.SchoolName : depts.FirstOrDefault(o => o.DeptID == teacher?.DeptID)?.DeptName; + //x.DeptOrSchoolName = x.TeacherType == "Out" ? schools.FirstOrDefault(o => o.Id == teacher?.SchoolId)?.SchoolName : depts.FirstOrDefault(o => o.DeptID == teacher?.DeptID)?.DeptName; x.TeacherName = teacher?.TeacherName; x.OriginChangeDate1 = DateTimeHelper.ConvertToDayString(x.OriginChangeDate); x.ChangeDate1 = DateTimeHelper.ConvertToDayString(x.ChangeDate); }); - result.result.DT_TableDataT1 = data; - return result; + return new ServicePageResult(filter.pageNum, total, filter.pageSize, data); } public override async Task> QueryForm(QueryForm body)