using JNPF.Common.Const;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Models.Authorize;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Model.DataBase;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev.Engine;
using JNPF.VisualDev.Engine.Core;
using JNPF.VisualDev.Engine.Model;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Entitys.Dto.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
using JNPF.VisualDev.Interfaces;
using JNPF.WorkFlow.Entitys.Entity;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.VisualDev;
///
/// 可视化开发基础 .
///
[ApiDescriptionSettings(Tag = "VisualDev", Name = "Base", Order = 171)]
[Route("api/visualdev/[controller]")]
public class VisualDevService : IVisualDevService, IDynamicApiController, ITransient
{
///
/// 服务基础仓储.
///
private readonly ISqlSugarRepository _visualDevRepository;
///
/// 字典服务.
///
private readonly IDictionaryDataService _dictionaryDataService;
///
/// 切库.
///
private readonly IDataBaseManager _changeDataBase;
///
/// 用户管理.
///
private readonly IUserManager _userManager;
///
/// 在线开发运行服务.
///
private readonly IRunService _runService;
///
/// 多租户事务.
///
private readonly ITenant _db;
///
/// 初始化一个类型的新实例.
///
public VisualDevService(
ISqlSugarRepository visualDevRepository,
IDataBaseManager changeDataBase,
IUserManager userManager,
IRunService runService,
IDictionaryDataService dictionaryDataService,
ISqlSugarClient context)
{
_visualDevRepository = visualDevRepository;
_dictionaryDataService = dictionaryDataService;
_userManager = userManager;
_runService = runService;
_changeDataBase = changeDataBase;
_db = context.AsTenant();
}
#region Get
///
/// 获取功能列表.
///
/// 请求参数.
///
[HttpGet("")]
public async Task GetList([FromQuery] VisualDevListQueryInput input)
{
SqlSugarPagedList? data = await _visualDevRepository.AsSugarClient().Queryable()
.WhereIF(!string.IsNullOrEmpty(input.keyword), a => a.FullName.Contains(input.keyword) || a.EnCode.Contains(input.keyword))
.WhereIF(!string.IsNullOrEmpty(input.category), a => a.Category == input.category)
.Where(a => a.DeleteMark == null && a.Type == input.type)
.OrderBy(a => a.SortCode, OrderByType.Asc)
.OrderBy(a => a.CreatorTime, OrderByType.Desc)
.OrderBy(a => a.LastModifyTime, OrderByType.Desc)
.Select(a => new VisualDevListOutput
{
id = a.Id,
fullName = a.FullName,
enCode = a.EnCode,
state = a.State,
type = a.Type,
webType = a.WebType,
tables = a.Tables,
description = a.Description,
creatorTime = a.CreatorTime,
lastModifyTime = a.LastModifyTime,
deleteMark = a.DeleteMark,
sortCode = a.SortCode,
parentId = a.Category,
isRelease = a.State,
enableFlow = a.EnableFlow,
pcIsRelease = SqlFunc.Subqueryable().Where(m => m.ModuleId == a.Id && m.Category == "Web" && m.DeleteMark == null && m.ModuleId != null).Count(),
appIsRelease = SqlFunc.Subqueryable().Where(m => m.ModuleId == a.Id && m.Category == "App" && m.DeleteMark == null && m.ModuleId != null).Count(),
category = SqlFunc.Subqueryable().Where(d => d.Id == a.Category).Select(d => d.FullName),
creatorUser = SqlFunc.Subqueryable().Where(u => u.Id == a.CreatorUserId).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account)),
lastModifyUser = SqlFunc.Subqueryable().Where(u => u.Id == a.LastModifyUserId).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account))
}).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult.SqlSugarPageResult(data);
}
///
/// 获取功能列表下拉框.
///
///
///
[HttpGet("Selector")]
public async Task GetSelector([FromQuery] VisualDevSelectorInput input)
{
var data = await _visualDevRepository.AsSugarClient().Queryable().Where(v => v.Type == input.type && v.DeleteMark == null).
OrderBy(a => a.Category).OrderBy(a => a.SortCode).ToListAsync();
List? output = data.Adapt>();
IEnumerable? parentIds = output.Select(x => x.parentId).ToList().Distinct();
List? pList = new List();
List? parentData = await _visualDevRepository.AsSugarClient().Queryable().Where(d => parentIds.Contains(d.Id) && d.DeleteMark == null).OrderBy(x => x.SortCode).ToListAsync();
foreach (DictionaryDataEntity? item in parentData)
{
VisualDevSelectorOutput? pData = item.Adapt();
pData.parentId = "-1";
pList.Add(pData);
}
return new { list = output.Union(pList).ToList().ToTree("-1") };
}
///
/// 获取功能信息.
///
/// 主键id.
///
[HttpGet("{id}")]
public async Task GetInfo(string id)
{
VisualDevEntity? data = await _visualDevRepository.AsQueryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
return data.Adapt();
}
///
/// 获取表单主表属性下拉框.
///
///
/// 1:过滤指定控件.
///
[HttpGet("{id}/FormDataFields")]
public async Task GetFormDataFields(string id, [FromQuery] int filterType)
{
var templateEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
TemplateParsingBase? tInfo = new TemplateParsingBase(templateEntity.Adapt()); // 解析模板
List? fieldsModels = tInfo.SingleFormData.FindAll(x => x.__vModel__.IsNotEmptyOrNull() && !JnpfKeyConst.RELATIONFORM.Equals(x.__config__.jnpfKey));
if (filterType.Equals(1))
{
fieldsModels = fieldsModels.FindAll(x => !JnpfKeyConst.UPLOADIMG.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.UPLOADFZ.Equals(x.__config__.jnpfKey)
&& !JnpfKeyConst.MODIFYUSER.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.MODIFYTIME.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.LINK.Equals(x.__config__.jnpfKey)
&& !JnpfKeyConst.BUTTON.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.ALERT.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.JNPFTEXT.Equals(x.__config__.jnpfKey)
&& !JnpfKeyConst.BARCODE.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.QRCODE.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.TABLE.Equals(x.__config__.jnpfKey)
&& !JnpfKeyConst.CREATEUSER.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.CREATETIME.Equals(x.__config__.jnpfKey) && !JnpfKeyConst.BILLRULE.Equals(x.__config__.jnpfKey)
&& !JnpfKeyConst.POPUPSELECT.Equals(x.__config__.jnpfKey));
}
List? output = fieldsModels.Select(x => new VisualDevFormDataFieldsOutput()
{
label = x.__config__.label,
vmodel = x.__vModel__
}).ToList();
return new { list = output };
}
///
/// 获取表单主表属性列表.
///
///
///
///
[HttpGet("{id}/FieldDataSelect")]
public async Task GetFieldDataSelect(string id, [FromQuery] VisualDevDataFieldDataListInput input)
{
Dictionary queryDic = new Dictionary();
if (!string.IsNullOrWhiteSpace(input.relationField) && !string.IsNullOrWhiteSpace(input.keyword)) queryDic.Add(input.relationField, input.keyword);
VisualDevEntity? templateEntity = await GetInfoById(id, true); // 取数据
TemplateParsingBase? tInfo = new TemplateParsingBase(templateEntity); // 解析模板
// 指定查询字段
if (input.IsNotEmptyOrNull() && input.columnOptions.IsNotEmptyOrNull())
{
List? showFieldList = input.columnOptions.Split(',').ToList(); // 显示的所有 字段
List? flist = new List();
List? clist = new List();
// 获取 调用 该功能表单 的功能模板
FieldsModel? smodel = tInfo.FieldsModelList.Where(x => x.__vModel__ == input.relationField).First();
smodel.searchType = 2;
flist.Add(smodel); // 添加 关联查询字段
if (tInfo.ColumnData == null)
{
tInfo.ColumnData = new ColumnDesignModel()
{
columnList = new List() { new IndexGridFieldModel() { prop = input.relationField, label = input.relationField } },
searchList = new List() { smodel.Adapt() }
};
}
if (!tInfo.ColumnData.columnList.Where(x => x.prop == input.relationField).Any())
tInfo.ColumnData.columnList.Add(new IndexGridFieldModel() { prop = input.relationField, label = input.relationField });
if (tInfo.ColumnData.defaultSidx.IsNotEmptyOrNull() && tInfo.FieldsModelList.Any(x => x.__vModel__ == tInfo.ColumnData?.defaultSidx))
flist.Add(tInfo.FieldsModelList.Where(x => x.__vModel__ == tInfo.ColumnData?.defaultSidx).FirstOrDefault()); // 添加 关联排序字段
tInfo.FieldsModelList.ForEach(item =>
{
if (showFieldList.Find(x => x == item.__vModel__) != null) flist.Add(item);
});
clist.Add(tInfo.ColumnData.columnList.Where(x => x.prop == input.relationField).FirstOrDefault()); // 添加 关联查询字段
if (tInfo.ColumnData.defaultSidx.IsNotEmptyOrNull() && tInfo.FieldsModelList.Any(x => x.__vModel__ == tInfo.ColumnData?.defaultSidx))
clist.Add(tInfo.ColumnData.columnList.Where(x => x.prop == tInfo.ColumnData?.defaultSidx).FirstOrDefault()); // 添加 关联排序字段
showFieldList.ForEach(item =>
{
if (!tInfo.ColumnData.columnList.Where(x => x.prop == item).Any())
clist.Add(new IndexGridFieldModel() { prop = item, label = item });
else
clist.Add(tInfo.ColumnData.columnList.Find(x => x.prop == item));
});
if (flist.Count > 0)
{
tInfo.FormModel.fields = flist.Distinct().ToList();
templateEntity.FormData = tInfo.FormModel.ToJsonString();
}
if (clist.Count > 0)
{
tInfo.ColumnData.columnList = clist.Distinct().ToList();
templateEntity.ColumnData = tInfo.ColumnData.ToJsonString();
}
}
// 获取值 无分页
VisualDevModelListQueryInput listQueryInput = new VisualDevModelListQueryInput
{
queryJson = queryDic.ToJsonString(),
currentPage = input.currentPage > 0 ? input.currentPage : 1,
pageSize = input.pageSize > 0 ? input.pageSize : 20,
dataType = "1",
sidx = tInfo.ColumnData.defaultSidx,
sort = tInfo.ColumnData.sort
};
return await _runService.GetRelationFormList(templateEntity, listQueryInput, "List");
}
///
/// 回滚模板.
///
/// 主键id.
///
[HttpGet("{id}/Actions/RollbackTemplate")]
public async Task RollbackTemplate(string id)
{
var vREntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(x => x.Id.Equals(id) && x.DeleteMark == null);
if (vREntity == null) throw Oops.Oh(ErrorCode.D1415);
VisualDevEntity? entity = vREntity.Adapt();
entity.State = 1;
await _visualDevRepository.AsSugarClient().Updateable(entity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
#endregion
#region Post
///
/// 新建功能信息.
///
/// 实体对象.
///
[HttpPost("")]
public async Task Create([FromBody] VisualDevCrInput input)
{
VisualDevEntity? entity = input.Adapt();
try
{
// 验证名称和编码是否重复
if (await _visualDevRepository.IsAnyAsync(x => x.DeleteMark == null && (x.FullName == input.fullName || x.EnCode == input.enCode))) throw Oops.Oh(ErrorCode.D1406);
if (input.formData.IsNotEmptyOrNull())
{
TemplateParsingBase? tInfo = new TemplateParsingBase(entity); // 解析模板
if (!tInfo.VerifyTemplate()) throw Oops.Oh(ErrorCode.D1401); // 验证模板
await VerifyPrimaryKeyPolicy(tInfo, entity.DbLinkId); // 验证雪花Id 和自增长Id 主键是否支持
}
_db.BeginTran(); // 开启事务
entity.State = 0;
// 添加功能
entity = await _visualDevRepository.AsSugarClient().Insertable(entity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
// 同步流程相关
if (entity.EnableFlow.Equals(1) && (!entity.Type.Equals(3) && !entity.Type.Equals(4)))
{
var fEntity = entity.Adapt();
fEntity.PropertyJson = entity.FormData;
fEntity.TableJson = entity.Tables;
fEntity.DraftJson = fEntity.ToJsonString();
fEntity.FlowType = 1;
fEntity.FormType = 2;
fEntity.FlowId = entity.Id;
await _visualDevRepository.AsSugarClient().Insertable(fEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
await SaveFlowTemplate(entity);
}
_db.CommitTran(); // 提交事务
}
catch (Exception)
{
_db.RollbackTran();
throw;
}
}
///
/// 修改接口.
///
/// 主键id
/// 参数
///
[HttpPut("{id}")]
public async Task Update(string id, [FromBody] VisualDevUpInput input)
{
VisualDevEntity? entity = input.Adapt();
try
{
if (!input.webType.Equals(4) && await _visualDevRepository.AsQueryable().AnyAsync(x => x.Id.Equals(id) && x.State.Equals(1)) && (entity.Tables.IsNullOrEmpty() || entity.Tables.Equals("[]")))
throw Oops.Oh(ErrorCode.D1416); // 已发布的模板 表不能为空.
// 验证名称和编码是否重复
if (await _visualDevRepository.IsAnyAsync(x => x.DeleteMark == null && x.Id != entity.Id && (x.FullName == input.fullName || x.EnCode == input.enCode))) throw Oops.Oh(ErrorCode.D1406);
if (input.formData.IsNotEmptyOrNull())
{
TemplateParsingBase? tInfo = new TemplateParsingBase(entity); // 解析模板
if (!tInfo.VerifyTemplate()) throw Oops.Oh(ErrorCode.D1401); // 验证模板
await VerifyPrimaryKeyPolicy(tInfo, entity.DbLinkId); // 验证雪花Id 和自增长Id 主键是否支持
}
_db.BeginTran(); // 开启事务
// 修改功能
await _visualDevRepository.AsSugarClient().Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
// 同步流程相关
if (entity.EnableFlow.Equals(1) && (!entity.Type.Equals(3) && !entity.Type.Equals(4)))
{
var fEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(x => x.Id.Equals(id));
if (fEntity != null)
{
// EnabledMark=0 未发布,EnabledMark=1 已发布
if (fEntity.EnabledMark.Equals(0))
{
fEntity.FullName = entity.FullName;
fEntity.EnCode = entity.EnCode;
fEntity.TableJson = entity.Tables;
fEntity.PropertyJson = entity.FormData;
fEntity.DraftJson = fEntity.ToJsonString();
}
else
{
var dEntity = fEntity.Copy();
dEntity.TableJson = entity.Tables;
dEntity.PropertyJson = entity.FormData;
fEntity = new FlowFormEntity();
fEntity.DraftJson = dEntity.ToJsonString();
fEntity.Id = id;
}
fEntity.FlowType = 1;
fEntity.FormType = 2;
fEntity.FlowId = id;
await _visualDevRepository.AsSugarClient().Updateable(fEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
await SaveFlowTemplate(entity);
}
else
{
fEntity = entity.Adapt();
fEntity.PropertyJson = entity.FormData;
fEntity.TableJson = entity.Tables;
fEntity.DraftJson = fEntity.ToJsonString();
fEntity.FlowType = 1;
fEntity.FormType = 2;
fEntity.FlowId = id;
await _visualDevRepository.AsSugarClient().Insertable(fEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
await SaveFlowTemplate(entity);
}
}
_db.CommitTran(); // 关闭事务
}
catch (Exception)
{
_db.RollbackTran();
throw;
}
}
///
/// 删除接口.
///
/// 主键id.
///
[HttpDelete("{id}")]
public async Task Delete(string id)
{
var entity = await _visualDevRepository.AsQueryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
await _visualDevRepository.AsSugarClient().Updateable(entity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandAsync();
// 同步删除线上版本
var rEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
if (rEntity != null) await _visualDevRepository.AsSugarClient().Updateable(rEntity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandAsync();
// 同步删除流程表单
var fEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
if (fEntity != null)
{
await _visualDevRepository.AsSugarClient().Updateable(fEntity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandAsync();
await _visualDevRepository.AsSugarClient().Deleteable().Where(x => x.FormId.Equals(fEntity.FlowId)).ExecuteCommandAsync();
}
// 同步删除流程引擎
var tEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
if (tEntity != null)
{
await _visualDevRepository.AsSugarClient().Updateable(tEntity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandAsync();
}
}
///
/// 复制.
///
/// 主键值.
///
[HttpPost("{id}/Actions/Copy")]
public async Task ActionsCopy(string id)
{
string? random = new Random().NextLetterAndNumberString(5);
VisualDevEntity? entity = await _visualDevRepository.AsQueryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
if (entity.State.Equals(1) && (!entity.Type.Equals(3) && !entity.Type.Equals(4)))
{
var vREntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == id && v.DeleteMark == null);
entity = vREntity.Adapt();
entity.State = 0;
}
entity.FullName = entity.FullName + "副本" + random;
entity.EnCode += random;
entity.State = 0;
entity.Id = null; // 复制的数据需要把Id清空,否则会主键冲突错误
entity.LastModifyTime = null;
if (entity.EnableFlow.Equals(1))
{
DictionaryDataEntity? categoryData = await _dictionaryDataService.GetInfo(entity.Category);
FlowEngineEntity? flowEngine = new FlowEngineEntity();
flowEngine.FlowTemplateJson = entity.FlowTemplateJson;
flowEngine.EnCode = "#visualDev" + entity.EnCode;
flowEngine.Type = 1;
flowEngine.FormType = 2;
flowEngine.FullName = entity.FullName;
flowEngine.Category = categoryData.EnCode;
flowEngine.VisibleType = 0;
flowEngine.Icon = "icon-ym icon-ym-node";
flowEngine.IconBackground = "#008cff";
flowEngine.Tables = entity.Tables;
flowEngine.DbLinkId = entity.DbLinkId;
flowEngine.FormTemplateJson = entity.FormData;
flowEngine.Version = "1";
flowEngine.LastModifyTime = null;
try
{
// 添加流程引擎
FlowEngineEntity? engineEntity = await _visualDevRepository.AsSugarClient().Insertable(flowEngine).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Creator()).ExecuteReturnEntityAsync();
entity.Id = engineEntity.Id;
entity = await _visualDevRepository.AsSugarClient().Insertable(entity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
}
catch
{
if (entity.FullName.Length >= 100 || entity.EnCode.Length >= 50) throw Oops.Oh(ErrorCode.D1403); // 数据长度超过 字段设定长度
else throw;
}
}
else
{
try
{
await _visualDevRepository.AsSugarClient().Insertable(entity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
catch
{
if (entity.FullName.Length >= 100 || entity.EnCode.Length >= 50) throw Oops.Oh(ErrorCode.D1403); // 数据长度超过 字段设定长度
else throw;
}
}
// 同步流程相关
if (entity.EnableFlow.Equals(1) && (!entity.Type.Equals(3) && !entity.Type.Equals(4)))
{
var fEntity = entity.Adapt();
fEntity.PropertyJson = entity.FormData;
fEntity.TableJson = entity.Tables;
fEntity.DraftJson = fEntity.ToJsonString();
fEntity.FlowType = 1;
fEntity.FormType = 2;
fEntity.FlowId = entity.Id;
await _visualDevRepository.AsSugarClient().Insertable(fEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
await SaveFlowTemplate(entity);
}
}
///
/// 功能同步菜单.
///
///
///
///
[HttpPost("{id}/Actions/Release")]
public async Task FuncToMenu(string id, [FromBody] VisualDevToMenuInput input)
{
input.id = id;
VisualDevEntity? entity = await _visualDevRepository.AsQueryable().FirstAsync(x => x.Id == input.id);
input.pcSystemId = input.pcSystemId.IsNullOrEmpty() ? _userManager.User.SystemId : input.pcSystemId;
input.appSystemId = input.appSystemId.IsNullOrEmpty() ? _userManager.User.SystemId : input.appSystemId;
input.pcModuleParentId = input.pcModuleParentId.IsNullOrWhiteSpace() ? "-1" : input.pcModuleParentId;
input.appModuleParentId = input.appModuleParentId.IsNullOrWhiteSpace() ? "-1" : input.appModuleParentId;
//if (entity.State == 0) throw Oops.Oh(ErrorCode.D1405);
if (entity.FormData.IsNullOrEmpty() && !entity.WebType.Equals(4)) throw Oops.Oh(ErrorCode.COM1013);
if ((entity.WebType.Equals(2) || entity.WebType.Equals(4)) && entity.ColumnData.IsNullOrEmpty()) throw Oops.Oh(ErrorCode.COM1014);
#region 旧的菜单、权限数据
var oldWebModule = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(x => x.ModuleId == input.id && x.Category == "Web" && x.DeleteMark == null);
var oldWebModuleButtonEntity = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.DeleteMark == null)
.WhereIF(oldWebModule != null, x => x.ModuleId == oldWebModule.Id).WhereIF(oldWebModule == null, x => x.ModuleId == "0").ToListAsync();
var oldWebModuleColumnEntity = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.DeleteMark == null)
.WhereIF(oldWebModule != null, x => x.ModuleId == oldWebModule.Id).WhereIF(oldWebModule == null, x => x.ModuleId == "0").ToListAsync();
var oldWebModuleFormEntity = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.DeleteMark == null)
.WhereIF(oldWebModule != null, x => x.ModuleId == oldWebModule.Id).WhereIF(oldWebModule == null, x => x.ModuleId == "0").ToListAsync();
var oldAppModule = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(x => x.ModuleId == input.id && x.Category == "App" && x.DeleteMark == null);
var oldAppModuleButtonEntity = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.DeleteMark == null)
.WhereIF(oldAppModule != null, x => x.ModuleId == oldAppModule.Id).WhereIF(oldAppModule == null, x => x.ModuleId == "0").ToListAsync();
var oldAppModuleColumnEntity = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.DeleteMark == null)
.WhereIF(oldAppModule != null, x => x.ModuleId == oldAppModule.Id).WhereIF(oldAppModule == null, x => x.ModuleId == "0").ToListAsync();
var oldAppModuleFormEntity = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.DeleteMark == null)
.WhereIF(oldAppModule != null, x => x.ModuleId == oldAppModule.Id).WhereIF(oldAppModule == null, x => x.ModuleId == "0").ToListAsync();
#endregion
var oldWebId = (oldWebModule != null ? oldWebModule.Id : "null");
if (_visualDevRepository.AsSugarClient().Queryable().Any(x => (x.EnCode == entity.EnCode || x.FullName == entity.FullName) && x.Id != oldWebId && x.Category == "Web" && x.DeleteMark == null))
throw Oops.Oh(ErrorCode.COM1015);
var oldAppId = (oldAppModule != null ? oldAppModule.Id : "null");
if (_visualDevRepository.AsSugarClient().Queryable().Any(x => (x.EnCode == entity.EnCode || x.FullName == entity.FullName) && x.Id != oldAppId && x.Category == "App" && x.DeleteMark == null))
throw Oops.Oh(ErrorCode.COM1015);
#region 数据视图
if (entity.WebType.Equals(4))
{
#region 菜单组装
var moduleModel = new ModuleEntity();
moduleModel.Id = oldWebModule != null ? oldWebModule.Id : SnowflakeIdHelper.NextId();
moduleModel.ModuleId = input.id;
moduleModel.ParentId = oldWebModule != null ? oldWebModule.ParentId : (input.pcModuleParentId.Equals(input.pcSystemId) ? "-1" : input.pcModuleParentId); // 父级菜单节点
moduleModel.Category = "Web";
moduleModel.FullName = entity.FullName;
moduleModel.EnCode = entity.EnCode;
moduleModel.Icon = "icon-ym icon-ym-webForm";
moduleModel.UrlAddress = oldWebModule != null ? oldWebModule.UrlAddress : "model/" + entity.EnCode;
moduleModel.Type = 3;
moduleModel.EnabledMark = 1;
moduleModel.IsColumnAuthorize = 1;
moduleModel.IsButtonAuthorize = 1;
moduleModel.IsFormAuthorize = 1;
moduleModel.IsDataAuthorize = 1;
moduleModel.SortCode = 999;
moduleModel.CreatorTime = DateTime.Now;
moduleModel.PropertyJson = (new { moduleId = input.id, iconBackgroundColor = string.Empty, isTree = 0 }).ToJsonString();
moduleModel.SystemId = oldWebModule != null ? oldWebModule.SystemId : input.pcSystemId;
#endregion
// 添加PC菜单
if (input.pc == 1)
{
var storModuleModel = _visualDevRepository.AsSugarClient().Storageable(moduleModel).Saveable().ToStorage(); // 存在更新不存在插入 根据主键
await storModuleModel.AsInsertable.ExecuteCommandAsync(); // 执行插入
await storModuleModel.AsUpdateable.ExecuteCommandAsync(); // 执行更新
}
// 添加App菜单
if (input.app == 1)
{
#region App菜单
moduleModel.Id = oldAppModule != null ? oldAppModule.Id : SnowflakeIdHelper.NextId();
moduleModel.ModuleId = input.id;
moduleModel.ParentId = oldAppModule != null ? oldAppModule.ParentId : (input.appModuleParentId.Equals(input.appSystemId) ? "-1" : input.appModuleParentId); // 父级菜单节点
moduleModel.Category = "App";
moduleModel.UrlAddress = oldAppModule != null ? oldAppModule.UrlAddress : "/pages/apply/dynamicModel/index?id=" + entity.EnCode;
moduleModel.SystemId = oldAppModule != null ? oldAppModule.SystemId : input.appSystemId;
#endregion
var storModuleModel = _visualDevRepository.AsSugarClient().Storageable(moduleModel).Saveable().ToStorage(); // 存在更新不存在插入 根据主键
await storModuleModel.AsInsertable.ExecuteCommandAsync(); // 执行插入
await storModuleModel.AsUpdateable.ExecuteCommandAsync(); // 执行更新
}
// 修改功能发布状态
await _visualDevRepository.AsUpdateable().SetColumns(it => it.State == 1).Where(it => it.Id == id).ExecuteCommandHasChangeAsync();
// 线上版本
if (!await _visualDevRepository.AsSugarClient().Queryable().AnyAsync(x => x.Id.Equals(id)))
{
var vReleaseEntity = entity.Adapt();
await _visualDevRepository.AsSugarClient().Insertable(vReleaseEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
}
else
{
var vReleaseEntity = entity.Adapt();
await _visualDevRepository.AsSugarClient().Updateable(vReleaseEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
return;
}
#endregion
TemplateParsingBase? tInfo = new TemplateParsingBase(entity); // 解析模板
// 无表转有表
if (!tInfo.IsHasTable)
{
string? mTableName = "mt" + entity.Id; // 主表名称
VisualDevEntity? res = await NoTblToTable(entity, mTableName);
if (res != null)
await _visualDevRepository.AsSugarClient().Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
else
throw Oops.Oh(ErrorCode.D1414);
tInfo = new TemplateParsingBase(res); // 解析模板
entity = res;
}
ColumnDesignModel? columnData = new ColumnDesignModel();
// 列配置模型
if (!string.IsNullOrWhiteSpace(entity.ColumnData))
{
columnData = entity.ColumnData.ToObject();
}
else
{
columnData = new ColumnDesignModel()
{
btnsList = new List(),
columnBtnsList = new List(),
customBtnsList = new List(),
columnList = new List(),
defaultColumnList = new List()
};
}
columnData.btnsList = columnData.btnsList.Union(columnData.columnBtnsList).ToList();
if (columnData.customBtnsList != null && columnData.customBtnsList.Any()) columnData.btnsList = columnData.btnsList.Union(columnData.customBtnsList).ToList();
ColumnDesignModel? appColumnData = new ColumnDesignModel();
// App列配置模型
if (!string.IsNullOrWhiteSpace(entity.AppColumnData))
{
appColumnData = tInfo.AppColumnData;
}
else
{
appColumnData = new ColumnDesignModel()
{
btnsList = new List(),
columnBtnsList = new List(),
customBtnsList = new List(),
columnList = new List(),
defaultColumnList = new List()
};
}
appColumnData.btnsList = appColumnData.btnsList.Union(appColumnData.columnBtnsList).ToList();
if (appColumnData.customBtnsList != null && appColumnData.customBtnsList.Any()) appColumnData.btnsList = appColumnData.btnsList.Union(appColumnData.customBtnsList).ToList();
try
{
_db.BeginTran();
#region 菜单组装
var moduleModel = new ModuleEntity();
moduleModel.Id = oldWebModule != null ? oldWebModule.Id : SnowflakeIdHelper.NextId();
moduleModel.ModuleId = input.id;
moduleModel.ParentId = oldWebModule != null ? oldWebModule.ParentId : (input.pcModuleParentId.Equals(input.pcSystemId) ? "-1" : input.pcModuleParentId); // 父级菜单节点
moduleModel.Category = "Web";
moduleModel.FullName = oldWebModule!=null ? oldWebModule.FullName : entity.FullName; //modifyby zhoukeda 发布功能不更新名称排序图标
moduleModel.EnCode = entity.EnCode;
moduleModel.Icon = oldWebModule!=null ? oldWebModule.Icon : "icon-ym icon-ym-webForm"; //modifyby zhoukeda 发布功能不更新名称排序图标
moduleModel.UrlAddress = oldWebModule != null ? oldWebModule.UrlAddress : "model/" + entity.EnCode;
moduleModel.Type = 3;
moduleModel.EnabledMark = 1;
moduleModel.IsColumnAuthorize = 1;
moduleModel.IsButtonAuthorize = 1;
moduleModel.IsFormAuthorize = 1;
moduleModel.IsDataAuthorize = 1;
moduleModel.SortCode = oldWebModule != null ? oldWebModule.SortCode : 999; //modifyby zhoukeda 发布功能不更新名称排序图标
moduleModel.CreatorTime = DateTime.Now;
moduleModel.PropertyJson = (new { moduleId = input.id, iconBackgroundColor = string.Empty, isTree = 0 }).ToJsonString();
moduleModel.SystemId = oldWebModule != null ? oldWebModule.SystemId : input.pcSystemId;
#endregion
#region 配置权限
// 按钮权限
var btnAuth = new List();
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_add", FullName = "新增", Icon = "el-icon-plus", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_download", FullName = "导出", Icon = "el-icon-download", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_upload", FullName = "导入", Icon = "el-icon-upload2", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_batchRemove", FullName = "批量删除", Icon = "el-icon-delete", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_edit", FullName = "编辑", Icon = "el-icon-edit", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_remove", FullName = "删除", Icon = "el-icon-delete", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_detail", FullName = "详情", Icon = "el-icon-tickets", ModuleId = moduleModel.Id });
columnData.customBtnsList.ForEach(item =>
{
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 1, SortCode = 0, ParentId = "-1", EnCode = item.value, FullName = item.label, ModuleId = moduleModel.Id });
});
columnData.btnsList.ForEach(item =>
{
var aut = btnAuth.Find(x => x.FullName == item.label);
if (aut != null) aut.EnabledMark = 1;
});
// 表单权限
var columnAuth = new List();
var fieldList = tInfo.AllFieldsModel;
var formAuth = new List();
var ctList = tInfo.AllFieldsModel.Where(x => x.__config__.jnpfKey == JnpfKeyConst.TABLE).ToList();
var childTableIndex = new Dictionary();
for (var i = 0; i < ctList.Count; i++) childTableIndex.Add(ctList[i].__vModel__, ctList[i].__config__.label + (i + 1));
fieldList = fieldList.Where(x => x.__config__.jnpfKey != JnpfKeyConst.TABLE).ToList();
fieldList.Where(x => x.__vModel__.IsNotEmptyOrNull()).ToList().ForEach(item =>
{
var fRule = item.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = item.__vModel__.ToLower().Contains("tablefield") && item.__vModel__.Contains("-") ? 2 : fRule;
var ctName = item.__vModel__.Split("-");
formAuth.Add(new ModuleFormEntity()
{
ParentId = "-1",
EnCode = item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ChildTableKey = fRule.Equals(2) ? ctName.FirstOrDefault() : string.Empty,
FieldRule = fRule,
ModuleId = moduleModel.Id,
FullName = fRule.Equals(2) ? childTableIndex[item.__vModel__.Split('-').First()] + "-" + item.__config__.label : item.__config__.label,
EnabledMark = 1,
SortCode = 0
});
});
ctList.ForEach(item => {
formAuth.Add(new ModuleFormEntity()
{
ParentId = "-1",
EnCode = item.__vModel__,
BindTable = tInfo.MainTableName,
ChildTableKey = item.__vModel__,
FieldRule = 0,
ModuleId = moduleModel.Id,
FullName = childTableIndex[item.__vModel__],
EnabledMark = 1,
SortCode = 0
});
});
// 列表权限
columnData.defaultColumnList.ForEach(item =>
{
var itemModel = fieldList.FirstOrDefault(x => x.__config__.jnpfKey == item.jnpfKey && x.__vModel__ == item.prop);
if (itemModel != null)
{
var fRule = itemModel.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = itemModel.__vModel__.ToLower().Contains("tablefield") && itemModel.__vModel__.Contains("-") ? 2 : fRule;
var ctName = item.__vModel__.Split("-");
columnAuth.Add(new ModuleColumnEntity()
{
ParentId = "-1",
EnCode = itemModel.__vModel__,
BindTable = fRule.Equals(2) ? itemModel.__config__.relationTable : itemModel.__config__.tableName,
ChildTableKey = fRule.Equals(2) ? itemModel.__vModel__.Split("-").FirstOrDefault() : string.Empty,
FieldRule = fRule,
ModuleId = moduleModel.Id,
FullName = fRule.Equals(2) ? childTableIndex[item.__vModel__.Split('-').First()] + item.__config__.label.Replace(item.__config__.label.Split("-").First(), string.Empty) : item.__config__.label,
EnabledMark = 0,
SortCode = 0
});
}
});
columnData.columnList.ForEach(item =>
{
var aut = columnAuth.Find(x => x.EnCode == item.prop);
if (aut != null) aut.EnabledMark = 1;
});
#endregion
// 添加PC菜单和权限
if (input.pc == 1)
{
var storModuleModel = _visualDevRepository.AsSugarClient().Storageable(moduleModel).Saveable().ToStorage(); // 存在更新不存在插入 根据主键
await storModuleModel.AsInsertable.ExecuteCommandAsync(); // 执行插入
await storModuleModel.AsUpdateable.ExecuteCommandAsync(); // 执行更新
#region 表单权限
if (columnData.useFormPermission)
{
if (!oldWebModuleFormEntity.Any())
{
await _visualDevRepository.AsSugarClient().Insertable(formAuth).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
else
{
var formAuthAddList = new List();
formAuth.ForEach(item =>
{
if (!oldWebModuleFormEntity.Any(x => x.EnCode == item.EnCode)) formAuthAddList.Add(item);
});
if (formAuthAddList.Any()) await _visualDevRepository.AsSugarClient().Insertable(formAuthAddList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
oldWebModuleFormEntity.ForEach(item =>
{
var it = formAuth.FirstOrDefault(x => x.EnCode == item.EnCode);
if (it == null) item.DeleteMark = 1; // 删除标识
else item.EnabledMark = 1; // 显示标识
});
await _visualDevRepository.AsSugarClient().Updateable(oldWebModuleFormEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
}
#endregion
#region 按钮权限
if (columnData.useBtnPermission)
{
if (!oldWebModuleButtonEntity.Any()) // 新增数据
{
await _visualDevRepository.AsSugarClient().Insertable(btnAuth).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
else // 修改增加数据权限
{
var btnAuthAddList = new List();
btnAuth.ForEach(item =>
{
if (!oldWebModuleButtonEntity.Any(x => x.EnCode == item.EnCode)) btnAuthAddList.Add(item);
});
if (btnAuthAddList.Any()) await _visualDevRepository.AsSugarClient().Insertable(btnAuthAddList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
oldWebModuleButtonEntity.ForEach(item =>
{
var it = btnAuth.FirstOrDefault(x => x.EnCode == item.EnCode);
if (it == null) item.DeleteMark = 1; // 删除标识
else item.EnabledMark = it.EnabledMark; // 显示标识
});
await _visualDevRepository.AsSugarClient().Updateable(oldWebModuleButtonEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
}
#endregion
#region 列表权限
if (columnData.useColumnPermission)
{
if (!oldWebModuleColumnEntity.Any()) // 新增数据
{
await _visualDevRepository.AsSugarClient().Insertable(columnAuth).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
else // 修改增加数据权限
{
var columnAuthAddList = new List();
columnAuth.ForEach(item =>
{
if (!oldWebModuleColumnEntity.Any(x => x.EnCode == item.EnCode)) columnAuthAddList.Add(item);
});
if (columnAuthAddList.Any()) await _visualDevRepository.AsSugarClient().Insertable(columnAuthAddList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
oldWebModuleColumnEntity.ForEach(item =>
{
var it = columnAuth.FirstOrDefault(x => x.EnCode == item.EnCode);
if (it == null) item.DeleteMark = 1; // 删除标识
else item.EnabledMark = it.EnabledMark; // 显示标识
});
await _visualDevRepository.AsSugarClient().Updateable(oldWebModuleColumnEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
}
#endregion
#region 数据权限
if (columnData.useDataPermission)
{
if (!_visualDevRepository.AsSugarClient().Queryable().Where(x => x.EnCode.Equals("jnpf_alldata") && x.ModuleId == moduleModel.Id && x.DeleteMark == null).Any())
{
// 全部数据权限方案
var AllDataAuthScheme = new ModuleDataAuthorizeSchemeEntity()
{
FullName = "全部数据",
EnCode = "jnpf_alldata",
AllData = 1,
ConditionText = string.Empty,
ConditionJson = string.Empty,
ModuleId = moduleModel.Id
};
await _visualDevRepository.AsSugarClient().Insertable(AllDataAuthScheme).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
}
// 创建用户和所属组织权限方案
// 只添加 主表控件的数据权限
var fList = fieldList.Where(x => !x.__vModel__.Contains("_jnpf_") && x.__vModel__.IsNotEmptyOrNull() && x.__config__.visibility.Contains("pc"))
.Where(x => x.__config__.jnpfKey == JnpfKeyConst.CREATEUSER || x.__config__.jnpfKey == JnpfKeyConst.CURRORGANIZE).ToList();
var authList = await MenuMergeDataAuth(moduleModel.Id, fList);
await MenuMergeDataAuthScheme(moduleModel.Id, authList, fList);
}
#endregion
}
#region App菜单、 权限组装
moduleModel.Id = oldAppModule != null ? oldAppModule.Id : SnowflakeIdHelper.NextId();
moduleModel.ModuleId = input.id;
moduleModel.ParentId = oldAppModule != null ? oldAppModule.ParentId : (input.appModuleParentId.Equals(input.appSystemId) ? "-1" : input.appModuleParentId); // 父级菜单节点
moduleModel.Category = "App";
moduleModel.UrlAddress = oldAppModule != null ? oldAppModule.UrlAddress : "/pages/apply/dynamicModel/index?id=" + entity.EnCode;
moduleModel.SystemId = oldAppModule != null ? oldAppModule.SystemId : input.appSystemId;
btnAuth = new List();
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_add", FullName = "新增", Icon = "el-icon-plus", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_edit", FullName = "编辑", Icon = "el-icon-edit", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_remove", FullName = "删除", Icon = "el-icon-delete", ModuleId = moduleModel.Id });
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 0, SortCode = 0, ParentId = "-1", EnCode = "btn_detail", FullName = "详情", Icon = "el-icon-tickets", ModuleId = moduleModel.Id });
appColumnData.customBtnsList.ForEach(item =>
{
btnAuth.Add(new ModuleButtonEntity() { EnabledMark = 1, SortCode = 0, ParentId = "-1", EnCode = item.value, FullName = item.label, ModuleId = moduleModel.Id });
});
appColumnData.btnsList.ForEach(item =>
{
var aut = btnAuth.Find(x => x.FullName == item.label);
if (aut != null) aut.EnabledMark = 1;
});
formAuth.Clear();
fieldList.Where(x => x.__vModel__.IsNotEmptyOrNull()).ToList().ForEach(item =>
{
var fRule = item.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = item.__vModel__.ToLower().Contains("tablefield") && item.__vModel__.Contains("-") ? 2 : fRule;
formAuth.Add(new ModuleFormEntity()
{
ParentId = "-1",
EnCode = item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ChildTableKey = fRule.Equals(2) ? item.__vModel__.Split("-").FirstOrDefault() : string.Empty,
FieldRule = fRule,
ModuleId = moduleModel.Id,
FullName = fRule.Equals(2) ? childTableIndex[item.__vModel__.Split('-').First()] + "-" + item.__config__.label : item.__config__.label,
EnabledMark = 1,
SortCode = 0
});
});
ctList.ForEach(item => {
formAuth.Add(new ModuleFormEntity()
{
ParentId = "-1",
EnCode = item.__vModel__,
BindTable = tInfo.MainTableName,
ChildTableKey = item.__vModel__,
FieldRule = 0,
ModuleId = moduleModel.Id,
FullName = childTableIndex[item.__vModel__],
EnabledMark = 1,
SortCode = 0
});
});
columnAuth.Clear();
appColumnData.defaultColumnList.ForEach(item =>
{
var itemModel = fieldList.FirstOrDefault(x => x.__config__.jnpfKey == item.jnpfKey && x.__vModel__ == item.prop);
if (itemModel != null)
{
var fRule = itemModel.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = itemModel.__vModel__.ToLower().Contains("tablefield") && itemModel.__vModel__.Contains("-") ? 2 : fRule;
columnAuth.Add(new ModuleColumnEntity()
{
ParentId = "-1",
EnCode = itemModel.__vModel__,
BindTable = fRule.Equals(2) ? itemModel.__config__.relationTable : itemModel.__config__.tableName,
ChildTableKey = fRule.Equals(2) ? itemModel.__vModel__.Split("-").FirstOrDefault() : string.Empty,
FieldRule = fRule,
ModuleId = moduleModel.Id,
FullName = fRule.Equals(2) ? childTableIndex[item.__vModel__.Split('-').First()] + item.__config__.label.Replace(item.__config__.label.Split("-").First(), string.Empty) : item.__config__.label,
EnabledMark = 0,
SortCode = 0
});
}
});
appColumnData.columnList.ForEach(item =>
{
var aut = columnAuth.Find(x => x.EnCode == item.prop);
if (aut != null) aut.EnabledMark = 1;
});
columnAuth.ForEach(item => { item.ModuleId = moduleModel.Id; });
#endregion
// 添加App菜单和权限
if (input.app == 1)
{
var storModuleModel = _visualDevRepository.AsSugarClient().Storageable(moduleModel).Saveable().ToStorage(); // 存在更新不存在插入 根据主键
await storModuleModel.AsInsertable.ExecuteCommandAsync(); // 执行插入
await storModuleModel.AsUpdateable.ExecuteCommandAsync(); // 执行更新
#region 表单权限
if (appColumnData.useFormPermission)
{
if (!oldAppModuleFormEntity.Any())
{
await _visualDevRepository.AsSugarClient().Insertable(formAuth).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
else
{
var formAuthAddList = new List();
formAuth.ForEach(item =>
{
if (!oldAppModuleFormEntity.Any(x => x.EnCode == item.EnCode)) formAuthAddList.Add(item);
});
if (formAuthAddList.Any()) await _visualDevRepository.AsSugarClient().Insertable(formAuthAddList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
oldAppModuleFormEntity.ForEach(item =>
{
var it = formAuth.FirstOrDefault(x => x.EnCode == item.EnCode);
if (it == null) item.DeleteMark = 1; // 删除标识
else item.EnabledMark = 1; // 显示标识
});
await _visualDevRepository.AsSugarClient().Updateable(oldAppModuleFormEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
}
#endregion
#region 按钮权限
if (appColumnData.useBtnPermission)
{
if (!oldAppModuleButtonEntity.Any()) // 新增数据
{
await _visualDevRepository.AsSugarClient().Insertable(btnAuth).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
else // 修改增加数据权限
{
var btnAuthAddList = new List();
btnAuth.ForEach(item =>
{
if (!oldAppModuleButtonEntity.Any(x => x.EnCode == item.EnCode)) btnAuthAddList.Add(item);
});
if (btnAuthAddList.Any()) await _visualDevRepository.AsSugarClient().Insertable(btnAuthAddList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
oldAppModuleButtonEntity.ForEach(item =>
{
var it = btnAuth.FirstOrDefault(x => x.EnCode == item.EnCode);
if (it == null) item.DeleteMark = 1; // 删除标识
else item.EnabledMark = it.EnabledMark; // 显示标识
});
await _visualDevRepository.AsSugarClient().Updateable(oldAppModuleButtonEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
}
#endregion
#region 列表权限
if (appColumnData.useColumnPermission)
{
if (!oldAppModuleColumnEntity.Any()) // 新增数据
{
await _visualDevRepository.AsSugarClient().Insertable(columnAuth).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
else // 修改增加数据权限
{
var columnAuthAddList = new List();
columnAuth.ForEach(item =>
{
if (!oldAppModuleColumnEntity.Any(x => x.EnCode == item.EnCode)) columnAuthAddList.Add(item);
});
if (columnAuthAddList.Any()) await _visualDevRepository.AsSugarClient().Insertable(columnAuthAddList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
oldAppModuleColumnEntity.ForEach(item =>
{
var it = columnAuth.FirstOrDefault(x => x.EnCode == item.EnCode);
if (it == null) item.DeleteMark = 1; // 删除标识
else item.EnabledMark = it.EnabledMark; // 显示标识
});
await _visualDevRepository.AsSugarClient().Updateable(oldAppModuleColumnEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
}
}
#endregion
#region 数据权限
if (appColumnData.useDataPermission)
{
// 全部数据权限
if (!_visualDevRepository.AsSugarClient().Queryable().Where(x => x.EnCode.Equals("jnpf_alldata") && x.ModuleId == moduleModel.Id && x.DeleteMark == null).Any())
{
// 全部数据权限方案
var AllDataAuthScheme = new ModuleDataAuthorizeSchemeEntity()
{
FullName = "全部数据",
EnCode = "jnpf_alldata",
AllData = 1,
ConditionText = string.Empty,
ConditionJson = string.Empty,
ModuleId = moduleModel.Id
};
await _visualDevRepository.AsSugarClient().Insertable(AllDataAuthScheme).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
}
// 创建用户和所属组织权限方案
// 只添加 主表控件的数据权限
var fList = fieldList.Where(x => !x.__vModel__.Contains("_jnpf_") && x.__vModel__.IsNotEmptyOrNull() && x.__config__.visibility.Contains("app"))
.Where(x => x.__config__.jnpfKey == JnpfKeyConst.CREATEUSER || x.__config__.jnpfKey == JnpfKeyConst.CURRORGANIZE).ToList();
var authList = await MenuMergeDataAuth(moduleModel.Id, fList);
await MenuMergeDataAuthScheme(moduleModel.Id, authList, fList);
}
#endregion
}
// 修改功能发布状态
await _visualDevRepository.AsUpdateable().SetColumns(it => it.State == 1).Where(it => it.Id == id).ExecuteCommandHasChangeAsync();
// 线上版本
if (!await _visualDevRepository.AsSugarClient().Queryable().AnyAsync(x => x.Id.Equals(id)))
{
var vReleaseEntity = entity.Adapt();
await _visualDevRepository.AsSugarClient().Insertable(vReleaseEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
// 同步添加流程表单
if (entity.EnableFlow.Equals(1))
{
if (!_visualDevRepository.AsSugarClient().Queryable().Any(x => x.TemplateId.Equals(entity.Id))) throw Oops.Oh(ErrorCode.D1421);
var fEntity = entity.Adapt();
fEntity.TableJson = entity.Tables;
fEntity.FlowType = 1;
fEntity.FormType = 2;
fEntity.EnabledMark = 1;
fEntity.PropertyJson = entity.FormData;
fEntity.DraftJson = fEntity.ToJsonString();
await _visualDevRepository.AsSugarClient().Updateable(fEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
await _visualDevRepository.AsSugarClient().Updateable().SetColumns(x => x.EnabledMark == 1).Where(it => it.Id == entity.Id).ExecuteCommandHasChangeAsync();
}
}
else
{
var vReleaseEntity = entity.Adapt();
await _visualDevRepository.AsSugarClient().Updateable(vReleaseEntity).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
if (entity.EnableFlow.Equals(1))
{
if (!_visualDevRepository.AsSugarClient().Queryable().Any(x => x.TemplateId.Equals(entity.Id))) throw Oops.Oh(ErrorCode.D1421);
var fEntity = entity.Adapt();
fEntity.TableJson = entity.Tables;
fEntity.FlowType = 1;
fEntity.FormType = 2;
fEntity.EnabledMark = 1;
fEntity.PropertyJson = entity.FormData;
fEntity.DraftJson = fEntity.ToJsonString();
if (!await _visualDevRepository.AsSugarClient().Queryable().AnyAsync(x => x.Id.Equals(id)))
await _visualDevRepository.AsSugarClient().Insertable(fEntity).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnEntityAsync();
else
await _visualDevRepository.AsSugarClient().Updateable(fEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
await _visualDevRepository.AsSugarClient().Updateable().SetColumns(x => x.EnabledMark == 1).Where(it => it.Id == entity.Id).ExecuteCommandHasChangeAsync();
}
}
var dbLink = await _runService.GetDbLink(entity.DbLinkId);
var MainTable = entity.Tables.ToList().Find(m => m.typeId.Equals("1")); // 主表
if (!_changeDataBase.IsAnyColumn(dbLink, MainTable?.table, "f_flowtaskid"))
{
var pFieldList = new List() { new DbTableFieldModel() { field = "F_FlowTaskId", fieldName = "流程任务Id", dataType = "varchar", dataLength = "50", allowNull = 1 } };
_changeDataBase.AddTableColumn(dbLink, MainTable?.table, pFieldList);
}
if (!_changeDataBase.IsAnyColumn(dbLink, MainTable?.table, "f_flowid"))
{
var pFieldList = new List() { new DbTableFieldModel() { field = "F_FlowId", fieldName = "流程引擎Id", dataType = "varchar", dataLength = "50", allowNull = 1 } };
_changeDataBase.AddTableColumn(dbLink, MainTable?.table, pFieldList);
}
_db.CommitTran();
}
catch (Exception)
{
_db.RollbackTran();
throw;
}
}
#endregion
#region PublicMethod
///
/// 获取功能信息.
///
/// 主键ID.
/// 是否获取发布版本.
///
[NonAction]
public async Task GetInfoById(string id, bool isGetRelease = false)
{
if (isGetRelease)
{
var vREntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(x => x.Id == id && x.DeleteMark == null);
if (vREntity != null && vREntity.EnableFlow == 1 && _visualDevRepository.AsSugarClient().Queryable().Any(x => x.Id.Equals(id)))
{
vREntity.FlowId = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.Id.Equals(id)).Select(x => x.FlowId).FirstAsync();
if (vREntity.FlowId.IsNotEmptyOrNull())
{
if (!_visualDevRepository.AsSugarClient().Queryable().Where(x => x.Id.Equals(vREntity.FlowId) && x.EnabledMark.Equals(1)).Any())
vREntity.EnableFlow = -1;
}
}
return vREntity.Adapt();
}
else
{
var vEntity = await _visualDevRepository.AsQueryable().FirstAsync(x => x.Id == id && x.DeleteMark == null);
if (_visualDevRepository.AsSugarClient().Queryable().Any(x => x.Id.Equals(id)))
vEntity.FlowId = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.Id.Equals(id)).Select(x => x.FlowId).FirstAsync();
return vEntity.Adapt();
}
}
///
/// 判断功能ID是否存在.
///
///
[NonAction]
public async Task GetDataExists(string id)
{
return await _visualDevRepository.IsAnyAsync(it => it.Id == id && it.DeleteMark == null);
}
///
/// 判断是否存在编码、名称相同的数据.
///
///
[NonAction]
public async Task GetDataExists(string enCode, string fullName)
{
return await _visualDevRepository.IsAnyAsync(it => it.EnCode == enCode && it.FullName == fullName && it.DeleteMark == null);
}
///
/// 新增导入数据.
///
///
///
[NonAction]
public async Task CreateImportData(VisualDevEntity input)
{
try
{
_db.BeginTran(); // 开启事务
StorageableResult? stor = _visualDevRepository.AsSugarClient().Storageable(input).Saveable().ToStorage(); // 存在更新不存在插入 根据主键
await stor.AsInsertable.ExecuteCommandAsync(); // 执行插入
await _visualDevRepository.AsSugarClient().Updateable(input).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
// 同步流程表单
var fEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == input.Id);
if (fEntity != null)
{
fEntity.DeleteMark = null;
fEntity.DeleteTime = null;
fEntity.DeleteUserId = null;
await _visualDevRepository.AsSugarClient().Updateable(fEntity).CallEntityMethod(m => m.LastModify()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId, it.LastModifyTime, it.LastModifyUserId }).ExecuteCommandAsync();
}
// 同步程引擎
var tEntity = await _visualDevRepository.AsSugarClient().Queryable().FirstAsync(v => v.Id == input.Id);
if (tEntity != null)
{
tEntity.DeleteMark = null;
tEntity.DeleteTime = null;
tEntity.DeleteUserId = null;
await _visualDevRepository.AsSugarClient().Updateable(tEntity).CallEntityMethod(m => m.LastModify()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId, it.LastModifyTime, it.LastModifyUserId }).ExecuteCommandAsync();
}
_db.CommitTran(); // 关闭事务
}
catch (Exception)
{
_db.RollbackTran();
throw;
}
}
///
/// 功能模板 无表 转 有表.
///
/// 功能实体.
/// 主表名称.
///
[NonAction]
public async Task NoTblToTable(VisualDevEntity vEntity, string mainTableName)
{
var dbtype = _visualDevRepository.AsSugarClient().CurrentConnectionConfig.DbType.ToString();
var isUpper = false; // 是否大写
if (dbtype.ToLower().Equals("oracle") || dbtype.ToLower().Equals("dm") || dbtype.ToLower().Equals("dm8")) isUpper = true;
else isUpper = false;
// Oracle和Dm数据库 表名全部大写, 其他全部小写
mainTableName = isUpper ? mainTableName.ToUpper() : mainTableName.ToLower();
FormDataModel formModel = vEntity.FormData.ToObjectOld();
List? fieldsModelList = TemplateAnalysis.AnalysisTemplateData(formModel.fields);
#region 创表信息组装
List? addTableList = new List(); // 表集合
// 主表信息
DbTableAndFieldModel? mainInfo = new DbTableAndFieldModel();
mainInfo.table = mainTableName;
mainInfo.tableName = vEntity.FullName;
mainInfo.FieldList = FieldsModelToTableFile(fieldsModelList, formModel.primaryKeyPolicy == 2);
if (vEntity.EnableFlow.Equals(1)) mainInfo.FieldList.Add(new DbTableFieldModel() { field = "F_FlowTaskId", fieldName = "流程任务Id", dataType = "varchar", dataLength = "50", allowNull = 1 });
if (vEntity.EnableFlow.Equals(1)) mainInfo.FieldList.Add(new DbTableFieldModel() { field = "F_FlowId", fieldName = "流程引擎Id", dataType = "varchar", dataLength = "50", allowNull = 1 });
if (formModel.logicalDelete) mainInfo.FieldList.Add(new DbTableFieldModel() { field = "F_DeleteMark", fieldName = "删除标识", dataType = "int", dataLength = "50", allowNull = 1 });
// 子表信息
Dictionary? childTableDic = new Dictionary();
fieldsModelList.Where(x => x.__config__.jnpfKey == JnpfKeyConst.TABLE).ToList().ForEach(item =>
{
DbTableAndFieldModel? childTInfo = new DbTableAndFieldModel();
childTInfo.table = "ct" + SnowflakeIdHelper.NextId();
childTInfo.table = isUpper ? childTInfo.table.ToUpper() : childTInfo.table.ToLower();
childTableDic.Add(item.__vModel__, childTInfo.table);
childTInfo.tableName = vEntity.FullName + "_子表";
childTInfo.FieldList = FieldsModelToTableFile(item.__config__.children, formModel.primaryKeyPolicy == 2);
childTInfo.FieldList.Add(new DbTableFieldModel() { dataLength = "50", allowNull = 1, dataType = "varchar", field = "F_Relation_Id", fieldName = vEntity.FullName + "_关联外键" });
addTableList.Add(childTInfo);
});
#endregion
#region 修改功能模板 有表改无表
List? modelTableList = new List();
// 处理主表
TableModel? mainTable = new TableModel();
mainTable.fields = new List();
mainTable.table = mainInfo.table;
mainTable.tableName = mainInfo.tableName;
mainTable.typeId = "1";
mainInfo.FieldList.ForEach(item => // 表字段
{
EntityFieldModel? etFieldModel = new EntityFieldModel();
etFieldModel.DataLength = item.dataLength;
etFieldModel.PrimaryKey = 1;
etFieldModel.DataType = item.dataType;
etFieldModel.Field = item.field;
etFieldModel.FieldName = item.fieldName;
mainTable.fields.Add(etFieldModel);
});
// 处理子表
addTableList.ForEach(item =>
{
TableModel? childInfo = new TableModel();
childInfo.fields = new List();
childInfo.table = item.table;
childInfo.tableName = item.tableName;
childInfo.tableField = "F_Relation_Id"; // 关联外键
childInfo.relationField = "F_Id"; // 关联主键
childInfo.typeId = "0";
item.FieldList.ForEach(it => // 子表字段
{
EntityFieldModel? etFieldModel = new EntityFieldModel();
etFieldModel.DataLength = it.dataLength;
etFieldModel.PrimaryKey = it.primaryKey.ParseToInt();
etFieldModel.DataType = it.dataType;
etFieldModel.Field = it.field;
etFieldModel.FieldName = it.fieldName;
childInfo.fields.Add(etFieldModel);
});
modelTableList.Add(childInfo);
});
modelTableList.Add(mainTable);
#region 给控件绑定 tableName、relationTable 属性
// 用字典反序列化, 避免多增加不必要的属性
Dictionary? dicFormModel = vEntity.FormData.ToObjectOld>();
List>? dicFieldsModelList = dicFormModel.FirstOrDefault(x => x.Key == "fields").Value.ToJsonString().ToObjectOld>>();
// 主表
MainFieldsBindTable(dicFieldsModelList, childTableDic, mainTableName);
// 子表
ChildFieldBindTable(dicFieldsModelList, childTableDic, mainTableName);
#endregion
dicFormModel["fields"] = dicFieldsModelList; // 修改表单控件
vEntity.FormData = dicFormModel.ToJsonString(); // 修改模板
vEntity.Tables = modelTableList.ToJsonString(); // 修改模板涉及表
addTableList.Add(mainInfo);
#endregion
try
{
_db.BeginTran(); // 执行事务
var link = await _runService.GetDbLink(vEntity.DbLinkId);
foreach (DbTableAndFieldModel? item in addTableList)
{
bool res = await _changeDataBase.Create(link, item, item.FieldList);
if (!res) throw null;
}
if (await _visualDevRepository.IsAnyAsync(x => x.Id.Equals(vEntity.Id)))
await _visualDevRepository.AsUpdateable(vEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync();
else
await _visualDevRepository.AsInsertable(vEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
_db.CommitTran(); // 提交事务
return vEntity;
}
catch (Exception e)
{
_db.RollbackTran(); // 回滚事务
return null;
}
}
#endregion
#region Private
///
/// 组件转换表字段.
///
/// 表单列表.
/// 主键是否自增长.
///
[NonAction]
private List FieldsModelToTableFile(List fmList, bool isIdentity)
{
List? fieldList = new List(); // 表字段
List? mList = fmList.Where(x => x.__config__.jnpfKey.IsNotEmptyOrNull())
.Where(x => x.__config__.jnpfKey != JnpfKeyConst.QRCODE && x.__config__.jnpfKey != JnpfKeyConst.BARCODE && x.__config__.jnpfKey != JnpfKeyConst.TABLE).ToList(); // 非存储字段
fieldList.Add(new DbTableFieldModel()
{
primaryKey = true,
dataType = isIdentity ? "int" : "varchar",
dataLength = "50",
identity = isIdentity,
field = "F_Id",
fieldName = "主键"
});
foreach (var item in mList)
{
// 不生成数据库字段(控件类型为:展示数据),关联表单、弹窗选择、计算公式.
if ((item.__config__.jnpfKey == JnpfKeyConst.RELATIONFORMATTR || item.__config__.jnpfKey == JnpfKeyConst.POPUPATTR || item.__config__.jnpfKey == JnpfKeyConst.CALCULATE) && item.__config__.isStorage.Equals(1))
continue;
DbTableFieldModel? field = new DbTableFieldModel();
field.field = item.__vModel__;
field.fieldName = item.__config__.label;
switch (item.__config__.jnpfKey)
{
case JnpfKeyConst.NUMINPUT:
field.dataType = item.precision > 1 ? "decimal" : "int";
field.dataLength = "50";
field.allowNull = 1;
break;
case JnpfKeyConst.DATE:
field.dataType = "DateTime";
field.dataLength = "50";
field.allowNull = 1;
break;
case JnpfKeyConst.TIME:
field.dataType = "varchar";
field.dataLength = "50";
field.allowNull = 1;
break;
case JnpfKeyConst.CREATETIME:
field.dataType = "DateTime";
field.dataLength = "50";
field.allowNull = 1;
break;
case JnpfKeyConst.MODIFYTIME:
field.dataType = "DateTime";
field.dataLength = "50";
field.allowNull = 1;
break;
case JnpfKeyConst.EDITOR:
field.dataType = "text";
field.dataLength = "50";
field.allowNull = 1;
break;
case JnpfKeyConst.CALCULATE:
field.dataType = "decimal";
field.dataLength = "50";
field.allowNull = 1;
break;
default:
field.dataType = "varchar";
field.dataLength = "500";
field.allowNull = 1;
break;
}
if (field.field.IsNotEmptyOrNull()) fieldList.Add(field);
}
return fieldList;
}
///
/// 组装菜单 数据权限 字段管理数据.
///
/// 菜单ID.
/// 功能模板控件集合.
///
private async Task> MenuMergeDataAuth(string menuId, List fields)
{
// 旧的自动生成的 字段管理
List? oldDataAuth = await _visualDevRepository.AsSugarClient().Queryable()
.Where(x => x.ModuleId == menuId && x.DeleteMark == null && x.SortCode.Equals(-9527))
.Where(x => x.ConditionText == "@organizationAndSuborganization" || x.ConditionText == "@organizeId"
|| x.ConditionText == "@userAraSubordinates" || x.ConditionText == "@userId"
|| x.ConditionText == "@branchManageOrganizeAndSub" || x.ConditionText == "@branchManageOrganize")
.ToListAsync();
List? authList = new List(); // 字段管理
List? noDelData = new List(); // 记录未删除
// 当前用户
FieldsModel? item = fields.FirstOrDefault(x => x.__config__.jnpfKey == JnpfKeyConst.CREATEUSER);
if (item != null)
{
var fRule = item.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = item.__vModel__.ToLower().Contains("tablefield") && item.__vModel__.Contains("-") ? 2 : fRule;
// 新增
if (!oldDataAuth.Any(x => x.EnCode == item.__vModel__ && x.ConditionText == "@userId"))
{
authList.Add(new ModuleDataAuthorizeEntity()
{
Id = SnowflakeIdHelper.NextId(),
ConditionSymbol = "Equal", // 条件符号
Type = "varchar", // 字段类型
FullName = item.__config__.label, // 字段说明
ConditionText = "@userId", // 条件内容(当前用户)
EnabledMark = 1,
SortCode = -9527,
FieldRule = fRule, // 主表/副表/子表
EnCode = fRule.Equals(1) ? item.__vModel__.Split("jnpf_").LastOrDefault() : item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ModuleId = menuId
});
}
if (!oldDataAuth.Any(x => x.EnCode == item.__vModel__ && x.ConditionText == "@userAraSubordinates"))
{
authList.Add(new ModuleDataAuthorizeEntity()
{
Id = SnowflakeIdHelper.NextId(),
ConditionSymbol = "Equal", // 条件符号
Type = "varchar", // 字段类型
FullName = item.__config__.label, // 字段说明
ConditionText = "@userAraSubordinates", // 条件内容(当前用户及下属)
EnabledMark = 1,
SortCode = -9527,
FieldRule = fRule, // 主表/副表/子表
EnCode = fRule.Equals(1) ? item.__vModel__.Split("jnpf_").LastOrDefault() : item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ModuleId = menuId
});
}
// 删除
List? delData = oldDataAuth.Where(x => x.EnCode != item.__vModel__ && (x.ConditionText == "@userId" || x.ConditionText == "@userAraSubordinates")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
noDelData = oldDataAuth.Except(delData).ToList(); // 记录未删除
}
else
{
// 删除
List? delData = oldDataAuth.Where(x => x.ConditionText == "@userId" || x.ConditionText == "@userAraSubordinates").ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
// 所属组织
item = fields.FirstOrDefault(x => x.__config__.jnpfKey == JnpfKeyConst.CURRORGANIZE);
if (item != null)
{
var fRule = item.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = item.__vModel__.ToLower().Contains("tablefield") && item.__vModel__.Contains("-") ? 2 : fRule;
// 新增
if (!oldDataAuth.Any(x => x.EnCode == item.__vModel__ && x.ConditionText == "@organizeId"))
{
authList.Add(new ModuleDataAuthorizeEntity()
{
Id = SnowflakeIdHelper.NextId(),
ConditionSymbol = "Equal", // 条件符号
Type = "varchar", // 字段类型
FullName = item.__config__.label, // 字段说明
ConditionText = "@organizeId", // 条件内容(当前组织)
EnabledMark = 1,
SortCode = -9527,
FieldRule = fRule, // 主表/副表/子表
EnCode = fRule.Equals(1) ? item.__vModel__.Split("jnpf_").LastOrDefault() : item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ModuleId = menuId
});
}
if (!oldDataAuth.Any(x => x.EnCode == item.__vModel__ && x.ConditionText == "@organizationAndSuborganization"))
{
authList.Add(new ModuleDataAuthorizeEntity()
{
Id = SnowflakeIdHelper.NextId(),
ConditionSymbol = "Equal", // 条件符号
Type = "varchar", // 字段类型
FullName = item.__config__.label, // 字段说明
ConditionText = "@organizationAndSuborganization", // 条件内容(当前组织及组织)
EnabledMark = 1,
SortCode = -9527,
FieldRule = fRule, // 主表/副表/子表
EnCode = fRule.Equals(1) ? item.__vModel__.Split("jnpf_").LastOrDefault() : item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ModuleId = menuId
});
}
// 删除
List? delData = oldDataAuth.Where(x => x.EnCode != item.__vModel__ && (x.ConditionText == "@organizeId" || x.ConditionText == "@organizationAndSuborganization")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
noDelData = oldDataAuth.Except(delData).ToList(); // 记录未删除
}
else
{
// 删除
List? delData = oldDataAuth.Where(x => x.ConditionText == "@organizeId" || x.ConditionText == "@organizationAndSuborganization").ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
// 当前分管组织
item = fields.FirstOrDefault(x => x.__config__.jnpfKey == JnpfKeyConst.CURRORGANIZE);
if (item != null)
{
var fRule = item.__vModel__.Contains("_jnpf_") ? 1 : 0;
fRule = item.__vModel__.ToLower().Contains("tablefield") && item.__vModel__.Contains("-") ? 2 : fRule;
// 新增
if (!oldDataAuth.Any(x => x.EnCode == item.__vModel__ && x.ConditionText == "@branchManageOrganize"))
{
authList.Add(new ModuleDataAuthorizeEntity()
{
Id = SnowflakeIdHelper.NextId(),
ConditionSymbol = "Equal", // 条件符号
Type = "varchar", // 字段类型
FullName = item.__config__.label, // 字段说明
ConditionText = "@branchManageOrganize", // 条件内容(当前分管组织)
EnabledMark = 1,
SortCode = -9527,
FieldRule = fRule, // 主表/副表/子表
EnCode = fRule.Equals(1) ? item.__vModel__.Split("jnpf_").LastOrDefault() : item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ModuleId = menuId
});
}
if (!oldDataAuth.Any(x => x.EnCode == item.__vModel__ && x.ConditionText == "@branchManageOrganizeAndSub"))
{
authList.Add(new ModuleDataAuthorizeEntity()
{
Id = SnowflakeIdHelper.NextId(),
ConditionSymbol = "Equal", // 条件符号
Type = "varchar", // 字段类型
FullName = item.__config__.label, // 字段说明
ConditionText = "@branchManageOrganizeAndSub", // 条件内容(当前分管组织及子组织)
EnabledMark = 1,
SortCode = -9527,
FieldRule = fRule, // 主表/副表/子表
EnCode = fRule.Equals(1) ? item.__vModel__.Split("jnpf_").LastOrDefault() : item.__vModel__,
BindTable = fRule.Equals(2) ? item.__config__.relationTable : item.__config__.tableName,
ModuleId = menuId
});
}
// 删除
List? delData = oldDataAuth.Where(x => x.EnCode != item.__vModel__ && (x.ConditionText == "@branchManageOrganize" || x.ConditionText == "@branchManageOrganizeAndSub")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
noDelData = oldDataAuth.Except(delData).ToList(); // 记录未删除
}
else
{
// 删除
List? delData = oldDataAuth.Where(x => x.ConditionText == "@branchManageOrganize" || x.ConditionText == "@branchManageOrganizeAndSub").ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
if (authList.Any()) await _visualDevRepository.AsSugarClient().Insertable(authList).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
if (noDelData.Any()) authList.AddRange(noDelData);
return authList.Any() ? authList : oldDataAuth;
}
///
/// 组装菜单 数据权限 方案管理数据.
///
/// 菜单ID.
/// 字段管理列表.
/// 功能模板控件集合.
///
private async Task MenuMergeDataAuthScheme(string menuId, List authList, List fields)
{
// 旧的自动生成的 方案管理
List? oldDataAuthScheme = await _visualDevRepository.AsSugarClient().Queryable()
.Where(x => x.ModuleId == menuId && x.DeleteMark == null && x.SortCode == -9527)
.Where(x => x.FullName == "当前用户" || x.FullName == "当前组织"
|| x.FullName == "当前用户及下属" || x.FullName == "当前组织及子组织"
|| x.FullName == "当前分管组织" || x.FullName == "当前分管组织及子组织")
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userId\"")
|| x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userAraSubordinates\"")
|| x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizeId\"")
|| x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizationAndSuborganization\"")
|| x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganize\"")
|| x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganizeAndSub\""))
.ToListAsync();
List? authSchemeList = new List(); // 方案管理
// 当前用户
FieldsModel? item = fields.FirstOrDefault(x => x.__config__.jnpfKey == JnpfKeyConst.CREATEUSER);
var condJson = new AuthorizeModuleResourceConditionModelInput()
{
logic = "and",
groups = new List() { new AuthorizeModuleResourceConditionItemModelInput() { id = "", bindTable = "", field = "", fieldRule = 0, value = "", type = "varchar", op = "Equal" } }
};
if (item != null)
{
ModuleDataAuthorizeEntity? model = authList.FirstOrDefault(x => x.EnCode == item.__vModel__ && x.ConditionText.Equals("@userId"));
if (model != null)
{
condJson.groups.First().id = model.Id;
condJson.groups.First().bindTable = model.BindTable;
condJson.groups.First().field = item.__vModel__;
condJson.groups.First().fieldRule = model.FieldRule.ParseToInt();
condJson.groups.First().value = "@userId";
// 新增
if (!oldDataAuthScheme.Any(x => x.ConditionText == "【{" + item.__config__.label + "} {等于} {@userId}】"))
{
authSchemeList.Add(new ModuleDataAuthorizeSchemeEntity()
{
FullName = "当前用户",
EnCode = SnowflakeIdHelper.NextId(),
SortCode = -9527,
ConditionText = "【{" + item.__config__.label + "} {等于} {@userId}】",
ConditionJson = new List() { condJson }.ToJsonString(),
ModuleId = menuId
});
}
model = authList.FirstOrDefault(x => x.EnCode == item.__vModel__ && x.ConditionText.Equals("@userAraSubordinates"));
condJson.groups.First().id = model.Id;
condJson.groups.First().op = "Equal";
condJson.groups.First().value = "@userAraSubordinates";
if (!oldDataAuthScheme.Any(x => x.ConditionText == "【{" + item.__config__.label + "} {等于} {@userAraSubordinates}】"))
{
authSchemeList.Add(new ModuleDataAuthorizeSchemeEntity()
{
FullName = "当前用户及下属",
EnCode = SnowflakeIdHelper.NextId(),
SortCode = -9527,
ConditionText = "【{" + item.__config__.label + "} {等于} {@userAraSubordinates}】",
ConditionJson = new List() { condJson }.ToJsonString(),
ModuleId = menuId
});
}
// 删除
//List? delData = oldDataAuthScheme.Where(x => x.EnCode != item.__vModel__
//&& (x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userId\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userAraSubordinates\""))).ToList();
//await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
else
{
// 删除
List? delData = oldDataAuthScheme
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userId\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userAraSubordinates\"")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
}
else
{
// 删除
List? delData = oldDataAuthScheme
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userId\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@userAraSubordinates\"")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
// 当前组织
item = fields.FirstOrDefault(x => x.__config__.jnpfKey == JnpfKeyConst.CURRORGANIZE);
if (item != null)
{
ModuleDataAuthorizeEntity? model = authList.FirstOrDefault(x => x.EnCode == item.__vModel__ && x.ConditionText.Equals("@organizeId"));
if (model != null)
{
condJson.groups.First().id = model.Id;
condJson.groups.First().bindTable = model.BindTable;
condJson.groups.First().field = item.__vModel__;
condJson.groups.First().fieldRule = model.FieldRule.ParseToInt();
condJson.groups.First().op = "Equal";
condJson.groups.First().value = "@organizeId";
// 新增
if (!oldDataAuthScheme.Any(x => x.ConditionText == "【{" + item.__config__.label + "} {等于} {@organizeId}】"))
{
authSchemeList.Add(new ModuleDataAuthorizeSchemeEntity()
{
FullName = "当前组织",
EnCode = SnowflakeIdHelper.NextId(),
SortCode = -9527,
ConditionText = "【{" + item.__config__.label + "} {等于} {@organizeId}】",
ConditionJson = new List() { condJson }.ToJsonString(),
ModuleId = menuId
});
}
model = authList.FirstOrDefault(x => x.EnCode == item.__vModel__ && x.ConditionText.Equals("@organizationAndSuborganization"));
condJson.groups.First().id = model.Id;
condJson.groups.First().op = "Equal";
condJson.groups.First().value = "@organizationAndSuborganization";
if (!oldDataAuthScheme.Any(x => x.ConditionText == "【{" + item.__config__.label + "} {等于} {@organizationAndSuborganization}】"))
{
authSchemeList.Add(new ModuleDataAuthorizeSchemeEntity()
{
FullName = "当前组织及子组织",
EnCode = SnowflakeIdHelper.NextId(),
SortCode = -9527,
ConditionText = "【{" + item.__config__.label + "} {等于} {@organizationAndSuborganization}】",
ConditionJson = new List() { condJson }.ToJsonString(),
ModuleId = menuId
});
}
// 删除
//List? delData = oldDataAuthScheme.Where(x => x.EnCode != item.__vModel__
//&& (x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizeId\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizationAndSuborganization\""))).ToList();
//await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
else
{
// 删除
List? delData = oldDataAuthScheme
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizeId\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizationAndSuborganization\"")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
}
else
{
// 删除
List? delData = oldDataAuthScheme
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizeId\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@organizationAndSuborganization\"")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
// 当前分管组织
item = fields.FirstOrDefault(x => x.__config__.jnpfKey == JnpfKeyConst.CURRORGANIZE);
if (item != null)
{
ModuleDataAuthorizeEntity? model = authList.FirstOrDefault(x => x.EnCode == item.__vModel__ && x.ConditionText.Equals("@branchManageOrganize"));
if (model != null)
{
condJson.groups.First().id = model.Id;
condJson.groups.First().bindTable = model.BindTable;
condJson.groups.First().field = item.__vModel__;
condJson.groups.First().fieldRule = model.FieldRule.ParseToInt();
condJson.groups.First().op = "Equal";
condJson.groups.First().value = "@branchManageOrganize";
// 新增
if (!oldDataAuthScheme.Any(x => x.ConditionText == "【{" + item.__config__.label + "} {等于} {@branchManageOrganize}】"))
{
authSchemeList.Add(new ModuleDataAuthorizeSchemeEntity()
{
FullName = "当前分管组织",
EnCode = SnowflakeIdHelper.NextId(),
SortCode = -9527,
ConditionText = "【{" + item.__config__.label + "} {等于} {@branchManageOrganize}】",
ConditionJson = new List() { condJson }.ToJsonString(),
ModuleId = menuId
});
}
model = authList.FirstOrDefault(x => x.EnCode == item.__vModel__ && x.ConditionText.Equals("@branchManageOrganizeAndSub"));
condJson.groups.First().id = model.Id;
condJson.groups.First().op = "Equal";
condJson.groups.First().value = "@branchManageOrganizeAndSub";
if (!oldDataAuthScheme.Any(x => x.ConditionText == "【{" + item.__config__.label + "} {等于} {@branchManageOrganizeAndSub}】"))
{
authSchemeList.Add(new ModuleDataAuthorizeSchemeEntity()
{
FullName = "当前分管组织及子组织",
EnCode = SnowflakeIdHelper.NextId(),
SortCode = -9527,
ConditionText = "【{" + item.__config__.label + "} {等于} {@branchManageOrganizeAndSub}】",
ConditionJson = new List() { condJson }.ToJsonString(),
ModuleId = menuId
});
}
// 删除
//List? delData = oldDataAuthScheme.Where(x => x.EnCode != item.__vModel__
//&& (x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganize\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganizeAndSub\""))).ToList();
//await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
else
{
// 删除
List? delData = oldDataAuthScheme
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganize\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganizeAndSub\"")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
}
else
{
// 删除
List? delData = oldDataAuthScheme
.Where(x => x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganize\"") || x.ConditionJson.Contains("\"op\":\"Equal\",\"value\":\"@branchManageOrganizeAndSub\"")).ToList();
await _visualDevRepository.AsSugarClient().Deleteable(delData).ExecuteCommandAsync();
}
if (authSchemeList.Any()) await _visualDevRepository.AsSugarClient().Insertable(authSchemeList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
}
///
/// 无限递归 给控件绑定tableName (绕过 布局控件).
///
///
///
///
private void MainFieldsBindTable(List> dicFieldsModelList, Dictionary childTableDic, string tableName)
{
foreach (Dictionary? item in dicFieldsModelList)
{
var obj = item["__config__"].ToObject>();
if (obj.ContainsKey("jnpfKey") && obj["jnpfKey"].Equals(JnpfKeyConst.TABLE)) obj["tableName"] = childTableDic[item["__vModel__"].ToString()];
else if (obj.ContainsKey("tableName")) obj["tableName"] = tableName;
// 关联表单属性和弹窗属性
if (obj.ContainsKey("jnpfKey") && (obj["jnpfKey"].Equals(JnpfKeyConst.RELATIONFORMATTR) || obj["jnpfKey"].Equals(JnpfKeyConst.POPUPATTR)))
{
string relationField = Convert.ToString(item["relationField"]);
string? rField = relationField.ReplaceRegex(@"_jnpfTable_(\w+)", string.Empty);
item["relationField"] = string.Format("{0}{1}{2}{3}", rField, "_jnpfTable_", tableName, "1");
}
// 递归
if (obj.ContainsKey("jnpfKey"))
{
if (obj["jnpfKey"].Equals(JnpfKeyConst.ROW) || obj["jnpfKey"].Equals(JnpfKeyConst.CARD) || obj["jnpfKey"].Equals(JnpfKeyConst.COLLAPSE))
{
var fmList = obj["children"].ToObject>>();
MainFieldsBindTable(fmList, childTableDic, tableName);
obj["children"] = fmList;
}
if (obj["jnpfKey"].Equals(JnpfKeyConst.TAB))
{
var fmList = obj["children"].ToObject>>();
foreach (var it in fmList)
{
var fmChild = it["__config__"].ToObject>();
var fmChildList = fmChild["children"].ToObject>>();
MainFieldsBindTable(fmChildList, childTableDic, tableName);
fmChild["children"] = fmChildList;
it["__config__"] = fmChild;
}
obj["children"] = fmList;
}
}
item["__config__"] = obj;
}
}
///
/// 子表绑定 tableName.
///
private void ChildFieldBindTable(List> dicFieldsModelList, Dictionary childTableDic, string tableName)
{
foreach (var item in dicFieldsModelList)
{
var obj = item["__config__"].ToObject>();
if (obj.ContainsKey("jnpfKey") && obj["jnpfKey"].Equals(JnpfKeyConst.TABLE))
{
var cList = obj["children"].ToObject>>();
foreach (var child in cList)
{
var cObj = child["__config__"].ToObject>();
if (cObj.ContainsKey("relationTable")) cObj["relationTable"] = childTableDic[item["__vModel__"].ToString()];
else cObj.Add("relationTable", childTableDic[item["__vModel__"].ToString()]);
if (cObj.ContainsKey("tableName")) cObj["tableName"] = tableName;
// 关联表单属性和弹窗属性
if (cObj.ContainsKey("jnpfKey") && (cObj["jnpfKey"].Equals(JnpfKeyConst.RELATIONFORMATTR) || cObj["jnpfKey"].Equals(JnpfKeyConst.POPUPATTR)))
{
string relationField = Convert.ToString(child["relationField"]);
string? rField = relationField.ReplaceRegex(@"_jnpfTable_(\w+)", string.Empty);
if (child.ContainsKey("relationField")) child["relationField"] = string.Format("{0}{1}{2}{3}", rField, "_jnpfTable_", cObj["tableName"], "0");
else child.Add("relationField", string.Format("{0}{1}{2}{3}", rField, "_jnpfTable_", cObj["tableName"], "0"));
}
child["__config__"] = cObj;
}
obj["children"] = cList;
}
// 递归
if (obj.ContainsKey("jnpfKey"))
{
if (obj["jnpfKey"].Equals(JnpfKeyConst.ROW) || obj["jnpfKey"].Equals(JnpfKeyConst.CARD) || obj["jnpfKey"].Equals(JnpfKeyConst.COLLAPSE))
{
var fmList = obj["children"].ToObject>>();
ChildFieldBindTable(fmList, childTableDic, tableName);
obj["children"] = fmList;
}
if (obj["jnpfKey"].Equals(JnpfKeyConst.TAB))
{
var fmList = obj["children"].ToObject>>();
foreach (var it in fmList)
{
var fmChild = it["__config__"].ToObject>();
var fmChildList = fmChild["children"].ToObject>>();
ChildFieldBindTable(fmChildList, childTableDic, tableName);
fmChild["children"] = fmChildList;
it["__config__"] = fmChild;
}
obj["children"] = fmList;
}
}
item["__config__"] = obj;
}
}
///
/// 验证主键策略 数据库表是否支持.
///
/// 模板信息.
/// 数据库连接id.
private async Task VerifyPrimaryKeyPolicy(TemplateParsingBase tInfo, string dbLinkId)
{
if (tInfo.IsHasTable)
{
DbLinkEntity link = await _runService.GetDbLink(dbLinkId);
tInfo.AllTable.ForEach(item =>
{
List? tableList = _changeDataBase.GetFieldList(link, item.table); // 获取主表所有列
var mainPrimary = tableList.Find(t => t.primaryKey); // 主表主键
if (mainPrimary == null) throw Oops.Oh(ErrorCode.D1409, "主键为空", item.table);
if (tInfo.FormModel.primaryKeyPolicy.Equals(2) && !mainPrimary.identity)
{
throw Oops.Oh(ErrorCode.D1409, "自增长ID,没有自增标识", item.table);
}
if (tInfo.FormModel.primaryKeyPolicy.Equals(1) && !(mainPrimary.dataType.ToLower().Equals("string") || mainPrimary.dataType.ToLower().Equals("varchar") || mainPrimary.dataType.ToLower().Equals("nvarchar")))
throw Oops.Oh(ErrorCode.D1409, "雪花ID", item.table);
});
_changeDataBase.ChangeDataBase(_changeDataBase.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName));
}
}
///
/// 同步到流程相关.
///
///
///
private async Task SaveFlowTemplate(VisualDevEntity input)
{
if (!(await _visualDevRepository.AsSugarClient().Queryable().AnyAsync(x => x.Id.Equals(input.Id))))
{
if (await _visualDevRepository.AsSugarClient().Queryable().AnyAsync(x => (x.EnCode == input.EnCode || x.FullName == input.FullName) && x.DeleteMark == null))
throw Oops.Oh(ErrorCode.COM1004);
var dicType = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.Id.Equals(input.Category)).FirstAsync();
var flowType = await _visualDevRepository.AsSugarClient().Queryable().Where(x => x.EnCode.Equals(dicType.EnCode) && x.DictionaryTypeId.Equals("507f4f5df86b47588138f321e0b0dac7")).FirstAsync();
var flowTemplateEntity = input.Adapt();
flowTemplateEntity.EnabledMark = 0;
flowTemplateEntity.Type = 1;
flowTemplateEntity.Category = flowType.Id;
//flowTemplateEntity.IconBackground = "#008cff";.
//flowTemplateEntity.Icon = "icon-ym icon-ym-node";
var result = await _visualDevRepository.AsSugarClient().Insertable(flowTemplateEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
if (result == null)
throw Oops.Oh(ErrorCode.COM1005);
}
}
#endregion
}