123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 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"
- "iot_manager_service/util/common"
- "math"
- "net/http"
- "strconv"
- )
- var Program = new(programCtl)
- type programCtl struct{}
- func (c *programCtl) Detail(ctx *gin.Context) {
- id, e := strconv.Atoi(ctx.Query("id"))
- if e != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- Program, err := service.ProgramService.Get(id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, Program))
- }
- func (c *programCtl) List(ctx *gin.Context) {
- searchValue := ctx.Query("searchValue")
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- s := ctx.Query("sysType")
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- sysType := -1
- if s != "" {
- sysType, _ = strconv.Atoi(s)
- }
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- libraries, err := service.ProgramService.List(claims.TenantId, searchValue, current, size, sysType)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(libraries)) / float64(size))
- rsp := model.RsqProgramList{
- Current: current,
- Size: size,
- Total: len(libraries),
- Pages: int(pages),
- Records: libraries,
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
- }
- func (c *programCtl) Remove(ctx *gin.Context) {
- ids := ctx.Query("ids")
- id, e := strconv.Atoi(ids)
- if e != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- err := service.ProgramService.Remove(claims.UserId, claims.TenantId, id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
- }
- func (c *programCtl) GetList(ctx *gin.Context) {
- name := ctx.Query("name")
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- Program, err := service.ProgramService.GetList(claims.TenantId, name)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, Program))
- }
- func (c *programCtl) Submit(ctx *gin.Context) {
- var req model.ReqProgramSubmit
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- e := service.ProgramService.Submit(claims.TenantId, claims.UserId, req)
- if e != nil {
- ctx.JSON(http.StatusOK, e)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
- }
- func (c *programCtl) GetLibraryList(ctx *gin.Context) {
- id := ctx.Query("id")
- programId, 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)
- libraries, err := service.ProgramService.GetLibraryList(claims.TenantId, programId)
- if err != nil {
- ctx.JSON(http.StatusOK, e)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, libraries))
- }
- func (c *programCtl) RelationDeviceList(ctx *gin.Context) {
- resolutionStr := ctx.Query("resolution")
- resolution, e := strconv.Atoi(resolutionStr)
- if e != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- libraries, err := service.ProgramService.RelationDeviceList(claims.TenantId, resolution)
- if err != nil {
- ctx.JSON(http.StatusOK, e)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, libraries))
- }
|