chart_service.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package media
  2. import (
  3. "eta/eta_mini_ht_api/common/component/config"
  4. "eta/eta_mini_ht_api/common/component/es"
  5. logger "eta/eta_mini_ht_api/common/component/log"
  6. "eta/eta_mini_ht_api/common/contants"
  7. "eta/eta_mini_ht_api/common/utils/page"
  8. chartService "eta/eta_mini_ht_api/domian/media"
  9. )
  10. type ChartInfo struct {
  11. ChartInfoId int
  12. ChartName string
  13. ChartImage string
  14. UniqueCode string
  15. }
  16. const (
  17. ESColumn = "chartName"
  18. )
  19. var (
  20. sortField = []string{"_score:desc"}
  21. htConfig = config.GetConfig(contants.HT).(*config.HTBizConfig)
  22. )
  23. func elastic() *es.ESClient {
  24. return es.GetInstance()
  25. }
  26. func AddChartToEs(chartInfo ChartInfo) {
  27. success := chartService.AddChartToEs(chartService.EsChartInfo{
  28. ChartInfoId: chartInfo.ChartInfoId,
  29. ChartName: chartInfo.ChartName,
  30. ChartImage: chartInfo.ChartImage,
  31. UniqueCode: chartInfo.UniqueCode,
  32. })
  33. if !success {
  34. logger.Error("新增图表到ES失败, chartInfoId:%d,uniqueCode:%s", chartInfo.ChartInfoId, chartInfo.UniqueCode)
  35. }
  36. }
  37. func SearchChartList(key string, ids []int, pageInfo page.PageInfo) (charts []ChartInfo, err error) {
  38. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  39. esChart, err := chartService.SearchChartList(key, ids, offset, pageInfo.PageSize)
  40. if err != nil {
  41. return
  42. }
  43. for _, chart := range esChart {
  44. charts = append(charts, convertChartInfo(chart))
  45. }
  46. return
  47. }
  48. func SearchAllChartList(key string, ids []int) (charts []ChartInfo, err error) {
  49. esChart, err := chartService.SearchAllChartList(key, ids)
  50. if err != nil {
  51. return
  52. }
  53. for _, chart := range esChart {
  54. charts = append(charts, convertChartInfo(chart))
  55. }
  56. return
  57. }
  58. func UpdateChartImage(image string, id int) bool {
  59. return chartService.UpdateChartImage(image, id)
  60. }
  61. func GetChartById(chartInfoId int) (info ChartInfo, err error) {
  62. chart, err := chartService.GetChartById(chartInfoId)
  63. if err != nil {
  64. return
  65. }
  66. info = convertChartInfo(chart)
  67. return
  68. }
  69. func convertChartInfo(chart chartService.EsChartInfo) ChartInfo {
  70. return ChartInfo{
  71. ChartInfoId: chart.ChartInfoId,
  72. ChartName: chart.ChartName,
  73. ChartImage: chart.ChartImage,
  74. UniqueCode: chart.UniqueCode,
  75. }
  76. }