resource_data.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/models/ficc_report"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataResp, err error) {
  13. uid := user.UserId
  14. list, e := models.GetResourceDataList(condition, pars, startSize, pageSize)
  15. if e != nil {
  16. err = errors.New("GetResourceDataList, Err: " + e.Error())
  17. return
  18. }
  19. mapItems := make(map[string]*models.CygxResourceDataResp)
  20. for _, v := range list {
  21. //预处理文章
  22. item := new(models.CygxResourceDataResp)
  23. item.Id = v.Id
  24. item.SourceId = v.SourceId
  25. item.Source = v.Source
  26. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  27. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  28. }
  29. var articleIds []int
  30. var newchartIds []int
  31. var roadshowIds []string
  32. var activityIds []int
  33. var activityvideoIds []string
  34. var activityvoiceIds []string
  35. var activityspecialIds []int
  36. var researchsummaryIds []int
  37. var minutessummaryIds []int
  38. var meetingreviewchaptIds []int
  39. var productinteriorIds []int
  40. var reportselectionIds []int // 报告精选
  41. var yanxuanSpecialIds []int // 研选专栏
  42. var askserieVideoIds []string //问答系列视频
  43. var ficcreporrtIds []string //FICC研报
  44. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
  45. for _, v := range list {
  46. if v.Source == "article" {
  47. articleIds = append(articleIds, v.SourceId)
  48. } else if v.Source == "newchart" {
  49. newchartIds = append(newchartIds, v.SourceId)
  50. } else if v.Source == "roadshow" {
  51. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  52. } else if v.Source == "activity" {
  53. activityIds = append(activityIds, v.SourceId)
  54. } else if v.Source == "activityvideo" {
  55. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  56. } else if v.Source == "activityvoice" {
  57. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  58. } else if v.Source == "activityspecial" {
  59. activityspecialIds = append(activityspecialIds, v.SourceId)
  60. } else if v.Source == "researchsummary" {
  61. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  62. } else if v.Source == "minutessummary" {
  63. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  64. } else if v.Source == "meetingreviewchapt" {
  65. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  66. } else if v.Source == "productinterior" {
  67. productinteriorIds = append(productinteriorIds, v.SourceId)
  68. } else if v.Source == "reportselection" {
  69. reportselectionIds = append(reportselectionIds, v.SourceId)
  70. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  71. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  72. } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
  73. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
  74. } else if v.Source == utils.CYGX_OBJ_FICC_REPORT {
  75. ficcreporrtIds = append(ficcreporrtIds, strconv.Itoa(v.SourceId))
  76. }
  77. }
  78. //处理文章
  79. if len(articleIds) > 0 {
  80. pars = make([]interface{}, 0)
  81. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  82. pars = append(pars, articleIds)
  83. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  84. if e != nil {
  85. err = errors.New("GetResourceDataList, Err: " + e.Error())
  86. return
  87. }
  88. listArticle, e = HandleArticleCategoryImg(listArticle)
  89. if e != nil {
  90. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  91. return
  92. }
  93. for _, v := range listArticle {
  94. v.Body = ""
  95. v.BodyHtml = ""
  96. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  97. }
  98. }
  99. //处理晨会精华
  100. if len(meetingreviewchaptIds) > 0 {
  101. //pars = make([]interface{}, 0)
  102. //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  103. //pars = append(pars, meetingreviewchaptIds)
  104. listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
  105. if e != nil {
  106. err = errors.New("GetCygxMorningMeetingReviewChapterListByIds, Err: " + e.Error())
  107. return
  108. }
  109. for _, v := range listrMeet {
  110. v.Content = AnnotationHtml(v.Content)
  111. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  112. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  113. }
  114. }
  115. //处理上周纪要汇总
  116. if len(minutessummaryIds) > 0 {
  117. pars = make([]interface{}, 0)
  118. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  119. pars = append(pars, minutessummaryIds)
  120. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  121. if e != nil {
  122. err = errors.New("GetResourceDataList, Err: " + e.Error())
  123. return
  124. }
  125. mapPv := GetCygxReportHistoryRecordListMap(minutessummaryIds, "szjyhz")
  126. for _, v := range listresearchsummary {
  127. v.Pv = mapPv[v.ArticleId]
  128. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  129. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  130. }
  131. }
  132. //处理本周纪要汇总
  133. if len(researchsummaryIds) > 0 {
  134. pars = make([]interface{}, 0)
  135. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  136. pars = append(pars, researchsummaryIds)
  137. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  138. if e != nil {
  139. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  140. return
  141. }
  142. mapPv := GetCygxReportHistoryRecordListMap(researchsummaryIds, "bzyjhz")
  143. for _, v := range listresearchsummary {
  144. v.Pv = mapPv[v.ArticleId]
  145. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  146. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  147. }
  148. }
  149. //处理产品内测
  150. if len(productinteriorIds) > 0 {
  151. pars = make([]interface{}, 0)
  152. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  153. pars = append(pars, productinteriorIds)
  154. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  155. if e != nil {
  156. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  157. return
  158. }
  159. ProductInteriorHistoryMap := GetCygxProductInteriorHistoryListPvMap(productinteriorIds)
  160. for _, v := range listProductInterior {
  161. v.Body = ProductInteriorHtml(v.Body)
  162. v.Pv = ProductInteriorHistoryMap[v.ProductInteriorId]
  163. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  164. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  165. }
  166. }
  167. detail, e := models.GetConfigByCode("city_img_url")
  168. if e != nil {
  169. err = errors.New("GetResourceDataList, Err: " + e.Error())
  170. return
  171. }
  172. detailChart, e := models.GetConfigByCode("chart_img_url")
  173. if e != nil {
  174. err = errors.New("GetResourceDataList, Err: " + e.Error())
  175. return
  176. }
  177. addressList := strings.Split(detail.ConfigValue, "{|}")
  178. mapAddress := make(map[string]string)
  179. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  180. mapChart := make(map[string]string)
  181. var cityName string
  182. var chartName string
  183. var imgUrl string
  184. var imgUrlChart string
  185. for _, v := range addressList {
  186. vslice := strings.Split(v, "_")
  187. cityName = vslice[0]
  188. imgUrl = vslice[len(vslice)-1]
  189. mapAddress[cityName] = imgUrl
  190. }
  191. for _, v := range chartList {
  192. vslice := strings.Split(v, "_")
  193. chartName = vslice[0]
  194. imgUrlChart = vslice[len(vslice)-1]
  195. mapChart[chartName] = imgUrlChart
  196. }
  197. var imgUrlResp string
  198. //处理活动
  199. if len(activityIds) > 0 {
  200. for _, vss := range activityIds {
  201. imgUrlResp += strconv.Itoa(vss) + ","
  202. }
  203. pars = make([]interface{}, 0)
  204. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  205. pars = append(pars, activityIds)
  206. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  207. if e != nil {
  208. err = errors.New("GetResourceDataList, Err: " + e.Error())
  209. return
  210. }
  211. //处理不同的报名方式按钮回显
  212. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  213. if e != nil {
  214. e = errors.New("GetActivitySignupResp, Err: " + e.Error())
  215. return
  216. }
  217. var activityListRersp []*models.ActivityDetail
  218. for _, v := range activityList {
  219. v.SignupType = mapActivitySignup[v.ActivityId]
  220. //activityListRersp = append(activityListRersp, ActivityButtonShow(v))
  221. }
  222. activityListRersp = ActivityArrButtonShow(activityList)
  223. for _, v := range activityListRersp {
  224. if v == nil {
  225. continue
  226. }
  227. if v.ActivityType == 0 {
  228. if mapAddress[v.City] != "" {
  229. imgUrlResp = mapAddress[v.City]
  230. } else {
  231. imgUrlResp = mapAddress["其它"]
  232. }
  233. } else {
  234. if mapChart[v.ChartPermissionName] != "" {
  235. imgUrlResp = mapChart[v.ChartPermissionName]
  236. }
  237. }
  238. v.SourceType = 1
  239. v.Expert, _ = GetReportContentTextSub(v.Expert)
  240. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  241. }
  242. }
  243. //处理图表
  244. if len(newchartIds) > 0 {
  245. pars = make([]interface{}, 0)
  246. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  247. pars = append(pars, newchartIds)
  248. chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
  249. if e != nil {
  250. err = errors.New("GetResourceDataList, Err: " + e.Error())
  251. return
  252. }
  253. for _, v := range chartDateList {
  254. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  255. }
  256. }
  257. //处理专项调研
  258. if len(activityspecialIds) > 0 {
  259. pars = make([]interface{}, 0)
  260. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  261. pars = append(pars, activityspecialIds)
  262. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  263. if e != nil {
  264. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  265. return
  266. }
  267. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  268. if e != nil {
  269. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  270. return
  271. }
  272. for _, v := range activitySpeciallist {
  273. if mapChart[v.ChartPermissionName] != "" {
  274. imgUrlResp = mapChart[v.ChartPermissionName]
  275. }
  276. if _, ok := UserMap[v.ActivityId]; ok {
  277. v.IsTrip = 1
  278. }
  279. if v.Days == 0 {
  280. v.TripStatus = 1
  281. v.TripImgLink = v.TripImgLink
  282. } else {
  283. v.TripStatus = 2
  284. v.TripImgLink = v.TripImgLinkFix
  285. v.ActivityTimeText = v.ActivityTimeTextByDay
  286. }
  287. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  288. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  289. if resultTimeStart.After(time.Now()) {
  290. v.ActiveState = 1
  291. } else if time.Now().After(resultTimeEnd) {
  292. v.ActiveState = 3
  293. } else {
  294. v.ActiveState = 2
  295. }
  296. v.ImgUrl = imgUrlResp
  297. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  298. }
  299. }
  300. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  301. audioIdstr := strings.Join(activityvoiceIds, ",")
  302. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  303. roadshowIdsStr := strings.Join(roadshowIds, ",")
  304. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  305. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  306. if e != nil {
  307. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  308. return
  309. }
  310. // 用户权限
  311. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  312. if e != nil {
  313. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  314. return
  315. }
  316. // 获取默认图配置
  317. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  318. if e != nil {
  319. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  320. return
  321. }
  322. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  323. for i := range list {
  324. // 权限
  325. au := new(models.UserPermissionAuthInfo)
  326. au.SellerName = authInfo.SellerName
  327. au.SellerMobile = authInfo.SellerMobile
  328. au.HasPermission = authInfo.HasPermission
  329. au.OperationMode = authInfo.OperationMode
  330. if au.HasPermission == 1 {
  331. // 非宏观权限进一步判断是否有权限
  332. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  333. au.HasPermission = 2
  334. }
  335. }
  336. // 无权限的弹框提示
  337. if au.HasPermission != 1 {
  338. if au.OperationMode == UserPermissionOperationModeCall {
  339. if list[i].Type == 1 {
  340. au.PopupMsg = UserPermissionPopupMsgCallActivity
  341. } else {
  342. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  343. }
  344. } else {
  345. if list[i].Type == 1 {
  346. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  347. } else {
  348. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  349. }
  350. }
  351. }
  352. list[i].AuthInfo = au
  353. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  354. // 默认图
  355. if list[i].BackgroundImg == "" {
  356. if list[i].Type == 1 {
  357. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  358. } else {
  359. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  360. }
  361. }
  362. // 分享图
  363. if list[i].ShareImg == "" {
  364. if list[i].Type == 1 {
  365. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  366. } else {
  367. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  368. }
  369. }
  370. }
  371. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  372. for _, item := range list {
  373. if item.Type == 1 {
  374. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  375. } else if item.Type == 2 {
  376. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  377. } else if item.Type == 3 {
  378. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  379. } else if item.Type == 4 {
  380. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  381. }
  382. }
  383. }
  384. //处理报告精选
  385. lenreportselectionIds := len(reportselectionIds)
  386. if lenreportselectionIds > 0 {
  387. pars = make([]interface{}, 0)
  388. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
  389. pars = append(pars, reportselectionIds)
  390. listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
  391. if e != nil {
  392. err = errors.New("GetReportSelectionList, Err: " + e.Error())
  393. return
  394. }
  395. mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
  396. for _, v := range listreportselection {
  397. v.Title += "(第" + v.Periods + "期)"
  398. v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
  399. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  400. v.Pv = mapPv[v.ArticleId]
  401. mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
  402. }
  403. }
  404. //处理研选专栏
  405. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  406. if lenyanxuanSpecialIds > 0 {
  407. pars = make([]interface{}, 0)
  408. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  409. pars = append(pars, yanxuanSpecialIds)
  410. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  411. if e != nil {
  412. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  413. return
  414. }
  415. for _, v := range listyanxuanSpecial {
  416. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  417. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  418. // Source PublishDate 字段兼容前端样式
  419. v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  420. v.PublishDate = v.PublishTime
  421. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  422. }
  423. }
  424. //处理FICC研报
  425. if len(ficcreporrtIds) > 0 {
  426. pars = make([]interface{}, 0)
  427. condition = ` AND a.report_id IN (` + utils.GetOrmInReplace(len(ficcreporrtIds)) + `)`
  428. pars = append(pars, ficcreporrtIds)
  429. listArticle, e := models.GetHomeList(condition, pars, 0, len(ficcreporrtIds))
  430. if e != nil {
  431. err = errors.New("GetHomeList, Err: " + e.Error())
  432. return
  433. }
  434. listArticle, e = HandleArticleCategoryImg(listArticle)
  435. if e != nil {
  436. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  437. return
  438. }
  439. for _, v := range listArticle {
  440. //fmt.Println(v.ArticleId)
  441. v.Body = ""
  442. v.Source = 0 //配合前端这里强制改为 0
  443. v.ArticleResponse = 0 //配合前端这里强制改为 0
  444. //v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  445. mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
  446. }
  447. //listArticle, e = HandleArticleCategoryImg(listArticle)
  448. //if e != nil {
  449. // err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  450. // return
  451. //}
  452. //for _, v := range listArticle {
  453. // //reportInfoItem := new(ficc_report.ReportDetail)
  454. // //reportInfoItem.ReportInfo.ReportId = v.ReportId
  455. // //reportInfoItem.ReportInfo.PublishTime = utils.StrTimeToTime(v.PublishDate)
  456. // //reportInfoItem.ReportInfo.Title = v.Title
  457. // mapItems[fmt.Sprint("ficcreport", v.ArticleId)].FiccReport = v
  458. //
  459. //}
  460. }
  461. for _, vList := range list {
  462. for _, v := range mapItems {
  463. //如果这些类型都为空,那么就不合并
  464. 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 {
  465. continue
  466. }
  467. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  468. items = append(items, v)
  469. }
  470. }
  471. }
  472. return
  473. }
  474. // 同步活动到最新数据表
  475. func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
  476. defer func() {
  477. if err != nil {
  478. go utils.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
  479. }
  480. }()
  481. if doType == "add" {
  482. item := new(models.CygxResourceData)
  483. item.SourceId = sourceId
  484. item.Source = source
  485. item.PublishDate = publishDate
  486. item.CreateTime = time.Now()
  487. _, err = models.AddCygxResourceData(item)
  488. } else if doType == "delete" {
  489. err = models.DeleteResourceData(sourceId, source)
  490. } else if doType == "update" {
  491. err = models.UpdateResourceData(sourceId, source, publishDate)
  492. }
  493. return
  494. }
  495. //func init130() {
  496. // //UpdateNewchartResourceData(5509)
  497. //
  498. // var condition string
  499. // var pars []interface{}
  500. // condition += ` AND publish_status = 1 `
  501. //
  502. // list, e := models.GetChartList(condition, pars, 0, 1000000)
  503. // if e != nil {
  504. // fmt.Println(e)
  505. // return
  506. // }
  507. //
  508. // for _, v := range list {
  509. // fmt.Println(v.ChartId)
  510. // UpdateNewchartResourceData(v.ChartId)
  511. // }
  512. //}
  513. // 更新图表
  514. func UpdateNewchartResourceData(sourceId int) {
  515. var err error
  516. defer func() {
  517. if err != nil {
  518. go utils.SendAlarmMsg("更新图表同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型", 3)
  519. }
  520. }()
  521. var source = utils.CYGX_OBJ_NEWCHART
  522. var condition string
  523. var pars []interface{}
  524. condition = ` AND chart_id = ? `
  525. pars = append(pars, sourceId)
  526. total, e := models.GetChartCount(condition, pars)
  527. if e != nil {
  528. err = errors.New("GetChartCount, Err: " + e.Error())
  529. return
  530. }
  531. //如果取消发布了就做删除处理
  532. if total == 0 {
  533. e = models.DeleteResourceData(sourceId, source)
  534. if e != nil {
  535. err = errors.New("DeleteResourceData, Err: " + e.Error())
  536. return
  537. }
  538. } else {
  539. //判断是否存在,如果不存在就新增,存在就更新
  540. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  541. if e != nil {
  542. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  543. return
  544. }
  545. detail, e := models.GetChartDetailByChartId(sourceId)
  546. if e != nil {
  547. err = errors.New("GetArticleDetailById, Err: " + e.Error())
  548. return
  549. }
  550. publishDate := detail.CreateDate
  551. item := new(models.CygxResourceData)
  552. item.SourceId = sourceId
  553. item.Source = source
  554. item.PublishDate = publishDate
  555. item.CreateTime = time.Now()
  556. item.SearchTitle = detail.Title
  557. item.SearchContent = ""
  558. item.SearchOrderTime = detail.CreateDate
  559. if totalData == 0 {
  560. _, e = models.AddCygxResourceData(item)
  561. if e != nil {
  562. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  563. return
  564. }
  565. } else {
  566. e = models.UpdateResourceDataByItem(item)
  567. if e != nil {
  568. err = errors.New("UpdateResourceData, Err: " + e.Error())
  569. return
  570. }
  571. }
  572. }
  573. return
  574. }
  575. // 批量删除最新图表数据
  576. func Deletenewchart(chartIdsDelete []int) (err error) {
  577. defer func() {
  578. if err != nil {
  579. fmt.Println(err)
  580. go utils.SendAlarmMsg("批量删除最新图表数据,Err:"+err.Error(), 3)
  581. }
  582. }()
  583. lenchartIdsDelete := len(chartIdsDelete)
  584. if lenchartIdsDelete == 0 {
  585. return
  586. }
  587. var condition string
  588. var pars []interface{}
  589. condition += ` AND source = 'newchart' AND source_id IN (` + utils.GetOrmInReplace(lenchartIdsDelete) + `) `
  590. pars = append(pars, chartIdsDelete)
  591. err = models.DeleteResourceDataList(condition, pars)
  592. return
  593. }
  594. //func init() {
  595. // UpdateArticleResourceData(9050)
  596. //}
  597. // 更新文章
  598. func UpdateArticleResourceData(sourceId int) {
  599. time.Sleep(1 * time.Second)
  600. var err error
  601. defer func() {
  602. if err != nil {
  603. fmt.Println("err:", err)
  604. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  605. }
  606. }()
  607. var source = utils.CYGX_OBJ_ARTICLE
  608. var condition string
  609. var pars []interface{}
  610. condition = ` AND publish_status = 1 AND article_id = ? `
  611. pars = append(pars, sourceId)
  612. total, e := models.GetCygxArticleCount(condition, pars)
  613. if e != nil {
  614. err = errors.New("GetCygxReportSelection, Err: " + err.Error())
  615. return
  616. }
  617. //如果取消发布了就做删除处理
  618. if total == 0 {
  619. e = models.DeleteResourceData(sourceId, source)
  620. if e != nil {
  621. err = errors.New("DeleteResourceData, Err: " + e.Error())
  622. return
  623. }
  624. //删除 cygx_resource_data 表关联的产业ID,标的ID
  625. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  626. if e != nil {
  627. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  628. return
  629. }
  630. } else {
  631. //判断是否存在,如果不存在就新增,存在就更新
  632. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  633. if e != nil {
  634. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  635. return
  636. }
  637. detail, e := models.GetArticleDetailById(sourceId)
  638. if e != nil {
  639. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  640. return
  641. }
  642. var resourceDataId int
  643. publishDate := time.Now().Format(utils.FormatDateTime)
  644. item := new(models.CygxResourceData)
  645. if detail.ArticleTypeId > 0 {
  646. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  647. } else {
  648. item.SearchTag = detail.MatchTypeName
  649. if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
  650. item.SearchTag = ""
  651. }
  652. //获取文章分类详情
  653. detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  654. if detailCategory != nil {
  655. item.ChartPermissionId = detailCategory.ChartPermissionId
  656. }
  657. }
  658. var industrialName string
  659. var subjectName string
  660. //建立首页资源表,与产业的关系
  661. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  662. if e != nil && e.Error() != utils.ErrNoRow() {
  663. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  664. return
  665. }
  666. for _, v := range industrialList {
  667. industrialName += v.IndustryName
  668. }
  669. //建立首页资源表,与标的 的关系
  670. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  671. if e != nil && e.Error() != utils.ErrNoRow() {
  672. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  673. return
  674. }
  675. for _, v := range subjectList {
  676. subjectName += v.SubjectName
  677. }
  678. item.SourceId = sourceId
  679. item.Source = source
  680. item.PublishDate = publishDate
  681. item.CreateTime = time.Now()
  682. item.SearchTitle = detail.Title
  683. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  684. if e != nil && e.Error() != utils.ErrNoRow() {
  685. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  686. return
  687. }
  688. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  689. if e != nil && e.Error() != utils.ErrNoRow() {
  690. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  691. return
  692. }
  693. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  694. item.SearchOrderTime = detail.PublishDate
  695. if totalData == 0 {
  696. newId, e := models.AddCygxResourceData(item)
  697. if e != nil {
  698. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  699. return
  700. }
  701. resourceDataId = int(newId)
  702. } else {
  703. e = models.UpdateResourceDataByItem(item)
  704. if e != nil {
  705. err = errors.New("UpdateResourceData, Err: " + e.Error())
  706. return
  707. }
  708. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  709. if e != nil {
  710. err = errors.New("UpdateResourceData, Err: " + e.Error())
  711. return
  712. }
  713. resourceDataId = sourceDetail.Id
  714. }
  715. //建立首页资源表,与产业的关系
  716. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  717. for _, v := range industrialList {
  718. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  719. industrialItem.SourceId = sourceId
  720. industrialItem.Source = source
  721. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  722. industrialItem.ResourceDataId = resourceDataId
  723. industrialItem.CreateTime = time.Now()
  724. industrialItems = append(industrialItems, industrialItem)
  725. }
  726. //建立首页资源表,与标的 的关系
  727. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  728. for _, v := range subjectList {
  729. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  730. subjectItem.SourceId = sourceId
  731. subjectItem.Source = source
  732. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  733. subjectItem.ResourceDataId = resourceDataId
  734. subjectItem.CreateTime = time.Now()
  735. subjectItems = append(subjectItems, subjectItem)
  736. }
  737. //插入关联信息
  738. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  739. if e != nil {
  740. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  741. return
  742. }
  743. }
  744. return
  745. }
  746. // 更新产业资源包
  747. func UpdateComprehensiveIndustrialResourceData(itemSource *ElasticComprehensiveDetail) {
  748. var err error
  749. defer func() {
  750. if err != nil {
  751. go utils.SendAlarmMsg("更新产业资源包到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(itemSource.SourceId), 3)
  752. }
  753. }()
  754. sourceId := itemSource.SourceId
  755. var source = itemSource.Source
  756. //判断是否存在,如果不存在就新增,存在就更新
  757. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  758. if e != nil {
  759. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  760. return
  761. }
  762. item := new(models.CygxResourceData)
  763. item.SourceId = sourceId
  764. item.Source = source
  765. item.PublishDate = itemSource.PublishDate
  766. item.CreateTime = time.Now()
  767. item.SearchTitle = itemSource.IndustryName + itemSource.SubjectNames
  768. item.SearchContent = ""
  769. item.SearchOrderTime = itemSource.PublishDate
  770. if totalData == 0 {
  771. _, e = models.AddCygxResourceData(item)
  772. if e != nil {
  773. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  774. return
  775. }
  776. } else {
  777. e = models.UpdateResourceDataByItem(item)
  778. if e != nil {
  779. err = errors.New("UpdateResourceData, Err: " + e.Error())
  780. return
  781. }
  782. }
  783. return
  784. }
  785. // 更新研选专栏 写入首页最新 cygx_resource_data 表
  786. func UpdateYanxuanSpecialResourceData(sourceId int) {
  787. var err error
  788. defer func() {
  789. if err != nil {
  790. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 2)
  791. }
  792. }()
  793. var source = utils.CYGX_OBJ_YANXUANSPECIAL
  794. var condition string
  795. var pars []interface{}
  796. condition = ` AND status = 3 AND id = ? `
  797. pars = append(pars, sourceId)
  798. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  799. if e != nil {
  800. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  801. return
  802. }
  803. //如果取消发布了就做删除处理
  804. if total == 0 {
  805. e = models.DeleteResourceData(sourceId, source)
  806. if e != nil {
  807. err = errors.New("DeleteResourceData, Err: " + e.Error())
  808. return
  809. }
  810. } else {
  811. //判断是否存在,如果不存在就新增,存在就更新
  812. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  813. if e != nil {
  814. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  815. return
  816. }
  817. detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
  818. if e != nil {
  819. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  820. return
  821. }
  822. publishDate := detail.PublishTime
  823. item := new(models.CygxResourceData)
  824. item.SourceId = sourceId
  825. item.Source = source
  826. item.PublishDate = publishDate
  827. item.CreateTime = time.Now()
  828. item.SearchTitle = detail.Title
  829. item.SearchContent = ""
  830. item.SearchOrderTime = publishDate
  831. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  832. if totalData == 0 {
  833. _, e := models.AddCygxResourceData(item)
  834. if e != nil {
  835. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  836. return
  837. }
  838. } else {
  839. e = models.UpdateResourceDataByItem(item)
  840. if e != nil {
  841. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  842. return
  843. }
  844. }
  845. }
  846. return
  847. }
  848. func initsql12_17() {
  849. listIndustrialResourceIds, e := models.GetSearchResourceList(0, " AND article_type_id > 0 ", 0, 9999)
  850. if e != nil {
  851. fmt.Println(e)
  852. return
  853. }
  854. var industrialResourceIdsHz []int
  855. for _, v := range listIndustrialResourceIds {
  856. industrialResourceIdsHz = append(industrialResourceIdsHz, v.IndustrialManagementId)
  857. }
  858. //date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  859. //合并产业关联的标的
  860. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsHz)
  861. if e != nil {
  862. fmt.Println(e)
  863. return
  864. }
  865. mapIndustrial := make(map[string]int)
  866. for _, v := range listSubjcet {
  867. for k2, v2 := range listIndustrialResourceIds {
  868. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  869. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  870. }
  871. }
  872. }
  873. //industrialsource := "industrialsourceHz"
  874. industrialsource := "industrialsourceYx"
  875. for _, v := range listIndustrialResourceIds {
  876. item := new(ElasticComprehensiveDetail)
  877. item.SourceId = v.IndustrialManagementId
  878. item.Source = industrialsource
  879. item.IndustryName = v.IndustryName
  880. var SubjectName []string
  881. for _, vN := range v.IndustrialSubjectList {
  882. SubjectName = append(SubjectName, vN.SubjectName)
  883. }
  884. item.SubjectNames = strings.Join(SubjectName, ",")
  885. item.PublishDate = v.PublishDate
  886. fmt.Println(item)
  887. UpdateComprehensiveIndustrialResourceData(item)
  888. }
  889. return
  890. }
  891. // 更新FICC研报
  892. func UpdateFICCReportResourceData(sourceId int, listFiccSet *ficc_report.GetReporteSetListResp) {
  893. var err error
  894. defer func() {
  895. if err != nil {
  896. fmt.Println("err:", err)
  897. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  898. }
  899. }()
  900. var source = utils.CYGX_OBJ_FICC_REPORT
  901. var condition string
  902. var pars []interface{}
  903. condition = ` AND publish_status = 1 AND report_id = ? `
  904. pars = append(pars, sourceId)
  905. total, e := models.GetCygxArticleCount(condition, pars)
  906. if e != nil {
  907. err = errors.New("GetCygxArticleCount, Err: " + err.Error())
  908. return
  909. }
  910. //如果取消发布了就做删除处理
  911. if total == 0 {
  912. e = models.DeleteResourceData(sourceId, source)
  913. if e != nil {
  914. err = errors.New("DeleteResourceData, Err: " + e.Error())
  915. return
  916. }
  917. //删除 cygx_resource_data 表关联的产业ID,标的ID
  918. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  919. if e != nil {
  920. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  921. return
  922. }
  923. } else {
  924. //判断是否存在,如果不存在就新增,存在就更新
  925. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  926. if e != nil {
  927. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  928. return
  929. }
  930. detail, e := models.GetArticleDetailByReportId(sourceId)
  931. if e != nil {
  932. err = errors.New("GetArticleDetailByReportId, Err: " + e.Error())
  933. return
  934. }
  935. var resourceDataId int
  936. publishDate := time.Now().Format(utils.FormatDateTime)
  937. item := new(models.CygxResourceData)
  938. if detail.ArticleTypeId > 0 {
  939. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  940. } else {
  941. item.SearchTag = detail.MatchTypeName
  942. if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
  943. item.SearchTag = ""
  944. }
  945. //获取文章分类详情
  946. detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  947. if detailCategory != nil {
  948. item.ChartPermissionId = detailCategory.ChartPermissionId
  949. }
  950. }
  951. var industrialName string
  952. var subjectName string
  953. //建立首页资源表,与产业的关系
  954. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  955. if e != nil && e.Error() != utils.ErrNoRow() {
  956. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  957. return
  958. }
  959. for _, v := range industrialList {
  960. industrialName += v.IndustryName
  961. }
  962. //建立首页资源表,与标的 的关系
  963. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  964. if e != nil && e.Error() != utils.ErrNoRow() {
  965. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  966. return
  967. }
  968. for _, v := range subjectList {
  969. subjectName += v.SubjectName
  970. }
  971. item.SourceId = sourceId
  972. item.Source = source
  973. item.PublishDate = publishDate
  974. item.CreateTime = time.Now()
  975. item.SearchTitle = detail.Title
  976. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  977. if e != nil && e.Error() != utils.ErrNoRow() {
  978. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  979. return
  980. }
  981. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  982. if e != nil && e.Error() != utils.ErrNoRow() {
  983. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  984. return
  985. }
  986. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  987. item.SearchOrderTime = detail.PublishDate
  988. //跟踪、深度、纪要三个自定义的搜索标签
  989. for _, vSt := range listFiccSet.List {
  990. if item.SearchTag == vSt.ClassifyNameSecond {
  991. item.TagName = vSt.TagName
  992. }
  993. }
  994. if totalData == 0 {
  995. newId, e := models.AddCygxResourceData(item)
  996. if e != nil {
  997. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  998. return
  999. }
  1000. resourceDataId = int(newId)
  1001. } else {
  1002. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  1003. if e != nil {
  1004. err = errors.New("UpdateResourceData, Err: " + e.Error())
  1005. return
  1006. }
  1007. item.PublishDate = sourceDetail.PublishDate
  1008. item.SearchOrderTime = sourceDetail.SearchOrderTime
  1009. e = models.UpdateResourceDataByItem(item)
  1010. if e != nil {
  1011. err = errors.New("UpdateResourceData, Err: " + e.Error())
  1012. return
  1013. }
  1014. resourceDataId = sourceDetail.Id
  1015. }
  1016. //建立首页资源表,与产业的关系
  1017. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  1018. for _, v := range industrialList {
  1019. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  1020. industrialItem.SourceId = sourceId
  1021. industrialItem.Source = source
  1022. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  1023. industrialItem.ResourceDataId = resourceDataId
  1024. industrialItem.CreateTime = time.Now()
  1025. industrialItems = append(industrialItems, industrialItem)
  1026. }
  1027. //建立首页资源表,与标的 的关系
  1028. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  1029. for _, v := range subjectList {
  1030. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  1031. subjectItem.SourceId = sourceId
  1032. subjectItem.Source = source
  1033. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  1034. subjectItem.ResourceDataId = resourceDataId
  1035. subjectItem.CreateTime = time.Now()
  1036. subjectItems = append(subjectItems, subjectItem)
  1037. }
  1038. //插入关联信息
  1039. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  1040. if e != nil {
  1041. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  1042. return
  1043. }
  1044. }
  1045. return
  1046. }