导表Excel处理
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
a3b69d45ae
commit
df87c56544
|
|
@ -74,14 +74,15 @@ public static class ExcelExportHelper
|
|||
{
|
||||
var itemDic = item.ConvertToDictionary();
|
||||
|
||||
//处理集合里面时间类型,根据当前语言将时间转变为字符串
|
||||
foreach (var itemValuePair in itemDic)
|
||||
{
|
||||
if (DateTime.TryParse(itemValuePair.Value?.ToString(), out DateTime result))
|
||||
{
|
||||
itemDic[itemValuePair.Key] = ExportExcelConverterDate.DateTimeInternationalToString(result);
|
||||
}
|
||||
}
|
||||
////处理集合里面时间类型,根据当前语言将时间转变为字符串
|
||||
//foreach (var itemValuePair in itemDic)
|
||||
//{
|
||||
// // 临床数据 1,1 会变成2024-01-01
|
||||
// if (itemValuePair.Value?.ToString().Length > 8 && DateTime.TryParse(itemValuePair.Value?.ToString(), out DateTime result))
|
||||
// {
|
||||
// itemDic[itemValuePair.Key] = ExportExcelConverterDate.DateTimeInternationalToString(result);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
foreach (var needTranslateProperty in needTranslatePropertyList)
|
||||
|
|
@ -242,6 +243,7 @@ public static class ExcelExportHelper
|
|||
|
||||
}
|
||||
|
||||
|
||||
public class DynamicColumnConfig
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -254,13 +256,19 @@ public static class ExcelExportHelper
|
|||
/// </summary>
|
||||
public int AutoColumnTitleRowIndex { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 模板列最后的索引
|
||||
/// </summary>
|
||||
public int TempalteLastColumnIndex { get; set; }
|
||||
|
||||
public bool IsCDISCExport { get; set; } = false;
|
||||
|
||||
//public List<string> CDISCList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 动态的列名
|
||||
/// 动态的列名 如果Id 重复,那么就按照名称填充,否则就按照Id 填充列数据
|
||||
/// </summary>
|
||||
public List<string> ColumnNameList { get; set; } = new List<string>();
|
||||
public List<ColumItem> ColumnIdNameList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 动态翻译的字典名
|
||||
|
|
@ -287,7 +295,31 @@ public static class ExcelExportHelper
|
|||
/// </summary>
|
||||
public string DynamicItemTitleName { get; set; }
|
||||
|
||||
public string DynamicItemTitleId { get; set; }
|
||||
|
||||
public List<int> RemoveColunmIndexList { get; set; } = new List<int>();
|
||||
|
||||
public class ColumItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public string CDISCCode { get; set; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is not ColumItem other) return false;
|
||||
return Id == other.Id && Name == other.Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Id, Name);
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> ColumnIdList => ColumnIdNameList == null ? new List<string>() : ColumnIdNameList.Select(t => t.Id.ToString()).ToList();
|
||||
public List<string> ColumnNameList => ColumnIdNameList == null ? new List<string>() : ColumnIdNameList.Select(t => t.Name).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -334,14 +366,14 @@ public static class ExcelExportHelper
|
|||
//var itemDic = JsonConvert.DeserializeObject<IDictionary<string, object>>(item.ToJsonNotIgnoreNull());
|
||||
var itemDic = item.ConvertToDictionary();
|
||||
|
||||
//处理集合里面时间类型,根据当前语言将时间转变为字符串
|
||||
foreach (var itemValuePair in itemDic)
|
||||
{
|
||||
if (DateTime.TryParse(itemValuePair.Value?.ToString(), out DateTime result))
|
||||
{
|
||||
itemDic[itemValuePair.Key] = ExportExcelConverterDate.DateTimeInternationalToString(result);
|
||||
}
|
||||
}
|
||||
////处理集合里面时间类型,根据当前语言将时间转变为字符串
|
||||
//foreach (var itemValuePair in itemDic)
|
||||
//{
|
||||
// if (itemValuePair.Value?.ToString().Length > 8 && DateTime.TryParse(itemValuePair.Value?.ToString(), out DateTime result))
|
||||
// {
|
||||
// itemDic[itemValuePair.Key] = ExportExcelConverterDate.DateTimeInternationalToString(result);
|
||||
// }
|
||||
//}
|
||||
|
||||
foreach (var needTranslateProperty in needTranslatePropertyList)
|
||||
{
|
||||
|
|
@ -420,7 +452,7 @@ public static class ExcelExportHelper
|
|||
workbook.RemoveSheetAt(1);
|
||||
}
|
||||
|
||||
//中文替换项目术语
|
||||
#region 中文替换项目术语
|
||||
if (data.TrialObjectNameList?.Count > 0)
|
||||
{
|
||||
var replaceObjectList = data.TrialObjectNameList;
|
||||
|
|
@ -456,21 +488,378 @@ public static class ExcelExportHelper
|
|||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
if (dynamicColumnConfig != null)
|
||||
{
|
||||
//var isCdics = dynamicColumnConfig.CDISCList.Count > 0;
|
||||
|
||||
var isCdics = dynamicColumnConfig.IsCDISCExport;
|
||||
|
||||
var sheet = workbook.GetSheetAt(0);
|
||||
|
||||
var cdicsRow = sheet.GetRow(dynamicColumnConfig.AutoColumnTitleRowIndex - 1);
|
||||
var titelRow = sheet.GetRow(dynamicColumnConfig.AutoColumnTitleRowIndex);
|
||||
var templateRow = sheet.GetRow(dynamicColumnConfig.AutoColumnTitleRowIndex + 1);
|
||||
|
||||
//动态移除列的数量
|
||||
var dynamicRemoveColunmCount = dynamicColumnConfig.RemoveColunmIndexList.Count();
|
||||
|
||||
//在动态列开始前移除的数量
|
||||
var beforeDynamicRemoveCount = dynamicColumnConfig.RemoveColunmIndexList.Where(t => t < dynamicColumnConfig.AutoColumnStartIndex).Count();
|
||||
|
||||
//动态添加列的数量
|
||||
var needAddCount = dynamicColumnConfig.ColumnNameList.Count;
|
||||
var needAddCount = dynamicColumnConfig.ColumnIdNameList.Count;
|
||||
|
||||
//原始表 最终索引
|
||||
var originTotalEndIndex = dynamicColumnConfig.TempalteLastColumnIndex;
|
||||
|
||||
//减去动态移除后原始结束索引
|
||||
var originRemoveEndIndex = originTotalEndIndex - dynamicRemoveColunmCount;
|
||||
|
||||
//最终表 动态列开始索引
|
||||
var dynamicColunmStartIndex = dynamicColumnConfig.AutoColumnStartIndex - beforeDynamicRemoveCount;
|
||||
|
||||
//最终表 动态列的终止索引
|
||||
var dynamicColunmEndIndex = dynamicColunmStartIndex + needAddCount - 1;
|
||||
|
||||
//最终表 最终索引
|
||||
var totalColunmEndIndex = originTotalEndIndex + needAddCount - dynamicRemoveColunmCount;
|
||||
|
||||
|
||||
//动态列后需要移动的数量
|
||||
var backMoveCount = totalColunmEndIndex - dynamicColunmEndIndex;
|
||||
|
||||
//删除需要动态删除的列 从大到小移除,否则索引会变
|
||||
foreach (var removeIndex in dynamicColumnConfig.RemoveColunmIndexList.OrderByDescending(t => t))
|
||||
{
|
||||
//将后面的列向前移动
|
||||
for (var i = 0; i < originTotalEndIndex - removeIndex; i++)
|
||||
{
|
||||
Console.WriteLine(titelRow.GetCell(removeIndex + i + 1).StringCellValue);
|
||||
titelRow.GetCell(removeIndex + i).SetCellValue(titelRow.GetCell(removeIndex + i + 1).StringCellValue);
|
||||
templateRow.GetCell(removeIndex + i).SetCellValue(templateRow.GetCell(removeIndex + i + 1).StringCellValue);
|
||||
|
||||
//后面的数据要清空
|
||||
titelRow.GetCell(removeIndex + i + 1).SetCellValue("");
|
||||
templateRow.GetCell(removeIndex + i + 1).SetCellValue("");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//创建新的列
|
||||
for (int i = originRemoveEndIndex; i < originRemoveEndIndex + needAddCount; i++)
|
||||
{
|
||||
|
||||
titelRow.CreateCell(i + 1);
|
||||
templateRow.CreateCell(i + 1);
|
||||
|
||||
if (isCdics)
|
||||
{
|
||||
cdicsRow.CreateCell(i + 1);
|
||||
}
|
||||
}
|
||||
//移动Title 和下面的模板标识
|
||||
|
||||
var gap = totalColunmEndIndex - originRemoveEndIndex;
|
||||
|
||||
for (int i = totalColunmEndIndex; i > dynamicColunmEndIndex; i--)
|
||||
{
|
||||
|
||||
titelRow.GetCell(i).SetCellValue(titelRow.GetCell(i - gap).StringCellValue);
|
||||
|
||||
templateRow.GetCell(i).SetCellValue(templateRow.GetCell(i - gap).StringCellValue);
|
||||
|
||||
if (isCdics)
|
||||
{
|
||||
cdicsRow.GetCell(i).SetCellValue(cdicsRow.GetCell(i - gap).StringCellValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//设置动态Tilte
|
||||
|
||||
for (int i = dynamicColunmStartIndex; i < dynamicColunmStartIndex + needAddCount; i++)
|
||||
{
|
||||
|
||||
var name = dynamicColumnConfig.ColumnIdNameList[i - dynamicColunmStartIndex].Name;
|
||||
|
||||
titelRow.GetCell(i).SetCellValue(name);
|
||||
templateRow.GetCell(i).SetCellValue("");
|
||||
|
||||
if (isCdics)
|
||||
{
|
||||
var cdicsCode = dynamicColumnConfig.ColumnIdNameList[i - dynamicColunmStartIndex].CDISCCode;
|
||||
|
||||
cdicsRow.GetCell(i).SetCellValue(cdicsCode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
using (var memoryStream2 = new MemoryStream())
|
||||
{
|
||||
workbook.Write(memoryStream2, true);
|
||||
|
||||
memoryStream2.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
templateStream = memoryStream2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MiniExcel
|
||||
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
var config = new OpenXmlConfiguration()
|
||||
{
|
||||
IgnoreTemplateParameterMissing = true,
|
||||
};
|
||||
|
||||
//await MiniExcel.SaveAsByTemplateAsync("testmini.xlsx", templateStream.ToArray(), translateData);
|
||||
|
||||
await MiniExcel.SaveAsByTemplateAsync(memoryStream, templateStream.ToArray(), translateData, config);
|
||||
|
||||
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
if (dynamicColumnConfig != null)
|
||||
{
|
||||
//Excel 列是按照名称填充 还是Id 填充
|
||||
var isExcelAddDataWithName = dynamicColumnConfig.ColumnIdNameList.Select(t => t.Id).Distinct().Count() == 1;
|
||||
|
||||
var dynamicTranslateDataList = await _dictionaryService.GetBasicDataSelect(dynamicColumnConfig.TranslateDicNameList.ToArray());
|
||||
|
||||
// 使用NPOI 进行二次处理
|
||||
var wb = new XSSFWorkbook(memoryStream);
|
||||
var sheet = wb.GetSheetAt(0);
|
||||
|
||||
var list = translatedDic["List"] as IList;
|
||||
|
||||
foreach (var itemResult in list)
|
||||
{
|
||||
var index = list.IndexOf(itemResult);
|
||||
|
||||
//从第四行开始处理动态列
|
||||
var row = sheet.GetRow(index + dynamicColumnConfig.AutoColumnTitleRowIndex + 1);
|
||||
|
||||
var itemDic = itemResult.ToDictionary();
|
||||
|
||||
var itemList = itemDic[dynamicColumnConfig.DynamicListName] as IList;
|
||||
|
||||
//这个数组是动态的,有的多,有的少,所以在此对比Title 一致才赋值
|
||||
foreach (var itemObj in itemList)
|
||||
{
|
||||
|
||||
var iteObjDic = itemObj.ToDictionary();
|
||||
|
||||
var itemDicName = iteObjDic.ContainsKey(dynamicColumnConfig.DynamicItemDicName) ? iteObjDic[dynamicColumnConfig.DynamicItemDicName]?.ToString() : "";
|
||||
var itemValue = iteObjDic[dynamicColumnConfig.DynamicItemValueName]?.ToString();
|
||||
|
||||
//var writeIndex = itemList.IndexOf(itemObj) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
|
||||
var writeIndex = 0;
|
||||
|
||||
if (isExcelAddDataWithName)
|
||||
{
|
||||
writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeIndex = dynamicColumnConfig.ColumnIdList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleId].ToString()) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
}
|
||||
|
||||
|
||||
if (itemDicName.IsNotNullOrEmpty())
|
||||
{
|
||||
|
||||
var translatedItemData = dynamicTranslateDataList[itemDicName].Where(t => t.Code.ToLower() == itemValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty;
|
||||
|
||||
row.GetCell(writeIndex).SetCellValue(translatedItemData);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.GetCell(writeIndex).SetCellValue(itemValue);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var memoryStream2 = new MemoryStream();
|
||||
wb.Write(memoryStream2, true);
|
||||
memoryStream2.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
memoryStream = memoryStream2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return (memoryStream, fileName);
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂时废弃--合并到上面
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="_commonDocumentRepository"></param>
|
||||
/// <param name="_hostEnvironment"></param>
|
||||
/// <param name="_dictionaryService"></param>
|
||||
/// <param name="translateType"></param>
|
||||
/// <param name="criterionType"></param>
|
||||
/// <param name="dynamicColumnConfig"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<(MemoryStream, string)> CDISC_DataExport_Async(string code, ExcelExportInfo data, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null, DynamicColumnConfig? dynamicColumnConfig = null)
|
||||
{
|
||||
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
|
||||
//判断是否有字典翻译
|
||||
|
||||
object translateData = data;
|
||||
|
||||
Dictionary<string, object> translatedDic = default;
|
||||
|
||||
if (_dictionaryService != null && translateType != null)
|
||||
{
|
||||
|
||||
//一个值 对应不同的字典翻译
|
||||
var needTranslatePropertyList = translateType.GetProperties().Where(t => t.IsDefined(typeof(DictionaryTranslateAttribute), true))
|
||||
.SelectMany(c =>
|
||||
c.GetCustomAttributes(typeof(DictionaryTranslateAttribute), false).Select(f => (DictionaryTranslateAttribute?)f).Where(t => t.CriterionType == criterionType || t.CriterionType == null)
|
||||
.Select(k => new { c.Name, k.DicParentCode, k.IsTranslateDenpendOtherProperty, k.DependPropertyName, k.DependPropertyValueStr })
|
||||
).ToList();
|
||||
|
||||
|
||||
|
||||
//字典表查询出所有需要翻译的数据
|
||||
|
||||
var translateDataList = await _dictionaryService.GetBasicDataSelect(needTranslatePropertyList.Select(t => t.DicParentCode).Distinct().ToArray());
|
||||
|
||||
var dic = data.ConvertToDictionary();
|
||||
//var dic = (JsonConvert.DeserializeObject<IDictionary<string, object>>(data.ToJsonNotIgnoreNull())).IfNullThrowException();
|
||||
|
||||
foreach (var key in dic.Keys)
|
||||
{
|
||||
//是数组 那么找到对应的属性 进行翻译
|
||||
if (dic[key] != null && dic[key].GetType().GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IList<>)))
|
||||
//if (dic[key].GetType().IsAssignableFrom(typeof(JArray)))
|
||||
{
|
||||
|
||||
var newObjList = new List<object>();
|
||||
var no = 1;
|
||||
foreach (var item in dic[key] as IList)
|
||||
//foreach (var item in dic[key] as JArray)
|
||||
{
|
||||
//var itemDic = JsonConvert.DeserializeObject<IDictionary<string, object>>(item.ToJsonNotIgnoreNull());
|
||||
var itemDic = item.ConvertToDictionary();
|
||||
|
||||
foreach (var needTranslateProperty in needTranslatePropertyList)
|
||||
{
|
||||
if (itemDic.Keys.Any(t => t == needTranslateProperty.Name))
|
||||
{
|
||||
//翻译的属性依赖其他属性
|
||||
if (needTranslateProperty.IsTranslateDenpendOtherProperty)
|
||||
{
|
||||
if (itemDic[needTranslateProperty.DependPropertyName]?.ToString().ToLower() == needTranslateProperty.DependPropertyValueStr.ToLower())
|
||||
{
|
||||
var beforeValue = itemDic[needTranslateProperty.Name]?.ToString();
|
||||
|
||||
itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty;
|
||||
}
|
||||
}
|
||||
//普通翻译 或者某一标准翻译
|
||||
else
|
||||
{
|
||||
var beforeValue = itemDic[needTranslateProperty.Name]?.ToString();
|
||||
|
||||
|
||||
itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
itemDic.Add("No", no++);
|
||||
newObjList.Add(itemDic);
|
||||
}
|
||||
|
||||
dic[key] = newObjList;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//data = dic;
|
||||
translateData = dic;
|
||||
translatedDic = dic;
|
||||
|
||||
}
|
||||
|
||||
|
||||
var (physicalPath, fileName) = await FileStoreHelper.GetCommonDocPhysicalFilePathAsync(_hostEnvironment, _commonDocumentRepository, code);
|
||||
|
||||
|
||||
//模板路径
|
||||
var tplPath = physicalPath;
|
||||
|
||||
#region 根据中英文 删除模板sheet
|
||||
|
||||
// 打开模板文件
|
||||
var templateFile = new FileStream(tplPath, FileMode.Open, FileAccess.Read);
|
||||
|
||||
// 获取文件流
|
||||
var templateStream = new MemoryStream();
|
||||
templateFile.CopyTo(templateStream);
|
||||
templateStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var workbook = new XSSFWorkbook(templateStream);
|
||||
|
||||
int sheetCount = workbook.NumberOfSheets;
|
||||
|
||||
if (sheetCount == 2)
|
||||
{
|
||||
if (isEn_US)
|
||||
{
|
||||
workbook.RemoveSheetAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
workbook.RemoveSheetAt(1);
|
||||
}
|
||||
|
||||
if (dynamicColumnConfig != null)
|
||||
{
|
||||
var sheet = workbook.GetSheetAt(0);
|
||||
|
||||
|
||||
var cdicsRow = sheet.GetRow(dynamicColumnConfig.AutoColumnTitleRowIndex - 1);
|
||||
var titelRow = sheet.GetRow(dynamicColumnConfig.AutoColumnTitleRowIndex);
|
||||
var templateRow = sheet.GetRow(dynamicColumnConfig.AutoColumnTitleRowIndex + 1);
|
||||
|
||||
//动态移除列的数量
|
||||
var dynamicRemoveColunmCount = dynamicColumnConfig.RemoveColunmIndexList.Count();
|
||||
|
||||
//在动态列开始前移除的数量
|
||||
var beforeDynamicRemoveCount = dynamicColumnConfig.RemoveColunmIndexList.Where(t => t < dynamicColumnConfig.AutoColumnStartIndex).Count();
|
||||
|
||||
//动态添加列的数量
|
||||
var needAddCount = dynamicColumnConfig.ColumnIdNameList.Count;
|
||||
|
||||
//原始表 最终索引
|
||||
var originTotalEndIndex = dynamicColumnConfig.TempalteLastColumnIndex;
|
||||
|
|
@ -512,6 +901,7 @@ public static class ExcelExportHelper
|
|||
//创建新的列
|
||||
for (int i = originTotalEndIndex; i < originTotalEndIndex + needAddCount; i++)
|
||||
{
|
||||
cdicsRow.CreateCell(i + 1);
|
||||
titelRow.CreateCell(i + 1);
|
||||
templateRow.CreateCell(i + 1);
|
||||
}
|
||||
|
|
@ -533,8 +923,11 @@ public static class ExcelExportHelper
|
|||
|
||||
for (int i = dynamicColunmStartIndex; i < dynamicColunmStartIndex + needAddCount; i++)
|
||||
{
|
||||
var name = dynamicColumnConfig.ColumnNameList[i - dynamicColunmStartIndex];
|
||||
var name = dynamicColumnConfig.ColumnIdNameList[i - dynamicColunmStartIndex].Name;
|
||||
|
||||
var cdicsCode = dynamicColumnConfig.ColumnIdNameList[i - dynamicColunmStartIndex].CDISCCode;
|
||||
|
||||
cdicsRow.GetCell(i).SetCellValue(cdicsCode);
|
||||
titelRow.GetCell(i).SetCellValue(name);
|
||||
templateRow.GetCell(i).SetCellValue("");
|
||||
}
|
||||
|
|
@ -568,6 +961,8 @@ public static class ExcelExportHelper
|
|||
|
||||
if (dynamicColumnConfig != null)
|
||||
{
|
||||
var isExcelAddDataWithName = dynamicColumnConfig.ColumnIdNameList.Select(t => t.Id).Count() == 1;
|
||||
|
||||
var dynamicTranslateDataList = await _dictionaryService.GetBasicDataSelect(dynamicColumnConfig.TranslateDicNameList.ToArray());
|
||||
|
||||
// 使用NPOI 进行二次处理
|
||||
|
|
@ -598,7 +993,15 @@ public static class ExcelExportHelper
|
|||
|
||||
//var writeIndex = itemList.IndexOf(itemObj) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
|
||||
var writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
var writeIndex = 0;
|
||||
if (isExcelAddDataWithName)
|
||||
{
|
||||
writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeIndex = dynamicColumnConfig.ColumnIdList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleId].ToString()) + dynamicColumnConfig.AutoColumnStartIndex;
|
||||
}
|
||||
|
||||
if (itemDicName.IsNotNullOrEmpty())
|
||||
{
|
||||
|
|
@ -634,6 +1037,7 @@ public static class ExcelExportHelper
|
|||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导出文件模板
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -42,9 +42,14 @@
|
|||
动态列开始的行index 从0开始
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.Service.ExcelExportHelper.DynamicColumnConfig.ColumnNameList">
|
||||
<member name="P:IRaCIS.Core.Application.Service.ExcelExportHelper.DynamicColumnConfig.TempalteLastColumnIndex">
|
||||
<summary>
|
||||
动态的列名
|
||||
模板列最后的索引
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.Service.ExcelExportHelper.DynamicColumnConfig.ColumnIdNameList">
|
||||
<summary>
|
||||
动态的列名 如果Id 重复,那么就按照名称填充,否则就按照Id 填充列数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.Service.ExcelExportHelper.DynamicColumnConfig.TranslateDicNameList">
|
||||
|
|
@ -72,6 +77,20 @@
|
|||
Excel Title Name
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.ExcelExportHelper.CDISC_DataExport_Async(System.String,IRaCIS.Application.Contracts.ExcelExportInfo,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.CommonDocument},Microsoft.AspNetCore.Hosting.IWebHostEnvironment,IRaCIS.Application.Interfaces.IDictionaryService,System.Type,System.Nullable{IRaCIS.Core.Domain.Share.CriterionType},IRaCIS.Core.Application.Service.ExcelExportHelper.DynamicColumnConfig)">
|
||||
<summary>
|
||||
暂时废弃--合并到上面
|
||||
</summary>
|
||||
<param name="code"></param>
|
||||
<param name="data"></param>
|
||||
<param name="_commonDocumentRepository"></param>
|
||||
<param name="_hostEnvironment"></param>
|
||||
<param name="_dictionaryService"></param>
|
||||
<param name="translateType"></param>
|
||||
<param name="criterionType"></param>
|
||||
<param name="dynamicColumnConfig"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.ExcelExportHelper.ExportTemplateAsync(IRaCIS.Application.Contracts.ExportTemplateServiceDto)">
|
||||
<summary>
|
||||
导出文件模板
|
||||
|
|
@ -861,16 +880,6 @@
|
|||
<param name="_dictionaryService"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.Common.ExcelExportService.GetAnalysisTaskList_Export(IRaCIS.Core.Application.ViewModel.VisitTaskQuery,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.CommonDocument},IRaCIS.Application.Interfaces.IDictionaryService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial})">
|
||||
<summary>
|
||||
一致性分析结果导出 7 8 分别是自身 和组件一致性
|
||||
</summary>
|
||||
<param name="inQuery"></param>
|
||||
<param name="_commonDocumentRepository"></param>
|
||||
<param name="_dictionaryService"></param>
|
||||
<param name="_trialRepository"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.Common.ExcelExportService.GetTrialReadingCriterionCanExportDocumentList(System.Guid)">
|
||||
<summary>
|
||||
获取阅片标准可以导出的列表
|
||||
|
|
@ -878,7 +887,7 @@
|
|||
<param name="trialReadingCriterionId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.Common.ExcelExportService.GetCommonEvaluationList_Export(IRaCIS.Core.Application.ViewModel.VisitTaskQuery,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.CommonDocument},IRaCIS.Application.Interfaces.IDictionaryService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial})">
|
||||
<member name="M:IRaCIS.Core.Application.Service.Common.ExcelExportService.GetCommonEvaluationList_Export(IRaCIS.Core.Application.ViewModel.VisitTaskQuery,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.CommonDocument},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingQuestionTrial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingTableQuestionTrial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingOncologyTaskInfo},IRaCIS.Application.Interfaces.IDictionaryService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial})">
|
||||
<summary>
|
||||
阅片结果表、阅片结果明细,评估病灶明细表, 裁判明细表导出,条件通过 ReadingExportType ( 1,2,3,4)区分
|
||||
</summary>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1140,22 +1140,49 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
public class CommonQuesionInfo
|
||||
{
|
||||
|
||||
//问题标识,肿瘤评估用于区分是什么问题
|
||||
public QuestionType? QuestionType { get; set; }
|
||||
|
||||
|
||||
public Guid QuestionId { get; set; }
|
||||
public string QuestionName { get; set; }
|
||||
|
||||
public string QuestionValue { get; set; }
|
||||
|
||||
public string TranslateDicName { get; set; }
|
||||
|
||||
public string CDISCCode { get; set; }
|
||||
|
||||
//外层问题会重复,所以需要分组名
|
||||
|
||||
public string Group { get; set; }
|
||||
}
|
||||
|
||||
public class ExportQuestionBasicInfo
|
||||
{
|
||||
public QuestionType? QuestionType { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public Guid QuestionId { get; set; }
|
||||
public string QuestionName { get; set; }
|
||||
public string TranslateDicName { get; set; }
|
||||
|
||||
public string GroupName { get; set; }
|
||||
|
||||
public int ShowOrder { get; set; }
|
||||
}
|
||||
public class CommonEvaluationExport
|
||||
{
|
||||
public List<CommonQuesionInfo> QuestionAnswerList { get; set; }
|
||||
|
||||
public List<decimal> SubjectCriterionReadingPeriodVisitNumList { get; set; }
|
||||
|
||||
public String TrialSiteCode { get; set; } = String.Empty;
|
||||
public string SubjectCode { get; set; } = String.Empty;
|
||||
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid SubjectId { get; set; }
|
||||
|
||||
public Guid? DoctorUserId { get; set; }
|
||||
|
||||
public string TaskName { get; set; }
|
||||
|
|
@ -1191,6 +1218,19 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
public string JudgeNote { get; set; } = string.Empty;
|
||||
|
||||
public string VisitNote { get; set; }
|
||||
|
||||
|
||||
#region 肿瘤学结果
|
||||
|
||||
[DictionaryTranslateAttribute("OncologyAssessType")]
|
||||
public string OncologyResult { get; set; } = string.Empty;
|
||||
|
||||
public string OncologyReason { get; set; } = string.Empty;
|
||||
|
||||
public string OncologyUserName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class CommonLessionExport : CommonEvaluationExport
|
||||
|
|
@ -1219,13 +1259,23 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
|
||||
public class CommonLessionQuestionAnswerInfo
|
||||
{
|
||||
public string LessionCode { get; set; }
|
||||
|
||||
public string LessionType { get; set; }
|
||||
|
||||
#region 肿瘤评估标准的时候需要
|
||||
|
||||
public QuestionMark? QuestionMark { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region 自定义表格名 特殊处理
|
||||
|
||||
public string TableName { get; set; }
|
||||
#endregion
|
||||
|
||||
|
||||
public Guid TableQuesionId { get; set; }
|
||||
|
||||
public string QuestionName { get; set; }
|
||||
|
||||
public string QuestionValue { get; set; }
|
||||
|
|
|
|||
|
|
@ -203,29 +203,29 @@ namespace IRaCIS.Core.Application.Service
|
|||
ExportResult readingExportType = ExportResult.None;
|
||||
|
||||
CreateMap<VisitTask, OverallTumorEvaluationExport>()
|
||||
// .ForMember(o => o.TrialReadingCriterionName, t => t.MapFrom(u => u.TrialReadingCriterion.CriterionName))
|
||||
.ForMember(o => o.IsBaseline, t => t.MapFrom(u => u.SourceSubjectVisit.IsBaseLine))
|
||||
.ForMember(o => o.JudgeArmEnum, t => t.MapFrom(u => u.JudgeResultTask.ArmEnum))
|
||||
// .ForMember(o => o.TrialReadingCriterionName, t => t.MapFrom(u => u.TrialReadingCriterion.CriterionName))
|
||||
.ForMember(o => o.IsBaseline, t => t.MapFrom(u => u.SourceSubjectVisit.IsBaseLine))
|
||||
.ForMember(o => o.JudgeArmEnum, t => t.MapFrom(u => u.JudgeResultTask.ArmEnum))
|
||||
|
||||
.ForMember(o => o.IsTrigerJudge, t => t.MapFrom(u => arbitrationRule == ArbitrationRule.Visit ? u.JudgeResultTaskId != null :
|
||||
(arbitrationRule == ArbitrationRule.Reading ?
|
||||
u.Subject.SubjectVisitTaskList.Any(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingCategory == ReadingCategory.Judge && t.TrialReadingCriterionId == trialReadingCriterionId && u.VisitTaskNum < t.VisitTaskNum) :
|
||||
false)))
|
||||
.ForMember(o => o.IsTrigerJudge, t => t.MapFrom(u => arbitrationRule == ArbitrationRule.Visit ? u.JudgeResultTaskId != null :
|
||||
(arbitrationRule == ArbitrationRule.Reading ?
|
||||
u.Subject.SubjectVisitTaskList.Any(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingCategory == ReadingCategory.Judge && t.TrialReadingCriterionId == trialReadingCriterionId && u.VisitTaskNum < t.VisitTaskNum) :
|
||||
false)))
|
||||
|
||||
.ForMember(o => o.JudgeNote, t => t.MapFrom(u => u.JudgeResultRemark))
|
||||
.ForMember(o => o.JudgeNote, t => t.MapFrom(u => u.JudgeResultRemark))
|
||||
|
||||
.ForMember(o => o.VisitNote, t => t.MapFrom(u => u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.AdjustReason).FirstOrDefault()!.Answer))
|
||||
.ForMember(o => o.VisitNote, t => t.MapFrom(u => u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.AdjustReason).FirstOrDefault()!.Answer))
|
||||
|
||||
.ForMember(o => o.OverallTumorEvaluationResult, t => t.MapFrom(u =>
|
||||
criterionType == CriterionType.PCWG3 ? u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.SiteVisitForTumorEvaluation).FirstOrDefault()!.Answer :
|
||||
(u.SourceSubjectVisit.IsBaseLine == true ?
|
||||
u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.ExistDisease).FirstOrDefault()!.Answer :
|
||||
u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.Tumor).Select(t => t.IsGlobalChange ? t.GlobalChangeAnswer : t.Answer).FirstOrDefault())
|
||||
))
|
||||
.ForMember(o => o.OverallTumorEvaluationResult, t => t.MapFrom(u =>
|
||||
criterionType == CriterionType.PCWG3 ? u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.SiteVisitForTumorEvaluation).FirstOrDefault()!.Answer :
|
||||
(u.SourceSubjectVisit.IsBaseLine == true ?
|
||||
u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.ExistDisease).FirstOrDefault()!.Answer :
|
||||
u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.Tumor).Select(t => t.IsGlobalChange ? t.GlobalChangeAnswer : t.Answer).FirstOrDefault())
|
||||
))
|
||||
|
||||
.ForMember(o => o.TrialSiteCode, t => t.MapFrom(u => u.Subject.TrialSite.TrialSiteCode))
|
||||
.ForMember(o => o.SubjectCode, t => t.MapFrom(u => u.Subject.Code))
|
||||
.ForMember(o => o.UserName, t => t.MapFrom(u => u.DoctorUser.UserName));
|
||||
.ForMember(o => o.TrialSiteCode, t => t.MapFrom(u => u.Subject.TrialSite.TrialSiteCode))
|
||||
.ForMember(o => o.SubjectCode, t => t.MapFrom(u => u.Subject.Code))
|
||||
.ForMember(o => o.UserName, t => t.MapFrom(u => u.DoctorUser.UserName));
|
||||
|
||||
CreateMap<VisitTask, AnalysisDynamicCommonExport>()
|
||||
.ForMember(o => o.IsBaseline, t => t.MapFrom(u => u.SourceSubjectVisit.IsBaseLine))
|
||||
|
|
@ -240,7 +240,10 @@ namespace IRaCIS.Core.Application.Service
|
|||
QuestionType = c.ReadingQuestionTrial.QuestionType,
|
||||
QuestionName = isEn_Us ? c.ReadingQuestionTrial.QuestionEnName : c.ReadingQuestionTrial.QuestionName,
|
||||
QuestionValue = c.IsGlobalChange ? c.GlobalChangeAnswer : c.Answer,
|
||||
TranslateDicName = c.ReadingQuestionTrial.DictionaryCode
|
||||
QuestionId = c.ReadingQuestionTrial.Id,
|
||||
TranslateDicName = c.ReadingQuestionTrial.DictionaryCode,
|
||||
//CDISCCode = c.ReadingQuestionTrial.CDISCCode,
|
||||
Group = isEn_Us ? c.ReadingQuestionTrial.GroupEnName : c.ReadingQuestionTrial.GroupName,
|
||||
})))
|
||||
;
|
||||
|
||||
|
|
@ -253,9 +256,19 @@ namespace IRaCIS.Core.Application.Service
|
|||
(arbitrationRule == ArbitrationRule.Reading ?
|
||||
u.Subject.SubjectVisitTaskList.Any(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingCategory == ReadingCategory.Judge && t.TrialReadingCriterionId == trialReadingCriterionId && u.VisitTaskNum < t.VisitTaskNum) :
|
||||
false)))
|
||||
.ForMember(o => o.JudgeNote, t => t.MapFrom(u => u.JudgeVisitTask.JudgeResultRemark))
|
||||
.ForMember(o => o.JudgeNote, t => t.MapFrom(u => u.ReadingCategory == ReadingCategory.Judge ? u.JudgeResultRemark : ""))
|
||||
.ForMember(o => o.VisitNote, t => t.MapFrom(u => u.ReadingTaskQuestionAnswerList.Where(c => c.ReadingQuestionTrial.QuestionType == QuestionType.AdjustReason).FirstOrDefault()!.Answer))
|
||||
//.ForMember(o => o.TrialSiteCode, t => t.MapFrom(u => u.Subject.TrialSite.TrialSiteCode))
|
||||
//.ForMember(o => o.IsSubjectHaveReadingPeriod, t => t.MapFrom(u => arbitrationRule == ArbitrationRule.Reading ?
|
||||
//u.Subject.ReadModuleList.Any(t => t.TrialReadingCriterionId == trialReadingCriterionId && t.ReadingSetType == ReadingSetType.ImageReading) : false))
|
||||
|
||||
|
||||
.ForMember(o => o.SubjectCriterionReadingPeriodVisitNumList, t => t.MapFrom(u =>
|
||||
u.Subject.ReadModuleList.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId && t.ReadingSetType == ReadingSetType.ImageReading).Select(c => c.SubjectVisit.VisitNum)))
|
||||
|
||||
//.ForMember(o => o.ResearchProgramNo, t => t.MapFrom(u => u.Trial.ResearchProgramNo))
|
||||
//.ForMember(o => o.VisitName, t => t.MapFrom(u => u.SourceSubjectVisit.VisitName))
|
||||
.ForMember(o => o.TrialSiteCode, t => t.MapFrom(u => u.Subject.TrialSite.TrialSiteCode))
|
||||
//.ForMember(o => o.LatestScanDate, t => t.MapFrom(u => u.SourceSubjectVisit.LatestScanDate))
|
||||
.ForMember(o => o.SubjectCode, t => t.MapFrom(u => u.Subject.Code))
|
||||
.ForMember(o => o.UserName, t => t.MapFrom(u => u.DoctorUser.UserName))
|
||||
.ForMember(o => o.QuestionAnswerList, t => t.MapFrom(u => u.ReadingTaskQuestionAnswerList
|
||||
|
|
@ -264,9 +277,10 @@ namespace IRaCIS.Core.Application.Service
|
|||
.Select(c => new CommonQuesionInfo()
|
||||
{
|
||||
QuestionType = c.ReadingQuestionTrial.QuestionType,
|
||||
QuestionId = c.ReadingQuestionTrial.Id,
|
||||
QuestionName = isEn_Us ? c.ReadingQuestionTrial.QuestionEnName : c.ReadingQuestionTrial.QuestionName,
|
||||
QuestionValue = c.IsGlobalChange?c.GlobalChangeAnswer: c.Answer,
|
||||
TranslateDicName = c.ReadingQuestionTrial.DictionaryCode
|
||||
QuestionValue = c.IsGlobalChange ? c.GlobalChangeAnswer : c.Answer,
|
||||
TranslateDicName = c.ReadingQuestionTrial.DictionaryCode,
|
||||
})))
|
||||
;
|
||||
|
||||
|
|
@ -279,11 +293,17 @@ namespace IRaCIS.Core.Application.Service
|
|||
.ForMember(o => o.LessionAnswerList, t => t.MapFrom(u => u.LesionAnswerList.Where(c => c.ReadingTableQuestionTrial.ExportResultStr.Contains(((int)readingExportType).ToString()))));
|
||||
|
||||
CreateMap<ReadingTableQuestionAnswer, CommonLessionQuestionAnswerInfo>()
|
||||
.ForMember(o => o.LessionCode, t => t.MapFrom(u => u.Lesion.RowMark))
|
||||
.ForMember(o => o.LessionType, t => t.MapFrom(u => (int?)u.ReadingQuestionTrial.LesionType))
|
||||
//.ForMember(o => o.LessionCode, t => t.MapFrom(u => u.Lesion.RowMark))
|
||||
//.ForMember(o => o.LessionType, t => t.MapFrom(u => (int?)u.ReadingQuestionTrial.LesionType))
|
||||
//.ForMember(o => o.ShowOrder, t => t.MapFrom(u => u.ReadingTableQuestionTrial.ShowOrder))
|
||||
//.ForMember(o => o.CustomUnit, t => t.MapFrom(u => u.ReadingTableQuestionTrial.CustomUnit))
|
||||
//.ForMember(o => o.Unit, t => t.MapFrom(u => u.ReadingTableQuestionTrial.Unit))
|
||||
.ForMember(o => o.TableQuesionId, t => t.MapFrom(u => u.ReadingTableQuestionTrial.Id))
|
||||
.ForMember(o => o.QuestionMark, t => t.MapFrom(u => u.ReadingTableQuestionTrial.QuestionMark))
|
||||
.ForMember(o => o.QuestionName, t => t.MapFrom(u => isEn_Us ? u.ReadingTableQuestionTrial.QuestionEnName : u.ReadingTableQuestionTrial.QuestionName))
|
||||
.ForMember(o => o.QuestionValue, t => t.MapFrom(u => u.Answer))
|
||||
//.ForMember(o => o.CDISCCode, t => t.MapFrom(u => u.ReadingTableQuestionTrial.CDISCCode))
|
||||
.ForMember(o => o.TableName, t => t.MapFrom(u => isEn_Us ? u.ReadingQuestionTrial.QuestionEnName : u.ReadingQuestionTrial.QuestionName))
|
||||
.ForMember(o => o.TranslateDicName, t => t.MapFrom(u => u.ReadingTableQuestionTrial.DictionaryCode))
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue