c_robot.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controllers
  2. import (
  3. "github.com/gogf/gf/v2/net/ghttp"
  4. "yx-dataset-server/app/bll"
  5. "yx-dataset-server/library/gplus"
  6. "yx-dataset-server/library/robot"
  7. )
  8. type Robot struct {
  9. RobotConfigBll bll.IRobotConfig
  10. }
  11. func NewRobot(bRobotConfig bll.IRobotConfig) *Robot {
  12. return &Robot{
  13. RobotConfigBll: bRobotConfig,
  14. }
  15. }
  16. // Create 创建数据
  17. // @Tags API-RobotConfig
  18. // @Summary 创建数据
  19. // @Param body schema.RobotConfig true "提交的数据"
  20. // @Success 200 schema.RobotConfig
  21. // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
  22. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  23. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  24. // @Router /robot/v1/robots/receive/{id}
  25. func (a *Robot) ReceiveMessage(r *ghttp.Request) {
  26. var data robot.DingTalkRobotMessage
  27. if err := gplus.ParseJson(r, &data); err != nil {
  28. gplus.ResError(r, err)
  29. }
  30. id := r.Get("id").String()
  31. ctx := gplus.NewContext(r)
  32. err := a.RobotConfigBll.ReceiveMessage(ctx, id, data)
  33. if err != nil {
  34. gplus.ResError(r, err)
  35. }
  36. ResSuccess(r, nil)
  37. }