autoreply.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package autoreply
  2. import (
  3. "wechat-conf/controllers"
  4. "wechat-conf/models/model"
  5. "wechat-conf/service/autoreply"
  6. )
  7. // AutoreplyController 信息
  8. type AutoreplyController struct {
  9. dao *autoreply.AutoreplyServ
  10. controllers.BaseController
  11. }
  12. // Constructor 初始化 Controller
  13. // @Title Constructor
  14. // @Description 初始化 Controller, 系统自动调用
  15. func (c *AutoreplyController) Constructor() {
  16. c.dao = autoreply.NewAutoreplyServ(c.Context)
  17. }
  18. func (c *AutoreplyController) GetAutoReplyList() {
  19. user := c.Context.Get("user").(*model.SysUser)
  20. page, _ := c.GetInt("page")
  21. pageSize, _ := c.GetInt("pagesize")
  22. autoType := c.GetString("autoType")
  23. list, err := c.dao.GetAutoReplyList(user.OrgId, autoType, page, pageSize)
  24. if err != nil {
  25. c.ResponseError(err)
  26. }
  27. c.ResponseJSON(list)
  28. }
  29. func (c *AutoreplyController) GetAutoReplyById() {
  30. autoreplyId := c.GetString(":autoreplyId")
  31. autoreply, err := c.dao.GetAutoReplyById(autoreplyId)
  32. if err != nil {
  33. c.ResponseError(err)
  34. }
  35. c.ResponseJSON(autoreply)
  36. }
  37. func (c *AutoreplyController) SaveAutoreply() {
  38. user := c.Context.Get("user").(*model.SysUser)
  39. autoreply := model.TaAutoReply{}
  40. if err := c.ParseForm(&autoreply); err != nil {
  41. c.ResponseError(err)
  42. }
  43. newAuto, err := c.dao.SaveAutoReply(autoreply, user.OrgId)
  44. if err != nil {
  45. c.ResponseError(err)
  46. }
  47. c.ResponseJSON(newAuto)
  48. }
  49. func (c *AutoreplyController) DeleteAutoReply() {
  50. autoreplyId := c.GetString(":autoreplyId")
  51. err := c.dao.DeleteAutoReply(autoreplyId)
  52. if err != nil {
  53. c.ResponseError(err)
  54. }
  55. c.ResponseJSON("删除成功")
  56. }
  57. func (c *AutoreplyController) ChangeIsUse() {
  58. user := c.Context.Get("user").(*model.SysUser)
  59. autoType := c.GetString(":autoType")
  60. isUse := c.GetString(":isUse")
  61. err := c.dao.DisableAutoreply(autoType, user.OrgId, isUse)
  62. if err != nil {
  63. c.ResponseError(err)
  64. }
  65. c.ResponseJSON("修改成功")
  66. }