using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.ValueObjects; using InterfaceForward.Repositories.ServiceProvider.Entitys; namespace InterfaceForward.Repositories.Interface.Services; /// /// 接口映射 /// public class InterfaceMapRepository : BasicRepository, IScopedDependency, IInterfaceMapRepository { /// /// 获取映射列表 /// /// /// public async Task> GetMapListAsync(GetMapListInputVO inputVo) { // 上下游一对多关系 var query = Context.Queryable() .LeftJoin((a, b) => a.UpStreamId == b.Id) // 系统接口 1 .LeftJoin((a, b, c) => a.DownStreamId == c.Id) // 服务商接口 N .LeftJoin((a, b, c, d) => c.ServiceProviderId == d.Id) .Filter(null, true) // 禁用全局过滤器 .Where(a => a.UpStreamId == inputVo.InterfaceId) .Where((a, b, c, d) => !a.IsDeleted && !b.IsDeleted && !c.IsDeleted && !d.IsDeleted) .WhereIF(!inputVo.NameOrCode.IsNullOrWhiteSpace(), (a, b, c, d) => d.Code.Contains(inputVo.NameOrCode) || d.Name.Contains(inputVo.NameOrCode)) .GroupBy(a => new { a.UpStreamId, a.ServiceProviderId }) .OrderBy(a => a.UpdateTime, OrderByType.Desc); return await query.Select((a, b, c, d) => new InterfaceMapOutputValueObject { SystemInterfaceId = a.UpStreamId, SystemInterfaceName = b.Name, SystemInterfaceCode = b.Code, ServiceProviderId = d.Id, ServiceProviderName = d.Name, ServiceProviderCode = d.Code, InterfaceName = SqlFunc.MappingColumn("GROUP_CONCAT(c.Name ORDER BY a.id SEPARATOR ',')"), InterfaceCode = SqlFunc.MappingColumn("GROUP_CONCAT(c.Code ORDER BY a.id SEPARATOR ',')"), UpdateTime = a.UpdateTime, PublishedVersion = a.PublishedVersion }).ToPagedListAsync(inputVo.PageIndex, inputVo.PageSize); } /// public async Task> GetParameterMapListAsync(List mapIds, bool isInParaMap) { /* select `a`.`Id` AS `InterfaceMapDetailId` , `t`.`Id` AS `InterfaceMapId` , `b`.`Id` AS `Id`, b.InterfaceId, `b`.`Alias` AS `Alias` , `b`.`CnName` AS `CnName` , `e`.`Name` AS `Type` , `b`.`IsInPara` AS `IsInPara`, `b`.`IsRequired` AS `IsRequired` , `b`.`Description` AS `Description` , `d`.`Id` AS `FixedId` , `d`.`FieldValue` AS `FixedValue` , `a`.`MappedParaId` AS `MapId` , `c`.`Alias` AS `MapAlias`, `c`.`CnName` AS `MapCnName` , `c`.`Description` AS `MapDescription` from t_interface_map t LEFT JOIN `t_parameter` `b` ON ( `t`.`UpStreamId` = `b`.`InterfaceId` ) and b.IsInPara = false AND ( `b`.`Type` <> 12 ) AND ( `b`.`Type` <> 10 ) and `b`.`IsDeleted` = 0 Left JOIN `t_interface_map_detail` `a` ON ( `t`.`Id` = `a`.`InterfaceMapId` ) and b.id = a.ParaId and a.IsDeleted = 0 Left JOIN `t_parameter` `c` ON ( `a`.`MappedParaId` = `c`.`Id` ) AND ( `c`.`IsDeleted` = 0 ) Left JOIN `t_parameter_fixed` `d` ON d.InterfaceId = b.InterfaceId and `b`.`Alias` = `d`.`FieldName` AND `d`.`FieldPositions` like concat('%', CAST(N'Body' AS CHAR),'%') AND d.IsDeleted = 0 Left JOIN `t_dictionary` `e` ON (( `b`.`Type` = `e`.`Id` ) AND ( `e`.`Type` = N'ParameterType' )) WHERE (( `t`.`UpStreamId` = 30 ) AND ( `t`.`ServiceProviderId` = 137 )) and t.IsDeleted = 0 and t.DownStreamId = 509 ORDER BY `b`.`Sort` ASC */ var ids = mapIds.JoinAsString(","); // 因为入参映射有多个 出参映射只有一个(挂在第一个映射) return await Context.SqlQueryable(@$" select `a`.`Id` AS `InterfaceMapDetailId` , `t`.`Id` AS `InterfaceMapId` , `b`.`Id` AS `Id`, b.InterfaceId, `b`.`Alias` AS `Alias` , `b`.`CnName` AS `CnName` , `e`.`Name` AS `Type`, `b`.`IsInPara` AS `IsInPara` , `b`.`IsRequired` AS `IsRequired` , `b`.`Description` AS `Description` , `d`.`Id` AS `FixedId` , `d`.`FieldValue` AS `FixedValue` , `a`.`MappedParaId` AS `MapId` , `c`.`Alias` AS `MapAlias`, `c`.`CnName` AS `MapCnName` , `c`.`Description` AS `MapDescription` from t_interface_map t LEFT JOIN `t_parameter` `b` ON {(isInParaMap ? "t.DownStreamId" : "t.UpStreamId")} = `b`.`InterfaceId` and b.IsInPara = {isInParaMap} AND ( `b`.`IsDeleted` = 0 ) AND ( `b`.`Type` <> 12 ) AND ( `b`.`Type` <> 10 ) Left JOIN `t_interface_map_detail` `a` ON ( `t`.`Id` = `a`.`InterfaceMapId` ) and b.id = a.ParaId and a.IsDeleted = 0 Left JOIN `t_parameter` `c` ON ( `a`.`MappedParaId` = `c`.`Id` ) AND ( `c`.`IsDeleted` = 0 ) Left JOIN `t_parameter_fixed` `d` ON d.InterfaceId = b.InterfaceId and `b`.`Alias` = `d`.`FieldName` AND `d`.`FieldPositions` like concat('%', CAST(N'Body' AS CHAR),'%') AND d.IsDeleted = 0 Left JOIN `t_dictionary` `e` ON (( `b`.`Type` = `e`.`Id` ) AND ( `e`.`Type` = N'ParameterType' )) WHERE {(isInParaMap ? $"t.id in ({ids})" : $"t.id = {mapIds.First()}")} and t.IsDeleted = 0 ORDER BY `b`.`Sort` ASC").ToListAsync(); } }