diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_RequestController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_RequestController.cs index 23204bb3..c7e89da3 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_RequestController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_RequestController.cs @@ -54,4 +54,12 @@ public class Ghre_RequestController : BaseController> ExportGroupExcel([FromBody] QueryExport filter, string type) + { + return await _service.ExportGroupExcel(filter, type); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs index 97d479cc..73f316cb 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs @@ -1,7 +1,5 @@ using Tiobon.Core.Common; -using Tiobon.Core.IServices.BASE; using Tiobon.Core.Model; -using Tiobon.Core.Model.Models; namespace Tiobon.Core.IServices; @@ -17,4 +15,6 @@ public interface IGhre_RequestServices : IBaseServices> QueryGroup(QueryBody filter, string type); Task Ushio_Sync(); + + Task> ExportGroupExcel(QueryExport body, string type); } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs b/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs index ca4b6d41..17c1343d 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs @@ -48,6 +48,7 @@ public class Ghre_PlanServices : BaseServices>(DT_TableDataT1[i].Month); //DT_TableDataT1[i].Month = await GetParaLabel("MonthSelect", DT_TableDataT1[i].Month); + DT_TableDataT1[i].InOrOut = await GetParaLabel("CourseInOrOut", DT_TableDataT1[i].InOrOut); if (DT_TableDataT1[i].Months.Any()) DT_TableDataT1[i].Months.ForEach(x => @@ -88,6 +89,9 @@ public class Ghre_PlanServices : BaseServices x.DeptID == DT_TableDataT1[i].DeptId).Select(x => x.DeptName).FirstOrDefault(); if (DT_TableDataT1[i].SchoolId.IsNotEmptyOrNull()) DT_TableDataT1[i].SchoolName = schools.Where(x => x.Id == DT_TableDataT1[i].SchoolId).Select(x => x.SchoolName).FirstOrDefault(); + + if (DT_TableDataT1[i].TrainNum != null && DT_TableDataT1[i].TrainDays != null) + DT_TableDataT1[i].TotalDays = DT_TableDataT1[i].TrainNum * DT_TableDataT1[i].TrainDays; } ModuleParam param = new ModuleParam() diff --git a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs index f5d2828f..90926f3b 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs @@ -772,4 +772,60 @@ WHERE B.IsEnable ! = A.IsEnable } #endregion + + + #region Excel导出 + public async Task> ExportGroupExcel(QueryExport body, string type) + { + QueryBody filter = new QueryBody(); + filter.pageNum = 1; + filter.pageSize = 1000000; + filter.jsonParam = body.jsonParam; + filter.langId = body.langId; + filter.menuName = body.menuName; + + 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 QueryGroup(filter, type); + + 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 = DbAccess.QueryList(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 = $"{$"/files/export/{id}/"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + path = path + body.exportSet.TitleName + ".xlsx"; + NPOIHelper.ExportExcel(dt, body.exportSet.TitleName, type == "Year" ? "培训需求统计-年度" : "培训需求统计-月度", physicsPath + path); + + var result = new ExcelData(); + result.filePath = "/Advanced" + path; + result.fileName = body.exportSet.TitleName + ".xlsx"; + return ServiceResult.OprateSuccess("导出成功", result); + } + #endregion + } \ No newline at end of file