1
This commit is contained in:
parent
446c0f14cc
commit
f32cae4e4a
131
server/light_backtask/task/recharge.go
Normal file
131
server/light_backtask/task/recharge.go
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"q5"
|
||||||
|
"f5"
|
||||||
|
"main/constant"
|
||||||
|
"fmt"
|
||||||
|
"mt"
|
||||||
|
"strings"
|
||||||
|
"jccommon"
|
||||||
|
)
|
||||||
|
|
||||||
|
type itemSoldOut struct {
|
||||||
|
Buyer string `json:"buyer"`
|
||||||
|
Passport string `json:"passport"`
|
||||||
|
OrderId string `json:"orderId"`
|
||||||
|
Currency string `json:"currency"`
|
||||||
|
Amount string `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type recharge struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *recharge) init() {
|
||||||
|
mt.Table.Contract.Traverse(func (ele *mt.Contract) bool {
|
||||||
|
if ele.GetName() == jccommon.CONTRACT_NAME_GameItemMall {
|
||||||
|
go this.process(ele.GetNetId(), ele.GetAddress())
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *recharge) unInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *recharge) process(netId int32, contractAddress string) {
|
||||||
|
key := fmt.Sprintf("recharge.lastIdx.%d.%s", netId, contractAddress)
|
||||||
|
if dbLastIdxStr, err := jccommon.GetDbParam(constant.BCEVENT_DB, key); err == nil {
|
||||||
|
f5.GetGoStyleDb().IncrementLoad(
|
||||||
|
constant.BCEVENT_DB,
|
||||||
|
"recharge." + q5.ToString(netId) + "." + contractAddress,
|
||||||
|
"t_blockchain_event",
|
||||||
|
q5.ToInt64(dbLastIdxStr),
|
||||||
|
func (lastIdx int64, maxIdx int64) (string, []string) {
|
||||||
|
sql := fmt.Sprintf(`
|
||||||
|
SELECT * FROM t_blockchain_event
|
||||||
|
WHERE idx > %d AND idx <= %d AND net_id = %d AND contract_address = ? AND event_name IN (?, ?)
|
||||||
|
ORDER BY idx LIMIT 1000
|
||||||
|
`,
|
||||||
|
lastIdx,
|
||||||
|
maxIdx,
|
||||||
|
netId)
|
||||||
|
params := []string{
|
||||||
|
contractAddress,
|
||||||
|
"ItemSoldOut",
|
||||||
|
}
|
||||||
|
return sql, params
|
||||||
|
},
|
||||||
|
func (newLastIdx int64) {
|
||||||
|
jccommon.SaveDbParam(constant.BCEVENT_DB, key, q5.ToString(newLastIdx))
|
||||||
|
},
|
||||||
|
this.saveToDb)
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("recharge.process getDBParam error %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *recharge) saveToDb(ds *f5.DataSet) bool {
|
||||||
|
f5.GetSysLog().Info("load ItemSoldOut idx:%s contract_name:%s event_name:%s",
|
||||||
|
ds.GetByName("idx"),
|
||||||
|
ds.GetByName("contract_name"),
|
||||||
|
ds.GetByName("event_name"))
|
||||||
|
idx := ds.GetByName("idx")
|
||||||
|
txhash := ds.GetByName("txhash")
|
||||||
|
logIndex := ds.GetByName("log_index")
|
||||||
|
netId := ds.GetByName("net_id")
|
||||||
|
eventName := ds.GetByName("event_name")
|
||||||
|
contractAddress := ds.GetByName("contract_address")
|
||||||
|
returnValues := ds.GetByName("return_values")
|
||||||
|
createTime := ds.GetByName("createtime")
|
||||||
|
modifyTime := ds.GetByName("modifytime")
|
||||||
|
|
||||||
|
decodeJsonOk := false
|
||||||
|
p := new(itemSoldOut)
|
||||||
|
if q5.DecodeJson(returnValues, p) == nil {
|
||||||
|
decodeJsonOk = true
|
||||||
|
var dbErr error
|
||||||
|
f5.GetGoStyleDb().Upsert(
|
||||||
|
constant.BCEVENT_DB,
|
||||||
|
"t_recharge",
|
||||||
|
[][]string{
|
||||||
|
{"txhash", txhash},
|
||||||
|
{"log_index", logIndex},
|
||||||
|
{"net_id", netId},
|
||||||
|
{"contract_address", contractAddress},
|
||||||
|
},
|
||||||
|
[][]string{},
|
||||||
|
[][]string{
|
||||||
|
{"txhash", txhash},
|
||||||
|
{"log_index", logIndex},
|
||||||
|
{"net_id", netId},
|
||||||
|
{"event_name", eventName},
|
||||||
|
{"contract_address", strings.ToLower(contractAddress)},
|
||||||
|
{"src_idx", idx},
|
||||||
|
{"buyer", p.Buyer},
|
||||||
|
{"passport", p.Passport},
|
||||||
|
{"order_id", p.OrderId},
|
||||||
|
{"currency", p.Currency},
|
||||||
|
{"amount", p.Amount},
|
||||||
|
{"createtime", createTime},
|
||||||
|
{"modifytime", modifyTime},
|
||||||
|
},
|
||||||
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||||
|
dbErr = err
|
||||||
|
})
|
||||||
|
if dbErr != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !decodeJsonOk {
|
||||||
|
jccommon.AddDbLog(constant.BCEVENT_DB, "recharge", "decodeJsonError",
|
||||||
|
map[string]string{
|
||||||
|
"param1": txhash,
|
||||||
|
"param2": netId,
|
||||||
|
"param3": eventName,
|
||||||
|
"param4": idx,
|
||||||
|
"param5": contractAddress,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
@ -11,6 +11,7 @@ type taskMgr struct {
|
|||||||
refreshMeta
|
refreshMeta
|
||||||
contribution
|
contribution
|
||||||
chainActivity
|
chainActivity
|
||||||
|
recharge
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *taskMgr) Init() {
|
func (this *taskMgr) Init() {
|
||||||
@ -21,9 +22,11 @@ func (this *taskMgr) Init() {
|
|||||||
//this.refreshMeta.init()
|
//this.refreshMeta.init()
|
||||||
//this.contribution.init()
|
//this.contribution.init()
|
||||||
this.chainActivity.init()
|
this.chainActivity.init()
|
||||||
|
this.recharge.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *taskMgr) UnInit() {
|
func (this *taskMgr) UnInit() {
|
||||||
|
this.recharge.unInit()
|
||||||
this.chainActivity.unInit()
|
this.chainActivity.unInit()
|
||||||
//this.contribution.unInit()
|
//this.contribution.unInit()
|
||||||
//this.refreshMeta.unInit()
|
//this.refreshMeta.unInit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user