Commit e3196c7e by wang

……

parent bde285f0
......@@ -41,6 +41,5 @@ func (this *JdServer) PushData(pushType string ,data interface{}) {
RecordErrLog(msg)
panic(nil)
}
}
......@@ -57,7 +57,7 @@ func (this *Token)getRealToken() string {
jdRequest.RequestTime=requestTime
jdRequest.Sign=this.getSignString(jdRequest)
jdRequest.Scope=""
err:=gout.POST(GetTokenUrl).Debug(true).SetForm(jdRequest).BindJSON(&jdRes).Do()
err:=gout.POST(GetTokenUrl).Debug(false).SetForm(jdRequest).BindJSON(&jdRes).Do()
if(err!=nil){
panic(err.Error())
}
......@@ -79,7 +79,7 @@ func (this *Token) setTokenCache(tokenMapData map[string]interface{}) {
redisWriteConn := gredis.Conn("search_w")
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)
if(err!=nil){
RecordErrLog("设置缓存token,json.Marshal 报错,err:"+err.Error())
......
......@@ -26,10 +26,16 @@ var skuService=NewSkuService()
func (this *SkuPushService)PushJd() {
actTime,endTime=GetDateTime()//固定住当天的开始时间和结束时间
start:=time.Now()
classId:=0
classRsp:=this.getClassList(classId)
defer func() {
end:=time.Now()
duration=end.Sub(start).String()
this.dingdingSucessPush()
}()
//[遍历分类]
for _,classInfo:=range classRsp{//遍历一级分类
......@@ -43,17 +49,18 @@ func (this *SkuPushService)PushJd() {
}
}
}
end:=time.Now()
duration=end.Sub(start).String()
this.dingdingSucessPush()
}
//push ClassID 包含的sku给京东
func (this *SkuPushService) pushForClass(classId int) {
if(classId!=0){
skuNum:=int64(0)
page:=1
for {
qskuReq:=&model.QuerySkuCreq{ClassId:classId,Page:page}
skuRsp,err:=skuService.GetSkuListByClass(qskuReq)
this.CheckError(err,"[GetSkuListByClass 错误];classID:"+string(classId))
......@@ -75,19 +82,28 @@ func (this *SkuPushService) pushForClass(classId int) {
break
}
//end
bytes,err:=json.Marshal(newSkuInfo)
this.CheckError(err,"[json.Marshal skudata 出错]")
JD.NewJdServer().PushData("sku",string(bytes))
skuNum+=int64(len(newSkuInfo))
classTotalCount++
page++
this.shutdown3000()//推送3000关闭
}
skuTotalCont+=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) {
rsp,err:=dao.GetClassList(parent_id)
......@@ -124,10 +140,13 @@ func (this *SkuPushService) CheckError(err error,pre ...string) {
}
//钉钉发送成功
func (this *SkuPushService) dingdingSucessPush() {
atm := time.Unix(actTime, 0)
etm:=time.Unix(endTime,0)
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)
msgt:=fmt.Sprintf("处理时长%s",duration)
msg:=msgTtile+msgS+msgt
msg:=msgTtile+msgT+msgS+msgt
res,err:=message.DingDingPush(msg)
if(err!=nil){
JD.RecordErrLog("发送钉钉错误:"+string(res.Errcode)+"msg:"+res.Errmsg)
......@@ -138,8 +157,8 @@ func (this *SkuPushService) dingdingSucessPush() {
//获取当天0点和23点59分的时间戳
func GetDateTime() (int64,int64){
//date := time.Now().Format("2006-01-02")
date:="2020-11-16"
date := time.Now().Format("2006-01-02")
//date:="2020-11-16"
//获取当前时区
loc, _ := time.LoadLocation("Asia/Shanghai")
......
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