123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package controllers
- import (
- "AIOTCOER/conf"
- "AIOTCOER/lib"
- "AIOTCOER/models/Device"
- "AIOTCOER/models/Product"
- beego "github.com/beego/beego/v2/server/web"
- )
- type ProductTypeController struct {
- beego.Controller
- }
- // *T_uuid T_name
- func (c *ProductTypeController) List() {
- PageIndex, _ := c.GetInt("PageIndex", 0)
- PageSize, _ := c.GetInt("PageSize", 10)
- ProductTyper := Product.ProductType{}
- c.ParseForm(&ProductTyper)
- ProductTyper.T_uuid = lib.Take_one(c.Ctx.GetCookie("T_uuid"), c.GetString("T_uuid"))
- //// 验证 TOKEY
- //if c.Ctx.Input.Host() != "127.0.0.1" {
- if len(ProductTyper.T_uuid) == 0 {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"}
- c.ServeJSON()
- return
- }
- //}
- ProductType_r, Total := ProductTyper.Lists(PageIndex, PageSize)
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductType_r, PageIndex, PageSize, Total)}
- c.ServeJSON()
- return
- }
- func (c *ProductTypeController) Get() {
- ProductTyper := Product.ProductType{}
- c.ParseForm(&ProductTyper)
- if !ProductTyper.Read() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "ProductID E!"}
- c.ServeJSON()
- return
- }
- // 验证 T_uuid
- T_uuid := lib.Take_one(c.Ctx.GetCookie("T_uuid"), c.GetString("T_uuid"))
- if len(T_uuid) != 0 {
- if ProductTyper.T_uuid != T_uuid {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductTyper}
- c.ServeJSON()
- return
- }
- ProductTyper_r := Product.ProductType_R{
- T_name: ProductTyper.T_name,
- T_panel: ProductTyper.T_panel,
- T_TabDataJson: ProductTyper.T_TabDataJson,
- CreateTime: ProductTyper.CreateTime,
- UpdateTime: ProductTyper.UpdateTime,
- }
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductTyper_r}
- c.ServeJSON()
- return
- }
- //func (c *ProductTypeController) Add() {
- // ProductType_r := Product.ProductType{}
- // c.ParseForm(&ProductType_r)
- //
- // if len(ProductType_r.T_uuid) != 8 {
- // c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"}
- // c.ServeJSON()
- // return
- // }
- //
- // ProductType_r.T_ProductID = lib.GetRandstring(8, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0)
- // ProductType_r.T_akey = lib.GetRandstring(32, "", 0)
- //
- // ProductType_r.Add()
- //
- // c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductType_r}
- // c.ServeJSON()
- // return
- //}
- func (c *ProductTypeController) Update() {
- T_ProductID := c.GetString("T_ProductID")
- T_uuid := lib.Take_one(c.Ctx.GetCookie("T_uuid"), c.GetString("T_uuid"))
- //logs.Println("T_uuid:",T_uuid)
- // 验证 TOKEY
- if len(T_uuid) == 0 {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"}
- c.ServeJSON()
- return
- }
- if len(T_ProductID) == 0 {
- if !conf.Config_AddProductType {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "此服务节点负载过大,禁止添加新的产品,请选择其他节点添加!"}
- c.ServeJSON()
- return
- }
- ProductType_r := Product.ProductType{}
- c.ParseForm(&ProductType_r)
- ProductType_r.T_uuid = T_uuid
- ProductType_r.T_ProductID = lib.GetRandstring(8, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0)
- ProductType_r.T_ProductKey = lib.GetRandstring(32, "", 0)
- ProductType_r.T_state = 1
- if len(ProductType_r.T_uuid) == 0 {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"}
- c.ServeJSON()
- return
- }
- ProductType_r.Add()
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductType_r}
- c.ServeJSON()
- return
- }
- ProductTyper := Product.ProductType{T_ProductID: c.GetString("T_ProductID")}
- if !ProductTyper.Read() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_ProductID E!"}
- c.ServeJSON()
- return
- }
- // 验证 TOKEY
- if ProductTyper.T_uuid != T_uuid {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid !"}
- c.ServeJSON()
- return
- }
- c.ParseForm(&ProductTyper)
- if !ProductTyper.Update("T_name","T_prot", "T_mode", "T_TabData") {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
- c.ServeJSON()
- return
- }
- Device.Device_CacheDelK_All(ProductTyper.T_ProductID) // 删除 关联设备缓存
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *ProductTypeController) Delete() {
- ProductTyper := Product.ProductType{}
- c.ParseForm(&ProductTyper)
- T_uuid := lib.Take_one(c.Ctx.GetCookie("T_uuid"), c.GetString("T_uuid"))
- if !ProductTyper.Read() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_ProductID E!"}
- c.ServeJSON()
- return
- }
- // 验证 TOKEY
- if ProductTyper.T_uuid != T_uuid {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"}
- c.ServeJSON()
- return
- }
- ProductTyper.T_state = 0
- if !ProductTyper.Update("T_state") {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
- c.ServeJSON()
- return
- }
- //Device.Device_CacheDelK_All(ProductTyper.T_ProductID) // 删除 关联设备缓存
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|