advice.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package cygx
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/utils"
  8. "strings"
  9. )
  10. // 优化建议
  11. type AdviceController struct {
  12. controllers.BaseAuthController
  13. }
  14. // @Title 优化建议列表
  15. // @Description 优化建议列表接口
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param KeyWord query string true "搜索关键词"
  19. // @Success 200 {object} cygx.AdviceListResp
  20. // @router /advice/list [get]
  21. func (this *AdviceController) List() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. sysUser := this.SysUser
  28. if sysUser == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. br.Ret = 408
  32. return
  33. }
  34. pageSize, _ := this.GetInt("PageSize")
  35. currentIndex, _ := this.GetInt("CurrentIndex")
  36. keyWord := this.GetString("KeyWord")
  37. keyWord = strings.Trim(keyWord, " ")
  38. keyWord = strings.Replace(keyWord, "'", "", -1)
  39. var total int
  40. resp := new(cygx.AdviceListResp)
  41. var startSize int
  42. if pageSize <= 0 {
  43. pageSize = utils.PageSize20
  44. }
  45. if currentIndex <= 0 {
  46. currentIndex = 1
  47. }
  48. startSize = paging.StartIndex(currentIndex, pageSize)
  49. var condition string
  50. var pars []interface{}
  51. if keyWord != "" {
  52. condition += ` AND (a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%' OR a.user_real_name LIKE '%` + keyWord + `%') `
  53. }
  54. total, err := cygx.GetAdviceListCount(condition, pars)
  55. if err != nil {
  56. br.Msg = "获取失败"
  57. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  58. return
  59. }
  60. list, err := cygx.GetAdviceList(condition, pars, startSize, pageSize)
  61. if err != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  64. return
  65. }
  66. if list == nil {
  67. list = make([]*cygx.CygxAdvice, 0)
  68. }
  69. page := paging.GetPaging(currentIndex, pageSize, total)
  70. resp.List = list
  71. resp.Paging = page
  72. br.Ret = 200
  73. br.Success = true
  74. br.Msg = "获取成功"
  75. br.Data = resp
  76. }