resource_data.go 30 KB

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