增加在IP名单中使用ipFrom和ipTo查找IP的API

This commit is contained in:
刘祥超
2021-10-26 09:17:33 +08:00
parent 5597a0af6c
commit a0ff24adb6
2 changed files with 16 additions and 4 deletions

View File

@@ -177,7 +177,7 @@ func (this *IPItemDAO) UpdateIPItem(tx *dbs.Tx, itemId int64, ipFrom string, ipT
}
// CountIPItemsWithListId 计算IP数量
func (this *IPItemDAO) CountIPItemsWithListId(tx *dbs.Tx, listId int64, keyword string) (int64, error) {
func (this *IPItemDAO) CountIPItemsWithListId(tx *dbs.Tx, listId int64, ipFrom string, ipTo string, keyword string) (int64, error) {
var query = this.Query(tx).
State(IPItemStateEnabled).
Attr("listId", listId)
@@ -185,11 +185,17 @@ func (this *IPItemDAO) CountIPItemsWithListId(tx *dbs.Tx, listId int64, keyword
query.Where("(ipFrom LIKE :keyword OR ipTo LIKE :keyword)").
Param("keyword", "%"+keyword+"%")
}
if len(ipFrom) > 0 {
query.Attr("ipFrom", ipFrom)
}
if len(ipTo) > 0 {
query.Attr("ipTo", ipTo)
}
return query.Count()
}
// ListIPItemsWithListId 查找IP列表
func (this *IPItemDAO) ListIPItemsWithListId(tx *dbs.Tx, listId int64, keyword string, offset int64, size int64) (result []*IPItem, err error) {
func (this *IPItemDAO) ListIPItemsWithListId(tx *dbs.Tx, listId int64, keyword string, ipFrom string, ipTo string, offset int64, size int64) (result []*IPItem, err error) {
var query = this.Query(tx).
State(IPItemStateEnabled).
Attr("listId", listId)
@@ -197,6 +203,12 @@ func (this *IPItemDAO) ListIPItemsWithListId(tx *dbs.Tx, listId int64, keyword s
query.Where("(ipFrom LIKE :keyword OR ipTo LIKE :keyword)").
Param("keyword", "%"+keyword+"%")
}
if len(ipFrom) > 0 {
query.Attr("ipFrom", ipFrom)
}
if len(ipTo) > 0 {
query.Attr("ipTo", ipTo)
}
_, err = query.
DescPk().
Slice(&result).