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 Tiobon.Core.Common; using Tiobon.Core.Model; using Newtonsoft.Json.Linq; using SqlSugar; using Newtonsoft.Json; using MySqlX.XDevAPI.Common; using System.Data; namespace Tiobon.Core.Services; /// /// 课程 (服务) /// public class Ghre_CourseServices : BaseServices, IGhre_CourseServices { private readonly IBaseRepository _dal; private IGhre_CourseClassServices _ghre_CourseClassServices; public Ghre_CourseServices(IBaseRepository dal, ICaching caching, IGhre_CourseClassServices ghre_CourseClassServices) { this._dal = dal; base.BaseDal = dal; _ghre_CourseClassServices = ghre_CourseClassServices; base._caching = caching; } public override async Task> QueryFilterPage(QueryBody filter) { RefAsync totalCount = 0; string sql = @"SELECT * FROM (SELECT A.*, B.ClassName CourseClassName, C.ClassName CourseClassName2, D.SceneName CourseSceneName, E.CourseWareName, F.StaffName ManagerStaffName, G.UserName CreateName, G.UserName UpdateName, CASE A.InOrOut WHEN 'In' THEN F.StaffName WHEN 'Out' THEN J.TeacherName END TeacherName FROM Ghre_Course A LEFT JOIN Ghre_CourseClass B ON A.CourseClassId = B.Id LEFT JOIN Ghre_CourseClass C ON A.CourseClassId2 = C.Id LEFT JOIN Ghre_CourseScene D ON A.CourseSceneId = D.Id LEFT JOIN Ghre_CourseWare E ON A.CourseWareId = E.Id LEFT JOIN Ghra_Staff F ON A.ManagerId = F.StaffID LEFT JOIN Ghrs_User G ON A.CreateBy = G.UserId LEFT JOIN Ghrs_User H ON A.UpdateBy = H.UserId LEFT JOIN Ghra_Staff I ON A.TeacherId = I.StaffID LEFT JOIN Ghre_Teacher J ON A.SchoolTeacherId = I.StaffID 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); data.ForEach(async x => { x.ChargeMethodLabel = await GetParaLabel("CourseChargeMethod", x.ChargeMethod); x.InOrOutLabel = await GetParaLabel("CourseInOrOut", x.InOrOut); x.IsOPenLabel = x.IsOPen == true ? "是" : "否"; }); return new ServicePageResult(filter.pageNum, totalCount, filter.pageSize, data); } public async Task> QueryList(QueryBody filter, string status) { RefAsync totalCount = 0; string sql = @"SELECT * FROM (SELECT A.*, B.ClassName CourseClassName, C.ClassName CourseClassName2, D.SceneName CourseSceneName, E.CourseWareName, F.StaffName ManagerStaffName, G.UserName CreateName, G.UserName UpdateName, CASE A.InOrOut WHEN 'In' THEN F.StaffName WHEN 'Out' THEN J.TeacherName END TeacherName FROM Ghre_Course A LEFT JOIN Ghre_CourseClass B ON A.CourseClassId = B.Id LEFT JOIN Ghre_CourseClass C ON A.CourseClassId2 = C.Id LEFT JOIN Ghre_CourseScene D ON A.CourseSceneId = D.Id LEFT JOIN Ghre_CourseWare E ON A.CourseWareId = E.Id LEFT JOIN Ghra_Staff F ON A.ManagerId = F.StaffID LEFT JOIN Ghrs_User G ON A.CreateBy = G.UserId LEFT JOIN Ghrs_User H ON A.UpdateBy = H.UserId LEFT JOIN Ghra_Staff I ON A.TeacherId = I.StaffID LEFT JOIN Ghre_Teacher J ON A.SchoolTeacherId = I.StaffID WHERE A.IsEnable = 1) A"; if (string.IsNullOrWhiteSpace(filter.orderBy)) filter.orderBy = "CreateTime DESC"; string conditions = " WHERE 1=1"; if (!string.IsNullOrWhiteSpace(status)) conditions += $" AND Status ='{status}'"; 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); if (name == "CourseNoOrName") { conditions += $" AND ( CourseNo LIKE '%{jsonParam.columnValue}%' OR CourseName LIKE '%{jsonParam.columnValue}%')"; continue; } 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; sql += conditions; var data = await Db.SqlQueryable(sql) .OrderBy(filter.orderBy) .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); data.ForEach(async x => { x.ChargeMethodLabel = await GetParaLabel("CourseChargeMethod", x.ChargeMethod); x.InOrOutLabel = await GetParaLabel("CourseInOrOut", x.InOrOut); x.IsOPenLabel = x.IsOPen == true ? "是" : "否"; }); return new ServicePageResult(filter.pageNum, totalCount, filter.pageSize, data); } public async Task> QueryDeptID(int StaffID) { string sql = $"SELECT A.DeptID from Ghra_Staff A LEFT JOIN Ghro_Dept B ON A.DeptID = B.DeptID WHERE A.StaffID='{StaffID}'"; int id = await Db.Ado.GetIntAsync(sql); return ServiceResult.OprateSuccess("查询成功!", id); } public async Task> QueryTeacher(long schoolId) { var result = new CommonSelect(); JArray TableColumn = new JArray(); JArray DT_TablePageInfoT1 = new JArray(); JArray DT_TableDataT1 = new JArray(); JObject searchItem = new JObject(); JObject item; DataTable dt; string sql; searchItem = [ new JProperty("defaultHidden", true), new JProperty("field","value"), new JProperty("label","讲师ID"), ]; TableColumn.Add(searchItem); searchItem = [ new JProperty("field","label"), new JProperty("label","讲师名称"), ]; TableColumn.Add(searchItem); sql = $"SELECT Id, TeacherNo , TeacherName FROM Ghre_Teacher WHERE IsEnable=1 AND SchoolId ='{schoolId}'"; dt = await Db.Ado.GetDataTableAsync(sql); for (int i = 0; i < dt.Rows.Count; i++) { item = [ new JProperty("value",long.Parse(dt.Rows[i]["Id"].ToString())), new JProperty("label",dt.Rows[i]["TeacherNo"].ToString()+"-"+dt.Rows[i]["TeacherName"].ToString()) ]; DT_TableDataT1.Add(item); } item = [ new JProperty("ListMax",100), new JProperty("ListMin",10), new JProperty("PageNum",1), new JProperty("PageSize",99999), new JProperty("TotalCount",dt.Rows.Count), new JProperty("UIType","Auto") ]; DT_TablePageInfoT1.Add(item); result.JM_TableColumnT1.TableColumn = TableColumn; result.DT_TableDataT1 = DT_TableDataT1; result.DT_TablePageInfoT1 = DT_TablePageInfoT1; return new ServiceResult() { Success = true, Message = "查询成功", Data = result, }; } }