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