123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/middleware"
- "iot_manager_service/app/multimedia/model"
- "iot_manager_service/app/multimedia/service"
- service2 "iot_manager_service/app/system/service"
- "iot_manager_service/util/common"
- "math"
- "net/http"
- "strconv"
- "strings"
- )
- // PublishLibraries 节目播放
- var PublishLibraries = new(PublishLibrariesCtl)
- type PublishLibrariesCtl struct{}
- // List 节目播放列表
- func (c *PublishLibrariesCtl) List(ctx *gin.Context) {
- searchValue := ctx.Query("searchValue")
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- sysType, _ := strconv.Atoi(ctx.Query("sysType"))
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- libraries, err := service.PublishLibrariesService.List(claims.TenantId, searchValue, current, size, sysType)
- for i, library := range libraries {
- stime := library.StartTime.DateString()
- etime := library.EndTime.DateString()
- libraries[i].PlayPeriod = stime + " - " + etime
- libraries[i].ResolutionName = service2.DictService.GetResolutionName(library.TenantId, library.Resolution)
- libraries[i].CountDeviceNum = len(strings.Split(library.InfoId, ","))
- }
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(libraries)) / float64(size))
- rsp := model.RsqPublishLibrariesList{
- Current: current,
- Size: size,
- Total: len(libraries),
- Pages: int(pages),
- Records: libraries,
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
- }
- // GetLibraryList 节目播放 预览
- func (c *PublishLibrariesCtl) GetLibraryList(ctx *gin.Context) {
- id := ctx.Query("id")
- librariesId, e := strconv.Atoi(id)
- if e != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- programId, err := service.PublishLibrariesService.GetProgram(librariesId)
- if err != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- list, errors := service.ProgramService.GetLibraryList(claims.TenantId, programId)
- if errors != nil {
- ctx.JSON(http.StatusOK, e)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, list))
- }
- // AffiliateEquipment 关联设备
- func (c *PublishLibrariesCtl) AffiliateEquipment(ctx *gin.Context) {
- sysType, _ := strconv.Atoi(ctx.Query("sysType"))
- deviceIds := ctx.Query("infoId") //设备id
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- devices, err := service.ProgramService.RelationDeviceListByIds(claims.TenantId, sysType, deviceIds)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, devices))
- }
- // UpdateStatus 变更状态
- func (c *PublishLibrariesCtl) UpdateStatus(ctx *gin.Context) {
- id, _ := strconv.Atoi(ctx.Query("id"))
- status, _ := strconv.Atoi(ctx.Query("status"))
- name := ctx.Query("name")
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- _, err := service.PublishLibrariesService.UpdateStatus(claims.TenantId, id, status, name)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
- }
|