package controllers
|
|
import (
|
"basic.com/valib/bhomeclient.git"
|
"basic.com/valib/logger.git"
|
"github.com/satori/go.uuid"
|
"vamicro/camera-common/models"
|
)
|
|
type AreaController struct {
|
}
|
|
// @Summary 添加menu的区域
|
// @Description 添加目录上区域
|
// @Produce json
|
// @Tags 国标目录树
|
// @Param name formData string true "区域名字"
|
// @Param parentid formData string true "上一级父id"
|
// @Success 200 {string} json "{"code":200, data:"添加的区域信息",msg:"请求成功", success:true}"
|
// @Failure 200 {string} json "{"code":"错误码", data:"出错信息",msg:"请求失败", success:false}"
|
// @Router /data/api-v/gb28181/area/add [post]
|
func (ac AreaController) AreaAdd(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
var pArea models.Area
|
var cArea models.Area
|
name := c.PostForm("name")
|
parentId := c.PostForm("parentId")
|
if parentId == "" || parentId == "0" {
|
cArea.Parentids = ",0,"
|
} else {
|
if _, err := pArea.SelectbyId(parentId); err != nil {
|
return &bhomeclient.Reply{ Success: false, Msg: "参数有误"}
|
}
|
cArea.Parentids = pArea.Parentids + parentId+","
|
}
|
cArea.Id = uuid.NewV4().String()
|
cArea.Name = name
|
cArea.Parentid = parentId
|
cArea.Type = models.TYPE_LOCAL_TREE
|
if err := cArea.Insert(); err != nil {
|
return &bhomeclient.Reply{ Success: false, Msg: "参数有误"}
|
}
|
return &bhomeclient.Reply{ Success: true, Data: cArea }
|
}
|
|
// @Summary 修改名字
|
// @Description 修改区域名字
|
// @Accept json
|
// @Produce json
|
// @Tags 国标目录树
|
// @Param id formData string true "区域id"
|
// @Param name formData string true "区域名字"
|
// @Param parentId formData string true "上一级父id"
|
// @Param alias formData string false "备注名称"
|
// @Success 200 {string} json "{"code":200, data:"删除的区域信息",msg:"请求成功", success:true}"
|
// @Failure 200 {string} json "{"code":"错误码", data:"出错信息",msg:"请求失败", success:false}"
|
// @Router /data/api-v/gb28181/area/update [post]
|
func (ac AreaController) AreaUpdate(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
var aram models.Area
|
|
id := c.PostForm("id")
|
if id == ""{
|
return &bhomeclient.Reply{ Success: false, Msg: "参数有误"}
|
}
|
name := c.PostForm("name")
|
parentId := c.PostForm("parentId")
|
if parentId == "" {
|
return &bhomeclient.Reply{ Success: false, Msg: "参数有误"}
|
}
|
alias := c.PostForm("alias")
|
rows, err := aram.SelectbyId(id)
|
if err != nil {
|
return &bhomeclient.Reply{ Success: false, Msg: err.Error()}
|
}
|
if rows == 0 {
|
return &bhomeclient.Reply{ Success: false, Msg: "没有记录"}
|
}
|
|
err = aram.Update(id, name, parentId, alias)
|
if err != nil {
|
return &bhomeclient.Reply{ Success: false, Msg: err.Error()}
|
}
|
return &bhomeclient.Reply{ Success: true, Data: aram}
|
}
|
|
// @Summary 删除一个区域
|
// @Description 点击删除按钮时删除一个区域
|
// @Produce json
|
// @Tags 国标目录树
|
// @Param id formData string true "当前id"
|
// @Success 200 {string} json "{"code":200, data:"删除的区域信息",msg:"请求成功", success:true}"
|
// @Failure 200 {string} json "{"code":"500", data:"出错信息",msg:"请求失败", success:false}"
|
// @Router /data/api-v/gb28181/area/del [post]
|
func (ac AreaController) AreaDelete(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
var aram models.Area
|
id := c.PostForm("id")
|
logger.Debug("AreaDelete id:",id)
|
if id == "" {
|
return &bhomeclient.Reply{ Success: false, Msg: "参数有误"}
|
}
|
|
rows, err := aram.SelectbyId(id)
|
if err != nil {
|
return &bhomeclient.Reply{ Success: false, Msg: err.Error()}
|
}
|
if rows == 0 {
|
return &bhomeclient.Reply{ Success: false, Msg: "没有记录"}
|
|
}
|
|
//如果存在子节点或者摄像机
|
msg, ishas := aram.IsHasCnode(id)
|
if ishas {
|
return &bhomeclient.Reply{ Success: false, Msg: msg }
|
}
|
|
if err := aram.Delete(id); err != nil {
|
return &bhomeclient.Reply{ Success: false, Msg: err.Error()}
|
} else {
|
return &bhomeclient.Reply{ Success: true, Msg: "删除成功"}
|
}
|
}
|
|
// @Summary 将摄像机挂到指定的目录树下
|
// @Description 将摄像机挂到指定的目录树下
|
// @Produce json
|
// @Tags 国标目录树
|
// @Param cameraId formData string true "摄像机id"
|
// @Param areaId formData string true "目录区域id"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/gb28181/camera/updateCameraArea [post]
|
func (ac AreaController) UpdateCameraArea(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
cameraId := c.PostForm("cameraId")
|
areaId := c.PostForm("areaId")
|
logger.Debug("UpdateCameraArea cameraId:", cameraId, "areaId:", areaId)
|
if cameraId == "" || areaId == "" {
|
return &bhomeclient.Reply{ Msg: "参数有误"}
|
}
|
var caE models.CameraArea
|
if caE.UpdateArea(cameraId, areaId) {
|
return &bhomeclient.Reply{ Success:true, Msg:"更新成功"}
|
} else {
|
return &bhomeclient.Reply{ Msg:"更新失败"}
|
}
|
}
|