培训需求统计新增导出

master
xiaochanghai 3 months ago
parent 28fa18724d
commit 5394b5472a
  1. 8
      Tiobon.Core.Api/Controllers/Ghre/Ghre_RequestController.cs
  2. 4
      Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs
  3. 4
      Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs
  4. 56
      Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs

@ -54,4 +54,12 @@ public class Ghre_RequestController : BaseController<IGhre_RequestServices, Ghre
return await _service.QueryGroup(filter, type);
}
#endregion
#region 新增
[HttpPost("ExportExcel/{type}")]
public async Task<ServiceResult<ExcelData>> ExportGroupExcel([FromBody] QueryExport filter, string type)
{
return await _service.ExportGroupExcel(filter, type);
}
#endregion
}

@ -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<Ghre_Request, Ghre_Reques
Task<ServicePageResult<Ghre_RequestDto>> QueryGroup(QueryBody filter, string type);
Task Ushio_Sync();
Task<ServiceResult<ExcelData>> ExportGroupExcel(QueryExport body, string type);
}

@ -48,6 +48,7 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
if (DT_TableDataT1[i].Month.IsNotEmptyOrNull())
DT_TableDataT1[i].Months = JsonHelper.JsonToObj<List<string>>(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<Ghre_Plan, Ghre_PlanDto, InsertGhr
DT_TableDataT1[i].DeptName = depts.Where(x => 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()

@ -772,4 +772,60 @@ WHERE B.IsEnable ! = A.IsEnable
}
#endregion
#region Excel导出
public async Task<ServiceResult<ExcelData>> 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<QueryExportColumn>(sql);
var fieldDescs = new Dictionary<string, string>();
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<ExcelData>.OprateSuccess("导出成功", result);
}
#endregion
}
Loading…
Cancel
Save