package services import ( "encoding/json" "fmt" "hongze/hongze_api/cache" "hongze/hongze_api/models" "hongze/hongze_api/services/alarm_msg" "hongze/hongze_api/services/go_redis" "hongze/hongze_api/utils" "time" ) func Task() { fmt.Println("start") //InitSetUnionId() //FixUnionId() fmt.Println("end") go AutoUpdateUserView() } // AutoUpdateUserView 自动添加阅读记录 func AutoUpdateUserView() { defer func() { if err := recover(); err != nil { fmt.Println("[AutoUpdateUserView]", err) } }() for { go_redis.BRPop2Func(utils.CACHE_KEY_USER_VIEW, func(b []byte) { var userViewRedisData cache.UserViewRedisData if err := json.Unmarshal(b, &userViewRedisData); err != nil { //fmt.Println(utils.APPNAME + " " + utils.RunMode + " 失败提醒:" + fmt.Sprint("AutoUpdateUserView ERR:", err, ";response data:", string(b))) go alarm_msg.SendAlarmMsg(utils.APPNAME+" "+utils.RunMode+" 失败提醒:"+fmt.Sprint("AutoUpdateUserView ERR:", err, ";response data:", string(b)), 2) //} //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 { //fmt.Println(utils.APPNAME + " " + utils.RunMode + " 失败提醒:" + fmt.Sprint("AutoUpdateUserView Update UpdateCompanyProductViewData ERR:", err, ";response data:", string(b))) go alarm_msg.SendAlarmMsg(utils.APPNAME+" "+utils.RunMode+" 失败提醒:"+fmt.Sprint("AutoUpdateUserView Update UpdateCompanyProductViewData ERR:", err, ";response data:", string(b)), 2) } // 添加报告阅读汇总记录 { source := userViewRedisData.Source if source == 0 { if userViewRedisData.ProductId == 2 { source = 4 } else { source = 1 } } item := &models.UserReportViewRecord{ Id: 1, Source: source, UserId: userViewRedisData.UserId, ReportId: userViewRedisData.ReportId, ReportChapterId: userViewRedisData.ReportChapterId, Mobile: userViewRedisData.Mobile, Email: userViewRedisData.Email, RealName: userViewRedisData.RealName, CompanyName: userViewRedisData.CompanyName, StopTime: userViewRedisData.StopTime, OutId: fmt.Sprint(userViewRedisData.OutId), CreateTime: userViewRedisData.ViewTime, } viewTime, tmpErr := time.ParseInLocation(utils.FormatDateTime, userViewRedisData.ViewTime, time.Local) if tmpErr != nil { //fmt.Println(utils.APPNAME+" "+utils.RunMode+" 失败提醒", fmt.Sprint("AutoUpdateUserView ADD UserReportViewRecord ERR:", tmpErr, ";response data:", string(b))) go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", fmt.Sprint("AutoUpdateUserView ADD UserReportViewRecord ERR:", tmpErr, ";response data:", string(b)), utils.EmailSendToUsers) } else { err = item.Insert(viewTime.Year(), item) if err != nil { //fmt.Println(utils.APPNAME+" "+utils.RunMode+" 失败提醒", fmt.Sprint("AutoUpdateUserView ADD UserReportViewRecord ERR:", err, ";response data:", string(b))) go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", fmt.Sprint("AutoUpdateUserView ADD UserReportViewRecord ERR:", err, ";response data:", string(b)), utils.EmailSendToUsers) } } } // 联系人的阅读时间 err = models.UpdateWxUserViewData(userViewRedisData.UserId, userViewRedisData.ProductId, userViewRedisData.ViewTime) if err != nil { //fmt.Println(utils.APPNAME + " " + utils.RunMode + " 失败提醒:" + fmt.Sprint("AutoUpdateUserView Update UpdateWxUserViewData ERR:", err, ";response data:", string(b))) go alarm_msg.SendAlarmMsg(utils.APPNAME+" "+utils.RunMode+" 失败提醒:"+fmt.Sprint("AutoUpdateUserView Update UpdateWxUserViewData ERR:", err, ";response data:", string(b)), 2) } } }) } }