package controllers import ( "Cold_Monitor/Nats/NatsServer" "Cold_Monitor/lib" "Cold_Monitor/models/Device" beego "github.com/beego/beego/v2/server/web" ) type MainController struct { beego.Controller } func (c *MainController) Get() { c.Data["Website"] = "beego.me" c.Data["Email"] = "astaxie@gmail.com" c.TplName = "index.tpl" } // 设备 列表 - 接口 func (c *MainController) Device_List() { b_, _, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } r_list := Device.Read_Device_BT_pid(T_pid) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_list} c.ServeJSON() return } // 设备 添加 - 接口 func (c *MainController) Device_Add() { b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } d_r := Device.Device{} c.ParseForm(&d_r) d_r.T_pid = T_pid Device.Add_Device(d_r) NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "设备添加", d_r.T_sn) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 设备 添加 - 接口 func (c *MainController) Device_Pu() { b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } d_r := Device.Device{} c.ParseForm(&d_r) Device_r, err := Device.Read_Device_ById(d_r.Id) if err != nil { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false) return } if Device_r.T_pid != T_pid { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false) return } Device_r.T_tab = d_r.T_tab Device.Update_Device(Device_r, "T_tab") NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "设备修改", d_r.T_sn) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 设备 添加 - 接口 func (c *MainController) Device_Del() { b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } d_r := Device.Device{} c.ParseForm(&d_r) Device_r, err := Device.Read_Device_ById(d_r.Id) if err != nil { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false) return } if Device_r.T_pid != T_pid { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false) return } Device.Delete_Device(Device_r) NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "设备删除", d_r.T_sn) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 控制组 列表 - 接口 func (c *MainController) ControlGroup_List() { b_, _, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } r_list := Device.Read_ControlGroup_ByT_pid(T_pid) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_list} c.ServeJSON() return } // 设备 添加 - 接口 func (c *MainController) ControlGroupAdd() { b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } d_r := Device.ControlGroup{} c.ParseForm(&d_r) d_r.T_pid = T_pid Device.Add_ControlGroup(d_r) NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "控制组添加", d_r.T_name) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 设备 添加 - 接口 func (c *MainController) ControlGroupPu() { b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } d_r := Device.ControlGroup{} c.ParseForm(&d_r) ControlGroupr, err := Device.Read_ControlGroup_ById(d_r.Id) if err != nil { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false) return } if ControlGroupr.T_pid != T_pid { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false) return } ControlGroupr.T_name = d_r.T_name ControlGroupr.T_text = d_r.T_text Device.Update_ControlGroup(ControlGroupr, "T_name", "T_text") NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "控制组修改", d_r.T_name) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 设备 添加 - 接口 func (c *MainController) ControlGroupDel() { b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey")) if !b_ { c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false) return } d_r := Device.ControlGroup{} c.ParseForm(&d_r) ControlGroupr, err := Device.Read_ControlGroup_ById(d_r.Id) if err != nil { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false) return } if ControlGroupr.T_pid != T_pid { c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false) return } Device.Delete_ControlGroup(ControlGroupr) NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "控制组删除", d_r.T_name) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }