From 46ecbd9f5a71c01df45e241c8d5795454dafe1f7 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 10 四月 2024 11:03:09 +0800
Subject: [PATCH] 字典支持关键字搜索

---
 controllers/dict.go               |    2 +-
 controllers/request/system_set.go |    1 +
 models/dict.go                    |   11 +++++++++++
 docs/swagger.yaml                 |    4 ++++
 docs/docs.go                      |    6 ++++++
 docs/swagger.json                 |    6 ++++++
 6 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/controllers/dict.go b/controllers/dict.go
index ef51e3f..31f0965 100644
--- a/controllers/dict.go
+++ b/controllers/dict.go
@@ -122,7 +122,7 @@
 	if params.DictType != nil {
 		search = search.SetDictType(params.DictType)
 	}
-	list, err := search.FindAll()
+	list, err := search.SetKeyword(params.Keyword).FindAll()
 
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
diff --git a/controllers/request/system_set.go b/controllers/request/system_set.go
index dd25cb7..b365be8 100644
--- a/controllers/request/system_set.go
+++ b/controllers/request/system_set.go
@@ -8,6 +8,7 @@
 type GetDictList struct {
 	PageInfo
 	DictType *constvar.DictType `json:"dictType" form:"dictType"` //瀛楀吀绫诲瀷
+	Keyword  string             `json:"keyword" form:"keyword"`   //鎼滅储鍏抽敭瀛�
 }
 
 type AddDict struct {
diff --git a/docs/docs.go b/docs/docs.go
index 1733581..b65018f 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -525,6 +525,12 @@
                         "in": "query"
                     },
                     {
+                        "type": "string",
+                        "description": "鎼滅储鍏抽敭瀛�",
+                        "name": "keyword",
+                        "in": "query"
+                    },
+                    {
                         "type": "integer",
                         "description": "椤电爜",
                         "name": "page",
diff --git a/docs/swagger.json b/docs/swagger.json
index 5ec2ec5..c769c39 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -513,6 +513,12 @@
                         "in": "query"
                     },
                     {
+                        "type": "string",
+                        "description": "鎼滅储鍏抽敭瀛�",
+                        "name": "keyword",
+                        "in": "query"
+                    },
+                    {
                         "type": "integer",
                         "description": "椤电爜",
                         "name": "page",
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 5bcdd0a..dd2307d 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1097,6 +1097,10 @@
         - DictTypeWorkshop
         - DictTypeColor
         - DictTypeSpec
+      - description: 鎼滅储鍏抽敭瀛�
+        in: query
+        name: keyword
+        type: string
       - description: 椤电爜
         in: query
         name: page
diff --git a/models/dict.go b/models/dict.go
index 00fc491..7e682d8 100644
--- a/models/dict.go
+++ b/models/dict.go
@@ -23,6 +23,7 @@
 		PageNum  int
 		PageSize int
 		Orm      *gorm.DB
+		Keyword  string
 	}
 )
 
@@ -64,6 +65,11 @@
 	return slf
 }
 
+func (slf *DictSearch) SetKeyword(keyword string) *DictSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
 func (slf *DictSearch) SetDictType(dt *constvar.DictType) *DictSearch {
 	slf.DictType = dt
 	return slf
@@ -92,6 +98,11 @@
 		db = db.Where("name = ?", slf.Name)
 	}
 
+	if slf.Keyword != "" {
+		kw := "%" + slf.Keyword + "%"
+		db = db.Where("name like ? or number like ?", kw, kw)
+	}
+
 	return db
 }
 

--
Gitblit v1.8.0