123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 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 LampPoleGroup = new(lampPoleGroupCtl)
- type lampPoleGroupCtl struct{}
- // Detail 获取详情
- func (c *lampPoleGroupCtl) Detail(ctx *gin.Context) {
- id, e := strconv.Atoi(ctx.Query("id"))
- if e != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- device, err := service.LampPoleGroupService.Get(id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, lampPoleGroupDaoToModel(*device)))
- }
- // CreateOrUpdate 新增、更新
- func (c *lampPoleGroupCtl) CreateOrUpdate(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- var req *dao.LampPoleGroup
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.LampPoleGroupService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
- ctx.JSON(http.StatusOK, err)
- }
- // List 获取分页列表
- func (c *lampPoleGroupCtl) List(ctx *gin.Context) {
- poleGroupName := ctx.Query("poleGroupName")
- 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.LampPoleGroupService.List(poleGroupName, current, size)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(devices)) / float64(size))
- rsp := model.RspLampPoleGroupList{
- Current: current,
- Size: size,
- Total: len(devices),
- Pages: int(pages),
- }
- for _, device := range devices {
- rsp.Records = append(rsp.Records, lampPoleGroupDaoToModel(device))
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
- }
- // Remove 删除
- func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- var req *model.ReqLampPoleGroupRemove
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.LampPoleGroupService.Remove(claims.UserId, claims.TenantId, req.IDs, req.Name)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
- }
- // GetList 获取下拉列表
- func (c *lampPoleGroupCtl) GetList(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- devices, err := service.LampPoleGroupService.GetList(claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
- }
- // FiltrationList 获取智能照明灯杆分组下拉(过滤掉没有灯控的分组显示)
- func (c *lampPoleGroupCtl) FiltrationList(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- devices, err := service.LampPoleGroupService.GetFiltration(claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
- }
- // GetTree 获取所有的灯杆分组所属灯杆
- func (c *lampPoleGroupCtl) GetTree(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- //todo 灯杆列表赋值
- // var rsp model.ReqLampPoleGroupSubmit
- devices, err := service.LampPoleGroupService.GetTree(claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
- }
- func lampPoleGroupDaoToModel(device dao.LampPoleGroup) model.LampPoleGroupDetail {
- return model.LampPoleGroupDetail{
- LampPoleGroup: device,
- PublicName: "",
- LampPoleVOList: []model.LampPoleDetail{},
- CameraList: []model.Camera{},
- SwitchBoxList: []model.SwitchBox{},
- InfoBoardList: []model.InfoBoard{},
- }
- }
|