ficc_report.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. package services
  2. //FICC研报
  3. import (
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/models/ficc_report"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. // GetMinClassify
  15. // @Description: 获取最小分类ID
  16. // @author: Roc
  17. // @datetime 2024-06-20 09:23:19
  18. // @param reportInfo *models.Report
  19. // @return minClassifyId int
  20. // @return minClassifyName string
  21. // @return err error
  22. func GetMinClassify(reportInfo *ficc_report.Report) (minClassifyId int, minClassifyName string, err error) {
  23. defer func() {
  24. if err != nil {
  25. go utils.SendAlarmMsg(fmt.Sprint("获取最小分类ID失败,报告ID:%d,Err:%s", reportInfo.Id, err.Error()), 2)
  26. }
  27. }()
  28. minClassifyId = reportInfo.ClassifyIdThird
  29. minClassifyName = reportInfo.ClassifyNameThird
  30. if minClassifyId <= 0 {
  31. minClassifyId = reportInfo.ClassifyIdSecond
  32. minClassifyName = reportInfo.ClassifyNameSecond
  33. }
  34. if minClassifyId <= 0 {
  35. minClassifyId = reportInfo.ClassifyIdFirst
  36. minClassifyName = reportInfo.ClassifyNameFirst
  37. }
  38. if minClassifyId <= 0 {
  39. err = errors.New("分类异常")
  40. }
  41. return
  42. }
  43. // 获取报告详情
  44. func GetReportDetail(userinfo *models.WxUserItem, reportId int) (reportDetail ficc_report.ReportDetail, err error) {
  45. //var errMsg string
  46. defer func() {
  47. if err != nil {
  48. fmt.Println(err)
  49. go utils.SendAlarmMsg(fmt.Sprint("获取研报详情失败 GetReportDetail ,err:", err.Error(), "ReportId:", reportId), 2)
  50. }
  51. }()
  52. detailArticle, e := models.GetArticleDetailByReportId(reportId)
  53. if e != nil {
  54. err = errors.New("报告查询出错" + e.Error())
  55. return
  56. }
  57. reportInfo, e := ficc_report.GetByReportId(reportId)
  58. if e != nil {
  59. //errMsg = err.Error()
  60. err = errors.New("报告查询出错" + e.Error())
  61. return
  62. }
  63. if reportInfo.Id == 0 {
  64. err = errors.New("报告不存在")
  65. return
  66. }
  67. if reportInfo.State != 2 && reportInfo.State != 6 {
  68. err = errors.New("报告未发布")
  69. return
  70. }
  71. // 获取最小分类
  72. minClassifyId, _, err := GetMinClassify(reportInfo)
  73. // 判断报告是否属于专栏报告
  74. firstClassify, e := ficc_report.GetByClassifyId(reportInfo.ClassifyIdFirst)
  75. if e != nil {
  76. err = errors.New("报告一级分类有误")
  77. return
  78. }
  79. // 最小分类
  80. var minClassify *ficc_report.Classify
  81. if reportInfo.ClassifyIdFirst == minClassifyId {
  82. minClassify = firstClassify
  83. } else {
  84. minClassify, e = ficc_report.GetByClassifyId(minClassifyId)
  85. if e != nil {
  86. err = errors.New("报告最小层级分类有误")
  87. return
  88. }
  89. }
  90. var hasPermission int
  91. var hasPower bool
  92. if userinfo.CompanyId > 1 {
  93. companyPermission, e := models.GetCompanyPermission(userinfo.CompanyId)
  94. if e != nil {
  95. err = errors.New("GetCompanyPermission")
  96. return
  97. }
  98. if companyPermission != "" {
  99. slice := strings.Split(companyPermission, ",")
  100. if utils.InArrayByStr(slice, "周期") {
  101. hasPower = true
  102. }
  103. }
  104. }
  105. if hasPower {
  106. hasPermission = 1
  107. } else {
  108. if userinfo.UserId == 0 {
  109. hasPermission = 1
  110. } else {
  111. hasPermission, e = GetUserPermissionCode(userinfo.UserId, userinfo.CompanyId)
  112. if e != nil {
  113. err = errors.New("GetUserPermissionCode")
  114. return
  115. }
  116. reportDetail.SellerName, reportDetail.SellerMobile, _ = GetSellerName(userinfo)
  117. }
  118. }
  119. reportDetail.HasPermission = hasPermission
  120. //判断权限
  121. var authOk bool
  122. var reportChapterIdList []int
  123. if reportInfo.HasChapter == 1 {
  124. if reportInfo.ClassifyNameFirst == "晨报" {
  125. //authOk, permissionCheckInfo, err = CheckDayReportPermission(userinfo, productAuthOk)
  126. } else {
  127. _, _, _, reportChapterIdList, err = CheckWeekReportPermission(userinfo, reportId, true)
  128. }
  129. }
  130. if hasPermission == 1 {
  131. authOk = true
  132. }
  133. reportItem := new(ficc_report.ReportItem)
  134. reportItem.ReportId = reportInfo.Id
  135. reportItem.Title = reportInfo.Title
  136. reportItem.PublishTime = reportInfo.PublishTime
  137. reportItem.ClassifyNameFirst = reportInfo.ClassifyNameFirst
  138. reportItem.ClassifyNameSecond = reportInfo.ClassifyNameSecond
  139. reportItem.Stage = reportInfo.Stage
  140. reportItem.Abstract = reportInfo.Abstract
  141. reportItem.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  142. reportItem.Frequency = reportInfo.Frequency
  143. reportItem.VideoName = reportInfo.VideoName
  144. reportItem.HasChapter = reportInfo.HasChapter
  145. reportItem.ReportLayout = reportInfo.ReportLayout
  146. reportItem.HeadImg = reportInfo.HeadImg
  147. reportItem.EndImg = reportInfo.EndImg
  148. reportItem.CanvasColor = reportInfo.CanvasColor
  149. reportItem.ArticleId = detailArticle.ArticleId
  150. reportItem.Disclaimer = GetConfigCodeDisclaimer()
  151. //版头版尾样式
  152. {
  153. if reportInfo.HeadResourceId > 0 {
  154. headResource, tmpErr := ficc_report.GetResourceItemById(reportInfo.HeadResourceId)
  155. if tmpErr != nil {
  156. err = tmpErr
  157. return
  158. }
  159. reportItem.HeadImg = headResource.ImgURL
  160. reportItem.HeadStyle = headResource.Style
  161. }
  162. if reportInfo.EndResourceId > 0 {
  163. endResource, tmpErr := ficc_report.GetResourceItemById(reportInfo.EndResourceId)
  164. if tmpErr != nil {
  165. err = tmpErr
  166. return
  167. }
  168. reportItem.EndImg = endResource.ImgURL
  169. reportItem.EndStyle = endResource.Style
  170. }
  171. }
  172. if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
  173. reportItem.VideoName = reportInfo.Title
  174. }
  175. reportItem.VideoSize = reportInfo.VideoSize
  176. reportItem.VideoPlaySeconds = reportInfo.VideoPlaySeconds
  177. reportItem.Author = reportInfo.Author
  178. // 分享背景图取二级分类配图, 二级没有配图时使用一级配图, 一级也没有使用默认图
  179. reportItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
  180. secondClassify, e := ficc_report.GetByClassifyId(reportInfo.ClassifyIdSecond)
  181. if e != nil {
  182. err = errors.New("报告二级分类有误")
  183. return
  184. }
  185. if secondClassify.YbShareBgImg != "" {
  186. reportItem.ShareBgImg = secondClassify.YbShareBgImg
  187. } else {
  188. if firstClassify.YbShareBgImg != "" {
  189. reportItem.ShareBgImg = firstClassify.YbShareBgImg
  190. }
  191. }
  192. var reportTypeList []*ficc_report.ReportChapterListItem
  193. if reportInfo.HasChapter == 1 {
  194. //(晨报和周报的banner图)
  195. if reportInfo.ClassifyNameFirst == "晨报" {
  196. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
  197. } else {
  198. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_week.jpg"
  199. }
  200. // 如果还没有配置banner图,则取晨报的
  201. if reportItem.BannerUrl == `` {
  202. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
  203. }
  204. if authOk {
  205. reportTypeList, err = GetChapterListByReportChapterIdList(reportInfo.ClassifyNameFirst, reportInfo.Id, reportChapterIdList)
  206. if err != nil {
  207. return
  208. }
  209. }
  210. } else {
  211. // 音频播放条图片用分类图片
  212. //reportItem.VideoImg = utils.HZ_DEFAULT_AVATAR
  213. //permissionIds, tmpErr := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(reportInfo.ClassifyIdSecond)
  214. //if tmpErr != nil {
  215. // errMsg = tmpErr.Error()
  216. // err = errors.New("查询报告权限失败")
  217. // return
  218. //}
  219. //if len(permissionIds) > 0 {
  220. // chartPermission, tmpErr := chart_permission.GetListByIds(permissionIds)
  221. // if tmpErr != nil {
  222. // errMsg = tmpErr.Error()
  223. // err = errors.New("查询品种信息失败")
  224. // return
  225. // }
  226. // lenChart := len(chartPermission)
  227. // for i := 0; i < lenChart; i++ {
  228. // if chartPermission[i].YbImgUrl != "" {
  229. // reportItem.VideoImg = utils.ALIYUN_YBIMG_HOST + chartPermission[i].YbImgUrl
  230. // break
  231. // }
  232. // }
  233. //}
  234. }
  235. //如果有权限则展示content
  236. if authOk {
  237. reportItem.Content = html.UnescapeString(reportInfo.Content)
  238. reportItem.VideoUrl = reportInfo.VideoUrl
  239. }
  240. if userinfo.UserId == 0 {
  241. reportItem.Content = utils.InterceptHtmlLength(reportInfo.Content, 200)
  242. }
  243. reportDetail.ReportInfo = reportItem
  244. reportDetail.ReportChapterList = reportTypeList
  245. //reportDetail.PermissionCheck = &permissionCheckInfo
  246. reportDetail.AuthOk = authOk
  247. //reportDetail.LikeNum = likeNum
  248. //reportDetail.LikeEnabled = likeEnabled
  249. reportDetail.ReportShowType = int(firstClassify.ShowType)
  250. reportDetail.ReportDetailShowType = int(minClassify.ReportDetailShowType)
  251. // 如果分类配置是列表展示,那么就移除content内容
  252. if minClassify.ReportDetailShowType == 2 {
  253. for _, v := range reportTypeList {
  254. v.Content = ``
  255. }
  256. } else {
  257. for _, v := range reportTypeList {
  258. v.Content = html.UnescapeString(v.Content)
  259. }
  260. }
  261. return
  262. }
  263. // CheckWeekReportPermission
  264. // @Description: 验证周报的权限(并获取拥有权限的章节id列表)
  265. // @author: Roc
  266. // @datetime 2024-06-24 11:06:52
  267. // @param userInfo user.UserInfo
  268. // @param reportId int
  269. // @param productAuthOk bool
  270. // @return authOk bool
  271. // @return permissionCheckInfo response.PermissionCheckInfo
  272. // @return validTypeIds []int 分类关联的章节类型ID列表
  273. // @return reportChapterIdList []int 并获取拥有权限的章节id列表
  274. // @return err error
  275. func CheckWeekReportPermission(userInfo *models.WxUserItem, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo ficc_report.PermissionCheckInfo, validTypeIds, reportChapterIdList []int, err error) {
  276. var permissionIds []int
  277. //var validPermissionIds []int //最后允许显示的章节
  278. // 当前报告的品种与章节列表的map
  279. permissionChapterList := make(map[int][]int)
  280. permissionIdMap := make(map[int]bool)
  281. typeIdMap := make(map[int]bool)
  282. reportChapterIdMap := make(map[int]bool)
  283. if productAuthOk {
  284. reportChapterMappingList, e := ficc_report.GetReportChapterPermissionMappingItemListByReportId(reportId)
  285. if e != nil && e.Error() != utils.ErrNoRow() {
  286. err = errors.New(e.Error())
  287. return
  288. }
  289. for _, v := range reportChapterMappingList {
  290. if _, ok := permissionIdMap[v.ChartPermissionId]; !ok {
  291. permissionIdMap[v.ChartPermissionId] = true
  292. permissionIds = append(permissionIds, v.ChartPermissionId)
  293. }
  294. if _, ok := typeIdMap[v.TypeId]; !ok {
  295. typeIdMap[v.TypeId] = true
  296. validTypeIds = append(validTypeIds, v.TypeId)
  297. }
  298. tmpList, ok := permissionChapterList[v.ChartPermissionId]
  299. if !ok {
  300. tmpList = make([]int, 0)
  301. }
  302. permissionChapterList[v.ChartPermissionId] = append(tmpList, v.ReportChapterId)
  303. if _, ok := reportChapterIdMap[v.ReportChapterId]; !ok {
  304. reportChapterIdMap[v.ReportChapterId] = true
  305. reportChapterIdList = append(reportChapterIdList, v.ReportChapterId) //走权益的校验权限,到这里的权限都可以用
  306. }
  307. }
  308. }
  309. return
  310. }
  311. // GetChapterListByReportChapterIdList
  312. // @Description: 根据报告获取章节列表
  313. // @author: Roc
  314. // @datetime 2024-06-24 11:23:36
  315. // @param classifyNameFirst string
  316. // @param reportId int
  317. // @param reportChapterIdList []int
  318. // @param reportCreateTime time.Time
  319. // @return reportTypeList response.ReportChapterList
  320. // @return err error
  321. func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int, reportChapterIdList []int) (reportTypeList ficc_report.ReportChapterList, err error) {
  322. var errMsg string
  323. defer func() {
  324. if err != nil {
  325. go utils.SendAlarmMsg(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg), 2)
  326. }
  327. }()
  328. //查询有效的章节
  329. typeList, e := ficc_report.GetEffectTypes()
  330. if e != nil {
  331. err = errors.New("章节类型查询出错" + e.Error())
  332. return
  333. }
  334. if len(typeList) == 0 {
  335. err = errors.New("无有效的章节")
  336. return
  337. }
  338. typeMap := make(map[uint64]*ficc_report.ReportChapterType)
  339. for _, v := range typeList {
  340. typeMap[v.ReportChapterTypeId] = v
  341. }
  342. var chapterList []*ficc_report.ReportChapter
  343. if len(reportChapterIdList) > 0 {
  344. //获取所有当前研报有权限的章节
  345. chapterList, e = ficc_report.GetListByChapterIds(reportChapterIdList)
  346. } else {
  347. // 获取所有报告章节
  348. chapterList, e = ficc_report.GetListByReportId(reportId, classifyNameFirst)
  349. }
  350. if e != nil && e.Error() != utils.ErrNoRow() {
  351. err = errors.New("章节查询出错" + e.Error())
  352. return
  353. }
  354. if len(chapterList) == 0 {
  355. err = errors.New("无有效章节")
  356. return
  357. }
  358. for _, item := range chapterList {
  359. typeItem, ok1 := typeMap[uint64(item.TypeId)]
  360. // 如果是配置的章节,那么就需要判断是否禁用,如果禁用,则不展示
  361. if item.TypeId > 0 && !ok1 {
  362. continue
  363. }
  364. temp := new(ficc_report.ReportChapterListItem)
  365. temp.ReportChapterId = item.ReportChapterId
  366. temp.TypeId = item.TypeId
  367. temp.TypeName = item.TypeName
  368. temp.Title = item.Title
  369. temp.Trend = item.Trend
  370. temp.ReportId = item.ReportId
  371. temp.Sort = item.Sort
  372. temp.PublishTime = item.PublishTime
  373. temp.VideoUrl = item.VideoUrl
  374. temp.VideoName = item.VideoName
  375. temp.VideoPlaySeconds = item.VideoPlaySeconds
  376. temp.VideoSize = item.VideoSize
  377. temp.Content = item.Content
  378. // 系统配置的参数,只有配置的章节类型,才能赋值
  379. if typeItem != nil {
  380. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  381. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  382. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  383. }
  384. reportTypeList = append(reportTypeList, temp)
  385. }
  386. //if len(reportTypeList) > 0 {
  387. // sort.Sort(reportTypeList)
  388. //}
  389. return
  390. }
  391. //func init() {
  392. // GetFiccRreportToCygxArticle()
  393. // //UpdateFICCReportResourceData(5542)
  394. //}
  395. // 获取FICC研报到查研观向数据库中
  396. func GetFiccRreportToCygxArticle() (err error) {
  397. defer func() {
  398. if err != nil {
  399. fmt.Println(err)
  400. go utils.SendAlarmMsg(fmt.Sprint("自动取消十分钟之内没有付款的的订单 CancelCygxOrder ,err:", err.Error()), 2)
  401. }
  402. }()
  403. var condition string
  404. var pars []interface{}
  405. //modifyTime := time.Now().Add(-10 * time.Minute)
  406. //condition = ` AND modify_time >= ? `
  407. //pars = append(pars, modifyTime)
  408. reportList, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
  409. if e != nil {
  410. err = errors.New("GetFiccRreportToCygxArticle, Err: " + e.Error())
  411. return
  412. }
  413. fmt.Println(len(reportList))
  414. if len(reportList) == 0 {
  415. return
  416. }
  417. var reportIds []int
  418. for _, v := range reportList {
  419. reportIds = append(reportIds, v.Id)
  420. }
  421. listFiccReport, e := models.GetCygxCygxArticleListByReportIds(reportIds)
  422. if e != nil {
  423. err = errors.New("GetCygxCygxArticleListByReportIds, Err: " + e.Error())
  424. return
  425. }
  426. mapFiccReport := make(map[int]int)
  427. for _, v := range listFiccReport {
  428. mapFiccReport[v.ReportId] = v.ArticleId
  429. }
  430. //量不大,先这么写吧
  431. for _, v := range reportList {
  432. time.Sleep(1 * time.Millisecond) // 延时一秒
  433. item := new(models.CygxArticle)
  434. item.ReportId = v.Id
  435. item.PublishDate = v.PublishTime.Format(utils.FormatDateTime)
  436. item.Title = v.Title
  437. item.Body = v.Content
  438. item.Abstract = v.Abstract
  439. item.CreateDate = time.Now().Format(utils.FormatDate)
  440. item.PublishStatus = 1
  441. item.IsReport = 1
  442. item.IsClass = 1
  443. if (v.ClassifyNameFirst == "宏观报告" && v.ClassifyNameSecond == "大类资产周报") || (v.ClassifyNameFirst == "晨会纪要" && v.ClassifyNameSecond == "晨会纪要") || (v.ClassifyNameFirst == "调研纪要" && v.ClassifyNameSecond == "黑色调研") {
  444. item.SubCategoryName = v.ClassifyNameSecond
  445. item.MatchTypeName = v.ClassifyNameSecond
  446. } else {
  447. continue
  448. }
  449. detailCategory, detailCategoryErr := models.GetCygxReportMappingCelueDetailByZhoQiCategoryName(item.SubCategoryName)
  450. if detailCategoryErr != nil {
  451. continue
  452. }
  453. item.CategoryId = detailCategory.CategoryId
  454. item.CategoryIdTwo = detailCategory.CategoryId
  455. var articleIdMax int
  456. //如果不存在就新增
  457. if mapFiccReport[v.Id] == 0 {
  458. maxArticleIdArticleInfo, e := models.GetMaxArticleIdInfo()
  459. if e != nil {
  460. err = errors.New("GetMaxArticleIdInfo, Err: " + e.Error())
  461. return
  462. }
  463. articleIdMax = maxArticleIdArticleInfo.ArticleId + 1
  464. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdMax))
  465. item.ArticleId = articleIdMax
  466. _, e = models.AddCygxArticles(item)
  467. if e != nil {
  468. err = errors.New("AddCygxArticles, Err: " + e.Error())
  469. return
  470. }
  471. } else {
  472. articleIdMax = mapFiccReport[v.Id]
  473. item.ArticleId = mapFiccReport[v.Id]
  474. updateParams := make(map[string]interface{})
  475. updateParams["Title"] = item.Title
  476. updateParams["PublishDate"] = item.PublishDate
  477. updateParams["Body"] = item.Body
  478. updateParams["Abstract"] = item.Abstract
  479. updateParams["PublishStatus"] = item.PublishStatus
  480. updateParams["SubCategoryName"] = item.SubCategoryName
  481. updateParams["MatchTypeName"] = item.MatchTypeName
  482. updateParams["CategoryId"] = item.CategoryId
  483. updateParams["CategoryIdTwo"] = item.CategoryIdTwo
  484. whereParam := map[string]interface{}{"article_id": item.ArticleId}
  485. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  486. if err != nil {
  487. fmt.Println("UpdateByExpr Err:" + err.Error())
  488. return err
  489. }
  490. }
  491. UpdateFICCReportResourceData(v.Id)
  492. AddCygxReportMappingCategoryGroupByArticleId(articleIdMax)
  493. }
  494. //获取已经同步到查研的FICC研报 对比,如果FICC研报已经取消发布,查研也做对应的删除
  495. listCygxFiccReport, e := models.GetCygxCygxArticleFiccReportList()
  496. if e != nil {
  497. err = errors.New("GetCygxCygxArticleFiccReportList, Err: " + e.Error())
  498. return
  499. }
  500. var cygxFiccReportIds []int
  501. for _, v := range listCygxFiccReport {
  502. cygxFiccReportIds = append(cygxFiccReportIds, v.ReportId)
  503. }
  504. lenArr := len(cygxFiccReportIds)
  505. if lenArr == 0 {
  506. return
  507. }
  508. condition = ` AND id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  509. pars = append(pars, cygxFiccReportIds)
  510. ficcReportListPush, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
  511. if e != nil {
  512. err = errors.New("GetFiccRreportToCygxArticle, Err: " + e.Error())
  513. return
  514. }
  515. var removeficcReporIds []int // 需要移除的报告ID
  516. ficcReporIdsPush := make(map[int]bool) // Ficc 研报还存在的报告ID
  517. for _, v := range ficcReportListPush {
  518. ficcReporIdsPush[v.Id] = true
  519. }
  520. for _, v := range listCygxFiccReport {
  521. if !ficcReporIdsPush[v.ReportId] {
  522. removeficcReporIds = append(removeficcReporIds, v.ReportId)
  523. }
  524. }
  525. if len(removeficcReporIds) > 0 {
  526. e = models.HideCygxResourceDataFiccReport(removeficcReporIds)
  527. if e != nil {
  528. err = errors.New("HideCygxResourceDataFiccReport, Err: " + e.Error())
  529. return
  530. }
  531. }
  532. fmt.Println("end")
  533. return
  534. }
  535. // 根据用户信息,获取跳转研报小程序详情信息
  536. func GetFiccReportXcxItem(user *models.WxUserItem) (itemSourceResp *models.CygxResourceDataResp) {
  537. var err error
  538. defer func() {
  539. if err != nil {
  540. fmt.Println(err)
  541. go utils.SendAlarmMsg(fmt.Sprint("根据用户信息,获取跳转研报小程序详情信息失败 GetFiccReportXcxItem ,err:", err.Error(), "UserId:", user.UserId), 2)
  542. }
  543. }()
  544. deUserId := utils.DesBase64Encrypt([]byte(strconv.Itoa(user.UserId)))
  545. itemSource := new(models.CygxResourceDataResp)
  546. itemSource.Source = utils.CYGX_OBJ_FICC_REPORT_XCX
  547. itemResp := new(models.FiccReportXcx)
  548. itemResp.Source = utils.CYGX_OBJ_FICC_REPORT_XCX
  549. itemResp.Title = "每日原油播报"
  550. itemResp.SecondTitle = "欧美市场隔夜复盘"
  551. itemResp.ImgUrl = utils.FICC_REPORT_ICO_HOME
  552. itemResp.Mobile = user.Mobile
  553. itemResp.SellerMobile = ""
  554. itemResp.SellerName = ""
  555. itemResp.Appid = utils.FICC_REPORT_APPID
  556. itemResp.SourceUrl = "pages/voice/voice?thirdCode="
  557. itemResp.ThirdCode = string(deUserId)
  558. //var hasPermission int
  559. var hasPersion bool
  560. if user.CompanyId > 1 {
  561. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  562. if e != nil {
  563. err = errors.New("获取用户权限信息失败" + e.Error())
  564. return
  565. }
  566. if companyPermission != "" {
  567. slice := strings.Split(companyPermission, ",")
  568. if utils.InArrayByStr(slice, "周期") {
  569. hasPersion = true
  570. }
  571. }
  572. }
  573. var hasPermission int
  574. var e error
  575. if hasPersion {
  576. hasPermission = 1
  577. } else {
  578. if user.UserId == 0 {
  579. hasPermission = 1
  580. } else {
  581. itemResp.HasPermission, itemResp.SellerName, itemResp.SellerMobile, _, err = GetUserHasPermissionArticle(user)
  582. if err != nil {
  583. return
  584. }
  585. hasPermission, e = GetUserPermissionCode(user.UserId, user.CompanyId)
  586. if e != nil {
  587. err = errors.New("GetUserPermissionCode")
  588. return
  589. }
  590. itemResp.SellerName, itemResp.SellerMobile, _ = GetSellerName(user)
  591. }
  592. }
  593. itemResp.HasPermission = hasPermission
  594. itemSource.FiccReportXcx = itemResp
  595. itemSourceResp = itemSource
  596. return
  597. }