Product.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package controllers
  2. import (
  3. "Cold_Api/Nats/NatsServer"
  4. "Cold_Api/conf"
  5. "Cold_Api/controllers/lib"
  6. "Cold_Api/models/Device"
  7. "Cold_Api/models/Product"
  8. "Cold_Api/models/System"
  9. beego "github.com/beego/beego/v2/server/web"
  10. "math"
  11. "strconv"
  12. )
  13. type ProductController struct {
  14. beego.Controller
  15. }
  16. func (c *ProductController) ProductUpgrade_List() {
  17. // 验证登录
  18. //b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  19. //if !b_ {
  20. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  21. // c.ServeJSON()
  22. // return
  23. //}
  24. type R_JSONS struct {
  25. //必须的大写开头
  26. Data []Product.ProductUpgrade_R
  27. Num int64
  28. Page int
  29. Page_size int
  30. }
  31. var r_jsons R_JSONS
  32. page, _ := c.GetInt("page")
  33. if page < 1 {
  34. page = 1
  35. }
  36. page_z, _ := c.GetInt("page_z")
  37. if page_z < 1 {
  38. page_z = conf.Page_size
  39. }
  40. T_model := c.GetString("T_model")
  41. r_jsons.Data, r_jsons.Num = Product.Read_ProductUpgrade_List(T_model, page, page_z)
  42. r_jsons.Page = page
  43. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  44. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  45. c.ServeJSON()
  46. return
  47. }
  48. func (c *ProductController) ProductUpgrade_T_model_List() {
  49. // 验证登录
  50. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  51. if !b_ {
  52. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  53. c.ServeJSON()
  54. return
  55. }
  56. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Product.Read_ProductUpgrade_T_model()}
  57. c.ServeJSON()
  58. return
  59. }
  60. func (c *ProductController) ProductUpgrade_Add() {
  61. // 验证登录
  62. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  63. if !b_ {
  64. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  65. c.ServeJSON()
  66. return
  67. }
  68. T_model := c.GetString("T_model")
  69. T_version := c.GetString("T_version")
  70. T_file := c.GetString("T_file")
  71. T_remarks := c.GetString("T_remarks")
  72. T_carryout, _ := c.GetInt("T_carryout")
  73. var_ := Product.ProductUpgrade{
  74. T_model: T_model,
  75. T_version: T_version,
  76. T_file: T_file,
  77. T_remarks: T_remarks,
  78. T_carryout: T_carryout,
  79. }
  80. Id, err := Product.Add_ProductUpgrade(var_)
  81. if err != nil {
  82. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  83. c.ServeJSON()
  84. return
  85. }
  86. deviceList := Device.Read_Device_List_ByT_model(T_model)
  87. for _, v := range deviceList {
  88. NatsServer.Up_ProductUpgrade(v.T_sn, T_version, T_file)
  89. System.Add_UserLogs_T(admin_r.T_uuid, "设备版本升级", "同步", "SN:"+v.T_sn+T_version+T_file)
  90. }
  91. System.Add_UserLogs_T(admin_r.T_uuid, "设备版本升级管理", "添加", var_)
  92. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  93. c.ServeJSON()
  94. return
  95. }
  96. func (c *ProductController) ProductUpgrade_Del() {
  97. // 验证登录
  98. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  99. if !b_ {
  100. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  101. c.ServeJSON()
  102. return
  103. }
  104. id, _ := c.GetInt("T_id")
  105. _, err := Product.Read_ProductUpgrade_ById(id)
  106. if err != nil {
  107. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  108. c.ServeJSON()
  109. return
  110. }
  111. if is := Product.Delete_ProductUpgrade_ById(id); !is {
  112. c.Data["json"] = lib.JSONS{Code: 203, Msg: "删除失败!"}
  113. c.ServeJSON()
  114. return
  115. }
  116. System.Add_UserLogs(admin_r.T_uuid, "设备版本升级管理", "删除", strconv.Itoa(id))
  117. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  118. c.ServeJSON()
  119. return
  120. }