package controllers import ( "Yunlot/lib" "Yunlot/models/Device" "Yunlot/models/Product" beego "github.com/beego/beego/v2/server/web" ) type ProductTypeController struct { beego.Controller } func (c *ProductTypeController) List() { PageIndex, _ := c.GetInt("PageIndex", 0) PageSize, _ := c.GetInt("PageSize", 10) ProductTyper := Product.ProductType{} c.ParseForm(&ProductTyper) // 验证 TOKEY if c.Ctx.Input.Host() != "127.0.0.1" { if len(ProductTyper.T_uuid) != 8 { 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 } // 验证 TOKEY if ProductTyper.T_uuid != c.GetString("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 } //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") // 验证 TOKEY if len(c.GetString("T_uuid")) == 0 { c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"} c.ServeJSON() return } if len(T_ProductID) == 0 { 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 } 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 != c.GetString("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_img", "T_prot", "T_TabData", "T_RelayData") { 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) if !ProductTyper.Read() { c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_ProductID E!"} c.ServeJSON() return } // 验证 TOKEY if ProductTyper.T_uuid != c.GetString("T_uuid") { c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_uuid!"} c.ServeJSON() return } if !ProductTyper.Delete() { 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 }