ficc_report.go 23 KB

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