123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- package controllers
- import (
- "bzd_server/conf"
- "bzd_server/lib"
- "bzd_server/models/Device"
- "bzd_server/models/System"
- beego "github.com/beego/beego/v2/server/web"
- "math"
- )
- type DeviceClassController struct {
- beego.Controller
- }
- // 列表 -
- func (c *DeviceClassController) List() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- var cnt int64
- List, cnt := Device.Read_DeviceClass_List(User_r.T_uuid,T_name, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 获取-
- func (c *DeviceClassController) Get() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- r, is := Device.Read_DeviceClass_ById(Id);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if User_r.T_uuid != r.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: r}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *DeviceClassController) Add() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- var_ := Device.DeviceClass{
- T_uuid: User_r.T_uuid,
- T_name: T_name,
- T_State: 1,
- }
- Id, is := Device.Add_DeviceClass(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid,"分类管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: Id}
- c.ServeJSON()
- return
- }
- // 修改-
- func (c *DeviceClassController) Up() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- r, is := Device.Read_DeviceClass_ById(Id);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if User_r.T_uuid != r.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- // .......
- if len(T_name) > 0{
- r.T_name = T_name
- }
- // .......
- if !Device.Update_DeviceClass(r,"T_name") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid,"分类管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除-
- func (c *DeviceClassController) Del() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if r, is := Device.Read_DeviceClass_ById(Id); is {
- if User_r.T_uuid != r.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if !Device.Delete_DeviceClass_(r) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid,"分类管理", "删除", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- //--------------------------
- // 列表 -
- func (c *DeviceClassController) List_List() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_class,_ := c.GetInt("T_class")
- T_sn := c.GetString("T_sn")
- r, is := Device.Read_DeviceClass_ById(T_class);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
- c.ServeJSON()
- return
- }
- if User_r.T_uuid != r.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- var cnt int64
- List, cnt := Device.Read_DeviceClassList_List(T_class,T_sn, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *DeviceClassController) List_Add() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_class,_ := c.GetInt("T_class")
- T_id,_ := c.GetInt("T_id")
- T_sn := c.GetString("T_sn")
- r, is := Device.Read_DeviceClass_ById(T_class);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
- c.ServeJSON()
- return
- }
- if User_r.T_uuid != r.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if _, is := Device.Read_Device(T_sn);!is{
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_sn 不存在!"}
- c.ServeJSON()
- return
- }
- var_ := Device.DeviceClassList{
- T_class: T_class,
- T_id: T_id,
- T_sn: T_sn,
- T_State: 1,
- }
- Id, is := Device.Add_DeviceClassList(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid,"分类设备管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: Id}
- c.ServeJSON()
- return
- }
- // 修改-
- func (c *DeviceClassController) List_Up() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_id,_ := c.GetInt("T_id")
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- r, is := Device.Read_DeviceClassList_ById(Id);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- Cr, is := Device.Read_DeviceClass_ById(r.T_class);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
- c.ServeJSON()
- return
- }
- if User_r.T_uuid != Cr.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- // .......
- r.T_id = T_id
- // .......
- if !Device.Update_DeviceClassList(r,"T_id") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid,"分类设备管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除-
- func (c *DeviceClassController) List_Del() {
- // 验证登录 User_is, User_r
- User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if r, is := Device.Read_DeviceClassList_ById(Id); is {
- Cr, is := Device.Read_DeviceClass_ById(r.T_class);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
- c.ServeJSON()
- return
- }
- if User_r.T_uuid != Cr.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if !Device.Delete_DeviceClassList_(r) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(User_r.T_uuid,"分类设备管理", "删除", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
|