cltled.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package controllers
  2. import (
  3. "lc/common/mqtt"
  4. "lc/common/protocol"
  5. )
  6. // 卡莱特屏幕新接口
  7. const (
  8. LED_STATUS_PREFIX string = "led_stat_" //LED实时状态
  9. POWER string = "power" //1电源状态
  10. VSN string = "vsn" //2音量
  11. TIME string = "time" //3亮度
  12. VOLUME string = "volume" //4播放节目名称
  13. BRIGHTNESS string = "brightness" //5最近连接时间
  14. )
  15. type reqData struct {
  16. Codes []string `json:"codes"` //多张sn
  17. Param interface{} `json:"param"` //请求参数
  18. }
  19. type CltledController struct {
  20. BaseController
  21. }
  22. // Act @Title 卡莱物信息屏
  23. // @Description 卡莱物信息屏全部接口
  24. // @Param body controllers.reqData true "数据"
  25. // @Success 0 {int} BaseResponse.Code "成功"
  26. // @Failure 1 {int} BaseResponse.Code "失败"
  27. // @router /v1/act [post]
  28. func (o *CltledController) Act() {
  29. act := o.Ctx.Input.Param(":actName")
  30. tenant := o.Ctx.Input.Param(":tenant")
  31. reqId := o.Ctx.Input.Param(":requestId")
  32. actList := map[string]interface{}{
  33. protocol.TP_LED_QUERY_INFO: "查询屏基础信息",
  34. protocol.TP_LED_QUERY_PGMS: "查询节目信息",
  35. protocol.TP_LED_SET_PGMS: "发布节目",
  36. protocol.TP_LED_SWITCH: "切换节目",
  37. protocol.TP_LED_DELETE: "删除一个或多个节目",
  38. protocol.TP_LED_CLEAN: "清除所有节目",
  39. protocol.TP_LED_SNAPSHOT: "截屏",
  40. protocol.TP_LED_QUERY_SCHEDULE: "获取排程",
  41. protocol.TP_LED_SET_SCHEDULE: "配置排程",
  42. protocol.TP_LED_QUERY_POWERSTATUS: "状态",
  43. protocol.TP_LED_SET_CMD: "下发远程指令",
  44. protocol.TP_LED_QUERY_BRIGHTCOLOR: "查询亮度色温",
  45. protocol.TP_LED_SET_BRIGHTNESS: "亮度调节",
  46. protocol.TP_LED_QUERY_VOLUME: "查询音量",
  47. protocol.TP_LED_SET_VOLUME: "调节音量 ",
  48. protocol.TP_LED_QUERY_RESOLUTION: "查询屏幕参数",
  49. }
  50. _, ok := actList[act]
  51. if !ok || tenant == "" {
  52. o.Response(Failure, "actName非法", nil)
  53. return
  54. }
  55. jsonStr := reqData{}
  56. body := o.Ctx.Input.RequestBody
  57. err := json.Unmarshal(body, &jsonStr)
  58. if err != nil {
  59. o.Response(Failure, "失败"+err.Error(), nil)
  60. return
  61. }
  62. for _, sn := range jsonStr.Codes {
  63. topic := getTopic(tenant, sn, act, reqId)
  64. err = GetMqttHandler().PublishJSON(topic, jsonStr.Param, mqtt.AtMostOnce)
  65. }
  66. if err != nil {
  67. o.Response(Failure, "失败"+err.Error(), nil)
  68. return
  69. }
  70. o.Response(Success, "成功", jsonStr)
  71. }
  72. func getTopic(tenant, sn, downORup, reqid string) string {
  73. // 生成新的 UUID
  74. //id := uuid.New()
  75. return tenant + "/" + protocol.DT_CLT_LED + "/" + sn + "/down/" + downORup + "/" + reqid
  76. }