package services import ( "encoding/json" "errors" "fmt" "hongze/hongze_clpt/models" "hongze/hongze_clpt/utils" "strconv" "strings" "time" ) // 根据行业处理所选的全部赛道字段 func DoXzsChooseSend(chartPermissionName string) string { var allIn string if chartPermissionName == utils.YI_YAO_NAME { allIn = "all_in_yi_yao" } else if chartPermissionName == utils.XIAO_FEI_NAME { allIn = "all_in_xiao_fei" } else if chartPermissionName == utils.KE_JI_NAME { allIn = "all_in_ke_ji" } else if chartPermissionName == utils.ZHI_ZAO_NAME { allIn = "all_in_zhi_zao" } else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN { allIn = "all_in_yan_xuan" } return allIn } // 行业关注或者取消关注的时候,对于用户全部赛道的影响 func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2) go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers) } }() detail, err := models.GetIndustrialManagementDetail(industrialManagementId) if err != nil { return err } categoryinfo, err := models.GetChartPermissionById(detail.ChartPermissionId) if err != nil { return err } var allIn string allIn = DoXzsChooseSend(categoryinfo.PermissionName) if allIn != "" { //如果取消关注就把该赛道设置为非全部赛道 if count == 1 { err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 0, uid) if err != nil { return err } } else { //医药、消费、科技、智造、研选下的产业赛道 mapIndustrial := make(map[int][]*models.IndustrialManagementRep) industrialList, err := models.GetindustrialManagement() if err != nil { return err } for _, v := range industrialList { mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v) } fllowNum, err := models.GetCountCygxIndustryFllowByUidAndChartPermissionId(uid, detail.ChartPermissionId) if err != nil { return err } if fllowNum == len(mapIndustrial[detail.ChartPermissionId]) { err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 1, uid) if err != nil { return err } } } } return err } // HandleIndustryList预处理产业列表字段 func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUserItem, resource string) (items []*models.IndustrialManagement, err error) { userId := user.UserId fllowList, err := models.GetUserFllowIndustrialList(userId) if err != nil { return } fllowMap := make(map[int]int) fllowTypeMap := make(map[int]int) if len(fllowList) > 0 { for _, v := range fllowList { fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId fllowTypeMap[v.IndustrialManagementId] = v.FollowType } } hotMap, e := IndustrialManagementHotMapGropuPermission() if e != nil { err = errors.New("获取hot标签失败,IndustrialManagementHotMapGropuPermission " + e.Error()) return } var condition string var pars []interface{} articleTypeIds, _ := GetYanXuanArticleTypeIds() //给默认值 if resource != "Yx" { resource = "Hz" } if articleTypeIds != "" { if resource == "Yx" { condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) ` } else { condition = ` AND a.article_type_id NOT IN (` + articleTypeIds + `) ` } } mapindustrialId, e := GetMicroRoadshowVideoMap() if e != nil { err = e return } //合并产业关联的标的 listSubjcet, err := models.GetThemeHeatSubjectList("") if err != nil { return } industrialIdArr := make([]int, 0) for k, v := range list { list[k].Source = 1 if fllowMap[v.IndustrialManagementId] > 0 { list[k].IsFollow = true } v.IsHot = hotMap[v.IndustrialManagementId] industrialIdArr = append(industrialIdArr, v.IndustrialManagementId) v.FollowType = fllowTypeMap[v.IndustrialManagementId] if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok { continue } videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId) if e != nil { err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error()) return } if videoSimple != nil && videoSimple.Id > 0 { v.IndustryVideo = videoSimple } v.AuthInfo = au } if len(industrialIdArr) > 0 { //合并产业关联的标的 conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)` pars = append(pars, industrialIdArr) listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject) if err != nil { return } mapIndustrial := make(map[string]int) for _, v := range listSubjcet { for k2, v2 := range list { if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 { list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v) mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId } } } } //获取产业关联的的文章用户是否阅读 mapIndustrialArticleHistory, err := GetUserArticleHistoryIndustrialNewPublishDate(user, industrialIdArr, articleTypeIds, resource) if err != nil { err = errors.New("获取产业关联的的文章用户是否阅读失败 " + err.Error()) return } mapUPdateTime := make(map[int]string) articleIdArr := make([]int, 0) //获取这些产业下最新更新的文章 var conditionindustrial string var parsindustrial []interface{} var industrialIds string if len(industrialIdArr) > 0 { conditionindustrial = condition + ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)` parsindustrial = append(parsindustrial, industrialIdArr) listUpdateTime, e := models.GetNewArticleDetailByIndustrialIds(parsindustrial, conditionindustrial) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetNewArticleDetailByIndustrialIds Err " + e.Error()) return } for _, v := range listUpdateTime { mapUPdateTime[v.IndustrialManagementId] = v.PublishDate articleIdArr = append(articleIdArr, v.ArticleId) } //时间线的更新时间 // maptimelineUPdateTime := make(map[int]string) listtimelinePublishdate, e := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } for _, v := range listtimelinePublishdate { if mapUPdateTime[v.IndustrialManagementId] != "" { if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) { mapUPdateTime[v.IndustrialManagementId] = v.PublishDate } } } //产品内测的更新时间线 listtProductInterior, e := models.GetNewProductInteriorByIndustrialIds(industrialIdArr) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } for _, v := range listtProductInterior { if mapUPdateTime[v.IndustrialManagementId] != "" { if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) { mapUPdateTime[v.IndustrialManagementId] = v.PublishDate } } } for _, id := range industrialIdArr { industrialIds += strconv.Itoa(id) + "," } industrialIds = strings.TrimRight(industrialIds, ",") articleList, e := models.GetReportIndustrialReadNumList(userId, industrialIds, user.CreatedTime) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } mapHistroyindustrialId := make(map[int]int) for _, v := range articleList { mapHistroyindustrialId[v.IndustrialManagementId] = v.Readnum } } nowTime := time.Now().Local() threeMonBefore := nowTime.AddDate(0, -3, 0) //查询用户今天是否看过时间线 //haveMorningMeeting := false //var morningMeetingTime string recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr) if err != nil && err.Error() != utils.ErrNoRow() { return } var industrialManagementIdstr string industrialIdMap := make(map[string]time.Time) for _, v := range recrodList { //fmt.Println(v.Router) //sliceindustrial := strings.Split(v.Router, "=") //industrialManagementIdstr = strings.TrimLeft(v.Router, utils.TIME_LINE_ROUTE) industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId) industrialIdMap[industrialManagementIdstr] = v.ModifyTime //fmt.Println(industrialManagementIdstr) //if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok { // if createTime.Before(v.CreateTime) { // industrialIdMap[industrialManagementIdstr] = v.CreateTime // } //} else { // industrialIdMap[industrialManagementIdstr] = v.CreateTime //} } morningMeetingTimeMap := make(map[int]time.Time) if industrialIds != "" { mmList, e := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds) if e != nil { err = e return } for _, v := range mmList { morningMeetingTimeMap[v.IndustryId] = v.CreateTime } } timeLineRedMap := make(map[int]bool, 0) for _, industrialId := range industrialIdArr { //if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok { // if createTime.Before(morningMeetingTimeMap[industrialId]) { // timeLineRedMap[industrialId] = true // } //} if industrialIdMap[strconv.Itoa(industrialId)].Before(morningMeetingTimeMap[industrialId]) { timeLineRedMap[industrialId] = true } } //fmt.Println(industrialIdMap["90"]) //fmt.Println(timeLineRedMap[90]) //fmt.Println(mapIndustrialArticleHistory[90]) for k, v := range list { list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId]) if userId > 0 { //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理 if mapIndustrialArticleHistory[v.IndustrialManagementId] || timeLineRedMap[v.IndustrialManagementId] { //if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] { if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) { list[k].IsRed = true } } } else { if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) { list[k].IsRed = true } list[k].IsFollow = true } list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId]) if resource == "Yx" { list[k].IsRed = false } // 关联报告发布时间均在3个月内则标记New if v.MinReportTime != "" { t, e := time.Parse(utils.FormatDateTime, v.MinReportTime) if e != nil { err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error()) return } if t.After(threeMonBefore) { list[k].IsNew = true } } if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { v.Source = 2 } else { v.Source = 1 } if v.TimeLineData == "" { v.ListTimeLine = make([]models.TimeLineReportResp, 0) } else { if err = json.Unmarshal([]byte(v.TimeLineData), &v.ListTimeLine); err != nil { e = errors.New("Unmarshal, Err: " + e.Error()) return } } } items = list return } func HandleIndustryListHzAndYx(list []*models.IndustrialManagement, user *models.WxUserItem, resource string) (items []*models.IndustrialManagement, err error) { var listHz []*models.IndustrialManagement var lisYx []*models.IndustrialManagement for _, v := range list { if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { lisYx = append(lisYx, v) } else { listHz = append(listHz, v) } } listHz, err = HandleIndustryList(listHz, user, "Hz") if err != nil { return } lisYx, err = HandleIndustryList(lisYx, user, "Yx") if err != nil { return } maplistHz := make(map[int]*models.IndustrialManagement) maplistYx := make(map[int]*models.IndustrialManagement) for _, v := range listHz { maplistHz[v.IndustrialManagementId] = v } for _, v := range lisYx { maplistYx[v.IndustrialManagementId] = v } for _, v := range list { if maplistHz[v.IndustrialManagementId] != nil { items = append(items, maplistHz[v.IndustrialManagementId]) } if maplistYx[v.IndustrialManagementId] != nil { items = append(items, maplistYx[v.IndustrialManagementId]) } } return } // 通过文章ID获取文章所关联的产业 func GetArticleIndustrialByArticleId(articleIds []int) (itemMap map[int][]*models.IndustrialManagementResp, err error) { lenarticleIds := len(articleIds) if lenarticleIds == 0 { return } var condition string var pars []interface{} condition = ` AND mg.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)` pars = append(pars, articleIds) industrialList, err := models.GetIndustrialListByarticleId(pars, condition) if err != nil { return } industrialMap := make(map[int][]*models.IndustrialManagementResp) if len(industrialList) > 0 { for _, v := range industrialList { item := new(models.IndustrialManagementResp) item.IndustrialManagementId = v.IndustrialManagementId item.IndustryName = v.IndustryName item.ChartPermissionId = v.ChartPermissionId industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item) } } itemMap = industrialMap return } // 获取研选文章类型的配置信息 func GetArticleTypeMap() (nameMapResp map[int]string, buttonStyleMapResp map[int]string, err error) { condition := " AND is_show_yanx = 1 " list, e := models.GetCygxArticleTypeListCondition(condition) if e != nil { err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error()) return } nameMap := make(map[int]string) buttonStyleMap := make(map[int]string) if len(list) > 0 { for _, v := range list { nameMap[v.ArticleTypeId] = v.ArticleTypeName buttonStyleMap[v.ArticleTypeId] = v.ButtonStyle } } nameMapResp = nameMap buttonStyleMapResp = buttonStyleMap return } // GetUserFollowIndustrialMap获取用户关注的产业 func GetUserFollowIndustrialMap(user *models.WxUserItem) (mapResp map[int]int, err error) { list, e := models.GetUserFllowIndustrialList(user.UserId) if e != nil { err = errors.New("GetUserFllowIndustrialList " + e.Error()) return } fllowMap := make(map[int]int) if len(list) > 0 { for _, v := range list { fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId } } mapResp = fllowMap return } // IndustrialManagementHotMapGropuPermission获取近一个月报告阅读数量最多的产业信息 根据行业分组 func IndustrialManagementHotMapGropuPermission() (mapResp map[int]bool, err error) { var topCond string var topPars []interface{} toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars) if err != nil { return } mapPermission := make(map[int][]*models.IndustrialManagement) mapPermissionMax := make(map[int]int) for _, v := range toplist { item := new(models.IndustrialManagement) item.ChartPermissionId = v.ChartPermissionId item.IndustrialManagementId = v.IndustrialManagementId item.ArticleReadNum = v.ArticleReadNum mapPermission[v.ChartPermissionId] = append(mapPermission[v.ChartPermissionId], item) } for k, v := range mapPermission { for _, item := range v { //mapPermissionMax[k] = item.ArticleReadNum if item.ArticleReadNum > mapPermissionMax[k] { mapPermissionMax[k] = item.ArticleReadNum } } } mapResp = make(map[int]bool, 0) for _, v := range toplist { if v.ArticleReadNum == mapPermissionMax[v.ChartPermissionId] { mapResp[v.IndustrialManagementId] = true } } return } // GetCygxIndustryFllowListTypeMapByMobile 根据手机号获取产业关注的信息 func GetCygxIndustryFllowListTypeMapByMobile(mobile string) (mapFollowTypeResp map[int]int) { if mobile == "" { return } var err error defer func() { if err != nil { fmt.Println("err:", err) go utils.SendAlarmMsg(fmt.Sprint("根据手机号获取产业关注的信息 失败,GetCygxIndustryFllowListTypeMapByMobile Err:"+err.Error()+"mobile", mobile), 3) } }() mapFollowTypeResp = make(map[int]int, 0) fllowList, e := models.GetCygxIndustryFllowList(mobile) //策略的处理 if e != nil { err = errors.New("GetUserFllowIndustrialList, Err: " + err.Error()) return } for _, v := range fllowList { mapFollowTypeResp[v.IndustrialManagementId] = v.FollowType } return } //func init() { // IndustrialManagementTimeLineDateList3(542) //} // 时间线关联文章的三条数据 func IndustrialManagementTimeLineDateList3(industrialManagementId int) (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2) } }() list, total, e := models.GetTimeLineReportIndustrialListTime(0, industrialManagementId, 0, 3) if e != nil { err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error()) return } fmt.Println(total) type TimeLineReportItem struct { Title string `description:"标题"` PublishDate string `description:"发布时间"` } //type TimeLIineData struct { // ListTimeLine []*TimeLineReportItem //} var listData []*TimeLineReportItem for _, v := range list { item := new(TimeLineReportItem) item.Title = v.Title item.PublishDate = utils.TimeRemoveHms2(v.PublishDate) listData = append(listData, item) } //var listData2 TimeLIineData //listData2.ListTimeLine = listData jsonData, err := json.Marshal(listData) if err != nil { fmt.Println("Error marshaling to JSON:", err) return } e = models.UpdateIndustrialManagementTimeLineData(industrialManagementId, string(jsonData)) fmt.Println(string(jsonData)) fmt.Println(e) return err }