aepCallbackController.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/operation/model"
  5. "iot_manager_service/app/operation/service"
  6. "iot_manager_service/util/common"
  7. "iot_manager_service/util/logger"
  8. "net/http"
  9. )
  10. var AepCallback = new(aepCallbackCtl)
  11. type aepCallbackCtl struct{}
  12. type aepCallbackCtlReq struct {
  13. ProductID string `json:"productId"`
  14. IMEI string `json:"IMEI"`
  15. Payload model.AepCallbackPayload `json:"payload"`
  16. Timestamp int64 `json:"timestamp"`
  17. }
  18. func (c aepCallbackCtl) Save(ctx *gin.Context) {
  19. var req *aepCallbackCtlReq
  20. if err := ctx.ShouldBindJSON(&req); err != nil {
  21. logger.Logger.Errorf("aepCallbackCtl err = %s \n", err.Error())
  22. ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
  23. return
  24. }
  25. //井盖设备
  26. if req.ProductID == "16682136" {
  27. err := service.AepCallbackRecordService.Save(req.Payload, req.Timestamp)
  28. if err != nil {
  29. logger.Logger.Errorf("16682136 aepCallbackCtl err = %s \n", err.Error())
  30. ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
  31. return
  32. }
  33. //TODO: 垃圾桶
  34. //} else if() {
  35. } else {
  36. logger.Logger.Errorf("不支持设备类型 aepCallbackCtl err = %s \n", req.ProductID)
  37. ctx.JSON(http.StatusOK, nil)
  38. return
  39. }
  40. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  41. }