classify.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/services"
  6. "hongze/hz_crm_api/utils"
  7. )
  8. // ClassifyController 分类
  9. type ClassifyController struct {
  10. BaseAuthController
  11. }
  12. // ListClassify
  13. // @Title 获取分类列表
  14. // @Description 获取分类列表
  15. // @Param KeyWord query string true "检索关键词"
  16. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  17. // @Param HideDayWeek query int false "是否隐藏晨周报"
  18. // @Success 200 {object} models.Classify
  19. // @router /list [get]
  20. func (this *ClassifyController) ListClassify() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. keyWord := this.GetString("KeyWord")
  27. companyType := this.GetString("CompanyType")
  28. hideDayWeek, _ := this.GetInt("HideDayWeek")
  29. req := new(services.GetClassifyListReq)
  30. req.Keyword = keyWord
  31. req.CompanyType = companyType
  32. req.HideDayWeek = hideDayWeek
  33. resp, err := services.GetClassifyList(req)
  34. if err != nil {
  35. br.Msg = "获取失败"
  36. br.ErrMsg = "获取失败,Err:" + err.Error()
  37. return
  38. }
  39. br.Data = resp
  40. br.Ret = 200
  41. br.Success = true
  42. br.Msg = "获取成功"
  43. }
  44. // @Title 含电话会分类列表
  45. // @Description 含电话会分类列表
  46. // @Success 200 {object} models.Classify
  47. // @router /tel_list [get]
  48. func (this *ClassifyController) TelListClassify() {
  49. // todo 获取电话会 是否需要改成从中间服务项目中获取
  50. br := new(models.BaseResponse).Init()
  51. defer func() {
  52. this.Data["json"] = br
  53. this.ServeJSON()
  54. }()
  55. resp := make([]*models.SimpleClassifyList, 0)
  56. var condition, orderRule string
  57. var pars []interface{}
  58. condition += ` AND has_teleconference = 1`
  59. telList, e := models.GetClassifyByCondition(condition, orderRule, pars)
  60. if e != nil {
  61. return
  62. }
  63. firstList := make([]*models.SimpleClassifyList, 0)
  64. secondList := make([]*models.SimpleClassifyList, 0)
  65. secondMap := make(map[int][]*models.SimpleClassifyList, 0)
  66. for i := range telList {
  67. if telList[i].ParentId == 0 {
  68. firstList = append(firstList, telList[i])
  69. } else {
  70. secondList = append(secondList, telList[i])
  71. secondMap[telList[i].ParentId] = append(secondMap[telList[i].ParentId], telList[i])
  72. }
  73. }
  74. for i := range firstList {
  75. firstList[i].Child = secondMap[firstList[i].Id]
  76. }
  77. resp = firstList
  78. br.Data = resp
  79. br.Ret = 200
  80. br.Success = true
  81. br.Msg = "获取成功"
  82. }
  83. // Edit
  84. // @Title 编辑报告分类
  85. // @Description 编辑报告分类
  86. // @Param request body services.EditClassifyReq true "type json string"
  87. // @Success 200 string "操作成功"
  88. // @router /edit [post]
  89. func (this *ClassifyController) Edit() {
  90. br := new(models.BaseResponse).Init()
  91. br.IsSendEmail = false
  92. defer func() {
  93. this.Data["json"] = br
  94. this.ServeJSON()
  95. }()
  96. sysUser := this.SysUser
  97. if sysUser == nil {
  98. br.Msg = "请登录"
  99. br.ErrMsg = "请登录,SysUser Is Empty"
  100. br.Ret = 408
  101. return
  102. }
  103. var req services.EditClassifyReq
  104. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  105. br.Msg = "参数解析异常!"
  106. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  107. return
  108. }
  109. if req.ClassifyId <= 0 {
  110. br.Msg = "分类ID有误"
  111. return
  112. }
  113. err, errMsg := services.EditReportClassify(&req)
  114. if err != nil {
  115. br.Msg = errMsg
  116. br.ErrMsg = "编辑报告分类失败, Err:" + err.Error()
  117. return
  118. }
  119. // 清除小程序端的章节缓存
  120. {
  121. key := "hongze_yb:report_chapter_type:GetEffectTypeID"
  122. _ = utils.Rc.Delete(key)
  123. }
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "操作成功"
  127. }