package controllers import ( "Yunlot/Plugin" "Yunlot/lib" "Yunlot/logs" "Yunlot/models/Product" "encoding/json" beego "github.com/beego/beego/v2/server/web" "time" ) type ProductModeController struct { beego.Controller } func (c *ProductModeController) ProductModeLists() { ProductProt_r, Total := Product.ProductModeLists() c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, 0, 0, Total)} c.ServeJSON() return } func (c *ProductModeController) Updata() { Id, _ := c.GetInt("Id", 0) if Id <= 0 { // 添加设备 //ProductProt_r := Product.ProductMode{} //c.ParseForm(&ProductProt_r) // //ProductProt_r.Id = 0 //ProductProt_r.Add() c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ""} c.ServeJSON() return } ProductModeMap_r, is := Product.ProductModeMap[Id] if !is { c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "Id E!"} c.ServeJSON() return } T_Config_map := c.GetString("T_Config_map") if len(T_Config_map) > 0 { logs.Println("修改配置参数:", T_Config_map) var articleSlide map[string]map[string]string err := json.Unmarshal([]byte(T_Config_map), &articleSlide) if err != nil { c.Data["json"] = lib.JSONS{Code: lib.Error, Msg: "Data err!"} c.ServeJSON() return } ProductModeMap_r.T_Config_map = articleSlide Plugin.PluginProductModeConfigPu(ProductModeMap_r) if ProductModeMap_r.T_state == 1 { Plugin.PluginGoStop(ProductModeMap_r) time.Sleep(time.Second * 2) Plugin.PluginGoRun(ProductModeMap_r) } } T_state, err := c.GetInt("T_state") if err == nil { logs.Println("T_state:", T_state) if T_state == 1 { time.Sleep(time.Second * 1) Plugin.PluginGoRun(ProductModeMap_r) } else { Plugin.PluginGoStop(ProductModeMap_r) } } c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"} c.ServeJSON() return }