- add optional params fromTime and toTime for TmpGetJxBadCommentsByStoreId
This commit is contained in:
@@ -608,24 +608,44 @@ func TmpGetJxBadCommentsNo(ctx *jxcontext.Context, storeID int) (count int, err
|
||||
return count, err
|
||||
}
|
||||
|
||||
func TmpGetJxBadCommentsByStoreId(ctx *jxcontext.Context, storeID, page, size, commentType int) (retVal map[string]interface{}, err error) {
|
||||
func TmpGetJxBadCommentsByStoreId(ctx *jxcontext.Context, storeID, offset, pageSize, commentType int, fromTime, toTime time.Time) (retVal map[string]interface{}, err error) {
|
||||
db := dao.GetDB()
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
FROM jx_bad_comments
|
||||
WHERE jxstoreid = ?
|
||||
WHERE 1 = 1
|
||||
`
|
||||
if commentType == GET_BAD_COMMENTS_TYPE {
|
||||
sql += " AND status = 0"
|
||||
sqlParams := []interface{}{}
|
||||
if storeID > 0 {
|
||||
sql += " AND jxstoreid = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
sql += " ORDER BY createtime DESC LIMIT ? OFFSET ?"
|
||||
if commentType == GET_BAD_COMMENTS_TYPE {
|
||||
sql += " AND status = ?"
|
||||
sqlParams = append(sqlParams, commentType)
|
||||
}
|
||||
if !utils.IsTimeZero(fromTime) {
|
||||
sql += " AND createtime >= ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if !utils.IsTimeZero(toTime) {
|
||||
sql += " AND createtime < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += " ORDER BY createtime DESC"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var commentList []*legacymodel.JxBadComments
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
dao.Rollback(db)
|
||||
}()
|
||||
globals.SugarLogger.Debug(sql)
|
||||
if err = dao.GetRows(db, &commentList, sql, utils.Int2Str(storeID), size, (page-1)*size); err == nil {
|
||||
if err = dao.GetRows(db, &commentList, sql, sqlParams...); err == nil {
|
||||
retVal = map[string]interface{}{
|
||||
"total": dao.GetLastTotalRowCount(db),
|
||||
"list": commentList,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ type JxBadComments struct {
|
||||
Userphone string `json:"userPhone" orm:"column(userphone);size(255);null" description:"评价的用户的联系方式"`
|
||||
Status int `json:"status" orm:"column(status)" description:"当前评论的状态(0:未解决 1:已解决)"`
|
||||
Createtime string `json:"createTime" orm:"column(createtime);size(255);null" description:"评论的创建时间"`
|
||||
Updatetime string `json:"updateTime" orm:"column(updatetime);size(255);null" description:"评论的修改时间"`
|
||||
Maxmodifytime int `json:"maxModifyTime" orm:"column(maxmodifytime);null" description:"评论可修改的最大时间"`
|
||||
Score int `json:"score4" orm:"column(score)" description:"评论的星级"`
|
||||
Scorecontent string `json:"score4Content" orm:"column(scorecontent);size(255);null" description:"评论的内容"`
|
||||
Vendertags string `json:"venderTags" orm:"column(vendertags);size(255);null" description:"评论的标签"`
|
||||
Updatetime string `json:"updateTime" orm:"column(updatetime);size(255);null" description:"评论的修改时间"`
|
||||
UpdatedScore int `json:"updatedScore" orm:"column(updated_score);null" description:"更改后的分数"`
|
||||
UpdatedScorecontent string `json:"updatedScoreContent" orm:"column(updated_scorecontent);size(255);null" description:"更改后的评论信息"`
|
||||
UpdatedVendertags string `json:"updatedVenderTags" orm:"column(updated_vendertags);size(255);null" description:"更改后的标签信息"`
|
||||
|
||||
@@ -115,7 +115,7 @@ func (c *PurchaseHandler) onOrderComment(msg *jdapi.CallbackOrderMsg) (err error
|
||||
}
|
||||
}
|
||||
} else {
|
||||
comment.Updatetime = utils.Timestamp2Str(utils.MustInterface2Int64(result["updateTime"].(map[string]interface{})["time"]) / 1000)
|
||||
comment.Updatetime = utils.Timestamp2Str(utils.MustInterface2Int64(result["createTime"].(map[string]interface{})["time"]) / 1000)
|
||||
comment.UpdatedMsg = string(utils.MustMarshal(result))
|
||||
comment.UpdatedScore = score
|
||||
comment.UpdatedScorecontent = utils.Interface2String(result["score4Content"])
|
||||
|
||||
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
@@ -207,12 +208,17 @@ func (c *StoreController) TmpGetJxBadCommentsNo() {
|
||||
// @Param type query int true "评论类型,0:差评,1:所有"
|
||||
// @Param page query int true "起始页,从1开始"
|
||||
// @Param size query int true "页大小"
|
||||
// @Param fromTime query string false "创建起始时间"
|
||||
// @Param toTime query string false "创建结束时间"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetJxBadCommentsByStoreId [get]
|
||||
func (c *StoreController) TmpGetJxBadCommentsByStoreId() {
|
||||
c.callTmpGetJxBadCommentsByStoreId(func(params *tStoreTmpGetJxBadCommentsByStoreIdParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.TmpGetJxBadCommentsByStoreId(params.Ctx, params.JxStoreId, params.Page, params.Size, params.Type)
|
||||
timeList, err2 := jxutils.BatchStr2Time(params.FromTime, params.ToTime)
|
||||
if err = err2; err == nil {
|
||||
retVal, err = cms.TmpGetJxBadCommentsByStoreId(params.Ctx, params.JxStoreId, (params.Page-1)*params.Size, params.Size, params.Type, timeList[0], timeList[1])
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -127,3 +127,19 @@ func (c *InitDataController) TransformJdSpu2Sku() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 重新处理京东差评
|
||||
// @Description 重新处理京东差评
|
||||
// @Param token header string true "认证token"
|
||||
// @Param isForce formData bool false "是否强制处理"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /ReProcessJdBadComment [post]
|
||||
func (c *InitDataController) ReProcessJdBadComment() {
|
||||
c.callReProcessJdBadComment(func(params *tInitdataReProcessJdBadCommentParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = tempop.ReProcessJdBadComment(params.Ctx, params.IsForce, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -247,6 +247,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"],
|
||||
beego.ControllerComments{
|
||||
Method: "ReProcessJdBadComment",
|
||||
Router: `/ReProcessJdBadComment`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TransferLegacyJdOrder",
|
||||
|
||||
Reference in New Issue
Block a user