Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wang
/
go_upload_sync
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dd43878b
authored
Aug 07, 2021
by
hcy001
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
标签
parent
9e07844a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
11 deletions
.gitignore
app/common/function/public.go
app/service/upload_sku_sync.go
cmd/main.go
config/dev/redis.toml
go.mod
go.sum
.gitignore
View file @
dd43878b
/.idea
/.idea
/=
/=
/logs
app/common/function/public.go
0 → 100644
View file @
dd43878b
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
app/service/upload_sku_sync.go
View file @
dd43878b
...
@@ -3,10 +3,12 @@ package service
...
@@ -3,10 +3,12 @@ package service
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/go-redis/redis/v7"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gconv"
"github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
common
"go_upload_sync/app/common/function"
"go_upload_sync/app/dao"
"go_upload_sync/app/dao"
ls
"go_upload_sync/util/lib"
ls
"go_upload_sync/util/lib"
"time"
"time"
...
@@ -53,15 +55,8 @@ func NewUploadObj(SkuReStr string) *UploadSkuSync {
...
@@ -53,15 +55,8 @@ func NewUploadObj(SkuReStr string) *UploadSkuSync {
/**
/**
@res string 接收 poolsku返回的结果
@res string 接收 poolsku返回的结果
@res 格式如下
@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
@return error
*/
*/
func
(
this
*
UploadSkuSync
)
Sync
()
error
{
func
(
this
*
UploadSkuSync
)
Sync
()
error
{
...
@@ -79,13 +74,13 @@ func (this *UploadSkuSync)Sync() error{
...
@@ -79,13 +74,13 @@ func (this *UploadSkuSync)Sync() error{
}
}
`
`
this.SkuReStr=Str*/
this.SkuReStr=Str*/
fmt
.
Println
(
this
.
SkuReStr
)
//打印初始数据
r
:=
gjson
.
Parse
(
this
.
SkuReStr
)
r
:=
gjson
.
Parse
(
this
.
SkuReStr
)
if
(
r
.
Exists
()
&&
r
.
IsObject
()){
if
(
r
.
Exists
()
&&
r
.
IsObject
()){
this
.
SkuRes
=
parseRes
(
r
)
this
.
SkuRes
=
parseRes
(
r
)
this
.
handle
()
this
.
handle
()
}
else
{
}
else
{
fmt
.
Println
(
"格式出错"
);
this
.
dingdingSucessPush
(
"格式出错"
);
this
.
dingdingSucessPush
(
"格式出错"
);
return
nil
return
nil
}
}
...
@@ -132,6 +127,42 @@ func (this *UploadSkuSync) handle() {
...
@@ -132,6 +127,42 @@ func (this *UploadSkuSync) handle() {
this
.
dingdingSucessPush
(
msg
);
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
()
isSucess
,
err
:=
this
.
IshandleSucess
()
if
(
err
!=
nil
){
if
(
err
!=
nil
){
...
@@ -153,6 +184,7 @@ func (this *UploadSkuSync) handle() {
...
@@ -153,6 +184,7 @@ func (this *UploadSkuSync) handle() {
this
.
dingdingSucessPush
(
msg
);
this
.
dingdingSucessPush
(
msg
);
return
return
}
}
this
.
PushStatus3HandleList
(
uploadInfo
)
//处理完推送下架队列
this
.
PushStatus3HandleList
(
uploadInfo
)
//处理完推送下架队列
this
.
PushWechatMsg
(
uploadInfo
)
//处理完 推送到微信通知队列
this
.
PushWechatMsg
(
uploadInfo
)
//处理完 推送到微信通知队列
}
}
...
...
cmd/main.go
View file @
dd43878b
...
@@ -21,6 +21,11 @@ func main() {
...
@@ -21,6 +21,11 @@ func main() {
boot
.
Init
(
configPath
,
logPath
)
boot
.
Init
(
configPath
,
logPath
)
//testrabbitmqPush("es_sku_add111","hello")
//testrabbitmqPush("es_sku_add111","hello")
//service.NewUploadObj("123").Sync()
//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
()
queue
.
Run
()
}
}
...
...
config/dev/redis.toml
View file @
dd43878b
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
password
=
"icDb29mLy2s"
password
=
"icDb29mLy2s"
host
=
[
host
=
[
"192.168.1.235:6379"
,
"192.168.1.235:6379"
,
"192.168.1.23
7
:6379"
,
"192.168.1.23
5
:6379"
,
]
]
go.mod
View file @
dd43878b
...
@@ -16,6 +16,7 @@ require (
...
@@ -16,6 +16,7 @@ require (
github.com/imroc/req v0.3.0
github.com/imroc/req v0.3.0
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/spf13/viper v1.7.1
github.com/spf13/viper v1.7.1
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.8
github.com/tidwall/gjson v1.6.8
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
...
...
go.sum
View file @
dd43878b
...
@@ -315,6 +315,7 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
...
@@ -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/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 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
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/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 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment