|
@@ -494,3 +494,128 @@ func Deletenewchart(chartIdsDelete []int) (err error) {
|
|
|
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.GetCygxReportSelectionBySourceAndId(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
|
|
|
+ }
|
|
|
+ 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
|
|
|
+}
|