Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wang
/
golang-open-platform
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
e3196c7e
authored
Mar 30, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
……
parent
bde285f0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
JD/service.go
JD/token.go
service/push_Jd/service_sku_push.go
JD/service.go
View file @
e3196c7e
...
@@ -41,6 +41,5 @@ func (this *JdServer) PushData(pushType string ,data interface{}) {
...
@@ -41,6 +41,5 @@ func (this *JdServer) PushData(pushType string ,data interface{}) {
RecordErrLog
(
msg
)
RecordErrLog
(
msg
)
panic
(
nil
)
panic
(
nil
)
}
}
}
}
JD/token.go
View file @
e3196c7e
...
@@ -57,7 +57,7 @@ func (this *Token)getRealToken() string {
...
@@ -57,7 +57,7 @@ func (this *Token)getRealToken() string {
jdRequest
.
RequestTime
=
requestTime
jdRequest
.
RequestTime
=
requestTime
jdRequest
.
Sign
=
this
.
getSignString
(
jdRequest
)
jdRequest
.
Sign
=
this
.
getSignString
(
jdRequest
)
jdRequest
.
Scope
=
""
jdRequest
.
Scope
=
""
err
:=
gout
.
POST
(
GetTokenUrl
)
.
Debug
(
tru
e
)
.
SetForm
(
jdRequest
)
.
BindJSON
(
&
jdRes
)
.
Do
()
err
:=
gout
.
POST
(
GetTokenUrl
)
.
Debug
(
fals
e
)
.
SetForm
(
jdRequest
)
.
BindJSON
(
&
jdRes
)
.
Do
()
if
(
err
!=
nil
){
if
(
err
!=
nil
){
panic
(
err
.
Error
())
panic
(
err
.
Error
())
}
}
...
@@ -79,7 +79,7 @@ func (this *Token) setTokenCache(tokenMapData map[string]interface{}) {
...
@@ -79,7 +79,7 @@ func (this *Token) setTokenCache(tokenMapData map[string]interface{}) {
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
defer
redisWriteConn
.
Close
()
tokenMapData
[
"realExpires"
]
=
gconv
.
Int64
(
tokenMapData
[
"expiresIn"
])
+
gconv
.
Int64
(
tokenMapData
[
"time"
])
*
1000
//毫秒
tokenMapData
[
"realExpires"
]
=
gconv
.
Int64
(
tokenMapData
[
"expiresIn"
])
*
1000
+
gconv
.
Int64
(
tokenMapData
[
"time"
])
//毫秒
bytes
,
err
:=
json
.
Marshal
(
tokenMapData
)
bytes
,
err
:=
json
.
Marshal
(
tokenMapData
)
if
(
err
!=
nil
){
if
(
err
!=
nil
){
RecordErrLog
(
"设置缓存token,json.Marshal 报错,err:"
+
err
.
Error
())
RecordErrLog
(
"设置缓存token,json.Marshal 报错,err:"
+
err
.
Error
())
...
...
service/push_Jd/service_sku_push.go
View file @
e3196c7e
...
@@ -26,10 +26,16 @@ var skuService=NewSkuService()
...
@@ -26,10 +26,16 @@ var skuService=NewSkuService()
func
(
this
*
SkuPushService
)
PushJd
()
{
func
(
this
*
SkuPushService
)
PushJd
()
{
actTime
,
endTime
=
GetDateTime
()
//固定住当天的开始时间和结束时间
actTime
,
endTime
=
GetDateTime
()
//固定住当天的开始时间和结束时间
start
:=
time
.
Now
()
start
:=
time
.
Now
()
classId
:=
0
classId
:=
0
classRsp
:=
this
.
getClassList
(
classId
)
classRsp
:=
this
.
getClassList
(
classId
)
defer
func
()
{
end
:=
time
.
Now
()
duration
=
end
.
Sub
(
start
)
.
String
()
this
.
dingdingSucessPush
()
}()
//[遍历分类]
//[遍历分类]
for
_
,
classInfo
:=
range
classRsp
{
//遍历一级分类
for
_
,
classInfo
:=
range
classRsp
{
//遍历一级分类
...
@@ -43,17 +49,18 @@ func (this *SkuPushService)PushJd() {
...
@@ -43,17 +49,18 @@ func (this *SkuPushService)PushJd() {
}
}
}
}
}
}
end
:=
time
.
Now
()
duration
=
end
.
Sub
(
start
)
.
String
()
this
.
dingdingSucessPush
()
}
}
//push ClassID 包含的sku给京东
//push ClassID 包含的sku给京东
func
(
this
*
SkuPushService
)
pushForClass
(
classId
int
)
{
func
(
this
*
SkuPushService
)
pushForClass
(
classId
int
)
{
if
(
classId
!=
0
){
if
(
classId
!=
0
){
skuNum
:=
int64
(
0
)
skuNum
:=
int64
(
0
)
page
:=
1
page
:=
1
for
{
for
{
qskuReq
:=&
model
.
QuerySkuCreq
{
ClassId
:
classId
,
Page
:
page
}
qskuReq
:=&
model
.
QuerySkuCreq
{
ClassId
:
classId
,
Page
:
page
}
skuRsp
,
err
:=
skuService
.
GetSkuListByClass
(
qskuReq
)
skuRsp
,
err
:=
skuService
.
GetSkuListByClass
(
qskuReq
)
this
.
CheckError
(
err
,
"[GetSkuListByClass 错误];classID:"
+
string
(
classId
))
this
.
CheckError
(
err
,
"[GetSkuListByClass 错误];classID:"
+
string
(
classId
))
...
@@ -75,19 +82,28 @@ func (this *SkuPushService) pushForClass(classId int) {
...
@@ -75,19 +82,28 @@ func (this *SkuPushService) pushForClass(classId int) {
break
break
}
}
//end
//end
bytes
,
err
:=
json
.
Marshal
(
newSkuInfo
)
bytes
,
err
:=
json
.
Marshal
(
newSkuInfo
)
this
.
CheckError
(
err
,
"[json.Marshal skudata 出错]"
)
this
.
CheckError
(
err
,
"[json.Marshal skudata 出错]"
)
JD
.
NewJdServer
()
.
PushData
(
"sku"
,
string
(
bytes
))
JD
.
NewJdServer
()
.
PushData
(
"sku"
,
string
(
bytes
))
skuNum
+=
int64
(
len
(
newSkuInfo
))
skuNum
+=
int64
(
len
(
newSkuInfo
))
classTotalCount
++
classTotalCount
++
page
++
page
++
this
.
shutdown3000
()
//推送3000关闭
}
}
skuTotalCont
+=
skuNum
skuTotalCont
+=
skuNum
common
.
PrintStdout
()
.
Printf
(
"classID:%d,推送 sku:%d 条"
,
classId
,
skuNum
)
common
.
PrintStdout
()
.
Printf
(
"classID:%d,推送 sku:%d 条"
,
classId
,
skuNum
)
}
}
}
}
func
(
this
*
SkuPushService
)
shutdown3000
()
{
if
(
skuTotalCont
>=
3000
){
//this.dingdingSucessPush()
msg
:=
fmt
.
Sprintf
(
"%d个就终止程序"
,
skuTotalCont
)
panic
(
msg
)
}
}
//获取分类列表
//获取分类列表
func
(
this
*
SkuPushService
)
getClassList
(
parent_id
int
)
(
QueryClassRspS
[]
model
.
QueryClassRsp
)
{
func
(
this
*
SkuPushService
)
getClassList
(
parent_id
int
)
(
QueryClassRspS
[]
model
.
QueryClassRsp
)
{
rsp
,
err
:=
dao
.
GetClassList
(
parent_id
)
rsp
,
err
:=
dao
.
GetClassList
(
parent_id
)
...
@@ -124,10 +140,13 @@ func (this *SkuPushService) CheckError(err error,pre ...string) {
...
@@ -124,10 +140,13 @@ func (this *SkuPushService) CheckError(err error,pre ...string) {
}
}
//钉钉发送成功
//钉钉发送成功
func
(
this
*
SkuPushService
)
dingdingSucessPush
()
{
func
(
this
*
SkuPushService
)
dingdingSucessPush
()
{
atm
:=
time
.
Unix
(
actTime
,
0
)
etm
:=
time
.
Unix
(
endTime
,
0
)
msgTtile
:=
"[京东推送]自动推送sku数据
\n
"
msgTtile
:=
"[京东推送]自动推送sku数据
\n
"
msgT
:=
fmt
.
Sprintf
(
"时间段:%s-%s
\n
"
,
atm
.
Format
(
"2006-01-02 15:04:05"
),
etm
.
Format
(
"2006-01-02 15:04:05"
))
msgS
:=
fmt
.
Sprintf
(
"总共推送class:%d个,sku:%d 条成功
\n
"
,
classTotalCount
,
skuTotalCont
)
msgS
:=
fmt
.
Sprintf
(
"总共推送class:%d个,sku:%d 条成功
\n
"
,
classTotalCount
,
skuTotalCont
)
msgt
:=
fmt
.
Sprintf
(
"处理时长%s"
,
duration
)
msgt
:=
fmt
.
Sprintf
(
"处理时长%s"
,
duration
)
msg
:=
msgTtile
+
msgS
+
msgt
msg
:=
msgTtile
+
msg
T
+
msg
S
+
msgt
res
,
err
:=
message
.
DingDingPush
(
msg
)
res
,
err
:=
message
.
DingDingPush
(
msg
)
if
(
err
!=
nil
){
if
(
err
!=
nil
){
JD
.
RecordErrLog
(
"发送钉钉错误:"
+
string
(
res
.
Errcode
)
+
"msg:"
+
res
.
Errmsg
)
JD
.
RecordErrLog
(
"发送钉钉错误:"
+
string
(
res
.
Errcode
)
+
"msg:"
+
res
.
Errmsg
)
...
@@ -138,8 +157,8 @@ func (this *SkuPushService) dingdingSucessPush() {
...
@@ -138,8 +157,8 @@ func (this *SkuPushService) dingdingSucessPush() {
//获取当天0点和23点59分的时间戳
//获取当天0点和23点59分的时间戳
func
GetDateTime
()
(
int64
,
int64
){
func
GetDateTime
()
(
int64
,
int64
){
//
date := time.Now().Format("2006-01-02")
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
date
:=
"2020-11-16"
//
date:="2020-11-16"
//获取当前时区
//获取当前时区
loc
,
_
:=
time
.
LoadLocation
(
"Asia/Shanghai"
)
loc
,
_
:=
time
.
LoadLocation
(
"Asia/Shanghai"
)
...
...
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