activity query
This commit is contained in:
parent
b71545def3
commit
ec3d7b3456
@ -3,7 +3,12 @@ package event
|
||||
import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"marketserver/constant"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
|
||||
. "main/global"
|
||||
"mt"
|
||||
"net/http"
|
||||
"q5"
|
||||
"strings"
|
||||
|
||||
@ -46,3 +51,138 @@ func (ea *EventApi) TxQuery(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ea *EventApi) ActivityQuery(c *gin.Context) {
|
||||
account := strings.ToLower(c.Param("account_address"))
|
||||
reqJson := struct {
|
||||
PageSize interface{} `json:"page_size"`
|
||||
Cursor interface{} `json:"cursor"`
|
||||
Search struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"search"`
|
||||
Filter struct {
|
||||
ItemIds []interface{} `json:"item_ids"`
|
||||
} `json:"filter"`
|
||||
Sort struct {
|
||||
Fields []struct {
|
||||
Name string `json:"name"`
|
||||
Type interface{} `json:"type"`
|
||||
} `json:"fields"`
|
||||
} `json:"sort"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errcode": 1,
|
||||
"errmsg": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 20)
|
||||
cursor := q5.SafeToInt64(reqJson.Cursor)
|
||||
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT * FROM t_chain_activity
|
||||
WHERE idx > %d AND (sender_address = ? OR to_address = ?) `,
|
||||
cursor)
|
||||
|
||||
params := []string{account, account}
|
||||
subFilters := []f5.DbQueryFilter{}
|
||||
|
||||
{
|
||||
itemIds := map[int32]int32{}
|
||||
if reqJson.Search.Name != "" {
|
||||
mt.Table.Item.Search(reqJson.Search.Name, itemIds)
|
||||
}
|
||||
for _, val := range reqJson.Filter.ItemIds {
|
||||
itemId := q5.SafeToInt32(val)
|
||||
itemIds[itemId] = 1
|
||||
}
|
||||
if len(itemIds) > 0 {
|
||||
inSub := `item_id IN (`
|
||||
i := 0
|
||||
for key, _ := range itemIds {
|
||||
if i == 0 {
|
||||
inSub += q5.ToString(key)
|
||||
} else {
|
||||
inSub += "," + q5.ToString(key)
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
inSub += ")"
|
||||
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
||||
}
|
||||
}
|
||||
orderBy := ""
|
||||
{
|
||||
for _, val := range reqJson.Sort.Fields {
|
||||
if val.Name == "price" && orderBy == "" {
|
||||
t := q5.SafeToInt32(val.Type)
|
||||
if t < 0 {
|
||||
orderBy = " ORDER BY price_len DESC, price DESC"
|
||||
} else {
|
||||
orderBy = " ORDER BY price_len ASC, price ASC"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rspObj := struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
Page common.StreamPagination `json:"page"`
|
||||
Rows []struct {
|
||||
Nft interface{} `json:"nft"`
|
||||
Type string `json:"type"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
Date int32 `json:"date"`
|
||||
} `json:"rows"`
|
||||
}{}
|
||||
q5.NewSlice(&rspObj.Rows, 0, 10)
|
||||
nfts := []*common.NftDto{}
|
||||
|
||||
f5.GetGoStyleDb().StreamPageQuery(
|
||||
constant.BCEVENT_DB,
|
||||
pageSize,
|
||||
cursor,
|
||||
sql,
|
||||
params,
|
||||
f5.GetDbFilter().Comp(subFilters...),
|
||||
orderBy,
|
||||
func(err error, pagination *f5.StreamPagination) {
|
||||
rspObj.Page.FillPage(pagination)
|
||||
},
|
||||
func(ds *f5.DataSet) {
|
||||
p := new(common.NftDto)
|
||||
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
||||
p.ContractAddress = ds.GetByName("contract_address")
|
||||
p.TokenId = ds.GetByName("token_id")
|
||||
p.Payload = map[string]string{}
|
||||
p.Payload.(map[string]string)["type"] = ds.GetByName("event_name")
|
||||
p.Payload.(map[string]string)["to"] = ds.GetByName("to_address")
|
||||
p.Payload.(map[string]string)["from"] = ds.GetByName("from_address")
|
||||
p.Payload.(map[string]string)["date"] = ds.GetByName("createtime")
|
||||
q5.AppendSlice(&nfts, p)
|
||||
})
|
||||
GetCacheMgr().GetNfts(nfts)
|
||||
{
|
||||
for _, val := range nfts {
|
||||
p := q5.NewSliceElement(&rspObj.Rows)
|
||||
jsonData := val.NftCache.GetJsonData()
|
||||
if jsonData != nil {
|
||||
if v, ok := jsonData.(map[string]interface{}); ok {
|
||||
v := q5.MapClone(v)
|
||||
tmpmap := val.Payload.(map[string]string)
|
||||
p.Type = tmpmap["type"]
|
||||
p.To = tmpmap["to"]
|
||||
p.From = tmpmap["from"]
|
||||
p.Date = q5.SafeToInt32(tmpmap["date"])
|
||||
jsonData = v
|
||||
}
|
||||
}
|
||||
p.Nft = jsonData
|
||||
}
|
||||
}
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
@ -10,4 +10,5 @@ type EventRouter struct{}
|
||||
func (er *EventRouter) InitRouter() {
|
||||
api := v1.ApiGroupApp.EventApiGroup
|
||||
f5.GetApp().GetGinEngine().GET("/api/chain/txhash/:net_id/:txhash", api.EventApi.TxQuery)
|
||||
f5.GetApp().GetGinEngine().POST("/api/chain/event/activity/:account_address", api.EventApi.ActivityQuery)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user