publishLibrariesController.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/middleware"
  5. "iot_manager_service/app/multimedia/model"
  6. "iot_manager_service/app/multimedia/service"
  7. service2 "iot_manager_service/app/system/service"
  8. "iot_manager_service/util/common"
  9. "math"
  10. "net/http"
  11. "strconv"
  12. "strings"
  13. )
  14. // PublishLibraries 节目播放
  15. var PublishLibraries = new(PublishLibrariesCtl)
  16. type PublishLibrariesCtl struct{}
  17. // List 节目播放列表
  18. func (c *PublishLibrariesCtl) List(ctx *gin.Context) {
  19. searchValue := ctx.Query("searchValue")
  20. current, _ := strconv.Atoi(ctx.Query("current"))
  21. size, _ := strconv.Atoi(ctx.Query("size"))
  22. sysType, _ := strconv.Atoi(ctx.Query("sysType"))
  23. if current == 0 {
  24. current = 1
  25. }
  26. if size <= 0 || size > 100 {
  27. size = 10
  28. }
  29. value, _ := ctx.Get(middleware.Authorization)
  30. claims := value.(*middleware.Claims)
  31. libraries, total, err := service.PublishLibrariesService.List(claims.TenantId, searchValue, current, size, sysType)
  32. for i, library := range libraries {
  33. stime := library.StartTime.DateString()
  34. etime := library.EndTime.DateString()
  35. libraries[i].PlayPeriod = stime + " - " + etime
  36. libraries[i].ResolutionName = service2.DictService.GetResolutionName(library.TenantId, library.Resolution)
  37. libraries[i].CountDeviceNum = len(strings.Split(library.InfoId, ","))
  38. }
  39. if err != nil {
  40. ctx.JSON(http.StatusOK, err)
  41. return
  42. }
  43. pages := math.Ceil(float64(total) / float64(size))
  44. rsp := model.RsqPublishLibrariesList{
  45. Current: current,
  46. Size: size,
  47. Total: int(total),
  48. Pages: int(pages),
  49. Records: libraries,
  50. }
  51. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  52. }
  53. // GetLibraryList 节目播放 预览
  54. func (c *PublishLibrariesCtl) GetLibraryList(ctx *gin.Context) {
  55. id := ctx.Query("id")
  56. librariesId, e := strconv.Atoi(id)
  57. if e != nil {
  58. ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
  59. return
  60. }
  61. value, _ := ctx.Get(middleware.Authorization)
  62. claims := value.(*middleware.Claims)
  63. programId, err := service.PublishLibrariesService.GetProgram(librariesId)
  64. if err != nil {
  65. ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
  66. return
  67. }
  68. list, errors := service.ProgramService.GetLibraryList(claims.TenantId, programId)
  69. if errors != nil {
  70. ctx.JSON(http.StatusOK, e)
  71. return
  72. }
  73. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, list))
  74. }
  75. // AffiliateEquipment 关联设备
  76. func (c *PublishLibrariesCtl) AffiliateEquipment(ctx *gin.Context) {
  77. sysType, _ := strconv.Atoi(ctx.Query("sysType"))
  78. deviceIds := ctx.Query("infoId") //设备id
  79. value, _ := ctx.Get(middleware.Authorization)
  80. claims := value.(*middleware.Claims)
  81. devices, err := service.ProgramService.RelationDeviceListByIds(claims.TenantId, sysType, deviceIds)
  82. if err != nil {
  83. ctx.JSON(http.StatusOK, err)
  84. return
  85. }
  86. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, devices))
  87. }
  88. // UpdateStatus 变更状态
  89. func (c *PublishLibrariesCtl) UpdateStatus(ctx *gin.Context) {
  90. id, _ := strconv.Atoi(ctx.Query("id"))
  91. status, _ := strconv.Atoi(ctx.Query("status"))
  92. name := ctx.Query("name")
  93. value, _ := ctx.Get(middleware.Authorization)
  94. claims := value.(*middleware.Claims)
  95. _, err := service.PublishLibrariesService.UpdateStatus(claims.TenantId, id, status, name)
  96. if err != nil {
  97. ctx.JSON(http.StatusOK, err)
  98. return
  99. }
  100. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
  101. }
  102. func (c *PublishLibrariesCtl) Remove(ctx *gin.Context) {
  103. value, _ := ctx.Get(middleware.Authorization)
  104. claims := value.(*middleware.Claims)
  105. ids, _ := strconv.Atoi(ctx.Query("ids"))
  106. err := service.PublishLibrariesService.Remove(claims.UserId, claims.TenantId, ids)
  107. if err != nil {
  108. ctx.JSON(http.StatusOK, err)
  109. return
  110. }
  111. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  112. }