From 8f24432a014dcfb4a4c8e9d45d8a8743900a8998 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:38:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E7=AB=99=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=AB=99=E5=85=B3=E8=81=94=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E5=8C=B9=E9=85=8D=20(#4198)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/pull/4198 --- backend/app/repo/website.go | 11 +++++++++-- backend/app/repo/website_domain.go | 6 ++++++ backend/app/service/website.go | 11 ++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/backend/app/repo/website.go b/backend/app/repo/website.go index c525337a8..4c4cc2545 100644 --- a/backend/app/repo/website.go +++ b/backend/app/repo/website.go @@ -18,6 +18,7 @@ type IWebsiteRepo interface { WithDefaultServer() DBOption WithDomainLike(domain string) DBOption WithRuntimeID(runtimeID uint) DBOption + WithIDs(ids []uint) DBOption Page(page, size int, opts ...DBOption) (int64, []model.Website, error) List(opts ...DBOption) ([]model.Website, error) GetFirst(opts ...DBOption) (model.Website, error) @@ -36,9 +37,15 @@ func NewIWebsiteRepo() IWebsiteRepo { type WebsiteRepo struct { } -func (w *WebsiteRepo) WithAppInstallId(appInstallId uint) DBOption { +func (w *WebsiteRepo) WithAppInstallId(appInstallID uint) DBOption { return func(db *gorm.DB) *gorm.DB { - return db.Where("app_install_id = ?", appInstallId) + return db.Where("app_install_id = ?", appInstallID) + } +} + +func (w *WebsiteRepo) WithIDs(ids []uint) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("id in (?)", ids) } } diff --git a/backend/app/repo/website_domain.go b/backend/app/repo/website_domain.go index 6624a2108..fa5c45560 100644 --- a/backend/app/repo/website_domain.go +++ b/backend/app/repo/website_domain.go @@ -14,6 +14,7 @@ type IWebsiteDomainRepo interface { WithWebsiteId(websiteId uint) DBOption WithPort(port int) DBOption WithDomain(domain string) DBOption + WithDomainLike(domain string) DBOption Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error) GetFirst(opts ...DBOption) (model.WebsiteDomain, error) GetBy(opts ...DBOption) ([]model.WebsiteDomain, error) @@ -44,6 +45,11 @@ func (w WebsiteDomainRepo) WithDomain(domain string) DBOption { return db.Where("domain = ?", domain) } } +func (w WebsiteDomainRepo) WithDomainLike(domain string) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("domain like ?", "%"+domain+"%") + } +} func (w WebsiteDomainRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error) { var domains []model.WebsiteDomain db := getDb(opts...).Model(&model.WebsiteDomain{}) diff --git a/backend/app/service/website.go b/backend/app/service/website.go index ed2cd7826..6bfdca35d 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -119,7 +119,16 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons } opts = append(opts, commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) if req.Name != "" { - opts = append(opts, websiteRepo.WithDomainLike(req.Name)) + domains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomainLike(req.Name)) + if len(domains) > 0 { + var websiteIds []uint + for _, domain := range domains { + websiteIds = append(websiteIds, domain.WebsiteID) + } + opts = append(opts, websiteRepo.WithIDs(websiteIds)) + } else { + opts = append(opts, websiteRepo.WithDomainLike(req.Name)) + } } if req.WebsiteGroupID != 0 { opts = append(opts, websiteRepo.WithGroupID(req.WebsiteGroupID))