天益报表导出功能

This commit is contained in:
2024-08-13 16:41:01 +08:00
parent f285bd6c82
commit bb07f37a16
4 changed files with 91 additions and 4 deletions

View File

@@ -35,4 +35,19 @@ public class VisualDevModelListQueryInput : PageInputBase
/// 工序编码
/// </summary>
public string process_code { get; set; }
#region
/// <summary>
/// 数据查询api(用于报表导出)
/// </summary>
public string customDataApi { get; set; }
/// <summary>
/// 数据查询字段列名对应关系(用于报表导出)
/// </summary>
public string fieldChnRelation { get; set; }
#endregion
}

View File

@@ -1,4 +1,5 @@
using JNPF.Common.Configuration;
using System.Dynamic;
using JNPF.Common.Configuration;
using JNPF.Common.Const;
using JNPF.Common.Core.Manager;
using JNPF.Common.Core.Manager.Files;
@@ -36,6 +37,7 @@ using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Tnb.Common.Utils;
namespace JNPF.VisualDev
{
@@ -450,6 +452,69 @@ namespace JNPF.VisualDev
}
}
#region
/// <summary>
/// (天益项目添加的定制代码) 报表导出
/// </summary>
async Task<dynamic> ReportExcel(VisualDevModelListQueryInput input)
{
// 全部页面导出 限制条数
if (input.dataType == "1") input.pageSize = 9999;
dynamic reqBody = new ExpandoObject();
CancellationTokenSource Ctu = new();
reqBody.currentPage = input.currentPage;
reqBody.pageSize = input.pageSize;
reqBody.sort = input.sort;
reqBody.sidx = input.sidx;
reqBody.queryJson = input.queryJson;
reqBody.menuId = "";
reqBody.superQueryJson = "";
string respBody = HttpClientHelper.PostStreamAsync($"http://localhost:9231{input.customDataApi}", reqBody, Ctu.Token).Result;
JObject respBodyObj = JObject.Parse(respBody.ToString());
JObject respBodyData = JObject.Parse(respBodyObj["data"].ToString());
JArray respBodyList = JArray.Parse(respBodyData["list"].ToString());
if (respBodyList.Count == 0)
return null;
JObject fieldChnRelationObj = JObject.Parse(input.fieldChnRelation);
// 字段列名对应关系
Dictionary<string, string> fieldChnRelation = new Dictionary<string, string>();
foreach (JProperty jProperty in fieldChnRelationObj.Properties())
fieldChnRelation.Add(jProperty.Name, jProperty.Value.ToString());
// 拼列名
List<FieldsModel> AllFieldsModel = new List<FieldsModel>();
JObject firstRow = respBodyList[0] as JObject;
foreach (JProperty jProperty in firstRow.Properties())
{
if (!fieldChnRelation.ContainsKey(jProperty.Name))
continue;
FieldsModel fieldsModel = new FieldsModel();
ConfigModel configModel = new ConfigModel();
configModel.label = fieldChnRelation[jProperty.Name];
fieldsModel.__config__ = configModel;
fieldsModel.__vModel__ = jProperty.Name;
AllFieldsModel.Add(fieldsModel);
}
// 拼值
var resultList = new List<Dictionary<string, object>>();
foreach (JObject row in respBodyList)
{
Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
foreach (JProperty jProperty in firstRow.Properties())
{
keyValuePairs.Add(jProperty.Name, jProperty.Value);
}
resultList.Add(keyValuePairs);
}
var excelName = string.Format("表单信息{0}", DateTime.Now.ToString("yyyyMMddHHmmssf"));
_cacheManager.Set(excelName + ".xls", string.Empty);
return await ExcelCreateModel(AllFieldsModel, resultList, input.selectKey, excelName);
}
#endregion
/// <summary>
/// 导出.
/// </summary>
@@ -459,6 +524,12 @@ namespace JNPF.VisualDev
[HttpPost("{modelId}/Actions/Export")]
public async Task<dynamic> Export(string modelId, [FromBody] VisualDevModelListQueryInput input)
{
#region
if (!string.IsNullOrEmpty(input.customDataApi))
return await ReportExcel(input);
#endregion
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(modelId, true);
if (input.dataType == "1") input.pageSize = 99999999;
PageResult<Dictionary<string, object>>? pageList = await _runService.GetListResult(templateEntity, input);