- 增加资产列表使用IP端口查询的功能
This commit is contained in:
@ -118,12 +118,13 @@ func (assetApi AssetApi) AssetPagingEndpoint(c echo.Context) error {
|
||||
protocol := c.QueryParam("protocol")
|
||||
tags := c.QueryParam("tags")
|
||||
ip := c.QueryParam("ip")
|
||||
port := c.QueryParam("port")
|
||||
active := c.QueryParam("active")
|
||||
|
||||
order := c.QueryParam("order")
|
||||
field := c.QueryParam("field")
|
||||
|
||||
items, total, err := repository.AssetRepository.Find(context.Background(), pageIndex, pageSize, name, protocol, tags, ip, active, order, field)
|
||||
items, total, err := repository.AssetRepository.Find(context.Background(), pageIndex, pageSize, name, protocol, tags, ip, port, active, order, field)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func (r assetRepository) FindByProtocolAndIds(c context.Context, protocol string
|
||||
return
|
||||
}
|
||||
|
||||
func (r assetRepository) Find(c context.Context, pageIndex, pageSize int, name, protocol, tags, ip, active, order, field string) (o []model.AssetForPage, total int64, err error) {
|
||||
func (r assetRepository) Find(c context.Context, pageIndex, pageSize int, name, protocol, tags, ip, port, active, order, field string) (o []model.AssetForPage, total int64, err error) {
|
||||
db := r.GetDB(c).Table("assets").Select("assets.id,assets.name,assets.ip,assets.port,assets.protocol,assets.active,assets.active_message,assets.owner,assets.created,assets.tags,assets.description, users.nickname as owner_name").Joins("left join users on assets.owner = users.id")
|
||||
dbCounter := r.GetDB(c).Table("assets")
|
||||
|
||||
@ -57,6 +57,11 @@ func (r assetRepository) Find(c context.Context, pageIndex, pageSize int, name,
|
||||
dbCounter = dbCounter.Where("assets.ip like ?", "%"+ip+"%")
|
||||
}
|
||||
|
||||
if len(port) > 0 {
|
||||
db = db.Where("assets.port = ?", port)
|
||||
dbCounter = dbCounter.Where("assets.port = ?", ip)
|
||||
}
|
||||
|
||||
if len(protocol) > 0 {
|
||||
db = db.Where("assets.protocol = ?", protocol)
|
||||
dbCounter = dbCounter.Where("assets.protocol = ?", protocol)
|
||||
|
Reference in New Issue
Block a user