| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using Attribute;
- using Model;
- using Model.Base;
- using Repository;
- using Service;
- using Microsoft.AspNetCore.Mvc;
- using Vo.Admin;
- using Dto.Admin;
- using Infrastructure;
- namespace Services
- {
- /// <summary>
- /// 接口信息Service业务层处理
- /// </summary>
- [AppService(ServiceType = typeof(IApiInfoService), ServiceLifetime = LifeTime.Transient)]
- public class ApiInfoService : BaseService<ApiInfo>, IApiInfoService
- {
- /// <summary>
- /// 接口信息-列表
- /// </summary>
- /// <param name="param">参数请求体</param>
- /// <param name="page">分页参数</param>
- /// <returns>列表</returns>
- public PagedInfo<GetApiInfoListVo> getApiInfoList([FromQuery] PagerInfo page, [FromQuery] ApiInfo param)
- {
- //拼装查询条件
- var predicate = Expressionable.Create<ApiInfo>();
- predicate = predicate.AndIF(param.serviceId > 0, m => m.serviceId == param.serviceId);
- predicate = predicate.AndIF(param.groupId > 0, m => m.groupId == param.groupId);
- predicate = predicate.AndIF(!string.IsNullOrEmpty(param.tabName), m => m.tabName.Contains(param.tabName));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(param.apiName), m => m.apiName.Contains(param.apiName));
- predicate = predicate.AndIF(param.apiKind > 0, m => m.apiKind == param.apiKind);
- var response = Queryable()
- .Where(predicate.ToExpression())
- .OrderByDescending(m => m.id)
- .ToPage<ApiInfo, GetApiInfoListVo>(page);
- return response;
- }
- /// <summary>
- /// 接口信息-字段关联接口列表
- /// </summary>
- /// <param name="param">参数请求体</param>
- /// <param name="page">分页参数</param>
- /// <returns>字段关联接口列表</returns>
- public PagedInfo<GetApiInfoListByProIdVo> getApiInfoListByProId([FromQuery] PagerInfo page, [FromQuery] ApiInfo param)
- {
- //拼装查询条件
- var predicate = Expressionable.Create<ApiInfo>();
- predicate = predicate.AndIF(param.serviceId > 0, m => m.serviceId == param.serviceId);
- var response = Queryable()
- .Where(predicate.ToExpression())
- .OrderByDescending(m => m.id)
- .ToPage<ApiInfo, GetApiInfoListByProIdVo>(page);
- return response;
- }
- /// <summary>
- /// 克隆接口
- /// </summary>
- /// <param name="param">参数请求体</param>
- public void copyApiInfo([FromBody] CopyApiInfoDto param, ApiGroup group)
- {
- // 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>
- public void initApiInfo([FromBody] InitApiInfoDto param)
- {
- var _DatabaseInfoService = App.GetService<IDatabaseInfoService>();
- var _DatabaseTableService = App.GetService<IDatabaseTableService>();
- var _DatabaseFieldService = App.GetService<IDatabaseFieldService>();
- var _ApiGroupService = App.GetService<IApiGroupService>();
- var apiGroup = _ApiGroupService.GetFirst(m => m.id == param.groupId) ?? new ApiGroup();
- 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 = !string.IsNullOrEmpty(field.validateAttribute) ? field.validateAttribute.Split(',') : Array.Empty<string>(),
- fieldDetail = field.fieldDetail ?? "",
- });
- }
- Add(new ApiInfo()
- {
- serviceId = apiGroup.serviceId,
- groupId = param.groupId,
- tabName = "基本信息",
- apiName = table.tableTitle + (apiKind == 1 ? "列表" : apiKind == 2 ? "详情" : apiKind == 3 ? "添加" : apiKind == 4 ? "修改" : "删除"),
- controllerFilePath = table.tableNameUpper,
- apiKind = apiKind,
- methodName = apiKind == 1 ? "get" + table.tableNameFirstUpper + "List" :
- apiKind == 2 ? "get" + table.tableNameFirstUpper + "Query" :
- apiKind == 3 ? "add" + table.tableNameFirstUpper :
- apiKind == 4 ? "update" + table.tableNameFirstUpper :
- "delete" + table.tableNameFirstUpper,
- apiDetail = apiKind == 1 ? "根据查询条件查询" + table.tableTitle + "列表数据" :
- apiKind == 2 ? "根据Id查询" + table.tableTitle + "某一条详情数据" :
- apiKind == 3 ? "添加" + table.tableTitle + "数据" :
- apiKind == 4 ? "修改" + table.tableTitle + "数据" :
- "根据Id删除" + table.tableTitle + "数据",
- apiParam = apiParam,
- createTime = DateTime.Now,
- linkTableId = tableId,
- pageFlag = apiKind == 1,
- createBy = App.UserName,
- });
- }
- }
- }
- }
- }
|