Commit dd43878b by hcy001

标签

parent 9e07844a
package common
import (
"encoding/json"
"fmt"
"time"
)
/*
定时任务打印输出
@parm jsonStr 需要json输出的内容
*/
func PrintDebug(flag string,str ...interface{}) {
if flag != "101" {
return
}
temp := "--"+(time.Now().Format("2006-01-02 15:04:05"));
for _,jsonStr := range str {
if v, p := jsonStr.(string); p {
temp = temp+"---"+v
}else{
jsonData,err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("错误:---",err)
}
temp = temp+"---"+string(jsonData)
}
}
fmt.Println(temp)
}
\ No newline at end of file
......@@ -3,10 +3,12 @@ package service
import (
"encoding/json"
"fmt"
"github.com/go-redis/redis/v7"
"github.com/gogf/gf/util/gconv"
"github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/tidwall/gjson"
common "go_upload_sync/app/common/function"
"go_upload_sync/app/dao"
ls "go_upload_sync/util/lib"
"time"
......@@ -53,15 +55,8 @@ func NewUploadObj(SkuReStr string) *UploadSkuSync {
/**
@res string 接收 poolsku返回的结果
@res 格式如下
{
"errcode": 0,
"errmsg": "ok",
"goods_id": 1161889823935244337,
"add_sku": 0,
"add_spu": 0,
"spu_id": 2161889823940624400,
"upload_log_id": 123
}
{"errcode":0,"errmsg":"ok","goods_id":1161889823935244337,"add_sku":0,"add_spu":0,"spu_id":2161889823940624400,"upload_log_id":123}
@return error
*/
func (this *UploadSkuSync)Sync() error{
......@@ -79,13 +74,13 @@ func (this *UploadSkuSync)Sync() error{
}
`
this.SkuReStr=Str*/
fmt.Println(this.SkuReStr) //打印初始数据
r:=gjson.Parse(this.SkuReStr)
if(r.Exists() && r.IsObject()){
this.SkuRes=parseRes(r)
this.handle()
}else{
fmt.Println("格式出错");
this.dingdingSucessPush("格式出错");
return nil
}
......@@ -132,6 +127,42 @@ func (this *UploadSkuSync) handle() {
this.dingdingSucessPush(msg);
}
//2021.8.6 计算标签
var item = make(map[string]string)
has, err := dao.Dao.GetDb("spu").Table("lie_sku_upload_item_0").Where("id = ?", this.SkuRes.UploadLogId).Cols("tags","goods_label").Get(&item)
if(has){
tags := gconv.Int64(item["tags"]);
goodsId := gconv.String(this.SkuRes.GoodsId)
redisCon := dao.Dao.GetRedisDbGroup("api");
//获取供应商属性
supplierTag,err := redisCon.HGet("supplier_search_tags",uploadInfo.SupplierCode).Result()
tempTags := make([]int64,0)
if tags > 0 {
tempTags = append(tempTags,tags);
}
if err != redis.Nil {
common.PrintDebug("101","供应商存在属性",supplierTag)
redisTags := gjson.Get(supplierTag,"tags").Array()
for _, name := range redisTags{
tempTags = append(tempTags,name.Int());
}
}
goodsTagJson,_ := json.Marshal(map[string]interface{}{
"goods_label":item["goods_label"],
"tags":tempTags,
})
goodsTagStr := string(goodsTagJson)
errs := redisCon.HSet("goods_tag",goodsId,goodsTagStr).Err() //写入缓存
if errs != nil {
fmt.Println(err)
}
common.PrintDebug("101","计算标签成功",goodsId,uploadInfo.SupplierCode,goodsTagStr)
}
//是否已经处理完成判断
isSucess,err:=this.IshandleSucess()
if(err!=nil){
......@@ -153,6 +184,7 @@ func (this *UploadSkuSync) handle() {
this.dingdingSucessPush(msg);
return
}
this.PushStatus3HandleList(uploadInfo)//处理完推送下架队列
this.PushWechatMsg(uploadInfo)//处理完 推送到微信通知队列
}
......
......@@ -21,6 +21,11 @@ func main() {
boot.Init(configPath, logPath)
//testrabbitmqPush("es_sku_add111","hello")
//service.NewUploadObj("123").Sync()
//service.NewUploadObj("{\"errcode\":0,\"errmsg\":\"ok\",\"goods_id\":1161889823935244337,\"add_sku\":0,\"add_spu\":0,\"spu_id\":2161889823940624400,\"up_sn\":\"u162823515563142400\",\"upload_log_id\":19004}").Sync()
queue.Run()
}
......
......@@ -10,5 +10,5 @@
password = "icDb29mLy2s"
host = [
"192.168.1.235:6379",
"192.168.1.237:6379",
"192.168.1.235:6379",
]
......@@ -16,6 +16,7 @@ require (
github.com/imroc/req v0.3.0
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/spf13/viper v1.7.1
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.8
google.golang.org/protobuf v1.25.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
......
......@@ -315,6 +315,7 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syyongx/php2go v0.9.4 h1:qUtETTHzqHzxZK8plkbkb0YawD8bpLpxNsbzHQmb22Y=
github.com/syyongx/php2go v0.9.4/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw=
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment