123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/models/ficc_report"
- "hongze/hongze_cygx/utils"
- "strconv"
- "strings"
- "time"
- )
- func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataResp, err error) {
- uid := user.UserId
- list, e := models.GetResourceDataList(condition, pars, startSize, pageSize)
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- mapItems := make(map[string]*models.CygxResourceDataResp)
- for _, v := range list {
- //预处理文章
- item := new(models.CygxResourceDataResp)
- item.Id = v.Id
- item.SourceId = v.SourceId
- item.Source = v.Source
- item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
- mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
- }
- var articleIds []int
- var newchartIds []int
- var roadshowIds []string
- var activityIds []int
- var activityvideoIds []string
- var activityvoiceIds []string
- var activityspecialIds []int
- var researchsummaryIds []int
- var minutessummaryIds []int
- var meetingreviewchaptIds []int
- var productinteriorIds []int
- var reportselectionIds []int // 报告精选
- var yanxuanSpecialIds []int // 研选专栏
- var askserieVideoIds []string //问答系列视频
- var ficcreporrtIds []string //FICC研报
- //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
- for _, v := range list {
- if v.Source == "article" {
- articleIds = append(articleIds, v.SourceId)
- } else if v.Source == "newchart" {
- newchartIds = append(newchartIds, v.SourceId)
- } else if v.Source == "roadshow" {
- roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
- } else if v.Source == "activity" {
- activityIds = append(activityIds, v.SourceId)
- } else if v.Source == "activityvideo" {
- activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
- } else if v.Source == "activityvoice" {
- activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
- } else if v.Source == "activityspecial" {
- activityspecialIds = append(activityspecialIds, v.SourceId)
- } else if v.Source == "researchsummary" {
- researchsummaryIds = append(researchsummaryIds, v.SourceId)
- } else if v.Source == "minutessummary" {
- minutessummaryIds = append(minutessummaryIds, v.SourceId)
- } else if v.Source == "meetingreviewchapt" {
- meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
- } else if v.Source == "productinterior" {
- productinteriorIds = append(productinteriorIds, v.SourceId)
- } else if v.Source == "reportselection" {
- reportselectionIds = append(reportselectionIds, v.SourceId)
- } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
- yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
- } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
- askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
- } else if v.Source == utils.CYGX_OBJ_FICC_REPORT {
- ficcreporrtIds = append(ficcreporrtIds, strconv.Itoa(v.SourceId))
- }
- }
- //处理文章
- if len(articleIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
- pars = append(pars, articleIds)
- listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- listArticle, e = HandleArticleCategoryImg(listArticle)
- if e != nil {
- err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
- return
- }
- for _, v := range listArticle {
- v.Body = ""
- v.BodyHtml = ""
- mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
- }
- }
- //处理晨会精华
- if len(meetingreviewchaptIds) > 0 {
- //pars = make([]interface{}, 0)
- //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
- //pars = append(pars, meetingreviewchaptIds)
- listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
- if e != nil {
- err = errors.New("GetCygxMorningMeetingReviewChapterListByIds, Err: " + e.Error())
- return
- }
- for _, v := range listrMeet {
- v.Content = AnnotationHtml(v.Content)
- v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
- mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
- }
- }
- //处理上周纪要汇总
- if len(minutessummaryIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
- pars = append(pars, minutessummaryIds)
- listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- mapPv := GetCygxReportHistoryRecordListMap(minutessummaryIds, "szjyhz")
- for _, v := range listresearchsummary {
- v.Pv = mapPv[v.ArticleId]
- v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
- mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
- }
- }
- //处理本周纪要汇总
- if len(researchsummaryIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
- pars = append(pars, researchsummaryIds)
- listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
- if e != nil {
- err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
- return
- }
- mapPv := GetCygxReportHistoryRecordListMap(researchsummaryIds, "bzyjhz")
- for _, v := range listresearchsummary {
- v.Pv = mapPv[v.ArticleId]
- v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
- mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
- }
- }
- //处理产品内测
- if len(productinteriorIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
- pars = append(pars, productinteriorIds)
- listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
- if e != nil {
- err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
- return
- }
- ProductInteriorHistoryMap := GetCygxProductInteriorHistoryListPvMap(productinteriorIds)
- for _, v := range listProductInterior {
- v.Body = ProductInteriorHtml(v.Body)
- v.Pv = ProductInteriorHistoryMap[v.ProductInteriorId]
- v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
- mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
- }
- }
- detail, e := models.GetConfigByCode("city_img_url")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- detailChart, e := models.GetConfigByCode("chart_img_url")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- addressList := strings.Split(detail.ConfigValue, "{|}")
- mapAddress := make(map[string]string)
- chartList := strings.Split(detailChart.ConfigValue, "{|}")
- mapChart := make(map[string]string)
- var cityName string
- var chartName string
- var imgUrl string
- var imgUrlChart string
- for _, v := range addressList {
- vslice := strings.Split(v, "_")
- cityName = vslice[0]
- imgUrl = vslice[len(vslice)-1]
- mapAddress[cityName] = imgUrl
- }
- for _, v := range chartList {
- vslice := strings.Split(v, "_")
- chartName = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapChart[chartName] = imgUrlChart
- }
- var imgUrlResp string
- //处理活动
- if len(activityIds) > 0 {
- for _, vss := range activityIds {
- imgUrlResp += strconv.Itoa(vss) + ","
- }
- pars = make([]interface{}, 0)
- condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
- pars = append(pars, activityIds)
- activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- //处理不同的报名方式按钮回显
- mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
- if e != nil {
- e = errors.New("GetActivitySignupResp, Err: " + e.Error())
- return
- }
- var activityListRersp []*models.ActivityDetail
- for _, v := range activityList {
- v.SignupType = mapActivitySignup[v.ActivityId]
- //activityListRersp = append(activityListRersp, ActivityButtonShow(v))
- }
- activityListRersp = ActivityArrButtonShow(activityList)
- for _, v := range activityListRersp {
- if v == nil {
- continue
- }
- if v.ActivityType == 0 {
- if mapAddress[v.City] != "" {
- imgUrlResp = mapAddress[v.City]
- } else {
- imgUrlResp = mapAddress["其它"]
- }
- } else {
- if mapChart[v.ChartPermissionName] != "" {
- imgUrlResp = mapChart[v.ChartPermissionName]
- }
- }
- v.SourceType = 1
- v.Expert, _ = GetReportContentTextSub(v.Expert)
- mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
- }
- }
- //处理图表
- if len(newchartIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
- pars = append(pars, newchartIds)
- chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- for _, v := range chartDateList {
- mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
- }
- }
- //处理专项调研
- if len(activityspecialIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
- pars = append(pars, activityspecialIds)
- activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
- return
- }
- UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
- if e != nil {
- err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
- return
- }
- for _, v := range activitySpeciallist {
- if mapChart[v.ChartPermissionName] != "" {
- imgUrlResp = mapChart[v.ChartPermissionName]
- }
- if _, ok := UserMap[v.ActivityId]; ok {
- v.IsTrip = 1
- }
- if v.Days == 0 {
- v.TripStatus = 1
- v.TripImgLink = v.TripImgLink
- } else {
- v.TripStatus = 2
- v.TripImgLink = v.TripImgLinkFix
- v.ActivityTimeText = v.ActivityTimeTextByDay
- }
- resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
- resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
- if resultTimeStart.After(time.Now()) {
- v.ActiveState = 1
- } else if time.Now().After(resultTimeEnd) {
- v.ActiveState = 3
- } else {
- v.ActiveState = 2
- }
- v.ImgUrl = imgUrlResp
- mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
- }
- }
- if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
- audioIdstr := strings.Join(activityvoiceIds, ",")
- activityVideoIdsStr := strings.Join(activityvideoIds, ",")
- roadshowIdsStr := strings.Join(roadshowIds, ",")
- askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
- list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
- if e != nil {
- err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
- return
- }
- // 用户权限
- authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
- if e != nil {
- err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
- return
- }
- // 获取默认图配置
- audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
- if e != nil {
- err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
- return
- }
- //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
- for i := range list {
- // 权限
- au := new(models.UserPermissionAuthInfo)
- au.SellerName = authInfo.SellerName
- au.SellerMobile = authInfo.SellerMobile
- au.HasPermission = authInfo.HasPermission
- au.OperationMode = authInfo.OperationMode
- if au.HasPermission == 1 {
- // 非宏观权限进一步判断是否有权限
- if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
- au.HasPermission = 2
- }
- }
- // 无权限的弹框提示
- if au.HasPermission != 1 {
- if au.OperationMode == UserPermissionOperationModeCall {
- if list[i].Type == 1 {
- au.PopupMsg = UserPermissionPopupMsgCallActivity
- } else {
- au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
- }
- } else {
- if list[i].Type == 1 {
- au.PopupMsg = UserPermissionPopupMsgApplyActivity
- } else {
- au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
- }
- }
- }
- list[i].AuthInfo = au
- list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
- // 默认图
- if list[i].BackgroundImg == "" {
- if list[i].Type == 1 {
- list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
- } else {
- list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
- }
- }
- // 分享图
- if list[i].ShareImg == "" {
- if list[i].Type == 1 {
- list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
- } else {
- list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
- }
- }
- }
- //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
- for _, item := range list {
- if item.Type == 1 {
- mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
- } else if item.Type == 2 {
- mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
- } else if item.Type == 3 {
- mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
- } else if item.Type == 4 {
- mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
- }
- }
- }
- //处理报告精选
- lenreportselectionIds := len(reportselectionIds)
- if lenreportselectionIds > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
- pars = append(pars, reportselectionIds)
- listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
- if e != nil {
- err = errors.New("GetReportSelectionList, Err: " + e.Error())
- return
- }
- mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
- for _, v := range listreportselection {
- v.Title += "(第" + v.Periods + "期)"
- v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
- v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
- v.Pv = mapPv[v.ArticleId]
- mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
- }
- }
- //处理研选专栏
- lenyanxuanSpecialIds := len(yanxuanSpecialIds)
- if lenyanxuanSpecialIds > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
- pars = append(pars, yanxuanSpecialIds)
- listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
- if e != nil {
- err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
- return
- }
- for _, v := range listyanxuanSpecial {
- v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
- v.Annotation, _ = GetReportContentTextSubNew(v.Content)
- // Source PublishDate 字段兼容前端样式
- v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
- v.PublishDate = v.PublishTime
- mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
- }
- }
- //处理FICC研报
- if len(ficcreporrtIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.report_id IN (` + utils.GetOrmInReplace(len(ficcreporrtIds)) + `)`
- pars = append(pars, ficcreporrtIds)
- listArticle, e := models.GetHomeList(condition, pars, 0, len(ficcreporrtIds))
- if e != nil {
- err = errors.New("GetHomeList, Err: " + e.Error())
- return
- }
- listArticle, e = HandleArticleCategoryImg(listArticle)
- if e != nil {
- err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
- return
- }
- for _, v := range listArticle {
- //fmt.Println(v.ArticleId)
- v.Body = ""
- v.Source = 0 //配合前端这里强制改为 0
- v.ArticleResponse = 0 //配合前端这里强制改为 0
- //v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
- mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
- }
- //listArticle, e = HandleArticleCategoryImg(listArticle)
- //if e != nil {
- // err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
- // return
- //}
- //for _, v := range listArticle {
- // //reportInfoItem := new(ficc_report.ReportDetail)
- // //reportInfoItem.ReportInfo.ReportId = v.ReportId
- // //reportInfoItem.ReportInfo.PublishTime = utils.StrTimeToTime(v.PublishDate)
- // //reportInfoItem.ReportInfo.Title = v.Title
- // mapItems[fmt.Sprint("ficcreport", v.ArticleId)].FiccReport = v
- //
- //}
- }
- for _, vList := range list {
- for _, v := range mapItems {
- //如果这些类型都为空,那么就不合并
- if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.ReportSelection == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil && v.FiccReport == nil {
- continue
- }
- if v.SourceId == vList.SourceId && v.Source == vList.Source {
- items = append(items, v)
- }
- }
- }
- return
- }
- // 同步活动到最新数据表
- func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
- }
- }()
- if doType == "add" {
- item := new(models.CygxResourceData)
- item.SourceId = sourceId
- item.Source = source
- item.PublishDate = publishDate
- item.CreateTime = time.Now()
- _, err = models.AddCygxResourceData(item)
- } else if doType == "delete" {
- err = models.DeleteResourceData(sourceId, source)
- } else if doType == "update" {
- err = models.UpdateResourceData(sourceId, source, publishDate)
- }
- return
- }
- //func init130() {
- // //UpdateNewchartResourceData(5509)
- //
- // var condition string
- // var pars []interface{}
- // condition += ` AND publish_status = 1 `
- //
- // list, e := models.GetChartList(condition, pars, 0, 1000000)
- // if e != nil {
- // fmt.Println(e)
- // return
- // }
- //
- // for _, v := range list {
- // fmt.Println(v.ChartId)
- // UpdateNewchartResourceData(v.ChartId)
- // }
- //}
- // 更新图表
- func UpdateNewchartResourceData(sourceId int) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("更新图表同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型", 3)
- }
- }()
- var source = utils.CYGX_OBJ_NEWCHART
- var condition string
- var pars []interface{}
- condition = ` AND chart_id = ? `
- pars = append(pars, sourceId)
- total, e := models.GetChartCount(condition, pars)
- if e != nil {
- err = errors.New("GetChartCount, Err: " + e.Error())
- return
- }
- //如果取消发布了就做删除处理
- if total == 0 {
- e = models.DeleteResourceData(sourceId, source)
- if e != nil {
- err = errors.New("DeleteResourceData, Err: " + e.Error())
- return
- }
- } else {
- //判断是否存在,如果不存在就新增,存在就更新
- totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
- if e != nil {
- err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
- return
- }
- detail, e := models.GetChartDetailByChartId(sourceId)
- if e != nil {
- err = errors.New("GetArticleDetailById, Err: " + e.Error())
- return
- }
- publishDate := detail.CreateDate
- item := new(models.CygxResourceData)
- item.SourceId = sourceId
- item.Source = source
- item.PublishDate = publishDate
- item.CreateTime = time.Now()
- item.SearchTitle = detail.Title
- item.SearchContent = ""
- item.SearchOrderTime = detail.CreateDate
- if totalData == 0 {
- _, e = models.AddCygxResourceData(item)
- if e != nil {
- err = errors.New("AddCygxResourceData, Err: " + e.Error())
- return
- }
- } else {
- e = models.UpdateResourceDataByItem(item)
- if e != nil {
- err = errors.New("UpdateResourceData, Err: " + e.Error())
- return
- }
- }
- }
- return
- }
- // 批量删除最新图表数据
- func Deletenewchart(chartIdsDelete []int) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("批量删除最新图表数据,Err:"+err.Error(), 3)
- }
- }()
- lenchartIdsDelete := len(chartIdsDelete)
- if lenchartIdsDelete == 0 {
- return
- }
- var condition string
- var pars []interface{}
- condition += ` AND source = 'newchart' AND source_id IN (` + utils.GetOrmInReplace(lenchartIdsDelete) + `) `
- pars = append(pars, chartIdsDelete)
- err = models.DeleteResourceDataList(condition, pars)
- return
- }
- //func init() {
- // UpdateArticleResourceData(9050)
- //}
- // 更新文章
- func UpdateArticleResourceData(sourceId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("err:", err)
- go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
- }
- }()
- var source = utils.CYGX_OBJ_ARTICLE
- var condition string
- var pars []interface{}
- condition = ` AND publish_status = 1 AND article_id = ? `
- pars = append(pars, sourceId)
- total, e := models.GetCygxArticleCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxReportSelection, Err: " + err.Error())
- return
- }
- //如果取消发布了就做删除处理
- if total == 0 {
- e = models.DeleteResourceData(sourceId, source)
- if e != nil {
- err = errors.New("DeleteResourceData, Err: " + e.Error())
- return
- }
- //删除 cygx_resource_data 表关联的产业ID,标的ID
- e = models.DeleteCygxResourceDataGroup(sourceId, source)
- if e != nil {
- err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
- return
- }
- } else {
- //判断是否存在,如果不存在就新增,存在就更新
- totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
- if e != nil {
- err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
- return
- }
- detail, e := models.GetArticleDetailById(sourceId)
- if e != nil {
- err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
- return
- }
- var resourceDataId int
- publishDate := time.Now().Format(utils.FormatDateTime)
- item := new(models.CygxResourceData)
- if detail.ArticleTypeId > 0 {
- item.SearchTag = detail.ArticleTypeName // 研选类型名称
- } else {
- item.SearchTag = detail.MatchTypeName
- if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
- item.SearchTag = ""
- }
- //获取文章分类详情
- detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
- if detailCategory != nil {
- item.ChartPermissionId = detailCategory.ChartPermissionId
- }
- }
- var industrialName string
- var subjectName string
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- for _, v := range industrialList {
- industrialName += v.IndustryName
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- for _, v := range subjectList {
- subjectName += v.SubjectName
- }
- item.SourceId = sourceId
- item.Source = source
- item.PublishDate = publishDate
- item.CreateTime = time.Now()
- item.SearchTitle = detail.Title
- annotation, e := utils.GetHtmlContentText(detail.Annotation)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- abstract, e := utils.GetHtmlContentText(detail.Abstract)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
- item.SearchOrderTime = detail.PublishDate
- if totalData == 0 {
- newId, e := models.AddCygxResourceData(item)
- if e != nil {
- err = errors.New("AddCygxResourceData, Err: " + e.Error())
- return
- }
- resourceDataId = int(newId)
- } else {
- e = models.UpdateResourceDataByItem(item)
- if e != nil {
- err = errors.New("UpdateResourceData, Err: " + e.Error())
- return
- }
- sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
- if e != nil {
- err = errors.New("UpdateResourceData, Err: " + e.Error())
- return
- }
- resourceDataId = sourceDetail.Id
- }
- //建立首页资源表,与产业的关系
- var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
- for _, v := range industrialList {
- var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
- industrialItem.SourceId = sourceId
- industrialItem.Source = source
- industrialItem.IndustrialManagementId = v.IndustrialManagementId
- industrialItem.ResourceDataId = resourceDataId
- industrialItem.CreateTime = time.Now()
- industrialItems = append(industrialItems, industrialItem)
- }
- //建立首页资源表,与标的 的关系
- var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
- for _, v := range subjectList {
- var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
- subjectItem.SourceId = sourceId
- subjectItem.Source = source
- subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
- subjectItem.ResourceDataId = resourceDataId
- subjectItem.CreateTime = time.Now()
- subjectItems = append(subjectItems, subjectItem)
- }
- //插入关联信息
- e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
- if e != nil {
- err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
- return
- }
- }
- return
- }
- // 更新产业资源包
- func UpdateComprehensiveIndustrialResourceData(itemSource *ElasticComprehensiveDetail) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("更新产业资源包到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(itemSource.SourceId), 3)
- }
- }()
- sourceId := itemSource.SourceId
- var source = itemSource.Source
- //判断是否存在,如果不存在就新增,存在就更新
- totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
- if e != nil {
- err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
- return
- }
- item := new(models.CygxResourceData)
- item.SourceId = sourceId
- item.Source = source
- item.PublishDate = itemSource.PublishDate
- item.CreateTime = time.Now()
- item.SearchTitle = itemSource.IndustryName + itemSource.SubjectNames
- item.SearchContent = ""
- item.SearchOrderTime = itemSource.PublishDate
- if totalData == 0 {
- _, e = models.AddCygxResourceData(item)
- if e != nil {
- err = errors.New("AddCygxResourceData, Err: " + e.Error())
- return
- }
- } else {
- e = models.UpdateResourceDataByItem(item)
- if e != nil {
- err = errors.New("UpdateResourceData, Err: " + e.Error())
- return
- }
- }
- return
- }
- // 更新研选专栏 写入首页最新 cygx_resource_data 表
- func UpdateYanxuanSpecialResourceData(sourceId int) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 2)
- }
- }()
- var source = utils.CYGX_OBJ_YANXUANSPECIAL
- var condition string
- var pars []interface{}
- condition = ` AND status = 3 AND id = ? `
- pars = append(pars, sourceId)
- total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
- return
- }
- //如果取消发布了就做删除处理
- if total == 0 {
- e = models.DeleteResourceData(sourceId, source)
- if e != nil {
- err = errors.New("DeleteResourceData, Err: " + e.Error())
- return
- }
- } else {
- //判断是否存在,如果不存在就新增,存在就更新
- totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
- if e != nil {
- err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
- return
- }
- detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
- if e != nil {
- err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
- return
- }
- publishDate := detail.PublishTime
- item := new(models.CygxResourceData)
- item.SourceId = sourceId
- item.Source = source
- item.PublishDate = publishDate
- item.CreateTime = time.Now()
- item.SearchTitle = detail.Title
- item.SearchContent = ""
- item.SearchOrderTime = publishDate
- item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
- if totalData == 0 {
- _, e := models.AddCygxResourceData(item)
- if e != nil {
- err = errors.New("AddCygxResourceData, Err: " + e.Error())
- return
- }
- } else {
- e = models.UpdateResourceDataByItem(item)
- if e != nil {
- err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
- return
- }
- }
- }
- return
- }
- func initsql12_17() {
- listIndustrialResourceIds, e := models.GetSearchResourceList(0, " AND article_type_id > 0 ", 0, 9999)
- if e != nil {
- fmt.Println(e)
- return
- }
- var industrialResourceIdsHz []int
- for _, v := range listIndustrialResourceIds {
- industrialResourceIdsHz = append(industrialResourceIdsHz, v.IndustrialManagementId)
- }
- //date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
- //合并产业关联的标的
- listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsHz)
- if e != nil {
- fmt.Println(e)
- return
- }
- mapIndustrial := make(map[string]int)
- for _, v := range listSubjcet {
- for k2, v2 := range listIndustrialResourceIds {
- if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
- listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
- }
- }
- }
- //industrialsource := "industrialsourceHz"
- industrialsource := "industrialsourceYx"
- for _, v := range listIndustrialResourceIds {
- item := new(ElasticComprehensiveDetail)
- item.SourceId = v.IndustrialManagementId
- item.Source = industrialsource
- item.IndustryName = v.IndustryName
- var SubjectName []string
- for _, vN := range v.IndustrialSubjectList {
- SubjectName = append(SubjectName, vN.SubjectName)
- }
- item.SubjectNames = strings.Join(SubjectName, ",")
- item.PublishDate = v.PublishDate
- fmt.Println(item)
- UpdateComprehensiveIndustrialResourceData(item)
- }
- return
- }
- // 更新FICC研报
- func UpdateFICCReportResourceData(sourceId int, listFiccSet *ficc_report.GetReporteSetListResp) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("err:", err)
- go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
- }
- }()
- var source = utils.CYGX_OBJ_FICC_REPORT
- var condition string
- var pars []interface{}
- condition = ` AND publish_status = 1 AND report_id = ? `
- pars = append(pars, sourceId)
- total, e := models.GetCygxArticleCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxArticleCount, Err: " + err.Error())
- return
- }
- //如果取消发布了就做删除处理
- if total == 0 {
- e = models.DeleteResourceData(sourceId, source)
- if e != nil {
- err = errors.New("DeleteResourceData, Err: " + e.Error())
- return
- }
- //删除 cygx_resource_data 表关联的产业ID,标的ID
- e = models.DeleteCygxResourceDataGroup(sourceId, source)
- if e != nil {
- err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
- return
- }
- } else {
- //判断是否存在,如果不存在就新增,存在就更新
- totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
- if e != nil {
- err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
- return
- }
- detail, e := models.GetArticleDetailByReportId(sourceId)
- if e != nil {
- err = errors.New("GetArticleDetailByReportId, Err: " + e.Error())
- return
- }
- var resourceDataId int
- publishDate := time.Now().Format(utils.FormatDateTime)
- item := new(models.CygxResourceData)
- if detail.ArticleTypeId > 0 {
- item.SearchTag = detail.ArticleTypeName // 研选类型名称
- } else {
- item.SearchTag = detail.MatchTypeName
- if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
- item.SearchTag = ""
- }
- //获取文章分类详情
- detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
- if detailCategory != nil {
- item.ChartPermissionId = detailCategory.ChartPermissionId
- }
- }
- var industrialName string
- var subjectName string
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- for _, v := range industrialList {
- industrialName += v.IndustryName
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- for _, v := range subjectList {
- subjectName += v.SubjectName
- }
- item.SourceId = sourceId
- item.Source = source
- item.PublishDate = publishDate
- item.CreateTime = time.Now()
- item.SearchTitle = detail.Title
- annotation, e := utils.GetHtmlContentText(detail.Annotation)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- abstract, e := utils.GetHtmlContentText(detail.Abstract)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
- item.SearchOrderTime = detail.PublishDate
- //跟踪、深度、纪要三个自定义的搜索标签
- for _, vSt := range listFiccSet.List {
- if item.SearchTag == vSt.ClassifyNameSecond {
- item.TagName = vSt.TagName
- }
- }
- if totalData == 0 {
- newId, e := models.AddCygxResourceData(item)
- if e != nil {
- err = errors.New("AddCygxResourceData, Err: " + e.Error())
- return
- }
- resourceDataId = int(newId)
- } else {
- sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
- if e != nil {
- err = errors.New("UpdateResourceData, Err: " + e.Error())
- return
- }
- item.PublishDate = sourceDetail.PublishDate
- item.SearchOrderTime = sourceDetail.SearchOrderTime
- e = models.UpdateResourceDataByItem(item)
- if e != nil {
- err = errors.New("UpdateResourceData, Err: " + e.Error())
- return
- }
- resourceDataId = sourceDetail.Id
- }
- //建立首页资源表,与产业的关系
- var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
- for _, v := range industrialList {
- var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
- industrialItem.SourceId = sourceId
- industrialItem.Source = source
- industrialItem.IndustrialManagementId = v.IndustrialManagementId
- industrialItem.ResourceDataId = resourceDataId
- industrialItem.CreateTime = time.Now()
- industrialItems = append(industrialItems, industrialItem)
- }
- //建立首页资源表,与标的 的关系
- var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
- for _, v := range subjectList {
- var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
- subjectItem.SourceId = sourceId
- subjectItem.Source = source
- subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
- subjectItem.ResourceDataId = resourceDataId
- subjectItem.CreateTime = time.Now()
- subjectItems = append(subjectItems, subjectItem)
- }
- //插入关联信息
- e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
- if e != nil {
- err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
- return
- }
- }
- return
- }
|