package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/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 //问答系列视频 //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)) } } //处理文章 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 } } 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(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] } } list[i].LabelKeywordImgLink = utils.LABEL_ICO_10 } //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 } } } //处理研选专栏 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 } yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds) // 专栏Pv 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 v.LabelKeyword = "专栏" v.Pv = yanxuanSpecialPv[v.Id] v.LabelKeywordImgLink = utils.LABEL_ICO_4 mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v } } for _, vList := range list { for _, v := range mapItems { //如果这些类型都为空,那么就不合并 if v.Article == 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 { 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 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 //获取文章分类详情 detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId) if detailCategory != nil { item.ChartPermissionId = detailCategory.ChartPermissionId } } item.SourceId = sourceId item.Source = source item.PublishDate = publishDate item.CreateTime = time.Now() 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 } //建立首页资源表,与产业的关系 industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } 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) } //建立首页资源表,与标的 的关系 subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } 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 }