From 7c0e628fd1517b076491366b7c74adac4e52dd44 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Tue, 2 Jul 2024 19:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=81=9C=E7=94=A8=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E5=81=9C=E7=94=A8=E8=AF=BE=E7=A8=8B=EF=BC=9B=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E5=90=AF=E7=94=A8=E8=AF=95=E5=8D=B7=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E8=AF=95=E5=8D=B7=E5=85=B3=E8=81=94=E7=9A=84?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=98=AF=E5=90=A6=20=E5=B7=B2=E5=81=9C?= =?UTF-8?q?=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Ghre/Ghre_CourseController.cs | 12 ++- .../Controllers/Ghre/Ghre_ExamController.cs | 7 ++ .../Ghre/Ghre_ExamPaperController.cs | 7 ++ Tiobon.Core.Common/Attribute/QueryFilter.cs | 1 + .../Ghre/IGhre_CourseServices.cs | 4 +- .../Ghre/IGhre_ExamPaperServices.cs | 4 +- .../Ghre/IGhre_ExamServices.cs | 2 + Tiobon.Core.Services/BASE/BaseServices.cs | 9 ++- Tiobon.Core.Services/CommonServices.cs | 6 ++ .../Ghre/Ghre_CourseServices.cs | 60 +++++++++++++-- .../Ghre/Ghre_ExamPaperServices.cs | 63 +++++++++++++++- .../Ghre/Ghre_ExamServices.cs | 73 ++++++++++++++++++- .../Ghre/Ghre_QuestionServices.cs | 2 +- 13 files changed, 232 insertions(+), 18 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs index e329fa5a..f27f3c09 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs @@ -1,4 +1,6 @@ -namespace Tiobon.Core.Api.Controllers; +using StackExchange.Profiling.Data; + +namespace Tiobon.Core.Api.Controllers; /// /// 课程(Controller) @@ -22,7 +24,7 @@ public class Ghre_CourseController : BaseController> QueryList(string status, [FromBody] QueryBody body) { - return await _service.QueryList(body, status); + return await _service.QueryList(body, status, null); } [HttpPost, Route("QueryDeptID/{StaffID}")] @@ -60,4 +62,10 @@ public class Ghre_CourseController : BaseController> ExportExcel([FromBody] QueryExport body, string status) + { + return await _service.ExportExcel(body, status); + } + } \ No newline at end of file diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs index f7df67a9..84b59eb0 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs @@ -167,4 +167,11 @@ public class Ghre_ExamController : BaseController> ExportExcel([FromBody] QueryExport body, string status) + { + return await _service.ExportExcel(body, status); + } + } \ No newline at end of file diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs index 021f8e1e..e40bfcf9 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs @@ -105,4 +105,11 @@ public class Ghre_ExamPaperController : BaseController> ExportExcel([FromBody] QueryExport body, string status) + { + return await _service.ExportExcel(body, status); + } } \ No newline at end of file diff --git a/Tiobon.Core.Common/Attribute/QueryFilter.cs b/Tiobon.Core.Common/Attribute/QueryFilter.cs index 80539d8f..84eab1e3 100644 --- a/Tiobon.Core.Common/Attribute/QueryFilter.cs +++ b/Tiobon.Core.Common/Attribute/QueryFilter.cs @@ -144,6 +144,7 @@ public class QueryExportField public List ExFields { get; set; } public string IsTitle { get; set; } public string TitleName { get; set; } + public List SelectRowKeys { get; set; } } diff --git a/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs index 6f8e3ce3..8ebbfa66 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs @@ -11,12 +11,14 @@ namespace Tiobon.Core.IServices public interface IGhre_CourseServices : IBaseServices { - Task> QueryList(QueryBody filter, string status); + Task> QueryList(QueryBody filter, string status, List ids); Task> QueryDeptID(int StaffID); Task> QueryTeacher(long? linkId); Task UpdateStatus(long[] ids, string status); Task> GetSelectAsync(long? linkId, string keyWords); + Task> ExportExcel(QueryExport body, string status); + } } \ No newline at end of file diff --git a/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs index cc991fef..8a3b9ee8 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs @@ -19,8 +19,10 @@ namespace Tiobon.Core.IServices Task UpdateStatus(long[] ids, string status); - Task> QueryList(QueryBody body, string status); + Task> QueryList(QueryBody body, string status, List ids = null); Task> GetSelectAsync(long? linkId, string KeyWords); + + Task> ExportExcel(QueryExport body, string status); } } \ No newline at end of file diff --git a/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs index fdf563b1..37492b94 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs @@ -30,5 +30,7 @@ namespace Tiobon.Core.IServices Task> QueryMessageLog(long id); Task InsertMessageLog(Ghre_ExamMessageLogDto insert); + + Task> ExportExcel(QueryExport body, string status); } } \ No newline at end of file diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 62935ca0..1d52dfb6 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -819,14 +819,19 @@ public class BaseServices : IBaseServ filter.pageNum = 1; filter.pageSize = 1000000; filter.langId = body.langId; - var data = await QueryFilterPage(filter); + + var condition = "1=1"; + if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any()) + condition += $" AND Id IN({string.Join(",", body.exportSet.SelectRowKeys)})"; + + var data = await QueryFilterPage(filter, condition); string sql = $@"SELECT * FROM Ghrs_PageSettingQuery WHERE IsEnable = 1 AND PageNo = '{body.menuName}' - AND defaultHidden = 'false' + AND (defaultHidden = 'false' OR defaultHidden is null) ORDER BY SortNo ASC"; var columns = await Db.Ado.SqlQueryAsync(sql); diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index fd9b36f9..ade0732a 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -901,6 +901,7 @@ public partial class CommonServices : BaseServices>, ICommon icon = "ghr-preview", position = "left" }); + result.DT_Procedure.ExportExcel = "/api/Ghre_ExamPaper/ExportExcel/Draft"; break; case "F_ExamPaperReleased": @@ -935,6 +936,7 @@ public partial class CommonServices : BaseServices>, ICommon position = "left" }); + result.DT_Procedure.ExportExcel = "/api/Ghre_ExamPaper/ExportExcel/Released"; break; case "F_ExamPaperDisabled": toolbar = result.JM_PageControlT1.Toolbar.Where(x => x.fnKey == "DetailYN").FirstOrDefault(); @@ -958,6 +960,7 @@ public partial class CommonServices : BaseServices>, ICommon icon = "ghr-preview", position = "left" }); + result.DT_Procedure.ExportExcel = "/api/Ghre_ExamPaper/ExportExcel/Disabled"; break; case "F_Training_CoursewWare": toolbar = result.JM_PageControlT1.Toolbar.Where(x => x.fnKey == "NewYN").FirstOrDefault(); @@ -1001,6 +1004,7 @@ public partial class CommonServices : BaseServices>, ICommon if (toolbar != null) { toolbar.fnKey = "TBD3YN"; } toolbar = result.JM_PageControlT1.Toolbar.Where(x => x.fnKey == "DetailYN").FirstOrDefault(); if (toolbar != null) { toolbar.fnKey = "TBD5YN"; } + result.DT_Procedure.ExportExcel = "/api/Ghre_Course/ExportExcel/Draft"; break; case "F_Training_Course_Released": @@ -1022,6 +1026,7 @@ public partial class CommonServices : BaseServices>, ICommon icon = "ghr-icon-stop", position = "left" }); + result.DT_Procedure.ExportExcel = "/api/Ghre_Course/ExportExcel/Released"; break; case "F_Training_Course_Disabled": @@ -1035,6 +1040,7 @@ public partial class CommonServices : BaseServices>, ICommon icon = "ghr-icon-stop", position = "left" }); + result.DT_Procedure.ExportExcel = "/api/Ghre_Course/ExportExcel/Disabled"; break; diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index 5bc906e2..817e202f 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -9,15 +9,11 @@ using Tiobon.Core.Model; using Newtonsoft.Json.Linq; using SqlSugar; using Newtonsoft.Json; -using MySqlX.XDevAPI.Common; using System.Data; -using System.Dynamic; -using Tiobon.Core.Common.DB.Dapper.Extensions; -using AgileObjects.AgileMapper; using Microsoft.AspNetCore.Http; using Tiobon.Core.Common.UserManager; using Tiobon.Core.Common.Helper; -using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; +using Org.BouncyCastle.Crypto; namespace Tiobon.Core.Services; @@ -125,7 +121,7 @@ public class Ghre_CourseServices : BaseServices> QueryList(QueryBody filter, string status) + public async Task> QueryList(QueryBody filter, string status, List ids) { RefAsync totalCount = 0; string sql = @"SELECT * @@ -161,6 +157,9 @@ public class Ghre_CourseServices : BaseServices() { Success = true, Message = "查询成功", Data = result, }; } #endregion + + + public async Task> ExportExcel(QueryExport body, string status) + { + QueryBody filter = new QueryBody(); + filter.pageNum = 1; + filter.pageSize = 1000000; + filter.langId = body.langId; + + var condition = "1=1"; + var ids = new List(); + if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any()) + ids = body.exportSet.SelectRowKeys; + + var data = await QueryList(filter, status, ids); + + + string sql = $@"SELECT * + FROM Ghrs_PageSettingQuery + WHERE IsEnable = 1 + AND PageNo = '{body.menuName}' + AND (defaultHidden = 'false' or defaultHidden is null) + ORDER BY SortNo ASC"; + + var columns = await Db.Ado.SqlQueryAsync(sql); + + var fieldDescs = new Dictionary(); + if (body.exportSet.ExFields.Any()) + body.exportSet.ExFields.ForEach(x => + { + if (columns.Any(o => o.field == x)) + fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label); + }); + else + fieldDescs = columns.ToDictionary(item => item.field, item => item.label); + var dt = ToDataTable(data.result.DT_TableDataT1, fieldDescs, null); + // 获取所有列名 + var dtColumns = dt.Columns; + + var id = SnowFlakeSingle.instance.getID(); + var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; + var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + path = path + body.exportSet.TitleName + ".xlsx"; + NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path); + return ServiceResult.OprateSuccess("导出成功", path); + } } \ 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 4272451b..5ea37777 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs @@ -3,14 +3,12 @@ using System.Data; using System.Net; using System.Text.RegularExpressions; using AgileObjects.AgileMapper; -using MathNet.Numerics.Distributions; using Microsoft.AspNetCore.Http; using MongoDB.Driver.Linq; using Newtonsoft.Json.Linq; using SqlSugar; using Tiobon.Core.Common; using Tiobon.Core.Common.Caches; -using Tiobon.Core.Common.DB.Dapper.Extensions; using Tiobon.Core.Common.Helper; using Tiobon.Core.Common.UserManager; using Tiobon.Core.IRepository.Base; @@ -104,9 +102,13 @@ public class Ghre_ExamPaperServices : BaseServices(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1); //} - public async Task> QueryList(QueryBody body, string status) + public async Task> QueryList(QueryBody body, string status, List ids = null) { - var data = await base.QueryFilterPage(body, $"Status='{status}'"); + var condition = $"Status='{status}'"; + if (ids != null && ids.Any()) + condition += $" AND Id IN({string.Join(",", ids)})"; + + var data = await base.QueryFilterPage(body, condition); var data1 = Mapper.Map(data.result.DT_TableDataT1).ToANew>(); var linkIds = data1.Where(x => x.LinkId != null).Select(x => x.LinkId.Value).Distinct().ToList(); @@ -136,6 +138,53 @@ public class Ghre_ExamPaperServices : BaseServices(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1); } + public async Task> ExportExcel(QueryExport body, string status) + { + QueryBody filter = new QueryBody(); + filter.pageNum = 1; + filter.pageSize = 1000000; + filter.langId = body.langId; + + var ids = new List(); + if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any()) + ids = body.exportSet.SelectRowKeys; + + var data = await QueryList(filter, status, ids); + + + string sql = $@"SELECT * + FROM Ghrs_PageSettingQuery + WHERE IsEnable = 1 + AND PageNo = '{body.menuName}' + AND (defaultHidden = 'false' or defaultHidden is null) + ORDER BY SortNo ASC"; + + var columns = await Db.Ado.SqlQueryAsync(sql); + + var fieldDescs = new Dictionary(); + if (body.exportSet.ExFields.Any()) + body.exportSet.ExFields.ForEach(x => + { + if (columns.Any(o => o.field == x)) + fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label); + }); + else + fieldDescs = columns.ToDictionary(item => item.field, item => item.label); + var dt = ToDataTable(data.result.DT_TableDataT1, fieldDescs, null); + // 获取所有列名 + var dtColumns = dt.Columns; + + var id = SnowFlakeSingle.instance.getID(); + var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; + var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + path = path + body.exportSet.TitleName + ".xlsx"; + NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path); + return ServiceResult.OprateSuccess("导出成功", path); + } + //public async Task> QueryFilterPage1(QueryBody filter, string status = null) //{ // if (string.IsNullOrWhiteSpace(filter.orderBy)) @@ -774,6 +823,12 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); if (status == "Released" && entity.Status != "Released") { + if (entity.LinkType == "CourseId" && !await _ghre_CourseServices.AnyAsync(entity.LinkId)) + return ServiceResult.OprateFailed($"试卷【{entity.PaperName}({entity.PaperNo})】,关联的课程,已被删除,请重新维护数据!"); + + if (entity.LinkType == "CourseSceneId" && !await _ghre_CourseSceneServices.AnyAsync(entity.LinkId)) + return ServiceResult.OprateFailed($"试卷【{entity.PaperName}({entity.PaperNo})】,关联的课程场景,已被删除,请重新维护数据!"); + string sql = @$"SELECT COUNT(0) FROM Ghre_ExamPaperQuestion A JOIN Ghre_Question B ON A.QuestionId = B.Id and B.IsEnable = 0 diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs index 7ce0d3b7..9973ff4a 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs @@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Http; using Tiobon.Core.Common.UserManager; using MongoDB.Driver.Linq; using Tiobon.Core.Common.DB.Dapper; +using Tiobon.Core.Common.Helper; namespace Tiobon.Core.Services; @@ -393,6 +394,25 @@ public class Ghre_ExamServices : BaseServices> QueryFilterPage1(QueryBody filter, string status = null) + public async Task> QueryFilterPage1(QueryBody filter, string status = null, List ids = null) { RefAsync totalCount = 0; string sql = @"SELECT * @@ -520,6 +540,9 @@ public class Ghre_ExamServices : BaseServices> ExportExcel(QueryExport body, string status) + { + QueryBody filter = new QueryBody(); + filter.pageNum = 1; + filter.pageSize = 1000000; + filter.langId = body.langId; + + var ids = new List(); + if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any()) + ids = body.exportSet.SelectRowKeys; + + var data = await QueryFilterPage1(filter, status, ids); + + + string sql = $@"SELECT * + FROM Ghrs_PageSettingQuery + WHERE IsEnable = 1 + AND PageNo = '{body.menuName}' + AND (defaultHidden = 'false' or defaultHidden is null) + ORDER BY SortNo ASC"; + + var columns = await Db.Ado.SqlQueryAsync(sql); + + var fieldDescs = new Dictionary(); + if (body.exportSet.ExFields.Any()) + body.exportSet.ExFields.ForEach(x => + { + if (columns.Any(o => o.field == x)) + fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label); + }); + else + fieldDescs = columns.ToDictionary(item => item.field, item => item.label); + var dt = ToDataTable(data.result.DT_TableDataT1, fieldDescs, null); + // 获取所有列名 + var dtColumns = dt.Columns; + + var id = SnowFlakeSingle.instance.getID(); + var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; + var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + path = path + body.exportSet.TitleName + ".xlsx"; + NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path); + return ServiceResult.OprateSuccess("导出成功", path); + } + + public async Task> QueryDefault(long Id) { var input = new DefaultGhre_ExamInput(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 30dcdb1c..6ef47aa7 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -158,7 +158,7 @@ public class Ghre_QuestionServices : BaseServices(filter.pageNum, data1.result.DT_TablePageInfoT1.TotalCount, filter.pageSize, data); } - public override async Task> QueryFilterPage(QueryBody filter) + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) { RefAsync totalCount = 0;