resource_data.go 37 KB

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