merge from 2023-03-14
This commit is contained in:
@@ -21,9 +21,9 @@ using JNPF.Systems.Entitys.Model.DataInterFace;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Engine;
|
||||
using JNPF.VisualDev.Engine.Core;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using JNPF.WorkFlow.Interfaces.Service;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -50,7 +50,7 @@ public class ExportImportDataHelper : ITransient
|
||||
/// <summary>
|
||||
/// 在线开发运行服务.
|
||||
/// </summary>
|
||||
private readonly IRunService _runService;
|
||||
private readonly RunService _runService;
|
||||
|
||||
/// <summary>
|
||||
/// 单据.
|
||||
@@ -93,7 +93,7 @@ public class ExportImportDataHelper : ITransient
|
||||
public ExportImportDataHelper(
|
||||
ISqlSugarRepository<OrganizeEntity> repositoryRepository,
|
||||
IUserManager userManager,
|
||||
IRunService runService,
|
||||
RunService runService,
|
||||
IBillRullService billRuleService,
|
||||
IDataInterfaceService dataInterfaceService,
|
||||
IDataBaseManager databaseService,
|
||||
@@ -369,6 +369,55 @@ public class ExportImportDataHelper : ITransient
|
||||
field.ableRoleIds = (att as CodeGenUploadAttribute).ableRoleIds;
|
||||
field.ableGroupIds = (att as CodeGenUploadAttribute).ableGroupIds;
|
||||
field.ableIds = (att as CodeGenUploadAttribute).ableIds;
|
||||
field.relational = (att as CodeGenUploadAttribute).showField;
|
||||
configModel = (att as CodeGenUploadAttribute).__config__.Adapt<ConfigModel>();
|
||||
configModel.label = string.Format("{0}({1})", configModel.label, field.__vModel__);
|
||||
field.__config__ = configModel;
|
||||
fieldList.Add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据转换模板解析.
|
||||
/// </summary>
|
||||
public static List<FieldsModel> GetDataConversionTemplateParsing<T>(T entity)
|
||||
{
|
||||
List<FieldsModel> fieldList = new List<FieldsModel>();
|
||||
foreach (PropertyInfo prop in entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
|
||||
{
|
||||
FieldsModel field = new FieldsModel();
|
||||
foreach (var att in prop.GetCustomAttributes(false))
|
||||
{
|
||||
if (att is CodeGenUploadAttribute)
|
||||
{
|
||||
var configModel = new ConfigModel();
|
||||
field.__vModel__ = (att as CodeGenUploadAttribute).__vModel__ ?? (att as CodeGenUploadAttribute).__Model__;
|
||||
field.level = (att as CodeGenUploadAttribute).level;
|
||||
field.min = (att as CodeGenUploadAttribute).min == 0 ? null : (att as CodeGenUploadAttribute).min;
|
||||
field.max = (att as CodeGenUploadAttribute).max == 0 ? null : (att as CodeGenUploadAttribute).max;
|
||||
field.activeTxt = (att as CodeGenUploadAttribute).activeTxt;
|
||||
field.inactiveTxt = (att as CodeGenUploadAttribute).inactiveTxt;
|
||||
field.format = (att as CodeGenUploadAttribute).format;
|
||||
field.multiple = (att as CodeGenUploadAttribute).multiple;
|
||||
field.separator = (att as CodeGenUploadAttribute).separator;
|
||||
field.__slot__ = (att as CodeGenUploadAttribute).__slot__.Adapt<SlotModel>();
|
||||
field.props = (att as CodeGenUploadAttribute).props.Adapt<PropsModel>();
|
||||
field.options = (att as CodeGenUploadAttribute).options;
|
||||
field.propsValue = (att as CodeGenUploadAttribute).propsValue;
|
||||
field.relationField = (att as CodeGenUploadAttribute).relationField;
|
||||
field.modelId = (att as CodeGenUploadAttribute).modelId;
|
||||
field.interfaceId = (att as CodeGenUploadAttribute).interfaceId;
|
||||
field.selectType = (att as CodeGenUploadAttribute).selectType;
|
||||
field.ableDepIds = (att as CodeGenUploadAttribute).ableDepIds;
|
||||
field.ablePosIds = (att as CodeGenUploadAttribute).ablePosIds;
|
||||
field.ableUserIds = (att as CodeGenUploadAttribute).ableUserIds;
|
||||
field.ableRoleIds = (att as CodeGenUploadAttribute).ableRoleIds;
|
||||
field.ableGroupIds = (att as CodeGenUploadAttribute).ableGroupIds;
|
||||
field.ableIds = (att as CodeGenUploadAttribute).ableIds;
|
||||
field.relational = (att as CodeGenUploadAttribute).showField;
|
||||
configModel = (att as CodeGenUploadAttribute).__config__.Adapt<ConfigModel>();
|
||||
configModel.label = string.Format("{0}({1})", configModel.label, field.__vModel__);
|
||||
field.__config__ = configModel;
|
||||
@@ -416,6 +465,56 @@ public class ExportImportDataHelper : ITransient
|
||||
field.ableRoleIds = (att as CodeGenUploadAttribute).ableRoleIds;
|
||||
field.ableGroupIds = (att as CodeGenUploadAttribute).ableGroupIds;
|
||||
field.ableIds = (att as CodeGenUploadAttribute).ableIds;
|
||||
field.relational = (att as CodeGenUploadAttribute).showField;
|
||||
configModel = (att as CodeGenUploadAttribute).__config__.Adapt<ConfigModel>();
|
||||
configModel.label = string.Format("{0}({1})", configModel.label, field.__vModel__);
|
||||
field.__config__ = configModel;
|
||||
fieldList.Add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据转换模板解析.
|
||||
/// </summary>
|
||||
public static List<FieldsModel> GetDataConversionTemplateParsing<T>(T entity, string tableName)
|
||||
{
|
||||
List<FieldsModel> fieldList = new List<FieldsModel>();
|
||||
foreach (PropertyInfo prop in entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
|
||||
{
|
||||
FieldsModel field = new FieldsModel();
|
||||
foreach (var att in prop.GetCustomAttributes(false))
|
||||
{
|
||||
if (att is CodeGenUploadAttribute)
|
||||
{
|
||||
var configModel = new ConfigModel();
|
||||
field.__vModel__ = string.Format("jnpf_{0}_jnpf_{1}", tableName, (att as CodeGenUploadAttribute).__vModel__ ?? (att as CodeGenUploadAttribute).__Model__);
|
||||
field.level = (att as CodeGenUploadAttribute).level;
|
||||
field.min = (att as CodeGenUploadAttribute).min == 0 ? null : (att as CodeGenUploadAttribute).min;
|
||||
field.max = (att as CodeGenUploadAttribute).max == 0 ? null : (att as CodeGenUploadAttribute).max;
|
||||
field.activeTxt = (att as CodeGenUploadAttribute).activeTxt;
|
||||
field.inactiveTxt = (att as CodeGenUploadAttribute).inactiveTxt;
|
||||
field.format = (att as CodeGenUploadAttribute).format;
|
||||
field.multiple = (att as CodeGenUploadAttribute).multiple;
|
||||
field.separator = (att as CodeGenUploadAttribute).separator;
|
||||
field.__slot__ = (att as CodeGenUploadAttribute).__slot__.Adapt<SlotModel>();
|
||||
field.props = (att as CodeGenUploadAttribute).props.Adapt<PropsModel>();
|
||||
field.options = (att as CodeGenUploadAttribute).options;
|
||||
field.propsValue = (att as CodeGenUploadAttribute).propsValue;
|
||||
field.relationField = (att as CodeGenUploadAttribute).relationField;
|
||||
field.modelId = (att as CodeGenUploadAttribute).modelId;
|
||||
field.interfaceId = (att as CodeGenUploadAttribute).interfaceId;
|
||||
field.selectType = (att as CodeGenUploadAttribute).selectType;
|
||||
field.ableDepIds = (att as CodeGenUploadAttribute).ableDepIds;
|
||||
field.ablePosIds = (att as CodeGenUploadAttribute).ablePosIds;
|
||||
field.ableUserIds = (att as CodeGenUploadAttribute).ableUserIds;
|
||||
field.ableRoleIds = (att as CodeGenUploadAttribute).ableRoleIds;
|
||||
field.ableGroupIds = (att as CodeGenUploadAttribute).ableGroupIds;
|
||||
field.ableIds = (att as CodeGenUploadAttribute).ableIds;
|
||||
field.relational = (att as CodeGenUploadAttribute).showField;
|
||||
configModel = (att as CodeGenUploadAttribute).__config__.Adapt<ConfigModel>();
|
||||
configModel.label = string.Format("{0}({1})", configModel.label, field.__vModel__);
|
||||
field.__config__ = configModel;
|
||||
@@ -660,78 +759,78 @@ public class ExportImportDataHelper : ITransient
|
||||
return new { dataRow = resData, headerRow = headerRow };
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 导入数据.
|
||||
///// </summary>
|
||||
///// <param name="tInfo">模板信息.</param>
|
||||
///// <param name="list">数据集合.</param>
|
||||
///// <returns>[成功列表,失败列表].</returns>
|
||||
//public async Task<object[]> ImportMenuData(TemplateParsingBase tInfo, List<Dictionary<string, object>> list)
|
||||
//{
|
||||
// List<Dictionary<string, object>> userInputList = ImportFirstVerify(tInfo, list);
|
||||
// List<FieldsModel> fieldsModelList = tInfo.AllFieldsModel.Where(x => tInfo.selectKey.Contains(x.__vModel__)).ToList();
|
||||
/// <summary>
|
||||
/// 导入数据.
|
||||
/// </summary>
|
||||
/// <param name="tInfo">模板信息.</param>
|
||||
/// <param name="list">数据集合.</param>
|
||||
/// <returns>[成功列表,失败列表].</returns>
|
||||
public async Task<object[]> ImportMenuData(TemplateParsingBase tInfo, List<Dictionary<string, object>> list)
|
||||
{
|
||||
List<Dictionary<string, object>> userInputList = ImportFirstVerify(tInfo, list);
|
||||
List<FieldsModel> fieldsModelList = tInfo.AllFieldsModel.Where(x => tInfo.selectKey.Contains(x.__vModel__)).ToList();
|
||||
|
||||
// var successList = new List<Dictionary<string, object>>();
|
||||
// var errorsList = new List<Dictionary<string, object>>();
|
||||
var successList = new List<Dictionary<string, object>>();
|
||||
var errorsList = new List<Dictionary<string, object>>();
|
||||
|
||||
// // 捞取控件解析数据
|
||||
// var cData = await GetCDataList(tInfo.AllFieldsModel, new Dictionary<string, List<Dictionary<string, string>>>());
|
||||
// var res = await ImportDataAssemble(fieldsModelList, userInputList, cData);
|
||||
// res.Where(x => x.ContainsKey("errorsInfo")).ToList().ForEach(item => errorsList.Add(item));
|
||||
// res.Where(x => !x.ContainsKey("errorsInfo")).ToList().ForEach(item => successList.Add(item));
|
||||
// 捞取控件解析数据
|
||||
var cData = await GetCDataList(tInfo.AllFieldsModel, new Dictionary<string, List<Dictionary<string, string>>>());
|
||||
var res = await ImportDataAssemble(fieldsModelList, userInputList, cData);
|
||||
res.Where(x => x.ContainsKey("errorsInfo")).ToList().ForEach(item => errorsList.Add(item));
|
||||
res.Where(x => !x.ContainsKey("errorsInfo")).ToList().ForEach(item => successList.Add(item));
|
||||
|
||||
// try
|
||||
// {
|
||||
// // 唯一验证已处理,入库前去掉.
|
||||
// tInfo.AllFieldsModel.Where(x => x.__config__.jnpfKey.Equals(JnpfKeyConst.COMINPUT) && x.__config__.unique).ToList().ForEach(item => item.__config__.unique = false);
|
||||
// _sqlSugarClient.BeginTran();
|
||||
// foreach (var item in successList)
|
||||
// {
|
||||
// if (item.ContainsKey("Update_MainTablePrimary_Id"))
|
||||
// {
|
||||
// string? mainId = item["Update_MainTablePrimary_Id"].ToString();
|
||||
// var haveTableSql = await _runService.GetUpdateSqlByTemplate(tInfo, new VisualDevModelDataUpInput() { data = item.ToJsonString() }, mainId);
|
||||
// foreach (var it in haveTableSql) await _databaseService.ExecuteSql(tInfo.DbLink, it); // 修改功能数据
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if ((tInfo.visualDevEntity?.EnableFlow.Equals(1)).ParseToBool())
|
||||
// {
|
||||
// var flowId = _repository.AsSugarClient().Queryable<WorkFlow.Entitys.Entity.FlowFormEntity>().First(x => x.Id.Equals(tInfo.visualDevEntity.Id)).FlowId;
|
||||
// await _flowTaskService.Create(new Common.Models.WorkFlow.FlowTaskSubmitModel() { formData = item.ToJsonString(), flowId = flowId, flowUrgent = 1 });
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// string? mainId = YitIdHelper.NextId().ToString();
|
||||
// var haveTableSql = await _runService.GetCreateSqlByTemplate(tInfo, new VisualDevModelDataCrInput() { data = item.ToJsonString() }, mainId);
|
||||
try
|
||||
{
|
||||
// 唯一验证已处理,入库前去掉.
|
||||
tInfo.AllFieldsModel.Where(x => x.__config__.jnpfKey.Equals(JnpfKeyConst.COMINPUT) && x.__config__.unique).ToList().ForEach(item => item.__config__.unique = false);
|
||||
_sqlSugarClient.BeginTran();
|
||||
foreach (var item in successList)
|
||||
{
|
||||
if (item.ContainsKey("Update_MainTablePrimary_Id"))
|
||||
{
|
||||
string? mainId = item["Update_MainTablePrimary_Id"].ToString();
|
||||
var haveTableSql = await _runService.GetUpdateSqlByTemplate(tInfo, new VisualDevModelDataUpInput() { data = item.ToJsonString() }, mainId);
|
||||
foreach (var it in haveTableSql) await _databaseService.ExecuteSql(tInfo.DbLink, it); // 修改功能数据
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((tInfo.visualDevEntity?.EnableFlow.Equals(1)).ParseToBool())
|
||||
{
|
||||
var flowId = _repository.AsSugarClient().Queryable<WorkFlow.Entitys.Entity.FlowFormEntity>().First(x => x.Id.Equals(tInfo.visualDevEntity.Id)).FlowId;
|
||||
await _flowTaskService.Create(new Common.Models.WorkFlow.FlowTaskSubmitModel() { formData = item, flowId = flowId, flowUrgent = 1, status = 1 });
|
||||
}
|
||||
else
|
||||
{
|
||||
string? mainId = YitIdHelper.NextId().ToString();
|
||||
var haveTableSql = await _runService.GetCreateSqlByTemplate(tInfo, new VisualDevModelDataCrInput() { data = item.ToJsonString() }, mainId);
|
||||
|
||||
// // 主表自增长Id.
|
||||
// if (haveTableSql.ContainsKey("MainTableReturnIdentity"))
|
||||
// {
|
||||
// mainId = haveTableSql["MainTableReturnIdentity"].First().First().Value.ToString();
|
||||
// haveTableSql.Remove("MainTableReturnIdentity");
|
||||
// }
|
||||
// foreach (var it in haveTableSql)
|
||||
// await _databaseService.ExecuteSql(tInfo.DbLink, it.Key, it.Value); // 新增功能数据
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// 主表自增长Id.
|
||||
if (haveTableSql.ContainsKey("MainTableReturnIdentity"))
|
||||
{
|
||||
mainId = haveTableSql["MainTableReturnIdentity"].First().First().Value.ToString();
|
||||
haveTableSql.Remove("MainTableReturnIdentity");
|
||||
}
|
||||
foreach (var it in haveTableSql)
|
||||
await _databaseService.ExecuteSql(tInfo.DbLink, it.Key, it.Value); // 新增功能数据
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// _sqlSugarClient.CommitTran();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// _sqlSugarClient.RollbackTran();
|
||||
// throw;
|
||||
// }
|
||||
_sqlSugarClient.CommitTran();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_sqlSugarClient.RollbackTran();
|
||||
throw;
|
||||
}
|
||||
|
||||
// errorsList.ForEach(item =>
|
||||
// {
|
||||
// if (item.ContainsKey("errorsInfo") && item["errorsInfo"].IsNotEmptyOrNull()) item["errorsInfo"] = item["errorsInfo"].ToString().TrimStart(',').TrimEnd(',');
|
||||
// });
|
||||
errorsList.ForEach(item =>
|
||||
{
|
||||
if (item.ContainsKey("errorsInfo") && item["errorsInfo"].IsNotEmptyOrNull()) item["errorsInfo"] = item["errorsInfo"].ToString().TrimStart(',').TrimEnd(',');
|
||||
});
|
||||
|
||||
// return new object[] { successList, errorsList };
|
||||
//}
|
||||
return new object[] { successList, errorsList };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Excel 转输出 Model.
|
||||
|
||||
Reference in New Issue
Block a user