@@ -34,15 +34,15 @@ func init() {
3434 })
3535}
3636
37- // 启用条目
37+ // EnableNodeGrant 启用条目
3838func (this * NodeGrantDAO ) EnableNodeGrant (tx * dbs.Tx , id uint32 ) (rowsAffected int64 , err error ) {
3939 return this .Query (tx ).
4040 Pk (id ).
4141 Set ("state" , NodeGrantStateEnabled ).
4242 Update ()
4343}
4444
45- // 禁用条目
45+ // DisableNodeGrant 禁用条目
4646func (this * NodeGrantDAO ) DisableNodeGrant (tx * dbs.Tx , id int64 ) (err error ) {
4747 _ , err = this .Query (tx ).
4848 Pk (id ).
@@ -51,7 +51,7 @@ func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
5151 return err
5252}
5353
54- // 查找启用中的条目
54+ // FindEnabledNodeGrant 查找启用中的条目
5555func (this * NodeGrantDAO ) FindEnabledNodeGrant (tx * dbs.Tx , id int64 ) (* NodeGrant , error ) {
5656 result , err := this .Query (tx ).
5757 Pk (id ).
@@ -63,7 +63,7 @@ func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant
6363 return result .(* NodeGrant ), err
6464}
6565
66- // 根据主键查找名称
66+ // FindNodeGrantName 根据主键查找名称
6767func (this * NodeGrantDAO ) FindNodeGrantName (tx * dbs.Tx , id uint32 ) (string , error ) {
6868 name , err := this .Query (tx ).
6969 Pk (id ).
@@ -72,7 +72,7 @@ func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, erro
7272 return name .(string ), err
7373}
7474
75- // 创建认证信息
75+ // CreateGrant 创建认证信息
7676func (this * NodeGrantDAO ) CreateGrant (tx * dbs.Tx , adminId int64 , name string , method string , username string , password string , privateKey string , description string , nodeId int64 ) (grantId int64 , err error ) {
7777 op := NewNodeGrantOperator ()
7878 op .AdminId = adminId
@@ -94,7 +94,7 @@ func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, me
9494 return types .Int64 (op .Id ), err
9595}
9696
97- // 修改认证信息
97+ // UpdateGrant 修改认证信息
9898func (this * NodeGrantDAO ) UpdateGrant (tx * dbs.Tx , grantId int64 , name string , method string , username string , password string , privateKey string , description string , nodeId int64 ) error {
9999 if grantId <= 0 {
100100 return errors .New ("invalid grantId" )
@@ -119,17 +119,26 @@ func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, me
119119 return err
120120}
121121
122- // 计算所有认证信息数量
123- func (this * NodeGrantDAO ) CountAllEnabledGrants (tx * dbs.Tx ) (int64 , error ) {
124- return this .Query (tx ).
125- State (NodeGrantStateEnabled ).
126- Count ()
122+ // CountAllEnabledGrants 计算所有认证信息数量
123+ func (this * NodeGrantDAO ) CountAllEnabledGrants (tx * dbs.Tx , keyword string ) (int64 , error ) {
124+ query := this .Query (tx ).
125+ State (NodeGrantStateEnabled )
126+ if len (keyword ) > 0 {
127+ query .Where ("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)" ).
128+ Param ("keyword" , "%" + keyword + "%" )
129+ }
130+ return query .Count ()
127131}
128132
129- // 列出单页的认证信息
130- func (this * NodeGrantDAO ) ListEnabledGrants (tx * dbs.Tx , offset int64 , size int64 ) (result []* NodeGrant , err error ) {
131- _ , err = this .Query (tx ).
132- State (NodeGrantStateEnabled ).
133+ // ListEnabledGrants 列出单页的认证信息
134+ func (this * NodeGrantDAO ) ListEnabledGrants (tx * dbs.Tx , keyword string , offset int64 , size int64 ) (result []* NodeGrant , err error ) {
135+ query := this .Query (tx ).
136+ State (NodeGrantStateEnabled )
137+ if len (keyword ) > 0 {
138+ query .Where ("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)" ).
139+ Param ("keyword" , "%" + keyword + "%" )
140+ }
141+ _ , err = query .
133142 Offset (offset ).
134143 Size (size ).
135144 DescPk ().
@@ -138,7 +147,7 @@ func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64
138147 return
139148}
140149
141- // 列出所有的认证信息
150+ // FindAllEnabledGrants 列出所有的认证信息
142151func (this * NodeGrantDAO ) FindAllEnabledGrants (tx * dbs.Tx ) (result []* NodeGrant , err error ) {
143152 _ , err = this .Query (tx ).
144153 State (NodeGrantStateEnabled ).
0 commit comments