修改excel和邮件

This commit is contained in:
2022-11-04 11:02:26 +08:00
parent fd02bc2dd5
commit 54bbfcfab2
8 changed files with 106 additions and 21 deletions
@@ -1,16 +1,75 @@
using IRaCIS.Core.Application.Helper;
using IRaCIS.Application.Interfaces;
using IRaCIS.Core.Application.Helper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IRaCIS.Core.Application.Service;
public static class ExcelExportHelper
{
//MiniExcel_Export
public static async Task<IActionResult> DataExportAsync(string code, object data, string exportFileNamePrefix, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment)
public static async Task<IActionResult> DataExportAsync(string code, object data, string exportFileNamePrefix, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService=null, Type? translateType=null)
{
//判断是否有字典翻译
if (_dictionaryService != null && translateType != null)
{
var needTranslatePropertyList = translateType.GetProperties().Where(t => t.IsDefined(typeof(DictionaryTranslateAttribute), false))
.Select(c => new { c.Name, DicParentCode = ((DictionaryTranslateAttribute?)c.GetCustomAttributes(typeof(DictionaryTranslateAttribute), false)[0])?.DicParentCode }).ToList()
;
//字典表查询出所有需要翻译的数据
var translateDataList = await _dictionaryService.GetBasicDataSelect(needTranslatePropertyList.Select(t => t.DicParentCode).ToArray());
var dic = JsonConvert.DeserializeObject<IDictionary<string, object>>(data.ToJsonStr());
foreach (var key in dic.Keys)
{
//是数组 那么找到对应的属性 进行翻译
if (dic[key].GetType().IsAssignableFrom(typeof(JArray)))
{
var newObjList = new List<object>();
var no = 1;
foreach (var item in dic[key] as JArray)
{
var itemDic = JsonConvert.DeserializeObject<IDictionary<string, object>>(item.ToJsonStr());
foreach (var needTranslateProperty in needTranslatePropertyList)
{
var beforeValue = itemDic[needTranslateProperty.Name].ToString();
itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue.ToLower()).FirstOrDefault()?.ValueCN;
}
itemDic.Add("No", no++);
newObjList.Add(itemDic);
}
dic[key] = newObjList;
}
}
data = dic;
}
var (physicalPath, fileNmae) = await FileStoreHelper.GetCommonDocPhysicalFilePathAsync(_hostEnvironment, _commonDocumentRepository, code);
@@ -56,7 +56,7 @@ public static class SendEmailHelper
//抄送
foreach (var copyToMailAddress in sMTPEmailConfig.CopyToMailAddressList)
{
//messageToSend.Cc.Add(copyToMailAddress);
messageToSend.Cc.Add(copyToMailAddress);
}
}