package services import ( "errors" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/utils" "time" ) // GetIndustryNewLabelMap 获取产业【新】标签Map func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) { labelMap = make(map[int]bool, 0) industryIdLen := len(industryIds) if industryIdLen == 0 { return } // 获取产业关联的报告最早发布时间及最近的发布时间 var timeCond string var timePars []interface{} timeCond += ` AND b.publish_status = 1` if industryIdLen > 0 { timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)` timePars = append(timePars, industryIds) } //只要弘则报告,不要研选报告 timeCond += ` AND b.article_id < ? ` timePars = append(timePars, utils.SummaryArticleId) industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars) if e != nil { err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error()) return } // 判断产业是否为新 nowTime := time.Now().Local() threeMonthBefore := nowTime.AddDate(0, -3, 0) nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local) industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0) for i := range industryTimeList { industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i] } for i := range industryIds { iid := industryIds[i] item := industryMap[iid] if item != nil { // 最早发布时间为空 / 最早发布时间在三个月前之后 if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) { labelMap[iid] = true } } else { // 产业无报告, 则为新产业 labelMap[iid] = true } } 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 } // GetLyjhTypeMap 获取路演精华对应分类ID func GetLyjhTypeMap() (mapResp map[int]int, err error) { defer func() { if err != nil { go utils.SendAlarmMsg("获取路演精华对应分类ID失败 ErrMsg:"+err.Error(), 2) } }() condition := " AND match_type_name = '路演精华' " var pars []interface{} list, e := models.GetReportMappingList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error()) return } mapResp = make(map[int]int, 0) if len(list) > 0 { for _, v := range list { mapResp[v.CategoryId] = v.CategoryId } } return } // GetLyjhArticleMap 获取路演精华对应文章ID func GetLyjhArticleMap() (mapResp map[int]bool, err error) { defer func() { if err != nil { go utils.SendAlarmMsg("获取路演精华对应文章ID失败 ErrMsg:"+err.Error(), 2) } }() condition := " AND match_type_name = '路演精华' " var pars []interface{} list, e := models.GetReportMappingList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error()) return } var categoryId []int mapResp = make(map[int]bool, 0) if len(list) > 0 { for _, v := range list { categoryId = append(categoryId, v.CategoryId) } } lencategoryId := len(categoryId) if lencategoryId > 0 { pars = make([]interface{}, 0) condition = ` AND a.category_id IN (` + utils.GetOrmInReplace(lencategoryId) + `)` pars = append(pars, categoryId) listArticle, e := models.GetHomeList(condition, pars, 0, 1000) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } for _, v := range listArticle { mapResp[v.ArticleId] = true } } return } // 行业关注或者取消关注的时候,对于用户全部赛道的影响 func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) { defer func() { if err != nil { 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 } // 根据行业处理所选的全部赛道字段 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 }