From bee89441b05cd92875069678a123bf32e5bb4ce3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 19 Jul 2024 13:01:00 +0800 Subject: [PATCH] 1 --- server/backtask/task/refresh_meta.go | 173 -------------------- server/backtask/task/repair_nft.go | 230 --------------------------- server/backtask/task/repair_order.go | 107 ------------- server/backtask/task/sysmail.go | 169 -------------------- server/backtask/task/taskmgr.go | 12 -- 5 files changed, 691 deletions(-) delete mode 100644 server/backtask/task/refresh_meta.go delete mode 100644 server/backtask/task/repair_nft.go delete mode 100644 server/backtask/task/repair_order.go delete mode 100644 server/backtask/task/sysmail.go diff --git a/server/backtask/task/refresh_meta.go b/server/backtask/task/refresh_meta.go deleted file mode 100644 index a003f6c0..00000000 --- a/server/backtask/task/refresh_meta.go +++ /dev/null @@ -1,173 +0,0 @@ -package task - -import ( - "q5" - "f5" - "mt" - "fmt" - "jccommon" - "main/constant" - //"math/rand" - "strings" - "net/http" - "io/ioutil" -) - -type nftInfo struct { - netId int32 - contractAddress string - tokenId string - apiMeta *apiNftMeta - nftMeta *nftMeta -} - -type apiNftMeta struct { - TokenId string `json:"token_id"` - Name string `json:"name"` - Description string `json:"description"` - Image string `json:"image"` - //ExternalUrl string `json:"external_url"` - //AnimationUrl string `json:"animation_url"` - //YoutubeUrl string `json:"youtube_url"` - Attributes []struct { - TraitType string `json:"trait_type"` - Value interface{} `json:"value"` - } `json:"attributes"` -} - -type nftMeta struct { - Name string `json:"name"` - Description string `json:"description"` - Image string `json:"image"` - ExternalUrl string `json:"external_url"` - AnimationUrl string `json:"animation_url"` - YoutubeUrl string `json:"youtube_url"` - TokenId string `json:"token_id"` - Attributes []struct { - TraitType string `json:"trait_type"` - Value interface{} `json:"value"` - } `json:"attributes"` -} - -type refreshMeta struct { - batchNfts []*nftInfo -} - -func (this* refreshMeta) init() { - this.batchNfts = []*nftInfo{} - //go this.process() -} - -func (this* refreshMeta) unInit() { -} - -func (this* refreshMeta) process() { - f5.GetGoStyleDb().LoopLoad( - constant.BCNFT_DB, - "refreshMeta", - "t_nft", - func () int64 { - return 30 - }, - func (lastIdx int64) string { - sql := fmt.Sprintf(` -SELECT * FROM t_nft WHERE idx > %d AND last_refresh_meta_time = 0 LIMIT 200`, - lastIdx, - ) - return sql - }, - []string{ - }, - func () int64 { - this.doRefresh() - this.batchNfts = []*nftInfo{} - return 60 + 10 - }, - func () int64 { - this.doRefresh() - this.batchNfts = []*nftInfo{} - return 60 + 10 - }, - this.repairHeroMeta) -} - -func (this* refreshMeta) repairHeroMeta(ds *f5.DataSet) bool { - f5.GetSysLog().Info("refresh meta %s %s %s", - ds.GetByName("net_id"), - ds.GetByName("contract_address"), - ds.GetByName("token_id")) - nft := new(nftInfo) - nft.netId = q5.ToInt32(ds.GetByName("net_id")) - nft.contractAddress = ds.GetByName("contract_address") - nft.tokenId = ds.GetByName("token_id") - /* - if nft.tokenId == "6240619010000001" { - q5.AppendSlice(&this.batchNfts, nft) - }*/ - q5.AppendSlice(&this.batchNfts, nft) - return true -} - -//https://api.sandbox.immutable.com/v1/chains/{chain_name}/collections/{contract_address}/nfts/refresh-metadata -func (this* refreshMeta) doRefresh() { - nftMetas := []*nftMeta{} - for _, v := range this.batchNfts { - f5.GetHttpCliMgr().SendGoStyleRequest( - mt.Table.Config.GetById(0).GetGameapiUrl() + "/webapp/index.php", - map[string]string{ - "c": "OutAppNft", - "a": "nftMetaView", - "net_id": q5.ToString(v.netId), - "token_type": q5.ToString(jccommon.NFT_TYPE_CFHERO), - "token_id": v.tokenId, - }, - func (rsp f5.HttpCliResponse) { - if rsp.GetErr() != nil { - f5.GetSysLog().Info("%s", rsp.GetErr()) - return - } - f5.GetSysLog().Info("token_id: %s %s", v.tokenId, rsp.GetRawData()) - var apiNft apiNftMeta - if q5.DecodeJson(rsp.GetRawData(), &apiNft) == nil { - if (apiNft.TokenId == v.tokenId) { - v.apiMeta = &apiNft - v.nftMeta = new(nftMeta) - v.nftMeta.Name = apiNft.Name - v.nftMeta.Description = apiNft.Description - v.nftMeta.Image = apiNft.Image - v.nftMeta.TokenId = apiNft.TokenId - v.nftMeta.Attributes = apiNft.Attributes - q5.AppendSlice(&nftMetas, v.nftMeta) - } - } - }) - } - if len(nftMetas) > 0 { - data := struct { - NftMetaData []*nftMeta `json:"nft_metadata"` - }{} - url := fmt.Sprintf("%s/v1/chains/%s/collections/%s/nfts/refresh-metadata", - mt.Table.Config.GetById(0).GetImmutableBaseUrl(), - mt.Table.Config.GetById(0).GetChainName(), - mt.Table.Config.GetById(0).GetHeroContractAddress()) - data.NftMetaData = nftMetas - req, _ := http.NewRequest("POST", - url, - strings.NewReader(q5.EncodeJson(data))) - req.Header.Set("x-immutable-api-key", mt.Table.Config.GetById(0).GetImmutableApiKey()) - req.Header.Set("Content-Type", "application/json; charset=utf-8") - resp, err := (&http.Client{}).Do(req) - if err != nil { - fmt.Printf("http error %s", err) - } - defer resp.Body.Close() - if bytes, err := ioutil.ReadAll(resp.Body); err == nil { - fmt.Printf("http ok status_code:%d %s",resp.StatusCode, string(bytes)) - if resp.StatusCode == 202 { - fmt.Printf("1111111111111111111111111111111111") - } - } else { - fmt.Printf("http error read %s", err) - } - } -} diff --git a/server/backtask/task/repair_nft.go b/server/backtask/task/repair_nft.go deleted file mode 100644 index 624d5bfa..00000000 --- a/server/backtask/task/repair_nft.go +++ /dev/null @@ -1,230 +0,0 @@ -package task - -import ( - "q5" - "f5" - "fmt" - "jccommon" - "main/constant" - "main/service" - "math/rand" -) - -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, - "repairNft.nft", - "t_nft", - func () int64 { - return 60 * 1 - }, - 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 () int64 { - return 10 - }, - func () int64 { - return 60 * 5 - }, - this.repairNft) -} - -func (this* repairNft) processOrder() { - f5.GetGoStyleDb().LoopLoad( - constant.BCNFT_DB, - "repairNft.order", - "t_order", - func () int64 { - return 60 + q5.ToInt64(rand.Intn(2)) - }, - 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 () int64 { - return 3 - }, - func () int64 { - return 60 * 5 - }, - this.repairOrder) -} - -func (this* repairNft) processSale() { - f5.GetGoStyleDb().LoopLoad( - constant.BCNFT_DB, - "repairNft.sale", - "t_sale", - func () int64 { - return 60 + q5.ToInt64(rand.Intn(2)) - }, - 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 () int64 { - return 10 - }, - func () int64 { - return 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) { - }) -} diff --git a/server/backtask/task/repair_order.go b/server/backtask/task/repair_order.go deleted file mode 100644 index 8c95ed5a..00000000 --- a/server/backtask/task/repair_order.go +++ /dev/null @@ -1,107 +0,0 @@ -package task - -import ( - "q5" - "f5" - "fmt" - "jccommon" - "main/constant" - "main/service" - "math/rand" - "math/big" -) - -type repairOrder struct { - -} - -func (this* repairOrder) init() { - go this.process() -} - -func (this* repairOrder) unInit() { -} - -func (this* repairOrder) process() { - f5.GetGoStyleDb().LoopLoad( - constant.BCNFT_DB, - "repairOrder", - "t_order", - func () int64 { - return 60 + q5.ToInt64(rand.Intn(3)) - }, - func (lastIdx int64) string { - sql := fmt.Sprintf(` -SELECT * FROM t_order WHERE idx > %d AND status = ? LIMIT 100`, - lastIdx, - ) - return sql - }, - []string{ - jccommon.ORDER_STATUS_ACTIVE, - }, - func () int64 { - return 3 - }, - func () int64 { - return 60 + q5.ToInt64(rand.Intn(3)) - }, - this.repairPrice) -} - -func (this* repairOrder) repairPrice(ds *f5.DataSet) bool { - if service.BcCurrency.GetLastRefreshOkTime() + 3600 * 2 < f5.GetApp().GetRealSeconds() { - return false - } - dbIdx := ds.GetByName("idx") - eventId := ds.GetByName("event_id") - srcPriceAmount := ds.GetByName("src_price_amount") - srcPriceContractAddress := ds.GetByName("src_price_contract_address") - srcPriceItemType := ds.GetByName("src_price_item_type") - if srcPriceAmount == "" { - p := new(jccommon.OrderUpdatedEvent) - err := q5.DecodeJson(ds.GetByName("event_data"), &p) - if err != nil { - return false - } - srcPriceAmount = p.Data.Buy[0].Amount - { - bnSrcPriceAmount, ok := new(big.Int).SetString(srcPriceAmount, 10) - if ok { - for _, val := range p.Data.Fees { - bnAmount, ok := new(big.Int).SetString(val.Amount, 10) - if ok { - bnSrcPriceAmount.Add(bnSrcPriceAmount, bnAmount) - } - } - srcPriceAmount = bnSrcPriceAmount.String() - } - } - srcPriceContractAddress = p.Data.Buy[0].ContractAddress - srcPriceItemType = p.Data.Buy[0].ItemType - } - srcPriceExchangeRate, price := service.BcCurrency.ExchangeUSD( - srcPriceAmount, srcPriceItemType, srcPriceContractAddress) - updateFields := [][]string{ - {"src_price_amount", srcPriceAmount}, - {"src_price_contract_address", srcPriceContractAddress}, - {"src_price_item_type", srcPriceItemType}, - {"price", price}, - {"price_len", q5.ToString(len(price))}, - {"src_price_exchange_rate", q5.ToString(srcPriceExchangeRate)}, - } - f5.GetGoStyleDb().Update( - constant.BCNFT_DB, - "t_order", - [][]string{ - {"idx", q5.ToString(dbIdx)}, - {"event_id", eventId}, - }, - updateFields, - func (err error, lastInsertId int64, rowsAffected int64) { - if err != nil { - return - } - }) - return true -} diff --git a/server/backtask/task/sysmail.go b/server/backtask/task/sysmail.go deleted file mode 100644 index af8307d4..00000000 --- a/server/backtask/task/sysmail.go +++ /dev/null @@ -1,169 +0,0 @@ -package task - -import ( - "q5" - "f5" - "time" - "fmt" - "sync" - "jccommon" - "main/constant" -) - -type sysMail struct { - lastSyncSysMailIdx int64 - syncSysMailCond *sync.Cond -} - -func (this* sysMail) init() { - this.syncSysMailCond = sync.NewCond(new(sync.Mutex)) - f5.GetGoStyleDb().OrmSelectOne( - constant.MAIL_DB, - "t_param", - [][]string{ - {"param_name", jccommon.PARAM_NAME_LAST_SYNC_SYS_MAIL_IDX}, - }, - func (err error, ds *f5.DataSet) { - if err != nil { - panic(fmt.Sprintf("sysMail init err:%s", err)) - return - } - if ds.Next() { - this.lastSyncSysMailIdx = q5.ToInt64(ds.GetByName("param_val1")) - } - go this.syncSysMail() - }) -} - -func (this* sysMail) unInit() { -} - -func (this *sysMail) syncSysMail() { - go func () { - var waitMs int64 = 1000 * 2 - for { - select { - case <-time.After(time.Millisecond * time.Duration(waitMs)): - waitMs = 1000 * 2 - this.syncSysMailCond.Broadcast() - } - } - }() - lastOutTick := q5.GetTickCount() - for true { - this.pullSysMail() - this.syncSysMailCond.L.Lock() - this.syncSysMailCond.Wait() - this.syncSysMailCond.L.Unlock() - if q5.GetTickCount() - lastOutTick > 1000 * 15 { - lastOutTick = q5.GetTickCount() - f5.GetSysLog().Info("sysMail lastSyncSysMailIdx:%d", this.lastSyncSysMailIdx) - } - } -} - -func (this *sysMail) pullSysMail() { - f5.GetGoStyleDb().SelectCustomQuery( - constant.MAIL_DB, - fmt.Sprintf("SELECT * FROM t_sys_mail WHERE idx>%d LIMIT 1000;", this.lastSyncSysMailIdx), - func (err error, ds *f5.DataSet) { - if err != nil { - f5.GetSysLog().Warning("pullSysMail %s", err) - return - } - for ds.Next() { - idx := q5.ToInt64(ds.GetByName("idx")) - f5.GetSysLog().Info("pullSysMail %s begin", idx) - if !this.writeMail(ds) { - return - } - f5.GetSysLog().Info("pullSysMail %s end", idx) - if idx > this.lastSyncSysMailIdx { - this.lastSyncSysMailIdx = idx - } - } - if ds.NumOfReaded() > 0 { - this.saveLastSyncSysMailIdx() - } - }) -} - -func (this *sysMail) writeMail(ds *f5.DataSet) bool { - mailId := q5.ToString(f5.GetApp().NewLockNodeUuid()) - unikey := ds.GetByName("unikey") - subject := ds.GetByName("subject") - content := ds.GetByName("content") - recipients := ds.GetByName("recipients") - attachments := ds.GetByName("attachments") - tag1 := q5.ToInt32(ds.GetByName("tag1")) - tag2 := q5.ToInt32(ds.GetByName("tag2")) - sendTime := q5.ToInt32(ds.GetByName("sendtime")) - expireTime := q5.ToInt32(ds.GetByName("expiretime")) - userRegStartTime := q5.ToInt32(ds.GetByName("user_reg_start_time")) - userRegEndTime := q5.ToInt32(ds.GetByName("user_reg_end_time")) - var ok = false - nowTime := f5.GetApp().GetRealSeconds() - f5.GetGoStyleDb().Upsert( - constant.MAIL_DB, - "t_mail", - [][]string{ - {"unikey", unikey}, - }, - [][]string{ - }, - [][]string{ - {"mail_id", mailId}, - {"mail_type", q5.ToString(jccommon.MAIL_TYPE_GROUP)}, - {"unikey", unikey}, - {"subject", subject}, - {"content", content}, - {"recipients", recipients}, - {"attachments", attachments}, - {"sendtime", q5.ToString(sendTime)}, - {"user_reg_start_time", q5.ToString(userRegStartTime)}, - {"user_reg_end_time", q5.ToString(userRegEndTime)}, - {"tag1", q5.ToString(tag1)}, - {"tag2", q5.ToString(tag2)}, - {"expiretime", q5.ToString(expireTime)}, - {"createtime", q5.ToString(nowTime)}, - {"modifytime", q5.ToString(nowTime)}, - }, - func (err error, lastInsertId int64, rowsAffected int64) { - ok = err == nil - if err != nil { - f5.GetSysLog().Info("writeMail err:%s", err) - } else { - { - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - e := new(jccommon.MailEvent) - e.EventName = jccommon.EVENT_MAIL_UPDATE - e.Param1 = q5.ToString(mailId) - e.CreateTime = nowDaySeconds - e.ModifyTime = nowDaySeconds - f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e) - } - } - }) - return ok -} - -func (this *sysMail) saveLastSyncSysMailIdx() { - f5.GetGoStyleDb().Upsert( - constant.MAIL_DB, - "t_param", - [][]string{ - {"param_name", jccommon.PARAM_NAME_LAST_SYNC_SYS_MAIL_IDX}, - }, - [][]string{ - {"param_val1", q5.ToString(this.lastSyncSysMailIdx)}, - }, - [][]string { - {"param_name", jccommon.PARAM_NAME_LAST_SYNC_SYS_MAIL_IDX}, - {"param_val1", q5.ToString(this.lastSyncSysMailIdx)}, - }, - func (err error, lastInsertId int64, rowsAffected int64) { - if err != nil { - f5.GetSysLog().Info("saveLastSyncSysMailIdx err:%s", err) - } - }) -} diff --git a/server/backtask/task/taskmgr.go b/server/backtask/task/taskmgr.go index 6c4391ac..8980b410 100644 --- a/server/backtask/task/taskmgr.go +++ b/server/backtask/task/taskmgr.go @@ -8,30 +8,18 @@ import ( type taskMgr struct { webHook goldBullionReturn - repairNft openGoldLock sync.Mutex - sysMail - repairOrder - refreshMeta nftLock } func (this *taskMgr) Init() { this.webHook.init() this.goldBullionReturn.init() - this.repairNft.init() - this.sysMail.init() - this.repairOrder.init() - //this.refreshMeta.init() this.nftLock.init() } func (this *taskMgr) UnInit() { this.nftLock.unInit() - //this.refreshMeta.unInit() - this.repairOrder.unInit() - this.sysMail.unInit() - this.repairNft.unInit() this.goldBullionReturn.unInit() this.webHook.unInit() }