ficc_report.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. var condition string
  409. var pars []interface{}
  410. modifyTime := time.Now().Add(-10 * time.Minute)
  411. condition = ` AND modify_time >= ? OR id = 11897 `
  412. pars = append(pars, modifyTime)
  413. reportList, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
  414. if e != nil {
  415. err = errors.New("GetFiccRreportToCygxArticle, Err: " + e.Error())
  416. return
  417. }
  418. fmt.Println(len(reportList))
  419. //if len(reportList) == 0 {
  420. // return
  421. //}
  422. //获取研报的匹配关系
  423. conf, e := models.GetConfigByCode(utils.GET_FICC_REPORT_SET)
  424. if e != nil {
  425. err = errors.New("GetConfigByCode, Err: " + e.Error())
  426. return
  427. }
  428. if conf.ConfigValue == "" {
  429. err = errors.New("同步FICC研报的规则配置值有误")
  430. return
  431. }
  432. listFiccSet := new(ficc_report.GetReporteSetListResp)
  433. if e = json.Unmarshal([]byte(conf.ConfigValue), &listFiccSet); e != nil {
  434. err = errors.New("同步FICC研报的规则配置值解析失败 Err: " + e.Error())
  435. return
  436. }
  437. if len(reportList) > 0 {
  438. var reportIds []int
  439. for _, v := range reportList {
  440. reportIds = append(reportIds, v.Id)
  441. }
  442. listFiccReport, e := models.GetCygxCygxArticleListByReportIds(reportIds)
  443. if e != nil {
  444. err = errors.New("GetCygxCygxArticleListByReportIds, Err: " + e.Error())
  445. return
  446. }
  447. mapFiccReport := make(map[int]int)
  448. for _, v := range listFiccReport {
  449. mapFiccReport[v.ReportId] = v.ArticleId
  450. }
  451. //量不大,先这么写吧
  452. for _, v := range reportList {
  453. time.Sleep(1 * time.Millisecond) // 延时一秒
  454. item := new(models.CygxArticle)
  455. item.ReportId = v.Id
  456. item.PublishDate = v.PublishTime.Format(utils.FormatDateTime)
  457. item.Title = v.Title
  458. if v.ClassifyNameFirst == "晨会纪要" && v.ClassifyNameSecond == "晨会纪要" {
  459. item.Title = "FICC/周期品晨会纪要"
  460. }
  461. item.CategoryName = utils.ZHOU_QI_NAME
  462. item.Body = v.Content
  463. item.Abstract = v.Abstract
  464. item.FieldName = "PVC烧碱双周报"
  465. item.CreateDate = time.Now().Format(utils.FormatDate)
  466. item.PublishStatus = 1
  467. item.IsReport = 1
  468. item.IsClass = 1
  469. item.CreateTime = time.Now()
  470. item.ChartPermissionName = utils.ZHOU_QI_NAME
  471. item.ChartPermissionId = utils.ZHOU_QI_ID
  472. var haveSet bool
  473. for _, vSet := range listFiccSet.List {
  474. if v.ClassifyNameFirst == vSet.ClassifyNameFirst && v.ClassifyNameSecond == vSet.ClassifyNameSecond {
  475. haveSet = true
  476. item.SubCategoryName = v.ClassifyNameSecond
  477. item.MatchTypeName = v.ClassifyNameSecond
  478. continue
  479. }
  480. }
  481. haveSet = true
  482. item.SubCategoryName = "PVC烧碱双周报"
  483. item.MatchTypeName = "PVC烧碱双周报"
  484. if !haveSet {
  485. continue
  486. }
  487. detailCategory, detailCategoryErr := models.GetCygxReportMappingCelueDetailByZhoQiCategoryName(item.SubCategoryName)
  488. if detailCategoryErr != nil {
  489. continue
  490. }
  491. item.CategoryId = detailCategory.CategoryId
  492. item.CategoryIdTwo = detailCategory.CategoryId
  493. var articleIdMax int
  494. //如果不存在就新增
  495. if mapFiccReport[v.Id] == 0 {
  496. maxArticleIdArticleInfo, e := models.GetMaxArticleIdInfo()
  497. if e != nil {
  498. err = errors.New("GetMaxArticleIdInfo, Err: " + e.Error())
  499. return
  500. }
  501. articleIdMax = maxArticleIdArticleInfo.ArticleId + 1
  502. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdMax))
  503. item.ArticleId = articleIdMax
  504. _, e = models.AddCygxArticles(item)
  505. if e != nil {
  506. err = errors.New("AddCygxArticles, Err: " + e.Error())
  507. return
  508. }
  509. } else {
  510. articleIdMax = mapFiccReport[v.Id]
  511. item.ArticleId = mapFiccReport[v.Id]
  512. updateParams := make(map[string]interface{})
  513. updateParams["Title"] = item.Title
  514. updateParams["PublishDate"] = item.PublishDate
  515. updateParams["Body"] = item.Body
  516. updateParams["Abstract"] = item.Abstract
  517. updateParams["PublishStatus"] = item.PublishStatus
  518. updateParams["SubCategoryName"] = item.SubCategoryName
  519. updateParams["MatchTypeName"] = item.MatchTypeName
  520. updateParams["FieldName"] = item.FieldName
  521. updateParams["CategoryId"] = item.CategoryId
  522. updateParams["CategoryIdTwo"] = item.CategoryIdTwo
  523. whereParam := map[string]interface{}{"article_id": item.ArticleId}
  524. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  525. if err != nil {
  526. fmt.Println("UpdateByExpr Err:" + err.Error())
  527. return err
  528. }
  529. }
  530. UpdateFICCReportResourceData(v.Id, listFiccSet)
  531. AddCygxReportMappingCategoryGroupByArticleId(articleIdMax)
  532. UpdateCygxZhouqiArticleMapTime(item.FieldName) //更新周期对应分类下所管理文章的更新时间
  533. }
  534. }
  535. //获取已经同步到查研的FICC研报 对比,如果FICC研报已经取消发布,查研也做对应的删除
  536. listCygxFiccReport, e := models.GetCygxCygxArticleFiccReportList()
  537. if e != nil {
  538. err = errors.New("GetCygxCygxArticleFiccReportList, Err: " + e.Error())
  539. return
  540. }
  541. var cygxFiccReportIds []int
  542. for _, v := range listCygxFiccReport {
  543. if v.PublishStatus == 1 {
  544. cygxFiccReportIds = append(cygxFiccReportIds, v.ReportId)
  545. }
  546. }
  547. lenArr := len(cygxFiccReportIds)
  548. if lenArr == 0 {
  549. return
  550. }
  551. reportByHandList, e := ficc_report.GetCygxFiccReportByHandList() // 手动同步过来的报告
  552. if e != nil {
  553. err = errors.New("GetCygxFiccReportByHandList, Err: " + e.Error())
  554. return
  555. }
  556. ficcReporIdsHand := make(map[int]bool) // Ficc 研报手动同步过来的报告ID
  557. for _, v := range reportByHandList {
  558. ficcReporIdsHand[v.FiccReportId] = true
  559. }
  560. condition = ` AND id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  561. pars = make([]interface{}, 0)
  562. pars = append(pars, cygxFiccReportIds)
  563. ficcReportListPush, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
  564. if e != nil {
  565. err = errors.New("GetFiccRreportToCygxArticle, Err: " + e.Error())
  566. return
  567. }
  568. var removeficcReporIds []int // 需要移除的报告ID
  569. ficcReporIdsPush := make(map[int]bool) // Ficc 研报还存在的报告ID
  570. for _, v := range ficcReportListPush {
  571. ficcReporIdsPush[v.Id] = true
  572. }
  573. for _, v := range listCygxFiccReport {
  574. if !ficcReporIdsPush[v.ReportId] && !ficcReporIdsHand[v.ReportId] { // 手动同步过来的报告不做删除处理
  575. removeficcReporIds = append(removeficcReporIds, v.ReportId)
  576. }
  577. }
  578. if len(removeficcReporIds) > 0 {
  579. e = models.HideCygxResourceDataFiccReport(removeficcReporIds)
  580. if e != nil {
  581. err = errors.New("HideCygxResourceDataFiccReport, Err: " + e.Error())
  582. return
  583. }
  584. }
  585. fmt.Println("end")
  586. return
  587. }
  588. // 根据用户信息,获取跳转研报小程序详情信息
  589. func GetFiccReportXcxItem(user *models.WxUserItem) (itemSourceResp *models.CygxResourceDataResp) {
  590. var err error
  591. defer func() {
  592. if err != nil {
  593. fmt.Println(err)
  594. go utils.SendAlarmMsg(fmt.Sprint("根据用户信息,获取跳转研报小程序详情信息失败 GetFiccReportXcxItem ,err:", err.Error(), "UserId:", user.UserId), 2)
  595. }
  596. }()
  597. deUserId := utils.DesBase64Encrypt([]byte(strconv.Itoa(user.UserId)))
  598. itemSource := new(models.CygxResourceDataResp)
  599. itemSource.Source = utils.CYGX_OBJ_FICC_REPORT_XCX
  600. itemResp := new(models.FiccReportXcx)
  601. itemResp.Source = utils.CYGX_OBJ_FICC_REPORT_XCX
  602. itemResp.Title = "每日原油播报"
  603. itemResp.SecondTitle = "欧美市场隔夜复盘"
  604. itemResp.ImgUrl = utils.FICC_REPORT_ICO_HOME
  605. itemResp.Mobile = user.Mobile
  606. itemResp.SellerMobile = ""
  607. itemResp.SellerName = ""
  608. itemResp.Appid = utils.FICC_REPORT_APPID
  609. itemResp.SourceUrl = "pages/voice/voice?thirdCode="
  610. itemResp.ThirdCode = string(deUserId)
  611. //var hasPermission int
  612. var hasPersion bool
  613. if user.CompanyId > 1 {
  614. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  615. if e != nil {
  616. err = errors.New("获取用户权限信息失败" + e.Error())
  617. return
  618. }
  619. if companyPermission != "" {
  620. slice := strings.Split(companyPermission, ",")
  621. if utils.InArrayByStr(slice, "周期") {
  622. hasPersion = true
  623. }
  624. }
  625. }
  626. var hasPermission int
  627. var e error
  628. if hasPersion {
  629. hasPermission = 1
  630. } else {
  631. if user.UserId == 0 {
  632. hasPermission = 1
  633. } else {
  634. itemResp.HasPermission, itemResp.SellerName, itemResp.SellerMobile, _, err = GetUserHasPermissionArticle(user)
  635. if err != nil {
  636. return
  637. }
  638. hasPermission, e = GetUserPermissionCode(user.UserId, user.CompanyId)
  639. if e != nil {
  640. err = errors.New("GetUserPermissionCode")
  641. return
  642. }
  643. itemResp.SellerName, itemResp.SellerMobile, _ = GetSellerName(user)
  644. }
  645. }
  646. itemResp.HasPermission = hasPermission
  647. itemSource.FiccReportXcx = itemResp
  648. itemSourceResp = itemSource
  649. return
  650. }
  651. //func init() {
  652. // strslice := []string{"晨会纪要", "煤炭", "铜行业数据点评", "石油石化", "黑色调研", "宏观G2观察", "黄金月报"}
  653. // for _, v := range strslice {
  654. // fmt.Println(v)
  655. // UpdateCygxZhouqiArticleMapTime(v)
  656. // }
  657. //}
  658. // UpdateCygxZhouqiArticleMapTime 更新周期对应分类下所管理文章的更新时间
  659. func UpdateCygxZhouqiArticleMapTime(fieldName string) {
  660. var err error
  661. defer func() {
  662. if err != nil {
  663. fmt.Println("err:", err)
  664. go utils.SendAlarmMsg(fmt.Sprint("更新周期对应分类下所管理文章的更新时间 失败,UpdateCygxZhouqiArticleMapTime Err:"+err.Error()+"fieldName", fieldName), 3)
  665. }
  666. }()
  667. detail, e := models.GetCygxZhouqiArticleMapByMatchTypeName(fieldName)
  668. if e != nil {
  669. err = errors.New("GetCygxZhouqiArticleMapByMatchTypeName, Err: " + err.Error())
  670. return
  671. }
  672. listCategory, e := models.GetCygxZhouqiArticleMapByParentId(detail.ParentId)
  673. if e != nil {
  674. err = errors.New("GetCygxZhouqiArticleMapByParentId, Err: " + err.Error())
  675. return
  676. }
  677. var matchTypeName = []string{}
  678. for _, v := range listCategory {
  679. matchTypeName = append(matchTypeName, v.MatchTypeName)
  680. }
  681. var condition string
  682. var pars []interface{}
  683. condition = " AND category_name = '周期' AND field_name IN ('" + strings.Join(matchTypeName, "','") + "') ORDER BY publish_date DESC "
  684. articleList, e := models.GetCygxCygxArticleList(condition, pars, 0, 1)
  685. if e != nil {
  686. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  687. return
  688. }
  689. //就一条数据
  690. for _, v := range articleList {
  691. e = models.UpdateCygxZhouqiArticleMapTime(v.PublishDate, detail.ParentId)
  692. }
  693. return
  694. }