knowledge.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package knowledge
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_bridge/controller/resp"
  5. "eta_gn/eta_bridge/global"
  6. knowledgeDao "eta_gn/eta_bridge/models/request/knowledge"
  7. "eta_gn/eta_bridge/services/index_data"
  8. "eta_gn/eta_bridge/services/knowledge"
  9. "github.com/gin-gonic/gin"
  10. )
  11. type KnowledgeController struct{}
  12. // ReportSave 存储
  13. func (k *KnowledgeController) ReportSave(c *gin.Context) {
  14. res, err := knowledge.ForwardRequest(c, global.CONFIG.EtaReport.Host+"v1/report/knowledge/upload")
  15. if err != nil {
  16. global.LOG.Error("knowledge save error: ", err)
  17. resp.Fail("保存失败", c)
  18. return
  19. }
  20. var result knowledge.KnowledgeUploadResp
  21. if e := json.Unmarshal(res, &result); e != nil {
  22. global.LOG.Error("knowledge save unmarshal error: ", e)
  23. resp.Fail("保存失败", c)
  24. return
  25. }
  26. if result.Ret != 200 {
  27. global.LOG.Info("knowledgeResp Ret:%d, Msg:%s, ErrMsg:%s ", result.Ret, result.Msg, result.ErrMsg)
  28. resp.Fail("保存失败", c)
  29. }
  30. resp.Ok("保存成功", c)
  31. }
  32. func (k *KnowledgeController) ViewPointSave(c *gin.Context) {
  33. var req knowledgeDao.KnowledgeRefreshReq
  34. if e := c.Bind(&req); e != nil {
  35. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  36. return
  37. }
  38. param := make(map[string]interface{})
  39. var res *index_data.MarketOverviewResp
  40. pageNum := 1
  41. for {
  42. param["pageNum"] = pageNum
  43. param["pageSize"] = req.PageSise
  44. if req.UpdateTime != "" {
  45. param["UPDATE_TIME"] = req.UpdateTime
  46. }
  47. tmp, err := index_data.GetMarketOverview(param)
  48. if err != nil {
  49. global.LOG.Error("knowledge save error: ", err)
  50. resp.Fail("保存失败", c)
  51. return
  52. }
  53. if res == nil {
  54. res = tmp
  55. } else {
  56. res.Data.Records = append(res.Data.Records, tmp.Data.Records...)
  57. }
  58. if res.Code != "000000" {
  59. global.LOG.Info("knowledgeResp Res:%v ", res)
  60. continue
  61. }
  62. if len(res.Data.Records) != req.PageSise {
  63. break
  64. }
  65. pageNum++
  66. }
  67. resp.OkData("保存成功", res, c)
  68. }