resource_data.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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. var err error
  600. defer func() {
  601. if err != nil {
  602. fmt.Println("err:", err)
  603. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  604. }
  605. }()
  606. var source = utils.CYGX_OBJ_ARTICLE
  607. var condition string
  608. var pars []interface{}
  609. condition = ` AND publish_status = 1 AND article_id = ? `
  610. pars = append(pars, sourceId)
  611. total, e := models.GetCygxArticleCount(condition, pars)
  612. if e != nil {
  613. err = errors.New("GetCygxReportSelection, Err: " + err.Error())
  614. return
  615. }
  616. //如果取消发布了就做删除处理
  617. if total == 0 {
  618. e = models.DeleteResourceData(sourceId, source)
  619. if e != nil {
  620. err = errors.New("DeleteResourceData, Err: " + e.Error())
  621. return
  622. }
  623. //删除 cygx_resource_data 表关联的产业ID,标的ID
  624. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  625. if e != nil {
  626. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  627. return
  628. }
  629. } else {
  630. //判断是否存在,如果不存在就新增,存在就更新
  631. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  632. if e != nil {
  633. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  634. return
  635. }
  636. detail, e := models.GetArticleDetailById(sourceId)
  637. if e != nil {
  638. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  639. return
  640. }
  641. var resourceDataId int
  642. publishDate := time.Now().Format(utils.FormatDateTime)
  643. item := new(models.CygxResourceData)
  644. if detail.ArticleTypeId > 0 {
  645. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  646. } else {
  647. item.SearchTag = detail.MatchTypeName
  648. if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
  649. item.SearchTag = ""
  650. }
  651. //获取文章分类详情
  652. detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  653. if detailCategory != nil {
  654. item.ChartPermissionId = detailCategory.ChartPermissionId
  655. }
  656. }
  657. var industrialName string
  658. var subjectName string
  659. //建立首页资源表,与产业的关系
  660. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  661. if e != nil && e.Error() != utils.ErrNoRow() {
  662. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  663. return
  664. }
  665. for _, v := range industrialList {
  666. industrialName += v.IndustryName
  667. }
  668. //建立首页资源表,与标的 的关系
  669. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  670. if e != nil && e.Error() != utils.ErrNoRow() {
  671. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  672. return
  673. }
  674. for _, v := range subjectList {
  675. subjectName += v.SubjectName
  676. }
  677. item.SourceId = sourceId
  678. item.Source = source
  679. item.PublishDate = publishDate
  680. item.CreateTime = time.Now()
  681. item.SearchTitle = detail.Title
  682. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  683. if e != nil && e.Error() != utils.ErrNoRow() {
  684. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  685. return
  686. }
  687. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  688. if e != nil && e.Error() != utils.ErrNoRow() {
  689. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  690. return
  691. }
  692. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  693. item.SearchOrderTime = detail.PublishDate
  694. if totalData == 0 {
  695. newId, e := models.AddCygxResourceData(item)
  696. if e != nil {
  697. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  698. return
  699. }
  700. resourceDataId = int(newId)
  701. } else {
  702. e = models.UpdateResourceDataByItem(item)
  703. if e != nil {
  704. err = errors.New("UpdateResourceData, Err: " + e.Error())
  705. return
  706. }
  707. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  708. if e != nil {
  709. err = errors.New("UpdateResourceData, Err: " + e.Error())
  710. return
  711. }
  712. resourceDataId = sourceDetail.Id
  713. }
  714. //建立首页资源表,与产业的关系
  715. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  716. for _, v := range industrialList {
  717. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  718. industrialItem.SourceId = sourceId
  719. industrialItem.Source = source
  720. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  721. industrialItem.ResourceDataId = resourceDataId
  722. industrialItem.CreateTime = time.Now()
  723. industrialItems = append(industrialItems, industrialItem)
  724. }
  725. //建立首页资源表,与标的 的关系
  726. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  727. for _, v := range subjectList {
  728. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  729. subjectItem.SourceId = sourceId
  730. subjectItem.Source = source
  731. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  732. subjectItem.ResourceDataId = resourceDataId
  733. subjectItem.CreateTime = time.Now()
  734. subjectItems = append(subjectItems, subjectItem)
  735. }
  736. //插入关联信息
  737. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  738. if e != nil {
  739. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  740. return
  741. }
  742. }
  743. return
  744. }
  745. // 更新产业资源包
  746. func UpdateComprehensiveIndustrialResourceData(itemSource *ElasticComprehensiveDetail) {
  747. var err error
  748. defer func() {
  749. if err != nil {
  750. go utils.SendAlarmMsg("更新产业资源包到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(itemSource.SourceId), 3)
  751. }
  752. }()
  753. sourceId := itemSource.SourceId
  754. var source = itemSource.Source
  755. //判断是否存在,如果不存在就新增,存在就更新
  756. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  757. if e != nil {
  758. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  759. return
  760. }
  761. item := new(models.CygxResourceData)
  762. item.SourceId = sourceId
  763. item.Source = source
  764. item.PublishDate = itemSource.PublishDate
  765. item.CreateTime = time.Now()
  766. item.SearchTitle = itemSource.IndustryName + itemSource.SubjectNames
  767. item.SearchContent = ""
  768. item.SearchOrderTime = itemSource.PublishDate
  769. if totalData == 0 {
  770. _, e = models.AddCygxResourceData(item)
  771. if e != nil {
  772. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  773. return
  774. }
  775. } else {
  776. e = models.UpdateResourceDataByItem(item)
  777. if e != nil {
  778. err = errors.New("UpdateResourceData, Err: " + e.Error())
  779. return
  780. }
  781. }
  782. return
  783. }
  784. // 更新研选专栏 写入首页最新 cygx_resource_data 表
  785. func UpdateYanxuanSpecialResourceData(sourceId int) {
  786. var err error
  787. defer func() {
  788. if err != nil {
  789. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 2)
  790. }
  791. }()
  792. var source = utils.CYGX_OBJ_YANXUANSPECIAL
  793. var condition string
  794. var pars []interface{}
  795. condition = ` AND status = 3 AND id = ? `
  796. pars = append(pars, sourceId)
  797. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  798. if e != nil {
  799. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  800. return
  801. }
  802. //如果取消发布了就做删除处理
  803. if total == 0 {
  804. e = models.DeleteResourceData(sourceId, source)
  805. if e != nil {
  806. err = errors.New("DeleteResourceData, Err: " + e.Error())
  807. return
  808. }
  809. } else {
  810. //判断是否存在,如果不存在就新增,存在就更新
  811. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  812. if e != nil {
  813. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  814. return
  815. }
  816. detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
  817. if e != nil {
  818. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  819. return
  820. }
  821. publishDate := detail.PublishTime
  822. item := new(models.CygxResourceData)
  823. item.SourceId = sourceId
  824. item.Source = source
  825. item.PublishDate = publishDate
  826. item.CreateTime = time.Now()
  827. item.SearchTitle = detail.Title
  828. item.SearchContent = ""
  829. item.SearchOrderTime = publishDate
  830. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  831. if totalData == 0 {
  832. _, e := models.AddCygxResourceData(item)
  833. if e != nil {
  834. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  835. return
  836. }
  837. } else {
  838. e = models.UpdateResourceDataByItem(item)
  839. if e != nil {
  840. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  841. return
  842. }
  843. }
  844. }
  845. return
  846. }
  847. func initsql12_17() {
  848. listIndustrialResourceIds, e := models.GetSearchResourceList(0, " AND article_type_id > 0 ", 0, 9999)
  849. if e != nil {
  850. fmt.Println(e)
  851. return
  852. }
  853. var industrialResourceIdsHz []int
  854. for _, v := range listIndustrialResourceIds {
  855. industrialResourceIdsHz = append(industrialResourceIdsHz, v.IndustrialManagementId)
  856. }
  857. //date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  858. //合并产业关联的标的
  859. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsHz)
  860. if e != nil {
  861. fmt.Println(e)
  862. return
  863. }
  864. mapIndustrial := make(map[string]int)
  865. for _, v := range listSubjcet {
  866. for k2, v2 := range listIndustrialResourceIds {
  867. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  868. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  869. }
  870. }
  871. }
  872. //industrialsource := "industrialsourceHz"
  873. industrialsource := "industrialsourceYx"
  874. for _, v := range listIndustrialResourceIds {
  875. item := new(ElasticComprehensiveDetail)
  876. item.SourceId = v.IndustrialManagementId
  877. item.Source = industrialsource
  878. item.IndustryName = v.IndustryName
  879. var SubjectName []string
  880. for _, vN := range v.IndustrialSubjectList {
  881. SubjectName = append(SubjectName, vN.SubjectName)
  882. }
  883. item.SubjectNames = strings.Join(SubjectName, ",")
  884. item.PublishDate = v.PublishDate
  885. fmt.Println(item)
  886. UpdateComprehensiveIndustrialResourceData(item)
  887. }
  888. return
  889. }
  890. // 更新FICC研报
  891. func UpdateFICCReportResourceData(sourceId int, listFiccSet *ficc_report.GetReporteSetListResp) {
  892. var err error
  893. defer func() {
  894. if err != nil {
  895. fmt.Println("err:", err)
  896. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  897. }
  898. }()
  899. var source = utils.CYGX_OBJ_FICC_REPORT
  900. var condition string
  901. var pars []interface{}
  902. condition = ` AND publish_status = 1 AND report_id = ? `
  903. pars = append(pars, sourceId)
  904. total, e := models.GetCygxArticleCount(condition, pars)
  905. if e != nil {
  906. err = errors.New("GetCygxArticleCount, Err: " + err.Error())
  907. return
  908. }
  909. //如果取消发布了就做删除处理
  910. if total == 0 {
  911. e = models.DeleteResourceData(sourceId, source)
  912. if e != nil {
  913. err = errors.New("DeleteResourceData, Err: " + e.Error())
  914. return
  915. }
  916. //删除 cygx_resource_data 表关联的产业ID,标的ID
  917. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  918. if e != nil {
  919. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  920. return
  921. }
  922. } else {
  923. //判断是否存在,如果不存在就新增,存在就更新
  924. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  925. if e != nil {
  926. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  927. return
  928. }
  929. detail, e := models.GetArticleDetailByReportId(sourceId)
  930. if e != nil {
  931. err = errors.New("GetArticleDetailByReportId, Err: " + e.Error())
  932. return
  933. }
  934. var resourceDataId int
  935. publishDate := time.Now().Format(utils.FormatDateTime)
  936. item := new(models.CygxResourceData)
  937. if detail.ArticleTypeId > 0 {
  938. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  939. } else {
  940. item.SearchTag = detail.MatchTypeName
  941. if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
  942. item.SearchTag = ""
  943. }
  944. //获取文章分类详情
  945. detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  946. if detailCategory != nil {
  947. item.ChartPermissionId = detailCategory.ChartPermissionId
  948. }
  949. }
  950. var industrialName string
  951. var subjectName string
  952. //建立首页资源表,与产业的关系
  953. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  954. if e != nil && e.Error() != utils.ErrNoRow() {
  955. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  956. return
  957. }
  958. for _, v := range industrialList {
  959. industrialName += v.IndustryName
  960. }
  961. //建立首页资源表,与标的 的关系
  962. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  963. if e != nil && e.Error() != utils.ErrNoRow() {
  964. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  965. return
  966. }
  967. for _, v := range subjectList {
  968. subjectName += v.SubjectName
  969. }
  970. item.SourceId = sourceId
  971. item.Source = source
  972. item.PublishDate = publishDate
  973. item.CreateTime = time.Now()
  974. item.SearchTitle = detail.Title
  975. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  976. if e != nil && e.Error() != utils.ErrNoRow() {
  977. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  978. return
  979. }
  980. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  981. if e != nil && e.Error() != utils.ErrNoRow() {
  982. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  983. return
  984. }
  985. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  986. item.SearchOrderTime = detail.PublishDate
  987. //跟踪、深度、纪要三个自定义的搜索标签
  988. for _, vSt := range listFiccSet.List {
  989. if item.SearchTag == vSt.ClassifyNameSecond {
  990. item.TagName = vSt.TagName
  991. }
  992. }
  993. if totalData == 0 {
  994. newId, e := models.AddCygxResourceData(item)
  995. if e != nil {
  996. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  997. return
  998. }
  999. resourceDataId = int(newId)
  1000. } else {
  1001. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  1002. if e != nil {
  1003. err = errors.New("UpdateResourceData, Err: " + e.Error())
  1004. return
  1005. }
  1006. item.PublishDate = sourceDetail.PublishDate
  1007. item.SearchOrderTime = sourceDetail.SearchOrderTime
  1008. e = models.UpdateResourceDataByItem(item)
  1009. if e != nil {
  1010. err = errors.New("UpdateResourceData, Err: " + e.Error())
  1011. return
  1012. }
  1013. resourceDataId = sourceDetail.Id
  1014. }
  1015. //建立首页资源表,与产业的关系
  1016. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  1017. for _, v := range industrialList {
  1018. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  1019. industrialItem.SourceId = sourceId
  1020. industrialItem.Source = source
  1021. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  1022. industrialItem.ResourceDataId = resourceDataId
  1023. industrialItem.CreateTime = time.Now()
  1024. industrialItems = append(industrialItems, industrialItem)
  1025. }
  1026. //建立首页资源表,与标的 的关系
  1027. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  1028. for _, v := range subjectList {
  1029. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  1030. subjectItem.SourceId = sourceId
  1031. subjectItem.Source = source
  1032. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  1033. subjectItem.ResourceDataId = resourceDataId
  1034. subjectItem.CreateTime = time.Now()
  1035. subjectItems = append(subjectItems, subjectItem)
  1036. }
  1037. //插入关联信息
  1038. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  1039. if e != nil {
  1040. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  1041. return
  1042. }
  1043. }
  1044. return
  1045. }