123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- package services
- import (
- "context"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "strings"
- "time"
- )
- //修改标签状态
- func UpdateIndustrialManagementLabel(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("修改失败,Err:", err.Error())
- }
- }()
- fmt.Println("修改状态0000")
- go models.UpdateIndustrialIsNewLabel()
- list, err := models.GetIndustrialMorethan10()
- if err != nil {
- return err
- }
- if len(list) == 0 {
- return
- }
- var idStr string
- for _, v := range list {
- idStr += v.IndustrialManagementId + ","
- }
- idStr = strings.TrimRight(idStr, ",")
- go models.UpdateIndustrialIsDeepLabel(idStr)
- //fmt.Println(idStr)
- //go models.UpdateActivitySattusToComplete()
- fmt.Println("修改状态完成")
- return
- }
- //修改活动状态
- func UpdateIndustrialManagementSubjectNnames() (err error) {
- defer func() {
- if err != nil {
- fmt.Println("修改失败,Err:", err.Error())
- }
- }()
- fmt.Println("修改产业关联标的")
- list, err := models.GetIndustrialManagementIds()
- if err != nil {
- return err
- }
- for _, v := range list {
- //fmt.Println(v.IndustrialManagementId)
- var nameSub string
- listSub, errdSub := models.GetcygxIndustrialSubject(v.IndustrialManagementId)
- if errdSub != nil {
- return errdSub
- }
- for _, v2 := range listSub {
- fmt.Println(v2.SubjectName)
- nameSub += v2.SubjectName + ","
- }
- nameSub += v.IndustryName
- go models.UpdateIndustrialManagementSubjectNames(nameSub, v.IndustrialManagementId)
- }
- if len(list) == 0 {
- return
- }
- fmt.Println("修改状态完成")
- return
- }
- func ChageIndustrialArticleNum(cont context.Context) (err error) {
- allList, err := models.IndustrialManagementAll()
- if err != nil {
- fmt.Println("GetArticleAll Err:", err.Error())
- return
- }
- for _, v := range allList {
- total, errTop := models.GetIndustrialManagementArtCount(v.IndustrialManagementId)
- if errTop != nil {
- fmt.Println("Top Err:", errTop.Error())
- return
- }
- if total > 0 {
- err = models.UpdateIndustrialManagementArtReadNum(total, v.IndustrialManagementId)
- if err != nil {
- fmt.Println("Update Err:", err.Error())
- return
- }
- }
- }
- return
- }
- func ReportBillboardUpdate(cont context.Context) (err error) {
- //修改产业关注数量
- go IndustryFllowCountUpdate()
- //修改文章收藏数量
- go ArticleCollectCountUpdate()
- return
- }
- //修改产业关注数量
- func IndustryFllowCountUpdate() (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("修改产业关注数量信息失败"+err.Error(), 2)
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- fllowList, err := models.GetUserFllowIndustrialCountList()
- if err != nil {
- return
- }
- for _, v := range fllowList {
- err = models.UpdateIndustrialManagementFllowNum(v.Num, v.IndustrialManagementId)
- if err != nil {
- return
- }
- }
- return err
- }
- //修改文章收藏数量
- func ArticleCollectCountUpdate() (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)
- }
- }()
- collectList, err := models.GetUserArticleCollectList()
- if err != nil {
- return
- }
- for _, v := range collectList {
- err = models.UpdateArticleCollectCountNum(v.Num, v.ArticleId)
- if err != nil {
- return
- }
- }
- 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
- }
- //行业关注或者取消关注的时候,对于用户全部赛道的影响
- 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
- }
- // 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
- }
- //func init() {
- // GetIndustrialManagementArticleNewPublishData()
- //}
- //批量修改获取产业关联文章的最新发布时间
- func GetIndustrialManagementArticleNewPublishData() (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("批量修改获取产业关联文章的最新发布时间"+"GetIndustrialManagementArticleNewPublishData ErrMsg:"+err.Error(), 2)
- }
- }()
- articleNewPublishDataList, e := models.GetIndustrialManagementArticleNewPublishData()
- if e != nil {
- err = errors.New("获取客户剩余报名次数失败 GetIndustrialManagementArticleNewPublishData, Err: " + e.Error())
- return
- }
- mapUPdateTime := make(map[int]string)
- var industrialManagementIds []int
- for _, v := range articleNewPublishDataList {
- if v.IndustrialManagementId > 0 {
- industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
- }
- mapUPdateTime[v.IndustrialManagementId] = v.UpdateTime
- }
- //时间线的更新时间
- listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
- if err != nil && err.Error() != utils.ErrNoRow() {
- 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
- }
- }
- }
- err = models.UpdateIndustrialManagementArticleNewPublishData(mapUPdateTime)
- return
- }
- //HandleIndustryList预处理产业列表字段
- func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUserItem) (items []*models.IndustrialManagement, err error) {
- userId := user.UserId
- fllowList, err := models.GetUserFllowIndustrialList(userId)
- if err != nil {
- return
- }
- fllowMap := make(map[int]int)
- if len(fllowList) > 0 {
- for _, v := range fllowList {
- fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
- }
- }
- 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 = 1
- }
- industrialIdArr = append(industrialIdArr, 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 {
- //合并产业关联的标的
- listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
- 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
- }
- }
- }
- }
- mapUPdateTime := make(map[int]string)
- articleIdArr := make([]int, 0)
- //获取这些产业下最新更新的文章
- listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- for _, v := range listUpdateTime {
- mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
- articleIdArr = append(articleIdArr, v.ArticleId)
- }
- //时间线的更新时间
- // maptimelineUPdateTime := make(map[int]string)
- listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- 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
- }
- }
- }
- //mapHistroyArticleId := make(map[int]int)
- //if userId > 0 {
- // listArticleHistory, e := models.GetUserToArticleHistory(userId, articleIdArr)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
- // return
- // }
- // for _, v := range listArticleHistory {
- // mapHistroyArticleId[v.ArticleId] = v.ArticleId
- // }
- //}
- articleList, err := models.GetReportIndustrialReadNumList(userId, industrialIdArr)
- mapHistroyindustrialId := make(map[int]int)
- for _, v := range articleList {
- mapHistroyindustrialId[v.IndustrialManagementId] = v.ReadNum
- }
- nowTime := time.Now().Local()
- threeMonBefore := nowTime.AddDate(0, -3, 0)
- for k, v := range list {
- list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
- if userId > 0 {
- //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
- //9.2修改为只要有未读的就标红
- if mapHistroyindustrialId[v.IndustrialManagementId] == 0 && 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 = 0
- }
- list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
- if userId > 0 {
- //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
- if mapHistroyindustrialId[v.IndustrialManagementId] == 0 && 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 = 0
- }
- // 关联报告发布时间均在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
- }
- }
- }
- items = list
- return
- }
|