package cygx import ( "errors" "fmt" "hongze/hz_crm_api/models/cygx" "hongze/hz_crm_api/services/alarm_msg" "hongze/hz_crm_api/utils" "strconv" "time" ) //首页最新页面数据逻辑处理 //activity //activityspecial //activityvideo //activityvoice //article //meetingreviewchapt //minutessummary //newchart //productinterior //reportselection //researchsummary //roadshow //func init() { // UpdateMicroRoadshowResourceData(7) //} // 更新活动 func UpdateActivityResourceData(sourceId int) { var err error //time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒 defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新活动 失败,UpdateActivityResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_ACTIVITY var condition string var pars []interface{} condition = ` AND publish_status = 1 AND activity_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetActivityCount(condition, pars) if e != nil { err = errors.New("GetCygxReportSelection, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } //删除 cygx_resource_data 表关联的产业ID,标的ID e = cygx.DeleteCygxResourceDataGroup(sourceId, source) if e != nil { err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetAddActivityInfoById(sourceId) if e != nil { err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error()) return } var resourceDataId int publishDate := detail.LastUpdatedTime // 活动最后更新时间作为排序时间 item := new(cygx.CygxResourceData) var industrialName string var subjectName string //建立首页资源表,与产业的关系 industrialList, e := cygx.GetIndustrialActivityGroupManagementList(sourceId, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(sourceId)) return } for _, v := range industrialList { industrialName += v.IndustryName } //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetSubjectActivityGroupManagementList(sourceId, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(sourceId)) return } for _, v := range subjectList { subjectName += v.SubjectName } item.SourceId = sourceId item.Source = source //分析师电话会(C类) item.SearchTag = detail.ActivityTypeName item.ChartPermissionId = detail.ChartPermissionId item.PublishDate = publishDate item.SearchTitle = detail.ActivityName item.SearchContent = detail.Label + industrialName + subjectName item.SearchOrderTime = detail.ActivityTime item.CreateTime = time.Now() if totalData == 0 { newId, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } resourceDataId = int(newId) } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } resourceDataId = sourceDetail.Id } var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement for _, v := range industrialList { var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement) industrialItem.SourceId = sourceId industrialItem.Source = source industrialItem.IndustrialManagementId = v.IndustrialManagementId industrialItem.ResourceDataId = resourceDataId industrialItem.CreateTime = time.Now() industrialItems = append(industrialItems, industrialItem) } //建立首页资源表,与标的 的关系 var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject for _, v := range subjectList { var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject) subjectItem.SourceId = sourceId subjectItem.Source = source subjectItem.IndustrialSubjectId = v.IndustrialSubjectId subjectItem.ResourceDataId = resourceDataId subjectItem.CreateTime = time.Now() subjectItems = append(subjectItems, subjectItem) } //插入关联信息 e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems) if e != nil { err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error()) return } } return } // 更新专项调研活动 func UpdateActivitySpecialResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新活动 失败,UpdateActivitySpecialResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_ACTIVITYSPECIAL var condition string var pars []interface{} condition = ` AND publish_status = 1 AND activity_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetActivityCount(condition, pars) if e != nil { err = errors.New("GetCygxReportSelection, Err: " + e.Error()) return } activityInfo, e := cygx.GetAddActivityInfoSpecialById(sourceId) if e != nil { err = errors.New("GetAddActivityInfoSpecialById, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } //删除 cygx_resource_data 表关联的产业ID,标的ID e = cygx.DeleteCygxResourceDataGroup(sourceId, source) if e != nil { err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } var resourceDataId int publishDate := activityInfo.PublishDate item := new(cygx.CygxResourceData) item.SourceId = sourceId item.Source = source //分析师电话会(C类) item.SearchTag = "" item.PublishDate = publishDate item.ChartPermissionId = activityInfo.ChartPermissionId item.CreateTime = time.Now() item.SearchTitle = activityInfo.ResearchTheme item.SearchContent = activityInfo.Label + activityInfo.IndustrialName + activityInfo.IndustrialSubjectName if activityInfo.Days > 0 { item.SearchOrderTime = activityInfo.ActivityTime } else { item.SearchOrderTime = activityInfo.PublishDate } if totalData == 0 { newId, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } resourceDataId = int(newId) } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } resourceDataId = sourceDetail.Id } //建立首页资源表,与产业的关系 industrialList, e := cygx.GetIndustrialActivityGroupManagementList(sourceId, 2) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(sourceId)) return } var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement for _, v := range industrialList { var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement) industrialItem.SourceId = sourceId industrialItem.Source = source industrialItem.IndustrialManagementId = v.IndustrialManagementId industrialItem.ResourceDataId = resourceDataId industrialItem.CreateTime = time.Now() industrialItems = append(industrialItems, industrialItem) } //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetSubjectArticleGroupManagementList(sourceId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject for _, v := range subjectList { var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject) subjectItem.SourceId = sourceId subjectItem.Source = source subjectItem.IndustrialSubjectId = v.IndustrialSubjectId subjectItem.ResourceDataId = resourceDataId subjectItem.CreateTime = time.Now() subjectItems = append(subjectItems, subjectItem) } //插入关联信息 e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems) if e != nil { err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error()) return } } return } // 更新文章 func UpdateArticleResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.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 := cygx.GetCygxArticleCount(condition, pars) if e != nil { err = errors.New("GetCygxReportSelection, Err: " + err.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } //删除 cygx_resource_data 表关联的产业ID,标的ID e = cygx.DeleteCygxResourceDataGroup(sourceId, source) if e != nil { err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetArticleDetailByArticleId(sourceId) if e != nil { err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error()) return } var resourceDataId int //publishDate := detail.CreateDate publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) if detail.ArticleTypeId > 0 { item.SearchTag = detail.ArticleTypeName // 研选类型名称 item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN } else { item.SearchTag = detail.MatchTypeName //获取文章分类详情 detailCategory, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId) if detailCategory != nil { item.ChartPermissionId = detailCategory.ChartPermissionId } } var industrialName string var subjectName string //建立首页资源表,与产业的关系 industrialList, e := cygx.GetIndustrialArticleGroupManagementList(sourceId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } for _, v := range industrialList { industrialName += v.IndustryName } //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetSubjectArticleGroupManagementList(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 := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } resourceDataId = int(newId) } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source) if e != nil { err = errors.New("GetCygxResourceDataByIdAndSource, Err: " + e.Error()) return } resourceDataId = sourceDetail.Id } var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement for _, v := range industrialList { var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement) industrialItem.SourceId = sourceId industrialItem.Source = source industrialItem.IndustrialManagementId = v.IndustrialManagementId industrialItem.ResourceDataId = resourceDataId industrialItem.CreateTime = time.Now() industrialItems = append(industrialItems, industrialItem) industrialName += v.IndustryName } var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject for _, v := range subjectList { var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject) subjectItem.SourceId = sourceId subjectItem.Source = source subjectItem.IndustrialSubjectId = v.IndustrialSubjectId subjectItem.ResourceDataId = resourceDataId subjectItem.CreateTime = time.Now() subjectItems = append(subjectItems, subjectItem) subjectName += v.SubjectName } //插入关联信息 e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems) if e != nil { err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error()) return } } return } // 更新产品内测 func UpdateProductInteriorResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新产品内测 失败,UpdateProductInteriorResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_PRODUCTINTERIOR var condition string var pars []interface{} condition = ` AND visible_range = 1 AND product_interior_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetCygxProductInteriorCount(condition, pars) if e != nil { err = errors.New("GetCygxReportSelection, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } //删除 cygx_resource_data 表关联的产业ID,标的ID e = cygx.DeleteCygxResourceDataGroup(sourceId, source) if e != nil { err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetCygxProductInteriorDetail(sourceId) if e != nil { err = errors.New("GetCygxReportSelectionInfoById, Err: " + err.Error()) return } mapMatchTypeName := GetCygxReportMappingCygxListMap() //报告匹配类型 var resourceDataId int publishDate := detail.CreateTime item := new(cygx.CygxResourceData) var industrialName string var subjectName string //建立首页资源表,与产业的关系 industrialList, e := cygx.GetProductInteriorIndustrialGroupManagementList(sourceId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } for _, v := range industrialList { industrialName += v.IndustryName } //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetProductInteriorIndustrialGroupSubjecttList(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.SearchTag = mapMatchTypeName[detail.MatchTypeId] item.PublishDate = publishDate if item.SearchTag != "观点周递" { item.ChartPermissionId = detail.ChartPermissionId //首页筛选任何行业时,无法筛选出【观点周递】类型的报告 } item.CreateTime = time.Now() item.SearchTitle = detail.Title item.SearchContent = detail.Abstract + industrialName + subjectName item.SearchOrderTime = detail.PublishTime if totalData == 0 { newId, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } resourceDataId = int(newId) } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } resourceDataId = sourceDetail.Id } var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement for _, v := range industrialList { var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement) industrialItem.SourceId = sourceId industrialItem.Source = source industrialItem.IndustrialManagementId = v.IndustrialManagementId industrialItem.ResourceDataId = resourceDataId industrialItem.CreateTime = time.Now() industrialItems = append(industrialItems, industrialItem) } var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject for _, v := range subjectList { var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject) subjectItem.SourceId = sourceId subjectItem.Source = source subjectItem.IndustrialSubjectId = v.IndustrialSubjectId subjectItem.ResourceDataId = resourceDataId subjectItem.CreateTime = time.Now() subjectItems = append(subjectItems, subjectItem) } //插入关联信息 e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems) if e != nil { err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error()) return } } return } // 更新晨会精华 (跟踪点评) func UpdateMeetingreviewchaptResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新产品内测 失败,UpdateMeetingreviewchaptResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_MEETINGREVIEWCHAPT total, e := cygx.GetCygxMorningMeetingReviewChapterCount(sourceId) if e != nil { err = errors.New("GetCygxReportSelection, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } //删除 cygx_resource_data 表关联的产业ID,标的ID e = cygx.DeleteCygxResourceDataGroup(sourceId, source) if e != nil { err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetCygxMorningMeetingReviewChapterDetail(sourceId) if e != nil { err = errors.New("GetCygxMorningMeetingReviewChapterDetail" + e.Error()) return } var resourceDataId int publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) var industrialName string var subjectName string //建立首页资源表,与产业的关系 var condition string var pars []interface{} condition = " AND industrial_management_id = ? " pars = append(pars, detail.IndustryId) //建立首页资源表,与产业的关系 industrialList, e := cygx.GetTopOneMonthArtReadNumIndustryAll(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } for _, v := range industrialList { industrialName += v.IndustryName } if detail.IndustrialSubjectIds != "" { condition = "" pars = make([]interface{}, 0) condition = " AND industrial_subject_id IN (" + detail.IndustrialSubjectIds + ") " //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetCygxIndustrialSubjectListCondition(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxIndustrialSubjectListCondition, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } for _, v := range subjectList { subjectName += v.SubjectName } } item.SourceId = sourceId item.Source = source item.SearchTag = "晨会精华" item.PublishDate = publishDate item.ChartPermissionId = detail.ChartPermissionId item.CreateTime = time.Now() item.SearchTitle = industrialName + subjectName + "晨会精华" content, e := utils.GetHtmlContentText(detail.Content) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } item.SearchContent = content item.SearchOrderTime = detail.MeetingTime.Format(utils.FormatDateTime) if totalData == 0 { newId, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } resourceDataId = int(newId) } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source) if e != nil { err = errors.New("UpdateResourceData, Err: " + e.Error()) return } resourceDataId = sourceDetail.Id } var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement for _, v := range industrialList { var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement) industrialItem.SourceId = sourceId industrialItem.Source = source industrialItem.IndustrialManagementId = v.IndustrialManagementId industrialItem.ResourceDataId = resourceDataId industrialItem.CreateTime = time.Now() industrialItems = append(industrialItems, industrialItem) } //return var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject //晨会精华如果关联的标的就做查询 if detail.IndustrialSubjectIds != "" { condition = "" pars = make([]interface{}, 0) condition = " AND industrial_subject_id IN (" + detail.IndustrialSubjectIds + ") " //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetCygxIndustrialSubjectListCondition(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxIndustrialSubjectListCondition, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId)) return } for _, v := range subjectList { var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject) subjectItem.SourceId = sourceId subjectItem.Source = source subjectItem.IndustrialSubjectId = v.IndustrialSubjectId subjectItem.ResourceDataId = resourceDataId subjectItem.CreateTime = time.Now() subjectItems = append(subjectItems, subjectItem) } } //插入关联信息 e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems) if e != nil { err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error()) return } } return } // 更新报告精选(重点公司) func UpdateReportSelectionResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新报告精选(重点公司) 失败,UpdateReportSelectionResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_REPORTSELECTION var condition string var pars []interface{} condition = ` AND visible_range = 1 AND article_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetCygxReportSelection(condition, pars) if e != nil { err = errors.New("GetCygxReportSelection, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetCygxReportSelectionInfoById(sourceId) if e != nil { err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error()) return } publishDate := detail.PublishDate item := new(cygx.CygxResourceData) item.SourceId = sourceId item.Source = source item.SearchTag = "重点公司" item.PublishDate = publishDate item.CreateTime = time.Now() item.SearchTitle = detail.Title item.SearchContent = "" item.SearchOrderTime = detail.PublishDate if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } // 更新本周研究汇总 func UpdateResearchSummaryResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新本周研究汇总 失败,UpdateResearchSummaryResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_RESEARCHSUMMARY var condition string var pars []interface{} condition = ` AND visible_range = 1 AND article_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetCygxResearchSummary(condition, pars) if e != nil { err = errors.New("GetCygxResearchSummary, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetCygxResearchSummaryInfoById(sourceId) if e != nil { err = errors.New("GetCygxResearchSummaryInfoById, Err: " + e.Error()) return } publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) item.SourceId = sourceId item.Source = source item.SearchTag = "本周研究汇总" item.PublishDate = publishDate item.CreateTime = time.Now() item.SearchTitle = detail.Title item.SearchContent = "" item.SearchOrderTime = detail.PublishDate if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } // 更新上周纪要汇总 func UpdateMinutesSummaryResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新上周纪要汇总 失败,UpdateMinutesSummaryResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_MINUTESSUMMARY var condition string var pars []interface{} condition = ` AND visible_range = 1 AND article_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetCygxMinutesSummary(condition, pars) if e != nil { err = errors.New("GetCygxResearchSummary, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetCygxMinutesSummaryInfoById(sourceId) if e != nil { err = errors.New("GetCygxMinutesSummaryInfoById, Err: " + e.Error()) return } publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) item.SourceId = sourceId item.Source = source item.SearchTag = "上周纪要汇总" item.PublishDate = publishDate item.CreateTime = time.Now() item.SearchTitle = detail.Title item.SearchContent = "" item.SearchOrderTime = detail.PublishDate if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } // 更新活动音频 func UpdateActivityVoiceResourceData(sourceId int) { time.Sleep(1 * time.Second) // 添加1秒的延迟 var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新更新活动音频 失败,UpdateActivityVoiceResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_ACTIVITYVOICE var condition string var pars []interface{} condition = ` AND activity_voice_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetCygxActivityVoiceCount(condition, pars) if e != nil { err = errors.New("GetCygxResearchSummary, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { //获取音频详情 voiceDetail, e := cygx.GetCygxActivityVoiceReqDetailByActivityVoiceId(sourceId) if e != nil { err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error()) return } activityId := voiceDetail.ActivityId //获取活动详情 activityInfo, e := cygx.GetAddActivityInfoById(activityId) if e != nil { err = errors.New("GetAddActivityInfoById, Err: " + e.Error()) return } //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) var industrialName string var subjectName string //建立首页资源表,与产业的关系 industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId)) return } for _, v := range industrialList { industrialName += v.IndustryName } //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId)) return } for _, v := range subjectList { subjectName += v.SubjectName } item.SourceId = sourceId item.Source = source //易董办会的分析师电话会,为路演回放 if voiceDetail.FileType == 1 { item.SearchTag = "路演回放" } else { item.SearchTag = "调研反馈" } item.PublishDate = publishDate item.ChartPermissionId = activityInfo.ChartPermissionId item.CreateTime = utils.StrDateToDate(activityInfo.ActivityTime) item.SearchTitle = voiceDetail.VoiceName item.SearchContent = activityInfo.Label + industrialName + subjectName item.SearchOrderTime = activityInfo.ActivityTime if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } // 更新活动视频 func UpdateActivityVideoResourceData(sourceId int) { time.Sleep(1 * time.Second) // 添加1秒的延迟 var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新更新活动视频 失败,UpdateActivityVideoResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_ACTIVITYVIDEO var condition string var pars []interface{} condition = ` AND v.video_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetActivityVideoCount(condition, pars) if e != nil { err = errors.New("GetCygxResearchSummary, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { videoDetail, e := cygx.GetCygxActivityVideoReqDetailByVideoId(sourceId) if e != nil { err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error()) return } activityId := videoDetail.ActivityId activityInfo, e := cygx.GetAddActivityInfoById(activityId) if e != nil { err = errors.New("GetAddActivityInfoById, Err: " + e.Error()) return } //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) var industrialName string var subjectName string //建立首页资源表,与产业的关系 industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId)) return } for _, v := range industrialList { industrialName += v.IndustryName } //建立首页资源表,与标的 的关系 subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId)) return } for _, v := range subjectList { subjectName += v.SubjectName } item.SourceId = sourceId item.Source = source //易董办会的分析师电话会,为路演回放 if videoDetail.FileType == 1 { item.SearchTag = "路演回放" } else { item.SearchTag = "调研反馈" } item.PublishDate = publishDate item.ChartPermissionId = activityInfo.ChartPermissionId item.CreateTime = utils.StrDateToDate(activityInfo.ActivityTime) item.SearchTitle = videoDetail.VideoName item.SearchContent = activityInfo.Label + industrialName + subjectName item.SearchOrderTime = activityInfo.ActivityTime if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } // 更新产业视频 func UpdateMicroRoadshowResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println("err:", err) go alarm_msg.SendAlarmMsg("更新产业视频 失败,UpdateMicroRoadshowResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3) } }() var source = utils.CYGX_OBJ_ROADSHOW var condition string var pars []interface{} condition = ` AND publish_status = 1 AND video_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetMicroRoadshowVideoListCount(condition, pars) if e != nil { err = errors.New("GetMicroRoadshowVideoListCount, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetMicroRoadshowVideoByVideoId(sourceId) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) item.SourceId = sourceId item.Source = source item.SearchTag = "" item.PublishDate = publishDate item.ChartPermissionId = detail.ChartPermissionId item.CreateTime = time.Now() item.SearchTitle = detail.VideoName item.SearchContent = detail.IndustryName item.SearchOrderTime = detail.PublishDate.Format(utils.FormatDateTime) if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } //func init() { // UpdateAskserieVideoResourceData(7) //} // 更新问答系列 写入首页最新 cygx_resource_data 表 func UpdateAskserieVideoResourceData(sourceId int) { var err error defer func() { if err != nil { fmt.Println(err) go alarm_msg.SendAlarmMsg(fmt.Sprint("更新问答系列ourceId: ", sourceId, err.Error()), 2) } }() var source = utils.CYGX_OBJ_ASKSERIEVIDEO var condition string var pars []interface{} condition = ` AND publish_status = 1 AND askserie_video_id = ? ` pars = append(pars, sourceId) total, e := cygx.GetCygxAskserieVideoCount(condition, pars) if e != nil { err = errors.New("GetCygxAskserieVideoCount, Err: " + e.Error()) return } //如果取消发布了就做删除处理 if total == 0 { e = cygx.DeleteResourceData(sourceId, source) if e != nil { err = errors.New("DeleteResourceData, Err: " + e.Error()) return } } else { //判断是否存在,如果不存在就新增,存在就更新 totalData, e := cygx.GetCygxResourceDataBySourceAndIdCount(sourceId, source) if e != nil { err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error()) return } detail, e := cygx.GetCygxAskserieVideoDetail(sourceId) if e != nil { err = errors.New("GetCygxAskserieVideoDetail, Err: " + e.Error()) return } publishDate := time.Now().Format(utils.FormatDateTime) item := new(cygx.CygxResourceData) item.SourceId = sourceId item.Source = source item.PublishDate = publishDate item.ChartPermissionId = detail.ChartPermissionId item.CreateTime = time.Now() item.SearchTitle = detail.VideoName item.SearchContent = detail.IndustryName item.SearchOrderTime = detail.PublishDate if totalData == 0 { _, e := cygx.AddCygxResourceData(item) if e != nil { err = errors.New("AddCygxResourceData, Err: " + e.Error()) return } } else { e = cygx.UpdateResourceDataByItem(item) if e != nil { err = errors.New("UpdateResourceDataByItem, Err: " + e.Error()) return } } } return } func init300() { //var condition string //var pars []interface{} // //{ // //活动 // var condition string // var pars []interface{} // condition = " AND publish_status = 1 AND activity_id NOT IN (SELECT source_id FROM cygx_resource_data WHERE source = 'activity') " // list, err := cygx.GetActivityListAll(condition, pars, 0, 9999) // if err != nil { // fmt.Println(err) // } // // //list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITY) // //if err != nil { // // fmt.Println(err) // //} // fmt.Println(len(list)) // for _, v := range list { // fmt.Println(v.ActivityId) // UpdateActivityResourceData(v.ActivityId) // } //} //12.4 //{ // //活动 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITY) // if err != nil { // fmt.Println(err) // } // // for _, v := range list { // detail, e := cygx.GetAddActivityInfoById(v.SourceId) // if e != nil { // err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error()) // fmt.Println(err) // return // } // item := new(cygx.CygxResourceData) // item.SourceId = v.SourceId // item.Source = utils.CYGX_OBJ_ACTIVITY // item.ChartPermissionId = detail.ChartPermissionId // fmt.Println(v.Source) // err = cygx.UpdateChartPermissionIdResourceDataByItem(item) // if err != nil { // fmt.Println(err) // return // } // } //} //{ // //专项调研活动 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYSPECIAL) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // UpdateActivitySpecialResourceData(v.SourceId) // } //} //{ // var condition string // var pars []interface{} // condition = " AND publish_status = 1 AND article_id NOT IN (SELECT source_id FROM cygx_resource_data WHERE source = 'article') " // // list, err := cygx.GetArticleRoadshowEssenceList(condition, pars, 0, 9999) // if err != nil { // fmt.Println(err) // return // } // fmt.Println(len(list)) // //return // //文章 // //list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ARTICLE) // //if err != nil { // // fmt.Println(err) // //} // for _, v := range list { // fmt.Println(v.ArticleId) // UpdateArticleResourceData(v.ArticleId) // } //} //{ // //文章//12.4 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ARTICLE) // if err != nil { // fmt.Println(err) // return // } // for _, v := range list { // detail, e := cygx.GetArticleDetailByArticleId(v.SourceId) // if e != nil { // err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error()) // fmt.Println(err) // return // } // // item := new(cygx.CygxResourceData) // if detail.ArticleTypeId > 0 { // //item.SearchTag = detail.ArticleTypeName // 研选类型名称 // item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN // } else { // //item.SearchTag = detail.MatchTypeName // //获取文章分类详情 // detailCategory, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId) // if detailCategory != nil { // item.ChartPermissionId = detailCategory.ChartPermissionId // }else{ // detailCategoryTwo, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryIdTwo) // if detailCategoryTwo != nil { // item.ChartPermissionId = detailCategoryTwo.ChartPermissionId // } // } // } // item.SourceId = v.SourceId // item.Source = utils.CYGX_OBJ_ARTICLE // fmt.Println(v.Source) // err = cygx.UpdateChartPermissionIdResourceDataByItem(item) // if err != nil { // fmt.Println(err) // return // } // } //} //{ // //产品内测 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_PRODUCTINTERIOR) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // UpdateProductInteriorResourceData(v.SourceId) // } //} // //{ // //晨会精华 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MEETINGREVIEWCHAPT) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // UpdateMeetingreviewchaptResourceData(v.SourceId) // } //} // //{ // //重点公司 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_REPORTSELECTION) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // //UpdateReportSelectionResourceData(v.SourceId) // } //} // //{ // //更新本周研究汇总 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_RESEARCHSUMMARY) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // //UpdateResearchSummaryResourceData(v.SourceId) // } //} // //{ // //更新本周研究汇总 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MINUTESSUMMARY) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // //UpdateMinutesSummaryResourceData(v.SourceId) // } //} //{ // //活动音频 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYVOICE) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // UpdateActivityVoiceResourceData(v.SourceId) // } //} //{ // //活动视频 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYVIDEO) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.SourceId) // UpdateActivityVideoResourceData(v.SourceId) // } //} //{ // //活动音频 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ROADSHOW) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.Source) // UpdateMicroRoadshowResourceData(v.SourceId) // } //} //{ // //问答系列视频 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ASKSERIEVIDEO) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.SourceId) // UpdateAskserieVideoResourceData(v.SourceId) // } //} //{ // //晨会精华 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MEETINGREVIEWCHAPT) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.SourceId) // UpdateMeetingreviewchaptResourceData(v.SourceId) // } //} //{ // //研选专栏 // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_YANXUANSPECIAL) // if err != nil { // fmt.Println(err) // } // for _, v := range list { // fmt.Println(v.SourceId) // UpdateYanxuanSpecialResourceData(v.SourceId) // } //} }