Commit b0650fac authored by shajiaiming's avatar shajiaiming

关系搜索

parent 62790096
...@@ -40,11 +40,21 @@ func GetWalletCoinRelationTotal(maps interface{}) (int, error) { ...@@ -40,11 +40,21 @@ func GetWalletCoinRelationTotal(maps interface{}) (int, error) {
func GetWalletCoinRelations(pageNum, pageSize int, maps interface{}) ([]*WalletCoinRelation, error) { func GetWalletCoinRelations(pageNum, pageSize int, maps interface{}) ([]*WalletCoinRelation, error) {
var coins []*WalletCoinRelation var coins []*WalletCoinRelation
conditions := make(map[string]interface{}) relation_map := make(map[string]interface{})
conditions["name"] = "ETH" coin_map := make(map[string]interface{})
conditions["sid"] = "ethereum" for key, value := range maps.(map[string]interface{}) {
conditions["platform"] = "ethereum" if ("platform_id" == key || "coin_id" == key) {
err := db.Preload("Coin", conditions).Debug().Where(maps).Offset(pageNum).Limit(pageSize).Find(&coins).Error relation_map[key] = value
}
if ("condition" == key) {
for k, v := range value.(map[string]interface{}) {
coin_map[k] = v
}
}
}
err := db.Preload("Coin", coin_map).Where(relation_map).Offset(pageNum).Limit(pageSize).Find(&coins).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
......
...@@ -25,19 +25,38 @@ func GetWalletCoinRelationCoinRelations(c *gin.Context) { ...@@ -25,19 +25,38 @@ func GetWalletCoinRelationCoinRelations(c *gin.Context) {
} else { } else {
platform_id = auth.PlatformId platform_id = auth.PlatformId
} }
name := ""
if arg := c.Query("name"); arg != "" {
name = c.Query("name")
}
platform := ""
if arg := c.Query("platform"); arg != "" {
platform = c.Query("platform")
}
chain := ""
if arg := c.Query("chain"); arg != "" {
chain = c.Query("chain")
}
walletCoinRelateionService := wallet_coin_relation_service.WalletCoinRelation{ walletCoinRelateionService := wallet_coin_relation_service.WalletCoinRelation{
PlatformId: platform_id, PlatformId: platform_id,
PageNum: util.GetPage(c), CoinCondition: struct {
PageSize: util.GetLimit(c), Name string
Chain string
Platform string
}{Name: name, Chain: chain, Platform: platform},
PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
} }
/* /*
_, err := walletCoinRelateionService.Count() _, err := walletCoinRelateionService.Count()
if err != nil { if err != nil {
handler.SendResponse(c, errno.ErrCountWalletCoinRelation, nil) handler.SendResponse(c, errno.ErrCountWalletCoinRelation, nil)
return return
} }
*/ */
coins, err := walletCoinRelateionService.GetAll() coins, err := walletCoinRelateionService.GetAll()
......
...@@ -7,12 +7,18 @@ import ( ...@@ -7,12 +7,18 @@ import (
type WalletCoinRelation struct { type WalletCoinRelation struct {
PlatformId int PlatformId int
CoinId int CoinId int
CoinInfo models.Coin CoinCondition CoinCondition
PageNum int PageNum int
PageSize int PageSize int
} }
type CoinCondition struct {
Name string
Chain string
Platform string
}
func (w *WalletCoinRelation) GetAll() ([]*models.Coin, error) { func (w *WalletCoinRelation) GetAll() ([]*models.Coin, error) {
var wallet_coin_relations []*models.WalletCoinRelation var wallet_coin_relations []*models.WalletCoinRelation
...@@ -61,6 +67,9 @@ func (c *WalletCoinRelation) Delete() error { ...@@ -61,6 +67,9 @@ func (c *WalletCoinRelation) Delete() error {
return models.DeleteWalletCoinRelation(c.PlatformId, c.CoinId) return models.DeleteWalletCoinRelation(c.PlatformId, c.CoinId)
} }
type Condition struct {
}
func (c *WalletCoinRelation) getMaps() (map[string]interface{}) { func (c *WalletCoinRelation) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{}) maps := make(map[string]interface{})
...@@ -72,5 +81,18 @@ func (c *WalletCoinRelation) getMaps() (map[string]interface{}) { ...@@ -72,5 +81,18 @@ func (c *WalletCoinRelation) getMaps() (map[string]interface{}) {
maps["coin_id"] = c.CoinId maps["coin_id"] = c.CoinId
} }
var condition = make(map[string]interface{})
if c.CoinCondition.Name != "" {
condition["name"] = c.CoinCondition.Name
}
if c.CoinCondition.Chain != "" {
condition["chain"] = c.CoinCondition.Chain
}
if c.CoinCondition.Platform != "" {
condition["platform"] = c.CoinCondition.Platform
}
maps["condition"] = condition
return maps return maps
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment