/// <summary> /// 初始化构建器 /// </summary> public List <BuilderOptions> InitBuilder(Project project) { var page = new BuilderPageParam { PageNumber = 1, PageSize = 1000, BuilderType = BuilderType.Builder }; //获取所有构建器 var builderParam = page; var allBuilders = _serviceProvider.GetService <IBuilderService>().GetBuilderPage(builderParam).Result.Datas.ToList(); //获取所有模板 var templates = _serviceProvider.GetService <ITemplateService>().GetTemplatePageAsync(page).Result.Datas .ToList(); var templateIds = templates.Select(x => x.Id); var builderTemplateId = allBuilders.Select(x => x.TemplateId); //通过差集计算出没有构建器的模板 var needInsert = templateIds.Except(builderTemplateId); //筛选出模板 var ts = templates.Where(x => needInsert.Contains(x.Id)).ToList(); var defaultProjectId = project.Id; //添加模板对应的构建器 名称和路径均为模板名 var builders = ts.Select(x => { var name = Path.GetFileNameWithoutExtension(x.TemplateName); var builder = new BuilderOptions($"{x.TemplateType}_{name}", name, "", name) { TemplateId = x.Id, DefaultProjectId = defaultProjectId }; return(builder); }).ToList(); var options = builders.Select(b => _serviceProvider.GetService <IBuilderService>().AddBuilder(b).Result).ToList(); return(options); }
/// <summary> /// 获取构建器分页 /// </summary> /// <param name="page"></param> /// <returns></returns> public async Task <PageView <BuilderOptions> > GetBuilderPage(BuilderPageParam page) { return(await _builderRep .Select .Include(x => x.Template) .WhereIf(page.BuilderType != null, x => x.Type == page.BuilderType) .WhereIf(!string.IsNullOrWhiteSpace(page.Keyword), x => x.Name.Contains(page.Keyword)) .GetPage(page)); }
public async Task <IActionResult> Get(BuilderPageParam page) { return(Success(await BuilderService.GetBuilderPage(page))); }