resource_data.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataResp, err error) {
  12. uid := user.UserId
  13. list, e := models.GetResourceDataList(condition, pars, startSize, pageSize)
  14. if e != nil {
  15. err = errors.New("GetResourceDataList, Err: " + e.Error())
  16. return
  17. }
  18. mapItems := make(map[string]*models.CygxResourceDataResp)
  19. for _, v := range list {
  20. //预处理文章
  21. item := new(models.CygxResourceDataResp)
  22. item.Id = v.Id
  23. item.SourceId = v.SourceId
  24. item.Source = v.Source
  25. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  26. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  27. }
  28. var articleIds []int
  29. var newchartIds []int
  30. var roadshowIds []string
  31. var activityIds []int
  32. var activityvideoIds []string
  33. var activityvoiceIds []string
  34. var activityspecialIds []int
  35. var researchsummaryIds []int
  36. var minutessummaryIds []int
  37. var meetingreviewchaptIds []int
  38. var productinteriorIds []int
  39. var reportselectionIds []int // 报告精选
  40. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
  41. for _, v := range list {
  42. if v.Source == "article" {
  43. articleIds = append(articleIds, v.SourceId)
  44. } else if v.Source == "newchart" {
  45. newchartIds = append(newchartIds, v.SourceId)
  46. } else if v.Source == "roadshow" {
  47. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  48. } else if v.Source == "activity" {
  49. activityIds = append(activityIds, v.SourceId)
  50. } else if v.Source == "activityvideo" {
  51. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  52. } else if v.Source == "activityvoice" {
  53. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  54. } else if v.Source == "activityspecial" {
  55. activityspecialIds = append(activityspecialIds, v.SourceId)
  56. } else if v.Source == "researchsummary" {
  57. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  58. } else if v.Source == "minutessummary" {
  59. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  60. } else if v.Source == "meetingreviewchapt" {
  61. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  62. } else if v.Source == "productinterior" {
  63. productinteriorIds = append(productinteriorIds, v.SourceId)
  64. } else if v.Source == "reportselection" {
  65. reportselectionIds = append(reportselectionIds, v.SourceId)
  66. }
  67. }
  68. //处理文章
  69. if len(articleIds) > 0 {
  70. pars = make([]interface{}, 0)
  71. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  72. pars = append(pars, articleIds)
  73. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  74. if e != nil {
  75. err = errors.New("GetResourceDataList, Err: " + e.Error())
  76. return
  77. }
  78. listArticle, e = HandleArticleCategoryImg(listArticle)
  79. if e != nil {
  80. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  81. return
  82. }
  83. for _, v := range listArticle {
  84. v.Body = ""
  85. v.BodyHtml = ""
  86. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  87. }
  88. }
  89. //处理晨会精华
  90. if len(meetingreviewchaptIds) > 0 {
  91. pars = make([]interface{}, 0)
  92. condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  93. pars = append(pars, meetingreviewchaptIds)
  94. listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  95. if e != nil {
  96. err = errors.New("GetResourceDataList, Err: " + e.Error())
  97. return
  98. }
  99. for _, v := range listrMeet {
  100. v.Content = AnnotationHtml(v.Content)
  101. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  102. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  103. }
  104. }
  105. //处理上周纪要汇总
  106. if len(minutessummaryIds) > 0 {
  107. pars = make([]interface{}, 0)
  108. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  109. pars = append(pars, minutessummaryIds)
  110. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  111. if e != nil {
  112. err = errors.New("GetResourceDataList, Err: " + e.Error())
  113. return
  114. }
  115. for _, v := range listresearchsummary {
  116. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  117. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  118. }
  119. }
  120. //处理本周纪要汇总
  121. if len(researchsummaryIds) > 0 {
  122. pars = make([]interface{}, 0)
  123. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  124. pars = append(pars, researchsummaryIds)
  125. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  126. if e != nil {
  127. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  128. return
  129. }
  130. for _, v := range listresearchsummary {
  131. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  132. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  133. }
  134. }
  135. //处理产品内测
  136. if len(productinteriorIds) > 0 {
  137. pars = make([]interface{}, 0)
  138. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  139. pars = append(pars, productinteriorIds)
  140. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  141. if e != nil {
  142. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  143. return
  144. }
  145. for _, v := range listProductInterior {
  146. v.Body = ProductInteriorHtml(v.Body)
  147. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  148. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  149. }
  150. }
  151. detail, e := models.GetConfigByCode("city_img_url")
  152. if e != nil {
  153. err = errors.New("GetResourceDataList, Err: " + e.Error())
  154. return
  155. }
  156. detailChart, e := models.GetConfigByCode("chart_img_url")
  157. if e != nil {
  158. err = errors.New("GetResourceDataList, Err: " + e.Error())
  159. return
  160. }
  161. addressList := strings.Split(detail.ConfigValue, "{|}")
  162. mapAddress := make(map[string]string)
  163. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  164. mapChart := make(map[string]string)
  165. var cityName string
  166. var chartName string
  167. var imgUrl string
  168. var imgUrlChart string
  169. for _, v := range addressList {
  170. vslice := strings.Split(v, "_")
  171. cityName = vslice[0]
  172. imgUrl = vslice[len(vslice)-1]
  173. mapAddress[cityName] = imgUrl
  174. }
  175. for _, v := range chartList {
  176. vslice := strings.Split(v, "_")
  177. chartName = vslice[0]
  178. imgUrlChart = vslice[len(vslice)-1]
  179. mapChart[chartName] = imgUrlChart
  180. }
  181. var imgUrlResp string
  182. //处理活动
  183. if len(activityIds) > 0 {
  184. for _, vss := range activityIds {
  185. imgUrlResp += strconv.Itoa(vss) + ","
  186. }
  187. pars = make([]interface{}, 0)
  188. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  189. pars = append(pars, activityIds)
  190. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  191. if e != nil {
  192. err = errors.New("GetResourceDataList, Err: " + e.Error())
  193. return
  194. }
  195. //处理不同的报名方式按钮回显
  196. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  197. if e != nil {
  198. e = errors.New("GetActivitySignupResp, Err: " + e.Error())
  199. return
  200. }
  201. var activityListRersp []*models.ActivityDetail
  202. for _, v := range activityList {
  203. v.SignupType = mapActivitySignup[v.ActivityId]
  204. //activityListRersp = append(activityListRersp, ActivityButtonShow(v))
  205. }
  206. activityListRersp = ActivityArrButtonShow(activityList)
  207. for _, v := range activityListRersp {
  208. if v == nil {
  209. continue
  210. }
  211. if v.ActivityType == 0 {
  212. if mapAddress[v.City] != "" {
  213. imgUrlResp = mapAddress[v.City]
  214. } else {
  215. imgUrlResp = mapAddress["其它"]
  216. }
  217. } else {
  218. if mapChart[v.ChartPermissionName] != "" {
  219. imgUrlResp = mapChart[v.ChartPermissionName]
  220. }
  221. }
  222. v.SourceType = 1
  223. v.Expert, _ = GetReportContentTextSub(v.Expert)
  224. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  225. }
  226. }
  227. //处理图表
  228. if len(newchartIds) > 0 {
  229. pars = make([]interface{}, 0)
  230. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  231. pars = append(pars, newchartIds)
  232. chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
  233. if e != nil {
  234. err = errors.New("GetResourceDataList, Err: " + e.Error())
  235. return
  236. }
  237. for _, v := range chartDateList {
  238. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  239. }
  240. }
  241. //处理专项调研
  242. if len(activityspecialIds) > 0 {
  243. pars = make([]interface{}, 0)
  244. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  245. pars = append(pars, activityspecialIds)
  246. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  247. if e != nil {
  248. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  249. return
  250. }
  251. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  252. if e != nil {
  253. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  254. return
  255. }
  256. for _, v := range activitySpeciallist {
  257. if mapChart[v.ChartPermissionName] != "" {
  258. imgUrlResp = mapChart[v.ChartPermissionName]
  259. }
  260. if _, ok := UserMap[v.ActivityId]; ok {
  261. v.IsTrip = 1
  262. }
  263. if v.Days == 0 {
  264. v.TripStatus = 1
  265. v.TripImgLink = v.TripImgLink
  266. } else {
  267. v.TripStatus = 2
  268. v.TripImgLink = v.TripImgLinkFix
  269. v.ActivityTimeText = v.ActivityTimeTextByDay
  270. }
  271. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  272. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  273. if resultTimeStart.After(time.Now()) {
  274. v.ActiveState = 1
  275. } else if time.Now().After(resultTimeEnd) {
  276. v.ActiveState = 3
  277. } else {
  278. v.ActiveState = 2
  279. }
  280. v.ImgUrl = imgUrlResp
  281. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  282. }
  283. }
  284. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  285. audioIdstr := strings.Join(activityvoiceIds, ",")
  286. ideoIdsStr := strings.Join(roadshowIds, ",")
  287. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  288. list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  289. if e != nil {
  290. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  291. return
  292. }
  293. for _, item := range list {
  294. if item.Type == 1 {
  295. //音频
  296. count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  297. if e != nil {
  298. err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  299. return
  300. }
  301. if count > 0 {
  302. item.IsCollect = true
  303. }
  304. } else if item.Type == 2 {
  305. //活动视频
  306. count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  307. if e != nil {
  308. err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  309. return
  310. }
  311. if count > 0 {
  312. item.IsCollect = true
  313. }
  314. } else if item.Type == 3 {
  315. //微路演视频
  316. count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  317. if e != nil {
  318. err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  319. return
  320. }
  321. if count > 0 {
  322. item.IsCollect = true
  323. }
  324. }
  325. }
  326. // 用户权限
  327. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  328. if e != nil {
  329. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  330. return
  331. }
  332. // 获取默认图配置
  333. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  334. if e != nil {
  335. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  336. return
  337. }
  338. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  339. for i := range list {
  340. // 权限
  341. au := new(models.UserPermissionAuthInfo)
  342. au.SellerName = authInfo.SellerName
  343. au.SellerMobile = authInfo.SellerMobile
  344. au.HasPermission = authInfo.HasPermission
  345. au.OperationMode = authInfo.OperationMode
  346. if au.HasPermission == 1 {
  347. // 非宏观权限进一步判断是否有权限
  348. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  349. au.HasPermission = 2
  350. }
  351. }
  352. // 无权限的弹框提示
  353. if au.HasPermission != 1 {
  354. if au.OperationMode == UserPermissionOperationModeCall {
  355. if list[i].Type == 1 {
  356. au.PopupMsg = UserPermissionPopupMsgCallActivity
  357. } else {
  358. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  359. }
  360. } else {
  361. if list[i].Type == 1 {
  362. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  363. } else {
  364. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  365. }
  366. }
  367. }
  368. list[i].AuthInfo = au
  369. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  370. // 默认图
  371. if list[i].BackgroundImg == "" {
  372. if list[i].Type == 1 {
  373. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  374. } else {
  375. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  376. }
  377. }
  378. // 分享图
  379. if list[i].ShareImg == "" {
  380. if list[i].Type == 1 {
  381. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  382. } else {
  383. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  384. }
  385. }
  386. }
  387. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  388. for _, item := range list {
  389. if item.Type == 1 {
  390. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  391. } else if item.Type == 2 {
  392. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  393. } else if item.Type == 3 {
  394. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  395. }
  396. }
  397. }
  398. //处理报告精选
  399. lenreportselectionIds := len(reportselectionIds)
  400. if lenreportselectionIds > 0 {
  401. pars = make([]interface{}, 0)
  402. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
  403. pars = append(pars, reportselectionIds)
  404. listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
  405. if e != nil {
  406. err = errors.New("GetReportSelectionList, Err: " + e.Error())
  407. return
  408. }
  409. for _, v := range listreportselection {
  410. v.Title += "(第" + v.Periods + "期)"
  411. v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
  412. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  413. mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
  414. }
  415. }
  416. for _, vList := range list {
  417. for _, v := range mapItems {
  418. //如果这些类型都为空,那么就不合并
  419. 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 {
  420. continue
  421. }
  422. if v.SourceId == vList.SourceId {
  423. items = append(items, v)
  424. }
  425. }
  426. }
  427. return
  428. }
  429. // 同步活动到最新数据表
  430. func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
  431. defer func() {
  432. if err != nil {
  433. go utils.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
  434. }
  435. }()
  436. if doType == "add" {
  437. item := new(models.CygxResourceData)
  438. item.SourceId = sourceId
  439. item.Source = source
  440. item.PublishDate = publishDate
  441. item.CreateTime = time.Now()
  442. _, err = models.AddCygxResourceData(item)
  443. } else if doType == "delete" {
  444. err = models.DeleteResourceData(sourceId, source)
  445. } else if doType == "update" {
  446. err = models.UpdateResourceData(sourceId, source, publishDate)
  447. }
  448. return
  449. }
  450. // 批量删除最新图表数据
  451. func Deletenewchart(chartIdsDelete []int) (err error) {
  452. defer func() {
  453. if err != nil {
  454. fmt.Println(err)
  455. go utils.SendAlarmMsg("批量删除最新图表数据,Err:"+err.Error(), 3)
  456. }
  457. }()
  458. lenchartIdsDelete := len(chartIdsDelete)
  459. if lenchartIdsDelete == 0 {
  460. return
  461. }
  462. var condition string
  463. var pars []interface{}
  464. condition += ` AND source = 'newchart' AND source_id IN (` + utils.GetOrmInReplace(lenchartIdsDelete) + `) `
  465. pars = append(pars, chartIdsDelete)
  466. err = models.DeleteResourceDataList(condition, pars)
  467. return
  468. }
  469. //func init() {
  470. // UpdateArticleResourceData(9050)
  471. //}
  472. // 更新文章
  473. func UpdateArticleResourceData(sourceId int) {
  474. var err error
  475. defer func() {
  476. if err != nil {
  477. fmt.Println("err:", err)
  478. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  479. }
  480. }()
  481. var source = utils.CYGX_OBJ_ARTICLE
  482. var condition string
  483. var pars []interface{}
  484. condition = ` AND publish_status = 1 AND article_id = ? `
  485. pars = append(pars, sourceId)
  486. total, e := models.GetCygxArticleCount(condition, pars)
  487. if e != nil {
  488. err = errors.New("GetCygxReportSelection, Err: " + err.Error())
  489. return
  490. }
  491. //如果取消发布了就做删除处理
  492. if total == 0 {
  493. e = models.DeleteResourceData(sourceId, source)
  494. if e != nil {
  495. err = errors.New("DeleteResourceData, Err: " + e.Error())
  496. return
  497. }
  498. //删除 cygx_resource_data 表关联的产业ID,标的ID
  499. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  500. if e != nil {
  501. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  502. return
  503. }
  504. } else {
  505. //判断是否存在,如果不存在就新增,存在就更新
  506. totalData, e := models.GetCygxReportSelectionBySourceAndId(sourceId, source)
  507. if e != nil {
  508. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  509. return
  510. }
  511. detail, e := models.GetArticleDetailById(sourceId)
  512. if e != nil {
  513. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  514. return
  515. }
  516. var resourceDataId int
  517. publishDate := time.Now().Format(utils.FormatDateTime)
  518. item := new(models.CygxResourceData)
  519. if detail.ArticleTypeId > 0 {
  520. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  521. } else {
  522. item.SearchTag = detail.MatchTypeName
  523. }
  524. item.SourceId = sourceId
  525. item.Source = source
  526. item.PublishDate = publishDate
  527. item.CreateTime = time.Now()
  528. if totalData == 0 {
  529. newId, e := models.AddCygxResourceData(item)
  530. if e != nil {
  531. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  532. return
  533. }
  534. resourceDataId = int(newId)
  535. } else {
  536. e = models.UpdateResourceDataByItem(item)
  537. if e != nil {
  538. err = errors.New("UpdateResourceData, Err: " + e.Error())
  539. return
  540. }
  541. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  542. if e != nil {
  543. err = errors.New("UpdateResourceData, Err: " + e.Error())
  544. return
  545. }
  546. resourceDataId = sourceDetail.Id
  547. }
  548. //建立首页资源表,与产业的关系
  549. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  550. if e != nil && e.Error() != utils.ErrNoRow() {
  551. err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  552. return
  553. }
  554. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  555. for _, v := range industrialList {
  556. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  557. industrialItem.SourceId = sourceId
  558. industrialItem.Source = source
  559. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  560. industrialItem.ResourceDataId = resourceDataId
  561. industrialItem.CreateTime = time.Now()
  562. industrialItems = append(industrialItems, industrialItem)
  563. }
  564. //建立首页资源表,与标的 的关系
  565. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  566. if e != nil && e.Error() != utils.ErrNoRow() {
  567. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  568. return
  569. }
  570. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  571. for _, v := range subjectList {
  572. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  573. subjectItem.SourceId = sourceId
  574. subjectItem.Source = source
  575. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  576. subjectItem.ResourceDataId = resourceDataId
  577. subjectItem.CreateTime = time.Now()
  578. subjectItems = append(subjectItems, subjectItem)
  579. }
  580. //插入关联信息
  581. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  582. if e != nil {
  583. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  584. return
  585. }
  586. }
  587. return
  588. }