216 lines
4.9 KiB
Go
216 lines
4.9 KiB
Go
package task
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"time"
|
|
"fmt"
|
|
"jccommon"
|
|
"main/constant"
|
|
"main/service"
|
|
)
|
|
|
|
type repairNft struct {
|
|
|
|
}
|
|
|
|
func (this* repairNft) init() {
|
|
go this.processNft()
|
|
go this.processOrder()
|
|
go this.processSale()
|
|
}
|
|
|
|
func (this* repairNft) unInit() {
|
|
}
|
|
|
|
func (this* repairNft) processNft() {
|
|
f5.GetGoStyleDb().LoopLoad(
|
|
constant.BCNFT_DB,
|
|
func (lastIdx int64) string {
|
|
sql := fmt.Sprintf(`
|
|
SELECT * FROM t_nft WHERE idx > %d AND item_id = 0 LIMIT 1000`,
|
|
lastIdx,
|
|
)
|
|
return sql
|
|
},
|
|
[]string{
|
|
},
|
|
func () time.Duration {
|
|
return time.Second * 10
|
|
},
|
|
func () time.Duration {
|
|
return time.Second * 60 * 5
|
|
},
|
|
this.repairNft)
|
|
}
|
|
|
|
func (this* repairNft) processOrder() {
|
|
f5.GetGoStyleDb().LoopLoad(
|
|
constant.BCNFT_DB,
|
|
func (lastIdx int64) string {
|
|
sql := fmt.Sprintf(`
|
|
SELECT * FROM t_order WHERE idx > %d AND item_id = 0 LIMIT 1000`,
|
|
lastIdx,
|
|
)
|
|
return sql
|
|
},
|
|
[]string{
|
|
},
|
|
func () time.Duration {
|
|
return time.Second * 10
|
|
},
|
|
func () time.Duration {
|
|
return time.Second * 60 * 5
|
|
},
|
|
this.repairOrder)
|
|
}
|
|
|
|
func (this* repairNft) processSale() {
|
|
f5.GetGoStyleDb().LoopLoad(
|
|
constant.BCNFT_DB,
|
|
func (lastIdx int64) string {
|
|
sql := fmt.Sprintf(`
|
|
SELECT * FROM t_sale WHERE idx > %d AND item_id = 0 LIMIT 1000`,
|
|
lastIdx,
|
|
)
|
|
return sql
|
|
},
|
|
[]string{
|
|
},
|
|
func () time.Duration {
|
|
return time.Second * 10
|
|
},
|
|
func () time.Duration {
|
|
return time.Second * 60 * 5
|
|
},
|
|
this.repairSale)
|
|
}
|
|
|
|
func (this* repairNft) repairNft(ds *f5.DataSet) bool {
|
|
netId := q5.ToInt32(ds.GetByName("net_id"))
|
|
contractAddress := ds.GetByName("contract_address")
|
|
tokenId := ds.GetByName("token_id")
|
|
switch q5.ToInt32(ds.GetByName("token_type")) {
|
|
case jccommon.NFT_TYPE_CFHERO:
|
|
{
|
|
var itemId int32
|
|
var quality int32
|
|
if service.GetHeroByTokenId(tokenId, &itemId, &quality) {
|
|
this.updateNftItemId(netId, contractAddress, tokenId, itemId)
|
|
}
|
|
}
|
|
case jccommon.NFT_TYPE_GOLD_BULLION:
|
|
{
|
|
var itemId int32
|
|
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
|
|
this.updateNftItemId(netId, contractAddress, tokenId, itemId)
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (this* repairNft) updateNftItemId(netId int32, contractAddress string, tokenId string,
|
|
itemId int32) {
|
|
f5.GetGoStyleDb().Update(
|
|
constant.BCNFT_DB,
|
|
"t_nft",
|
|
[][]string {
|
|
{"net_id", q5.ToString(netId)},
|
|
{"contract_address", contractAddress},
|
|
{"token_id", tokenId},
|
|
{"item_id", q5.ToString(0)},
|
|
},
|
|
[][]string {
|
|
{"item_id", q5.ToString(itemId)},
|
|
},
|
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
|
})
|
|
}
|
|
|
|
func (this* repairNft) repairOrder(ds *f5.DataSet) bool {
|
|
netId := q5.ToInt32(ds.GetByName("net_id"))
|
|
contractAddress := ds.GetByName("contract_address")
|
|
tokenId := ds.GetByName("token_id")
|
|
switch q5.ToInt32(ds.GetByName("token_type")) {
|
|
case jccommon.NFT_TYPE_CFHERO:
|
|
{
|
|
var itemId int32
|
|
var quality int32
|
|
if service.GetHeroByTokenId(tokenId, &itemId, &quality) {
|
|
this.updateOrder(netId, contractAddress, tokenId, itemId, quality)
|
|
}
|
|
}
|
|
case jccommon.NFT_TYPE_GOLD_BULLION:
|
|
{
|
|
var itemId int32
|
|
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
|
|
this.updateOrder(netId, contractAddress, tokenId, itemId, 0)
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (this* repairNft) updateOrder(netId int32, contractAddress string, tokenId string,
|
|
itemId int32, quality int32) {
|
|
f5.GetGoStyleDb().Update(
|
|
constant.BCNFT_DB,
|
|
"t_order",
|
|
[][]string {
|
|
{"net_id", q5.ToString(netId)},
|
|
{"contract_address", contractAddress},
|
|
{"token_id", tokenId},
|
|
{"item_id", q5.ToString(0)},
|
|
},
|
|
[][]string {
|
|
{"item_id", q5.ToString(itemId)},
|
|
{"hero_quality", q5.ToString(quality)},
|
|
},
|
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
|
})
|
|
}
|
|
|
|
func (this* repairNft) repairSale(ds *f5.DataSet) bool {
|
|
netId := q5.ToInt32(ds.GetByName("net_id"))
|
|
contractAddress := ds.GetByName("contract_address")
|
|
tokenId := ds.GetByName("token_id")
|
|
switch q5.ToInt32(ds.GetByName("token_type")) {
|
|
case jccommon.NFT_TYPE_CFHERO:
|
|
{
|
|
var itemId int32
|
|
var quality int32
|
|
if service.GetHeroByTokenId(tokenId, &itemId, &quality) {
|
|
this.updateSale(netId, contractAddress, tokenId, itemId, quality)
|
|
}
|
|
}
|
|
case jccommon.NFT_TYPE_GOLD_BULLION:
|
|
{
|
|
var itemId int32
|
|
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
|
|
this.updateSale(netId, contractAddress, tokenId, itemId, 0)
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (this* repairNft) updateSale(netId int32, contractAddress string, tokenId string,
|
|
itemId int32, quality int32) {
|
|
f5.GetGoStyleDb().Update(
|
|
constant.BCNFT_DB,
|
|
"t_sale",
|
|
[][]string {
|
|
{"net_id", q5.ToString(netId)},
|
|
{"contract_address", contractAddress},
|
|
{"token_id", tokenId},
|
|
{"item_id", q5.ToString(0)},
|
|
},
|
|
[][]string {
|
|
{"item_id", q5.ToString(itemId)},
|
|
{"hero_quality", q5.ToString(quality)},
|
|
},
|
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
|
})
|
|
}
|