default.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package controllers
  2. import (
  3. "Cold_Monitor/Nats/NatsServer"
  4. "Cold_Monitor/lib"
  5. "Cold_Monitor/models/Device"
  6. beego "github.com/beego/beego/v2/server/web"
  7. )
  8. type MainController struct {
  9. beego.Controller
  10. }
  11. func (c *MainController) Get() {
  12. c.Data["Website"] = "beego.me"
  13. c.Data["Email"] = "astaxie@gmail.com"
  14. c.TplName = "index.tpl"
  15. }
  16. // 设备 列表 - 接口
  17. func (c *MainController) Device_List() {
  18. b_, _, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  19. if !b_ {
  20. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  21. return
  22. }
  23. r_list := Device.Read_Device_BT_pid(T_pid)
  24. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_list}
  25. c.ServeJSON()
  26. return
  27. }
  28. // 设备 添加 - 接口
  29. func (c *MainController) Device_Add() {
  30. b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  31. if !b_ {
  32. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  33. return
  34. }
  35. d_r := Device.Device{}
  36. c.ParseForm(&d_r)
  37. d_r.T_pid = T_pid
  38. Device.Add_Device(d_r)
  39. NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "设备添加", d_r.T_sn)
  40. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  41. c.ServeJSON()
  42. return
  43. }
  44. // 设备 添加 - 接口
  45. func (c *MainController) Device_Pu() {
  46. b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  47. if !b_ {
  48. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  49. return
  50. }
  51. d_r := Device.Device{}
  52. c.ParseForm(&d_r)
  53. Device_r, err := Device.Read_Device_ById(d_r.Id)
  54. if err != nil {
  55. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false)
  56. return
  57. }
  58. if Device_r.T_pid != T_pid {
  59. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false)
  60. return
  61. }
  62. Device_r.T_tab = d_r.T_tab
  63. Device.Update_Device(Device_r, "T_tab")
  64. NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "设备修改", d_r.T_sn)
  65. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  66. c.ServeJSON()
  67. return
  68. }
  69. // 设备 添加 - 接口
  70. func (c *MainController) Device_Del() {
  71. b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  72. if !b_ {
  73. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  74. return
  75. }
  76. d_r := Device.Device{}
  77. c.ParseForm(&d_r)
  78. Device_r, err := Device.Read_Device_ById(d_r.Id)
  79. if err != nil {
  80. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false)
  81. return
  82. }
  83. if Device_r.T_pid != T_pid {
  84. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false)
  85. return
  86. }
  87. Device.Delete_Device(Device_r)
  88. NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "设备删除", d_r.T_sn)
  89. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  90. c.ServeJSON()
  91. return
  92. }
  93. // 控制组 列表 - 接口
  94. func (c *MainController) ControlGroup_List() {
  95. b_, _, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  96. if !b_ {
  97. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  98. return
  99. }
  100. r_list := Device.Read_ControlGroup_ByT_pid(T_pid)
  101. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_list}
  102. c.ServeJSON()
  103. return
  104. }
  105. // 设备 添加 - 接口
  106. func (c *MainController) ControlGroupAdd() {
  107. b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  108. if !b_ {
  109. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  110. return
  111. }
  112. d_r := Device.ControlGroup{}
  113. c.ParseForm(&d_r)
  114. d_r.T_pid = T_pid
  115. Device.Add_ControlGroup(d_r)
  116. NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "控制组添加", d_r.T_name)
  117. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  118. c.ServeJSON()
  119. return
  120. }
  121. // 设备 添加 - 接口
  122. func (c *MainController) ControlGroupPu() {
  123. b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  124. if !b_ {
  125. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  126. return
  127. }
  128. d_r := Device.ControlGroup{}
  129. c.ParseForm(&d_r)
  130. ControlGroupr, err := Device.Read_ControlGroup_ById(d_r.Id)
  131. if err != nil {
  132. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false)
  133. return
  134. }
  135. if ControlGroupr.T_pid != T_pid {
  136. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false)
  137. return
  138. }
  139. ControlGroupr.T_name = d_r.T_name
  140. ControlGroupr.T_text = d_r.T_text
  141. Device.Update_ControlGroup(ControlGroupr, "T_name", "T_text")
  142. NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "控制组修改", d_r.T_name)
  143. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  144. c.ServeJSON()
  145. return
  146. }
  147. // 设备 添加 - 接口
  148. func (c *MainController) ControlGroupDel() {
  149. b_, User_r, T_pid := NatsServer.Verification(c.Ctx.GetCookie("User_tokey"), c.Ctx.Input.Query("User_tokey"))
  150. if !b_ {
  151. c.Ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
  152. return
  153. }
  154. d_r := Device.ControlGroup{}
  155. c.ParseForm(&d_r)
  156. ControlGroupr, err := Device.Read_ControlGroup_ById(d_r.Id)
  157. if err != nil {
  158. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "Id E!"}, true, false)
  159. return
  160. }
  161. if ControlGroupr.T_pid != T_pid {
  162. c.Ctx.Output.JSON(lib.JSONS{Code: 203, Msg: "T_pid E!"}, true, false)
  163. return
  164. }
  165. Device.Delete_ControlGroup(ControlGroupr)
  166. NatsServer.AddUserLogs(User_r.T_uuid, "动环控制", "控制组删除", d_r.T_name)
  167. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  168. c.ServeJSON()
  169. return
  170. }