autoreply.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. autoreply := model.TaAutoReply{}
  39. if err := c.ParseForm(&autoreply); err != nil {
  40. c.ResponseError(err)
  41. }
  42. newAuto, err := c.dao.SaveAutoReply(autoreply)
  43. if err != nil {
  44. c.ResponseError(err)
  45. }
  46. c.ResponseJSON(newAuto)
  47. }
  48. func (c *AutoreplyController) DeleteAutoReply() {
  49. autoreplyId := c.GetString(":autoreplyId")
  50. err := c.dao.DeleteAutoReply(autoreplyId)
  51. if err != nil {
  52. c.ResponseError(err)
  53. }
  54. c.ResponseJSON("删除成功")
  55. }