|
@@ -16,6 +16,19 @@ namespace Services
|
|
|
[AppService(ServiceType = typeof(IApiInfoService), ServiceLifetime = LifeTime.Transient)]
|
|
[AppService(ServiceType = typeof(IApiInfoService), ServiceLifetime = LifeTime.Transient)]
|
|
|
public class ApiInfoService : BaseService<ApiInfo>, IApiInfoService
|
|
public class ApiInfoService : BaseService<ApiInfo>, IApiInfoService
|
|
|
{
|
|
{
|
|
|
|
|
+ private readonly IApiGroupService _ApiGroupService;
|
|
|
|
|
+ private readonly IDatabaseInfoService _DatabaseInfoService;
|
|
|
|
|
+ private readonly IDatabaseTableService _DatabaseTableService;
|
|
|
|
|
+ private readonly IDatabaseFieldService _DatabaseFieldService;
|
|
|
|
|
+
|
|
|
|
|
+ public ApiInfoService(IApiGroupService ApiGroupService, IDatabaseInfoService DatabaseInfoService, IDatabaseTableService DatabaseTableService, IDatabaseFieldService DatabaseFieldService)
|
|
|
|
|
+ {
|
|
|
|
|
+ _ApiGroupService = ApiGroupService;
|
|
|
|
|
+ _DatabaseInfoService = DatabaseInfoService;
|
|
|
|
|
+ _DatabaseTableService = DatabaseTableService;
|
|
|
|
|
+ _DatabaseFieldService = DatabaseFieldService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 接口信息-列表
|
|
/// 接口信息-列表
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -57,12 +70,102 @@ namespace Services
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 克隆接口
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="param">参数请求体</param>
|
|
|
|
|
+ public void copyApiInfo([FromBody] CopyApiInfoDto param)
|
|
|
|
|
+ {
|
|
|
|
|
+ var group = _ApiGroupService.GetFirst(m => m.id == param.targetGroupId) ?? new ApiGroup();
|
|
|
|
|
+ List<int> apiIdList = param.sourceApiId.ToList();
|
|
|
|
|
+ var sourceApis = GetList(m => apiIdList.Contains(m.id)).ToList();
|
|
|
|
|
+ foreach(ApiInfo sourceApi in sourceApis)
|
|
|
|
|
+ {
|
|
|
|
|
+ ApiInfo newApi = new ApiInfo();
|
|
|
|
|
+ newApi.serviceId = group.serviceId;
|
|
|
|
|
+ newApi.groupId = param.targetGroupId;
|
|
|
|
|
+ newApi.tabName = sourceApi.tabName;
|
|
|
|
|
+ newApi.apiName = sourceApi.apiName;
|
|
|
|
|
+ newApi.controllerFilePath = sourceApi.controllerFilePath;
|
|
|
|
|
+ newApi.usageScenarios = sourceApi.usageScenarios;
|
|
|
|
|
+ newApi.apiKind = sourceApi.apiKind;
|
|
|
|
|
+ newApi.methodName = sourceApi.methodName;
|
|
|
|
|
+ newApi.apiDetail = sourceApi.apiDetail;
|
|
|
|
|
+ newApi.apiParam = sourceApi.apiParam;
|
|
|
|
|
+ newApi.createTime = DateTime.Now;
|
|
|
|
|
+ Add(newApi);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 初始化接口
|
|
/// 初始化接口
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
public void initApiInfo([FromBody] InitApiInfoDto param)
|
|
public void initApiInfo([FromBody] InitApiInfoDto param)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ foreach(int tableId in param.sourceTableId)
|
|
|
|
|
+ {
|
|
|
|
|
+ var table = _DatabaseTableService.GetById(tableId) ?? new DatabaseTable();
|
|
|
|
|
+ var database = _DatabaseInfoService.GetFirst(m => m.id == table.databaseId) ?? new DatabaseInfo();
|
|
|
|
|
+ var fields = _DatabaseFieldService.GetList(m => m.tableId == table.id);
|
|
|
|
|
+ for (int apiKind = 1; apiKind <= 5; apiKind++)
|
|
|
|
|
+ {
|
|
|
|
|
+ var apiParam = new List<ApiParamObject>();
|
|
|
|
|
+ foreach(var field in fields)
|
|
|
|
|
+ {
|
|
|
|
|
+ bool reqParam = false;
|
|
|
|
|
+ bool resParam = false;
|
|
|
|
|
+ if((field.showQuery && apiKind == 1) || (field.showEdit && (apiKind == 3 || apiKind == 4)))
|
|
|
|
|
+ {
|
|
|
|
|
+ reqParam = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if((apiKind == 2 || apiKind == 4 || apiKind == 5) && field.primaryKey)
|
|
|
|
|
+ {
|
|
|
|
|
+ reqParam = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(field.showList && (apiKind == 1 || apiKind == 2))
|
|
|
|
|
+ {
|
|
|
|
|
+ resParam = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ apiParam.Add(new ApiParamObject()
|
|
|
|
|
+ {
|
|
|
|
|
+ id = field.id,
|
|
|
|
|
+ fieldTitle = field.fieldTitle,
|
|
|
|
|
+ fieldName = field.fieldName,
|
|
|
|
|
+ fieldType = field.fieldType,
|
|
|
|
|
+ reqParam = reqParam,
|
|
|
|
|
+ resParam = resParam,
|
|
|
|
|
+ resType = field.fieldType,
|
|
|
|
|
+ checkAttribute = field.validateAttribute.Split(','),
|
|
|
|
|
+ fieldDetail = field.fieldDetail,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Add(new ApiInfo()
|
|
|
|
|
+ {
|
|
|
|
|
+ serviceId = 0,
|
|
|
|
|
+ groupId = param.groupId,
|
|
|
|
|
+ tabName = table.tableName,
|
|
|
|
|
+ apiName = table.tableName + (apiKind == 1 ? "列表" : apiKind == 2 ? "详情" : apiKind == 3 ? "添加" : apiKind == 4 ? "修改" : "删除"),
|
|
|
|
|
+ controllerFilePath = "/api/" + database.dbName + "/" + table.tableName,
|
|
|
|
|
+ usageScenarios = 1,
|
|
|
|
|
+ apiKind = apiKind,
|
|
|
|
|
+ methodName = apiKind == 1 ? "get" + Utils.transferName(table.tableName) + "List" :
|
|
|
|
|
+ apiKind == 2 ? "get" + Utils.transferName(table.tableName) + "Query" :
|
|
|
|
|
+ apiKind == 3 ? "add" + Utils.transferName(table.tableName) :
|
|
|
|
|
+ apiKind == 4 ? "update" + Utils.transferName(table.tableName) :
|
|
|
|
|
+ "delete" + Utils.transferName(table.tableName),
|
|
|
|
|
+ apiDetail = apiKind == 1 ? "根据查询条件查询" + table.tableName + "列表数据" :
|
|
|
|
|
+ apiKind == 2 ? "根据Id查询" + table.tableName + "某一条详情数据" :
|
|
|
|
|
+ apiKind == 3 ? "添加" + table.tableName + "数据" :
|
|
|
|
|
+ apiKind == 4 ? "修改" + table.tableName + "数据" :
|
|
|
|
|
+ "根据Id删除" + table.tableName + "数据",
|
|
|
|
|
+ apiParam = apiParam,
|
|
|
|
|
+ createTime = DateTime.Now,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|