help.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package http
  2. import (
  3. "go-common/app/interface/main/web/conf"
  4. "go-common/app/interface/main/web/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func helpList(c *bm.Context) {
  10. var (
  11. rs []*model.HelpList
  12. err error
  13. )
  14. v := new(struct {
  15. PTypeID string `form:"parentTypeId" validate:"required"`
  16. })
  17. if err = c.Bind(v); err != nil {
  18. return
  19. }
  20. if rs, err = webSvc.HelpList(c, v.PTypeID); err != nil {
  21. c.JSON(nil, ecode.Degrade)
  22. return
  23. }
  24. c.JSON(rs, nil)
  25. }
  26. func helpDetail(c *bm.Context) {
  27. var (
  28. total int
  29. detail []*model.HelpDeatil
  30. list []*model.HelpList
  31. err error
  32. )
  33. v := new(struct {
  34. PTypeID string `form:"questionTypeId" validate:"required"`
  35. KeyFlag int `form:"keyFlag" default:"1" validate:"min=1"`
  36. FID string `form:"fId"`
  37. Pn int `form:"pn" default:"1" validate:"min=1"`
  38. Ps int `form:"ps" default:"15" validate:"min=1"`
  39. })
  40. if err = c.Bind(v); err != nil {
  41. return
  42. }
  43. if v.Ps > conf.Conf.Rule.MaxHelpPageSize {
  44. v.Ps = conf.Conf.Rule.MaxHelpPageSize
  45. }
  46. if detail, list, total, err = webSvc.HelpDetail(c, v.FID, v.PTypeID, v.KeyFlag, v.Pn, v.Ps); err != nil {
  47. c.JSON(nil, ecode.Degrade)
  48. log.Error("webSvc.HelpDetail(%s,%d,%d,%d) error(%v)", v.PTypeID, v.KeyFlag, v.Pn, v.Ps, err)
  49. return
  50. }
  51. data := make(map[string]interface{}, 2)
  52. rsDetail := make(map[string]interface{}, 2)
  53. page := map[string]int{
  54. "num": v.Pn,
  55. "size": v.Ps,
  56. "total": total,
  57. }
  58. rsDetail["items"] = detail
  59. rsDetail["page"] = page
  60. data["detail"] = rsDetail
  61. data["list"] = list
  62. c.JSON(data, nil)
  63. }
  64. func helpSearch(c *bm.Context) {
  65. var (
  66. total int
  67. list []*model.HelpDeatil
  68. err error
  69. )
  70. v := new(struct {
  71. PTypeID string `form:"questionTypeId" default:"-1"`
  72. KeyWords string `form:"keyWords" validate:"required"`
  73. KeyFlag int `form:"keyFlag" default:"1" validate:"min=1"`
  74. Pn int `form:"pn" default:"1" validate:"min=1"`
  75. Ps int `form:"ps" default:"15" validate:"min=1"`
  76. })
  77. if err = c.Bind(v); err != nil {
  78. return
  79. }
  80. if v.Ps > conf.Conf.Rule.MaxHelpPageSize {
  81. v.Ps = conf.Conf.Rule.MaxHelpPageSize
  82. }
  83. if list, total, err = webSvc.HelpSearch(c, v.PTypeID, v.KeyWords, v.KeyFlag, v.Pn, v.Ps); err != nil {
  84. c.JSON(nil, err)
  85. log.Error("webSvc.HelpDetail(%s,%d,%d,%d) error(%v)", v.KeyWords, v.KeyFlag, v.Pn, v.Ps, err)
  86. return
  87. }
  88. data := make(map[string]interface{}, 2)
  89. page := map[string]int{
  90. "num": v.Pn,
  91. "size": v.Ps,
  92. "total": total,
  93. }
  94. data["page"] = page
  95. data["list"] = list
  96. c.JSON(data, nil)
  97. }