|
@@ -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() {
|
|
|
|
|
|
fmt.Println("end")
|
|
|
|
|
|
-
|
|
|
+ go 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) {
|
|
|
+ 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)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|