- add optional params fromTime and toTime for TmpGetJxBadCommentsByStoreId
This commit is contained in:
@@ -3,6 +3,7 @@ package tempop
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel2"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -23,6 +25,12 @@ import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
var innerDataPat *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
innerDataPat = regexp.MustCompile(`"result":(.*),"code":200`)
|
||||
}
|
||||
|
||||
func Convert2JDSPU(ctx *jxcontext.Context, count int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
@@ -772,3 +780,70 @@ func TransformJdSpu2Sku(ctx *jxcontext.Context, skuNameIDs []int, count int, isA
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func ReProcessJdBadComment(ctx *jxcontext.Context, isForce, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM jx_bad_comments
|
||||
`
|
||||
if !isForce {
|
||||
sql += " WHERE (createtime IS NULL OR createtime = '') OR (updatetime IS NULL OR updatetime = '')"
|
||||
}
|
||||
// sql += " LIMIT 1"
|
||||
db := dao.GetDB()
|
||||
var commentList []*legacymodel.JxBadComments
|
||||
if err = dao.GetRows(db, &commentList, sql); err == nil {
|
||||
if len(commentList) > 0 {
|
||||
rootTask := tasksch.NewParallelTask("ReProcessJdBadComment", nil, ctx.GetUserName(), func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
badComment := batchItemList[0].(*legacymodel.JxBadComments)
|
||||
comment1, _ := unmarshalCommentText(badComment.Msg)
|
||||
comment2, _ := unmarshalCommentText(badComment.UpdatedMsg)
|
||||
if len(comment1) > 0 {
|
||||
badComment.Createtime = utils.Timestamp2Str(utils.MustInterface2Int64(comment1["createTime"].(map[string]interface{})["time"]) / 1000)
|
||||
badComment.Msg = string(utils.MustMarshal(comment1))
|
||||
if len(comment2) > 0 {
|
||||
badComment.Updatetime = utils.Timestamp2Str(utils.MustInterface2Int64(comment2["createTime"].(map[string]interface{})["time"]) / 1000)
|
||||
badComment.UpdatedMsg = string(utils.MustMarshal(comment2))
|
||||
} else if badComment.UpdatedMsg != "" {
|
||||
badComment.OrderFlag = "1"
|
||||
}
|
||||
_, err = dao.UpdateEntity(db, badComment)
|
||||
}
|
||||
return nil, err
|
||||
}, commentList)
|
||||
tasksch.ManageTask(rootTask).Run()
|
||||
if !isAsync {
|
||||
_, err = rootTask.GetResult(0)
|
||||
} else {
|
||||
hint = rootTask.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func unmarshalCommentText(commentStr string) (retVal map[string]interface{}, isNeedUpdate bool) {
|
||||
var err error
|
||||
for {
|
||||
var retVal map[string]interface{} // 必须要用局部变量
|
||||
if commentStr == "" {
|
||||
return nil, false
|
||||
}
|
||||
if err = jxutils.Strings2Objs(commentStr, &retVal); err == nil {
|
||||
if retVal["data"] != nil {
|
||||
commentStr = retVal["data"].(string)
|
||||
} else if retVal["result"] != nil {
|
||||
return retVal["result"].(map[string]interface{}), true
|
||||
} else {
|
||||
return retVal, false
|
||||
}
|
||||
} else {
|
||||
strList := innerDataPat.FindStringSubmatch(commentStr)
|
||||
if strList[1] != "" {
|
||||
commentStr = strList[1]
|
||||
} else {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user