ProductMode.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package controllers
  2. import (
  3. "Yunlot/Plugin"
  4. "Yunlot/lib"
  5. "Yunlot/logs"
  6. "Yunlot/models/Product"
  7. "encoding/json"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "time"
  10. )
  11. type ProductModeController struct {
  12. beego.Controller
  13. }
  14. func (c *ProductModeController) ProductModeLists() {
  15. ProductProt_r, Total := Product.ProductModeLists()
  16. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, 0, 0, Total)}
  17. c.ServeJSON()
  18. return
  19. }
  20. func (c *ProductModeController) Updata() {
  21. Id, _ := c.GetInt("Id", 0)
  22. if Id <= 0 {
  23. // 添加设备
  24. //ProductProt_r := Product.ProductMode{}
  25. //c.ParseForm(&ProductProt_r)
  26. //
  27. //ProductProt_r.Id = 0
  28. //ProductProt_r.Add()
  29. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ""}
  30. c.ServeJSON()
  31. return
  32. }
  33. ProductModeMap_r, is := Product.ProductModeMap[Id]
  34. if !is {
  35. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "Id E!"}
  36. c.ServeJSON()
  37. return
  38. }
  39. T_Config_map := c.GetString("T_Config_map")
  40. if len(T_Config_map) > 0 {
  41. logs.Println("修改配置参数:", T_Config_map)
  42. var articleSlide map[string]map[string]string
  43. err := json.Unmarshal([]byte(T_Config_map), &articleSlide)
  44. if err != nil {
  45. c.Data["json"] = lib.JSONS{Code: lib.Error, Msg: "Data err!"}
  46. c.ServeJSON()
  47. return
  48. }
  49. ProductModeMap_r.T_Config_map = articleSlide
  50. Plugin.PluginProductModeConfigPu(ProductModeMap_r)
  51. if ProductModeMap_r.T_state == 1 {
  52. Plugin.PluginGoStop(ProductModeMap_r)
  53. time.Sleep(time.Second * 2)
  54. Plugin.PluginGoRun(ProductModeMap_r)
  55. }
  56. }
  57. T_state, err := c.GetInt("T_state")
  58. if err == nil {
  59. logs.Println("T_state:", T_state)
  60. if T_state == 1 {
  61. time.Sleep(time.Second * 1)
  62. Plugin.PluginGoRun(ProductModeMap_r)
  63. } else {
  64. Plugin.PluginGoStop(ProductModeMap_r)
  65. }
  66. }
  67. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  68. c.ServeJSON()
  69. return
  70. }