ficc_report.go 23 KB

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