123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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
- }
|