|
@@ -1,7 +1,11 @@
|
|
|
package services
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
+ "hongze/hongze_api/cache"
|
|
|
+ "hongze/hongze_api/models"
|
|
|
+ "hongze/hongze_api/utils"
|
|
|
)
|
|
|
|
|
|
func Task() {
|
|
@@ -10,28 +14,30 @@ func Task() {
|
|
|
//FixUnionId()
|
|
|
fmt.Println("end")
|
|
|
|
|
|
- //go AutoUpdateUserView()
|
|
|
+ go AutoUpdateUserView()
|
|
|
}
|
|
|
|
|
|
// AutoUpdateUserView 自动添加阅读记录
|
|
|
-//func AutoUpdateUserView() {
|
|
|
-// defer func() {
|
|
|
-// if err := recover(); err != nil {
|
|
|
-// fmt.Println("[AutoUpdateUserView]", err)
|
|
|
-// }
|
|
|
-// }()
|
|
|
-// for {
|
|
|
-// utils.Rc.Brpop(utils.CACHE_KEY_USER_VIEW, func(b []byte) {
|
|
|
-// fmt.Println(string(b))
|
|
|
-// var userViewRedisData cache.UserViewRedisData
|
|
|
-// if err := json.Unmarshal(b, &userViewRedisData); err != nil {
|
|
|
-// fmt.Println("json unmarshal wrong!")
|
|
|
-// //}
|
|
|
-// //if _, err := models.AddLogs(&log); err != nil {
|
|
|
-// // fmt.Println("AddLogs:", err.Error(), log)
|
|
|
-// } else {
|
|
|
-// models.UpdateCompanyProductViewData(userViewRedisData.CompanyId, userViewRedisData.ProductId, userViewRedisData.ViewTime)
|
|
|
-// }
|
|
|
-// })
|
|
|
-// }
|
|
|
-//}
|
|
|
+func AutoUpdateUserView() {
|
|
|
+ defer func() {
|
|
|
+ if err := recover(); err != nil {
|
|
|
+ fmt.Println("[AutoUpdateUserView]", err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ for {
|
|
|
+ utils.Rc.Brpop(utils.CACHE_KEY_USER_VIEW, func(b []byte) {
|
|
|
+ var userViewRedisData cache.UserViewRedisData
|
|
|
+ if err := json.Unmarshal(b, &userViewRedisData); err != nil {
|
|
|
+ go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", fmt.Sprint("AutoUpdateUserView ERR:", err, ";response data:", string(b)), utils.EmailSendToUsers)
|
|
|
+ //}
|
|
|
+ //if _, err := models.AddLogs(&log); err != nil {
|
|
|
+ // fmt.Println("AddLogs:", err.Error(), log)
|
|
|
+ } else {
|
|
|
+ err = models.UpdateCompanyProductViewData(userViewRedisData.CompanyId, userViewRedisData.ProductId, userViewRedisData.ViewTime)
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", fmt.Sprint("AutoUpdateUserView Update CompanyProduct ERR:", err, ";response data:", string(b)), utils.EmailSendToUsers)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|