IntelligentLightingStrategy.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/device/model"
  5. "iot_manager_service/app/device/service"
  6. "iot_manager_service/util"
  7. "math"
  8. "net/http"
  9. "strconv"
  10. )
  11. var IntelligentLighting = new(intelligentLightingCtl)
  12. type intelligentLightingCtl struct{}
  13. func (c *intelligentLightingCtl) Detail(ctx *gin.Context) {
  14. publicId, e := strconv.Atoi(ctx.Query("publicId"))
  15. if e != nil {
  16. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
  17. return
  18. }
  19. if publicId == 0 {
  20. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.RelationIdInvalid, nil))
  21. return
  22. }
  23. //当前类型1=灯杆2=灯杆分组
  24. relationType, e := strconv.Atoi(ctx.Query("type"))
  25. if e != nil {
  26. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
  27. return
  28. }
  29. if relationType == model.RelationTypeLight {
  30. detail, err := service.IntelligentLightingService.GetDetailByLight(publicId)
  31. if err != nil {
  32. ctx.JSON(http.StatusOK, err)
  33. return
  34. }
  35. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
  36. } else if relationType == model.RelationTypeLampPoleGroup {
  37. detail, err := service.IntelligentLightingService.GetDetailByGroup(publicId)
  38. if err != nil {
  39. ctx.JSON(http.StatusOK, err)
  40. return
  41. }
  42. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
  43. } else {
  44. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.RelationTypeInvalid, nil))
  45. }
  46. }
  47. func (c *intelligentLightingCtl) List(ctx *gin.Context) {
  48. searchValue := ctx.Query("searchValue")
  49. groupId := ctx.Query("groupId")
  50. current, _ := strconv.Atoi(ctx.Query("current"))
  51. size, _ := strconv.Atoi(ctx.Query("size"))
  52. if current == 0 {
  53. current = 1
  54. }
  55. if size <= 0 || size > 100 {
  56. size = 10
  57. }
  58. strategies, err := service.IntelligentLightingService.List(searchValue, groupId, current, size)
  59. if err != nil {
  60. ctx.JSON(http.StatusOK, err)
  61. return
  62. }
  63. pages := math.Ceil(float64(len(strategies)) / float64(size))
  64. rsp := model.RspIntelligentLightList{
  65. Current: current,
  66. Size: size,
  67. Total: len(strategies),
  68. Pages: int(pages),
  69. Records: strategies,
  70. }
  71. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
  72. }
  73. func (c *intelligentLightingCtl) RelationList(ctx *gin.Context) {
  74. }
  75. func (c *intelligentLightingCtl) Relation(ctx *gin.Context) {
  76. }
  77. func (c *intelligentLightingCtl) Remove(ctx *gin.Context) {
  78. }
  79. func (c *intelligentLightingCtl) ChangeHandSwitch(ctx *gin.Context) {
  80. }
  81. func (c *intelligentLightingCtl) GetStatus(ctx *gin.Context) {
  82. }