resource_data.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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 = 0 //配合前端这里强制改为 0
  443. //v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  444. mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
  445. }
  446. //listArticle, e = HandleArticleCategoryImg(listArticle)
  447. //if e != nil {
  448. // err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  449. // return
  450. //}
  451. //for _, v := range listArticle {
  452. // //reportInfoItem := new(ficc_report.ReportDetail)
  453. // //reportInfoItem.ReportInfo.ReportId = v.ReportId
  454. // //reportInfoItem.ReportInfo.PublishTime = utils.StrTimeToTime(v.PublishDate)
  455. // //reportInfoItem.ReportInfo.Title = v.Title
  456. // mapItems[fmt.Sprint("ficcreport", v.ArticleId)].FiccReport = v
  457. //
  458. //}
  459. }
  460. for _, vList := range list {
  461. for _, v := range mapItems {
  462. //如果这些类型都为空,那么就不合并
  463. 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 {
  464. continue
  465. }
  466. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  467. items = append(items, v)
  468. }
  469. }
  470. }
  471. return
  472. }
  473. // 同步活动到最新数据表
  474. func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
  475. defer func() {
  476. if err != nil {
  477. go utils.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
  478. }
  479. }()
  480. if doType == "add" {
  481. item := new(models.CygxResourceData)
  482. item.SourceId = sourceId
  483. item.Source = source
  484. item.PublishDate = publishDate
  485. item.CreateTime = time.Now()
  486. _, err = models.AddCygxResourceData(item)
  487. } else if doType == "delete" {
  488. err = models.DeleteResourceData(sourceId, source)
  489. } else if doType == "update" {
  490. err = models.UpdateResourceData(sourceId, source, publishDate)
  491. }
  492. return
  493. }
  494. //func init130() {
  495. // //UpdateNewchartResourceData(5509)
  496. //
  497. // var condition string
  498. // var pars []interface{}
  499. // condition += ` AND publish_status = 1 `
  500. //
  501. // list, e := models.GetChartList(condition, pars, 0, 1000000)
  502. // if e != nil {
  503. // fmt.Println(e)
  504. // return
  505. // }
  506. //
  507. // for _, v := range list {
  508. // fmt.Println(v.ChartId)
  509. // UpdateNewchartResourceData(v.ChartId)
  510. // }
  511. //}
  512. // 更新图表
  513. func UpdateNewchartResourceData(sourceId int) {
  514. var err error
  515. defer func() {
  516. if err != nil {
  517. go utils.SendAlarmMsg("更新图表同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型", 3)
  518. }
  519. }()
  520. var source = utils.CYGX_OBJ_NEWCHART
  521. var condition string
  522. var pars []interface{}
  523. condition = ` AND chart_id = ? `
  524. pars = append(pars, sourceId)
  525. total, e := models.GetChartCount(condition, pars)
  526. if e != nil {
  527. err = errors.New("GetChartCount, Err: " + e.Error())
  528. return
  529. }
  530. //如果取消发布了就做删除处理
  531. if total == 0 {
  532. e = models.DeleteResourceData(sourceId, source)
  533. if e != nil {
  534. err = errors.New("DeleteResourceData, Err: " + e.Error())
  535. return
  536. }
  537. } else {
  538. //判断是否存在,如果不存在就新增,存在就更新
  539. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  540. if e != nil {
  541. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  542. return
  543. }
  544. detail, e := models.GetChartDetailByChartId(sourceId)
  545. if e != nil {
  546. err = errors.New("GetArticleDetailById, Err: " + e.Error())
  547. return
  548. }
  549. publishDate := detail.CreateDate
  550. item := new(models.CygxResourceData)
  551. item.SourceId = sourceId
  552. item.Source = source
  553. item.PublishDate = publishDate
  554. item.CreateTime = time.Now()
  555. item.SearchTitle = detail.Title
  556. item.SearchContent = ""
  557. item.SearchOrderTime = detail.CreateDate
  558. if totalData == 0 {
  559. _, e = models.AddCygxResourceData(item)
  560. if e != nil {
  561. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  562. return
  563. }
  564. } else {
  565. e = models.UpdateResourceDataByItem(item)
  566. if e != nil {
  567. err = errors.New("UpdateResourceData, Err: " + e.Error())
  568. return
  569. }
  570. }
  571. }
  572. return
  573. }
  574. // 批量删除最新图表数据
  575. func Deletenewchart(chartIdsDelete []int) (err error) {
  576. defer func() {
  577. if err != nil {
  578. fmt.Println(err)
  579. go utils.SendAlarmMsg("批量删除最新图表数据,Err:"+err.Error(), 3)
  580. }
  581. }()
  582. lenchartIdsDelete := len(chartIdsDelete)
  583. if lenchartIdsDelete == 0 {
  584. return
  585. }
  586. var condition string
  587. var pars []interface{}
  588. condition += ` AND source = 'newchart' AND source_id IN (` + utils.GetOrmInReplace(lenchartIdsDelete) + `) `
  589. pars = append(pars, chartIdsDelete)
  590. err = models.DeleteResourceDataList(condition, pars)
  591. return
  592. }
  593. //func init() {
  594. // UpdateArticleResourceData(9050)
  595. //}
  596. // 更新文章
  597. func UpdateArticleResourceData(sourceId int) {
  598. var err error
  599. defer func() {
  600. if err != nil {
  601. fmt.Println("err:", err)
  602. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  603. }
  604. }()
  605. var source = utils.CYGX_OBJ_ARTICLE
  606. var condition string
  607. var pars []interface{}
  608. condition = ` AND publish_status = 1 AND article_id = ? `
  609. pars = append(pars, sourceId)
  610. total, e := models.GetCygxArticleCount(condition, pars)
  611. if e != nil {
  612. err = errors.New("GetCygxReportSelection, Err: " + err.Error())
  613. return
  614. }
  615. //如果取消发布了就做删除处理
  616. if total == 0 {
  617. e = models.DeleteResourceData(sourceId, source)
  618. if e != nil {
  619. err = errors.New("DeleteResourceData, Err: " + e.Error())
  620. return
  621. }
  622. //删除 cygx_resource_data 表关联的产业ID,标的ID
  623. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  624. if e != nil {
  625. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  626. return
  627. }
  628. } else {
  629. //判断是否存在,如果不存在就新增,存在就更新
  630. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  631. if e != nil {
  632. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  633. return
  634. }
  635. detail, e := models.GetArticleDetailById(sourceId)
  636. if e != nil {
  637. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  638. return
  639. }
  640. var resourceDataId int
  641. publishDate := time.Now().Format(utils.FormatDateTime)
  642. item := new(models.CygxResourceData)
  643. if detail.ArticleTypeId > 0 {
  644. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  645. } else {
  646. item.SearchTag = detail.MatchTypeName
  647. if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
  648. item.SearchTag = ""
  649. }
  650. //获取文章分类详情
  651. detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  652. if detailCategory != nil {
  653. item.ChartPermissionId = detailCategory.ChartPermissionId
  654. }
  655. }
  656. var industrialName string
  657. var subjectName string
  658. //建立首页资源表,与产业的关系
  659. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  660. if e != nil && e.Error() != utils.ErrNoRow() {
  661. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  662. return
  663. }
  664. for _, v := range industrialList {
  665. industrialName += v.IndustryName
  666. }
  667. //建立首页资源表,与标的 的关系
  668. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  669. if e != nil && e.Error() != utils.ErrNoRow() {
  670. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  671. return
  672. }
  673. for _, v := range subjectList {
  674. subjectName += v.SubjectName
  675. }
  676. item.SourceId = sourceId
  677. item.Source = source
  678. item.PublishDate = publishDate
  679. item.CreateTime = time.Now()
  680. item.SearchTitle = detail.Title
  681. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  682. if e != nil && e.Error() != utils.ErrNoRow() {
  683. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  684. return
  685. }
  686. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  687. if e != nil && e.Error() != utils.ErrNoRow() {
  688. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  689. return
  690. }
  691. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  692. item.SearchOrderTime = detail.PublishDate
  693. if totalData == 0 {
  694. newId, e := models.AddCygxResourceData(item)
  695. if e != nil {
  696. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  697. return
  698. }
  699. resourceDataId = int(newId)
  700. } else {
  701. e = models.UpdateResourceDataByItem(item)
  702. if e != nil {
  703. err = errors.New("UpdateResourceData, Err: " + e.Error())
  704. return
  705. }
  706. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  707. if e != nil {
  708. err = errors.New("UpdateResourceData, Err: " + e.Error())
  709. return
  710. }
  711. resourceDataId = sourceDetail.Id
  712. }
  713. //建立首页资源表,与产业的关系
  714. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  715. for _, v := range industrialList {
  716. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  717. industrialItem.SourceId = sourceId
  718. industrialItem.Source = source
  719. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  720. industrialItem.ResourceDataId = resourceDataId
  721. industrialItem.CreateTime = time.Now()
  722. industrialItems = append(industrialItems, industrialItem)
  723. }
  724. //建立首页资源表,与标的 的关系
  725. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  726. for _, v := range subjectList {
  727. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  728. subjectItem.SourceId = sourceId
  729. subjectItem.Source = source
  730. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  731. subjectItem.ResourceDataId = resourceDataId
  732. subjectItem.CreateTime = time.Now()
  733. subjectItems = append(subjectItems, subjectItem)
  734. }
  735. //插入关联信息
  736. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  737. if e != nil {
  738. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  739. return
  740. }
  741. }
  742. return
  743. }
  744. // 更新产业资源包
  745. func UpdateComprehensiveIndustrialResourceData(itemSource *ElasticComprehensiveDetail) {
  746. var err error
  747. defer func() {
  748. if err != nil {
  749. go utils.SendAlarmMsg("更新产业资源包到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(itemSource.SourceId), 3)
  750. }
  751. }()
  752. sourceId := itemSource.SourceId
  753. var source = itemSource.Source
  754. //判断是否存在,如果不存在就新增,存在就更新
  755. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  756. if e != nil {
  757. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  758. return
  759. }
  760. item := new(models.CygxResourceData)
  761. item.SourceId = sourceId
  762. item.Source = source
  763. item.PublishDate = itemSource.PublishDate
  764. item.CreateTime = time.Now()
  765. item.SearchTitle = itemSource.IndustryName + itemSource.SubjectNames
  766. item.SearchContent = ""
  767. item.SearchOrderTime = itemSource.PublishDate
  768. if totalData == 0 {
  769. _, e = models.AddCygxResourceData(item)
  770. if e != nil {
  771. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  772. return
  773. }
  774. } else {
  775. e = models.UpdateResourceDataByItem(item)
  776. if e != nil {
  777. err = errors.New("UpdateResourceData, Err: " + e.Error())
  778. return
  779. }
  780. }
  781. return
  782. }
  783. // 更新研选专栏 写入首页最新 cygx_resource_data 表
  784. func UpdateYanxuanSpecialResourceData(sourceId int) {
  785. var err error
  786. defer func() {
  787. if err != nil {
  788. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 2)
  789. }
  790. }()
  791. var source = utils.CYGX_OBJ_YANXUANSPECIAL
  792. var condition string
  793. var pars []interface{}
  794. condition = ` AND status = 3 AND id = ? `
  795. pars = append(pars, sourceId)
  796. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  797. if e != nil {
  798. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  799. return
  800. }
  801. //如果取消发布了就做删除处理
  802. if total == 0 {
  803. e = models.DeleteResourceData(sourceId, source)
  804. if e != nil {
  805. err = errors.New("DeleteResourceData, Err: " + e.Error())
  806. return
  807. }
  808. } else {
  809. //判断是否存在,如果不存在就新增,存在就更新
  810. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  811. if e != nil {
  812. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  813. return
  814. }
  815. detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
  816. if e != nil {
  817. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  818. return
  819. }
  820. publishDate := detail.PublishTime
  821. item := new(models.CygxResourceData)
  822. item.SourceId = sourceId
  823. item.Source = source
  824. item.PublishDate = publishDate
  825. item.CreateTime = time.Now()
  826. item.SearchTitle = detail.Title
  827. item.SearchContent = ""
  828. item.SearchOrderTime = publishDate
  829. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  830. if totalData == 0 {
  831. _, e := models.AddCygxResourceData(item)
  832. if e != nil {
  833. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  834. return
  835. }
  836. } else {
  837. e = models.UpdateResourceDataByItem(item)
  838. if e != nil {
  839. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  840. return
  841. }
  842. }
  843. }
  844. return
  845. }
  846. func initsql12_17() {
  847. listIndustrialResourceIds, e := models.GetSearchResourceList(0, " AND article_type_id > 0 ", 0, 9999)
  848. if e != nil {
  849. fmt.Println(e)
  850. return
  851. }
  852. var industrialResourceIdsHz []int
  853. for _, v := range listIndustrialResourceIds {
  854. industrialResourceIdsHz = append(industrialResourceIdsHz, v.IndustrialManagementId)
  855. }
  856. //date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  857. //合并产业关联的标的
  858. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsHz)
  859. if e != nil {
  860. fmt.Println(e)
  861. return
  862. }
  863. mapIndustrial := make(map[string]int)
  864. for _, v := range listSubjcet {
  865. for k2, v2 := range listIndustrialResourceIds {
  866. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  867. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  868. }
  869. }
  870. }
  871. //industrialsource := "industrialsourceHz"
  872. industrialsource := "industrialsourceYx"
  873. for _, v := range listIndustrialResourceIds {
  874. item := new(ElasticComprehensiveDetail)
  875. item.SourceId = v.IndustrialManagementId
  876. item.Source = industrialsource
  877. item.IndustryName = v.IndustryName
  878. var SubjectName []string
  879. for _, vN := range v.IndustrialSubjectList {
  880. SubjectName = append(SubjectName, vN.SubjectName)
  881. }
  882. item.SubjectNames = strings.Join(SubjectName, ",")
  883. item.PublishDate = v.PublishDate
  884. fmt.Println(item)
  885. UpdateComprehensiveIndustrialResourceData(item)
  886. }
  887. return
  888. }
  889. // 更新FICC研报
  890. func UpdateFICCReportResourceData(sourceId int) {
  891. var err error
  892. defer func() {
  893. if err != nil {
  894. fmt.Println("err:", err)
  895. go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  896. }
  897. }()
  898. var source = utils.CYGX_OBJ_FICC_REPORT
  899. var condition string
  900. var pars []interface{}
  901. condition = ` AND publish_status = 1 AND report_id = ? `
  902. pars = append(pars, sourceId)
  903. total, e := models.GetCygxArticleCount(condition, pars)
  904. if e != nil {
  905. err = errors.New("GetCygxArticleCount, Err: " + err.Error())
  906. return
  907. }
  908. //如果取消发布了就做删除处理
  909. if total == 0 {
  910. e = models.DeleteResourceData(sourceId, source)
  911. if e != nil {
  912. err = errors.New("DeleteResourceData, Err: " + e.Error())
  913. return
  914. }
  915. //删除 cygx_resource_data 表关联的产业ID,标的ID
  916. e = models.DeleteCygxResourceDataGroup(sourceId, source)
  917. if e != nil {
  918. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  919. return
  920. }
  921. } else {
  922. //判断是否存在,如果不存在就新增,存在就更新
  923. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  924. if e != nil {
  925. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  926. return
  927. }
  928. detail, e := models.GetArticleDetailByReportId(sourceId)
  929. if e != nil {
  930. err = errors.New("GetArticleDetailByReportId, Err: " + e.Error())
  931. return
  932. }
  933. var resourceDataId int
  934. publishDate := time.Now().Format(utils.FormatDateTime)
  935. item := new(models.CygxResourceData)
  936. if detail.ArticleTypeId > 0 {
  937. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  938. } else {
  939. item.SearchTag = detail.MatchTypeName
  940. if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
  941. item.SearchTag = ""
  942. }
  943. //获取文章分类详情
  944. detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  945. if detailCategory != nil {
  946. item.ChartPermissionId = detailCategory.ChartPermissionId
  947. }
  948. }
  949. var industrialName string
  950. var subjectName string
  951. //建立首页资源表,与产业的关系
  952. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  953. if e != nil && e.Error() != utils.ErrNoRow() {
  954. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  955. return
  956. }
  957. for _, v := range industrialList {
  958. industrialName += v.IndustryName
  959. }
  960. //建立首页资源表,与标的 的关系
  961. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  962. if e != nil && e.Error() != utils.ErrNoRow() {
  963. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  964. return
  965. }
  966. for _, v := range subjectList {
  967. subjectName += v.SubjectName
  968. }
  969. item.SourceId = sourceId
  970. item.Source = source
  971. item.PublishDate = publishDate
  972. item.CreateTime = time.Now()
  973. item.SearchTitle = detail.Title
  974. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  975. if e != nil && e.Error() != utils.ErrNoRow() {
  976. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  977. return
  978. }
  979. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  980. if e != nil && e.Error() != utils.ErrNoRow() {
  981. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  982. return
  983. }
  984. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  985. item.SearchOrderTime = detail.PublishDate
  986. if totalData == 0 {
  987. newId, e := models.AddCygxResourceData(item)
  988. if e != nil {
  989. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  990. return
  991. }
  992. resourceDataId = int(newId)
  993. } else {
  994. e = models.UpdateResourceDataByItem(item)
  995. if e != nil {
  996. err = errors.New("UpdateResourceData, Err: " + e.Error())
  997. return
  998. }
  999. sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
  1000. if e != nil {
  1001. err = errors.New("UpdateResourceData, Err: " + e.Error())
  1002. return
  1003. }
  1004. resourceDataId = sourceDetail.Id
  1005. }
  1006. //建立首页资源表,与产业的关系
  1007. var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
  1008. for _, v := range industrialList {
  1009. var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
  1010. industrialItem.SourceId = sourceId
  1011. industrialItem.Source = source
  1012. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  1013. industrialItem.ResourceDataId = resourceDataId
  1014. industrialItem.CreateTime = time.Now()
  1015. industrialItems = append(industrialItems, industrialItem)
  1016. }
  1017. //建立首页资源表,与标的 的关系
  1018. var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
  1019. for _, v := range subjectList {
  1020. var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
  1021. subjectItem.SourceId = sourceId
  1022. subjectItem.Source = source
  1023. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  1024. subjectItem.ResourceDataId = resourceDataId
  1025. subjectItem.CreateTime = time.Now()
  1026. subjectItems = append(subjectItems, subjectItem)
  1027. }
  1028. //插入关联信息
  1029. e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  1030. if e != nil {
  1031. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  1032. return
  1033. }
  1034. }
  1035. return
  1036. }