123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/device/dao"
- "iot_manager_service/app/device/model"
- "iot_manager_service/app/device/service"
- "iot_manager_service/app/middleware"
- "iot_manager_service/util"
- "math"
- "net/http"
- "strconv"
- )
- // 抓拍单元管理对象
- var CaptureUint = new(captureUintCtl)
- type captureUintCtl struct{}
- func (c *captureUintCtl) Detail(ctx *gin.Context) {
- id, e := strconv.Atoi(ctx.Query("id"))
- if e != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- deviceType := ctx.Query("type")
- if deviceType == model.TypeCapture {
- device, err := service.CaptureUintService.GetCapture(id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
- } else if deviceType == model.TypePoint {
- device, err := service.CaptureUintService.GetPoint(id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
- } else {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.TypeInvalid, nil))
- }
- }
- func (c *captureUintCtl) CaptureList(ctx *gin.Context) {
- searchValue := ctx.Query("searchValue")
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- devices, err := service.CaptureUintService.CaptureList(searchValue, current, size)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(devices)) / float64(size))
- rsp := model.RspCaptureList{
- Current: current,
- Size: size,
- Total: len(devices),
- Pages: int(pages),
- Records: devices,
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
- }
- func (c *captureUintCtl) CaptureSubmit(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- // 参数验证
- var req *model.CaptureDetail
- if err := ctx.ShouldBind(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.CaptureUintService.CaptureSubmit(claims.UserId, claims.TenantId, req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, nil)
- }
- func (c *captureUintCtl) PointList(ctx *gin.Context) {
- searchValue := ctx.Query("searchValue")
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- devices, err := service.CaptureUintService.PointList(searchValue, current, size)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(devices)) / float64(size))
- rsp := model.RspPointList{
- Current: current,
- Size: size,
- Total: len(devices),
- Pages: int(pages),
- Records: devices,
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
- }
- func (c *captureUintCtl) PointSubmit(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- // 参数验证
- var req *dao.CheckPoint
- if err := ctx.ShouldBind(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.CaptureUintService.PointSubmit(claims.UserId, claims.TenantId, req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, nil)
- }
- func (c *captureUintCtl) CaptureGetList(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- devices, err := service.CaptureUintService.CaptureGetList(claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
- }
- func (c *captureUintCtl) PointGetList(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- devices, err := service.CaptureUintService.PointGetList(claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
- }
- func (c *captureUintCtl) Remove(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- var req *model.ReqCaptureRemove
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- if req.Type == model.TypeCapture {
- err := service.CaptureUintService.RemoveCapture(claims.UserId, req.IDs)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
- } else if req.Type == model.TypePoint {
- err := service.CaptureUintService.RemovePoint(claims.UserId, req.IDs)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
- } else {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.TypeInvalid, nil))
- }
- }
|