lampPoleGroupController.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/dao"
  5. "iot_manager_service/app/model"
  6. "iot_manager_service/app/service"
  7. "iot_manager_service/app/utils"
  8. "net/http"
  9. "strconv"
  10. )
  11. // 灯杆分组管理对象
  12. var LampPoleGroup = new(lampPoleGroupCtl)
  13. type lampPoleGroupCtl struct{}
  14. // Detail 获取详情
  15. func (c *lampPoleGroupCtl) Detail(ctx *gin.Context) {
  16. id, e := strconv.Atoi(ctx.Query("id"))
  17. if e != nil {
  18. ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(e.Error(), nil))
  19. return
  20. }
  21. device, err := service.LampPoleGroupService.Get(id)
  22. if err != nil {
  23. ctx.JSON(http.StatusOK, err)
  24. return
  25. }
  26. ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, device))
  27. }
  28. // CreateOrUpdate 新增、更新
  29. func (c *lampPoleGroupCtl) CreateOrUpdate(ctx *gin.Context) {
  30. var req *model.ReqLampPoleGroupSubmit
  31. if err := ctx.ShouldBindJSON(&req); err != nil {
  32. ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(err.Error(), nil))
  33. return
  34. }
  35. err := service.LampPoleGroupService.CreateOrUpdate(req)
  36. ctx.JSON(http.StatusOK, err)
  37. }
  38. // List 获取分页列表
  39. func (c *lampPoleGroupCtl) List(ctx *gin.Context) {
  40. poleGroupName := ctx.Query("poleGroupName")
  41. current, _ := strconv.Atoi(ctx.Query("current"))
  42. size, _ := strconv.Atoi(ctx.Query("size"))
  43. if current == 0 {
  44. current = 1
  45. }
  46. if size <= 0 || size > 100 {
  47. size = 10
  48. }
  49. devices, err := service.LampPoleGroupService.List(poleGroupName, current, size)
  50. if err != nil {
  51. ctx.JSON(http.StatusOK, err)
  52. return
  53. }
  54. rsp := model.RspLampPoleGroupList{
  55. Current: current,
  56. Size: size,
  57. Total: len(devices),
  58. }
  59. for _, device := range devices {
  60. rsp.Records = append(rsp.Records, lampPoleGroupDaoToModel(device))
  61. }
  62. ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, rsp))
  63. }
  64. // Remove 删除
  65. func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {
  66. var req *model.ReqLampPoleGroupRemove
  67. if err := ctx.ShouldBindJSON(&req); err != nil {
  68. ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(err.Error(), nil))
  69. return
  70. }
  71. err := service.LampPoleGroupService.Remove(req.IDs)
  72. if err != nil {
  73. ctx.JSON(http.StatusOK, err)
  74. return
  75. }
  76. ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, nil))
  77. }
  78. // GetList 获取下拉列表
  79. func (c *lampPoleGroupCtl) GetList(ctx *gin.Context) {
  80. devices, err := service.LampPoleGroupService.GetList()
  81. if err != nil {
  82. ctx.JSON(http.StatusOK, err)
  83. return
  84. }
  85. ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, devices))
  86. }
  87. // FiltrationList 获取智能照明灯杆分组下拉(过滤掉没有灯控的分组显示)
  88. func (c *lampPoleGroupCtl) FiltrationList(ctx *gin.Context) {
  89. devices, err := service.LampPoleGroupService.GetFiltration()
  90. if err != nil {
  91. ctx.JSON(http.StatusOK, err)
  92. return
  93. }
  94. ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, devices))
  95. }
  96. // GetTree 获取所有的灯杆分组所属灯杆
  97. func (c *lampPoleGroupCtl) GetTree(ctx *gin.Context) {
  98. //todo 灯杆列表赋值
  99. // var rsp model.ReqLampPoleGroupSubmit
  100. devices, err := service.LampPoleGroupService.GetTree()
  101. if err != nil {
  102. ctx.JSON(http.StatusOK, err)
  103. return
  104. }
  105. ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, devices))
  106. }
  107. func lampPoleGroupDaoToModel(device dao.LampPoleGroup) model.ReqLampPoleGroupSubmit {
  108. return model.ReqLampPoleGroupSubmit{
  109. ID: device.ID,
  110. PoleGroupName: device.PoleGroupName,
  111. CountLampPole: device.CountLampPole,
  112. Remark: device.Remark,
  113. TenantId: device.TenantId,
  114. CreateTime: device.CreateTime,
  115. CreateUser: device.CreateUser,
  116. UpdateTime: device.UpdateTime,
  117. UpdateUser: device.UpdateUser,
  118. IsDeleted: device.IsDeleted,
  119. Tag: device.Tag,
  120. PublicName: "",
  121. LampPoleVOList: nil,
  122. CameraList: nil,
  123. SwitchBoxList: nil,
  124. InfoBoardList: nil,
  125. }
  126. }