From c0d659e300fda62f7430b1c9d6f8020f17ab84df Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 19 Feb 2019 16:36:31 +0800 Subject: [PATCH] - add optional params fromTime and toTime for TmpGetJxBadCommentsByStoreId --- business/jxstore/cms/store.go | 32 ++++++-- business/jxstore/tempop/tempop.go | 75 +++++++++++++++++++ business/model/legacymodel/jxbadcomments.go | 2 +- .../purchase/jd/order_legacy_comment.go | 2 +- controllers/cms_store.go | 8 +- controllers/temp_op.go | 16 ++++ routers/commentsRouter_controllers.go | 8 ++ 7 files changed, 134 insertions(+), 9 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 91033bac0..b7e254b1c 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -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, diff --git a/business/jxstore/tempop/tempop.go b/business/jxstore/tempop/tempop.go index 74db5db05..2f0200905 100644 --- a/business/jxstore/tempop/tempop.go +++ b/business/jxstore/tempop/tempop.go @@ -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 + } + } + } +} diff --git a/business/model/legacymodel/jxbadcomments.go b/business/model/legacymodel/jxbadcomments.go index 230167655..f189d4d65 100644 --- a/business/model/legacymodel/jxbadcomments.go +++ b/business/model/legacymodel/jxbadcomments.go @@ -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:"更改后的标签信息"` diff --git a/business/partner/purchase/jd/order_legacy_comment.go b/business/partner/purchase/jd/order_legacy_comment.go index 362d4d957..f55d3e13f 100644 --- a/business/partner/purchase/jd/order_legacy_comment.go +++ b/business/partner/purchase/jd/order_legacy_comment.go @@ -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"]) diff --git a/controllers/cms_store.go b/controllers/cms_store.go index 07bdf9238..d8312afad 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -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 }) } diff --git a/controllers/temp_op.go b/controllers/temp_op.go index f2f26dfe3..74097fdfa 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -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 + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 1fb6f93a9..4616368dc 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -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",