infoCollection.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package controllers
  2. import (
  3. "ColdVerify_server/Nats/NatsServer"
  4. "ColdVerify_server/conf"
  5. "ColdVerify_server/lib"
  6. "ColdVerify_server/models/Account"
  7. "ColdVerify_server/models/InfoCollection"
  8. "ColdVerify_server/models/System"
  9. beego "github.com/beego/beego/v2/server/web"
  10. "math"
  11. )
  12. type InfoCollectionController struct {
  13. beego.Controller
  14. }
  15. // 列表 -
  16. func (c *InfoCollectionController) List() {
  17. // 验证登录 User_is, User_r
  18. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  19. if !User_is {
  20. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  21. c.ServeJSON()
  22. return
  23. }
  24. var r_jsons lib.R_JSONS
  25. page, _ := c.GetInt("page")
  26. if page < 1 {
  27. page = 1
  28. }
  29. page_z, _ := c.GetInt("page_z")
  30. if page_z < 1 {
  31. page_z = conf.Page_size
  32. }
  33. T_name := c.GetString("T_name")
  34. T_uuid := c.GetString("T_uuid")
  35. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  36. var T_admin string
  37. if User_r.T_power > 2 {
  38. T_admin = User_r.T_uuid
  39. }
  40. var cnt int
  41. List, cnt := InfoCollection.Read_InfoCollection_List(T_uuid, T_admin, T_name, AdminMap, page, page_z)
  42. page_size := math.Ceil(float64(cnt) / float64(page_z))
  43. r_jsons.List = List
  44. r_jsons.Page = page
  45. r_jsons.Page_size = int(page_size)
  46. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  47. r_jsons.Num = cnt
  48. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  49. c.ServeJSON()
  50. return
  51. }
  52. // 列表 -
  53. func (c *InfoCollectionController) UserInfoCollectionList() {
  54. // 验证登录 User_is, User_r
  55. User_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  56. if !User_is {
  57. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  58. c.ServeJSON()
  59. return
  60. }
  61. var r_jsons lib.R_JSONS
  62. page, _ := c.GetInt("page")
  63. if page < 1 {
  64. page = 1
  65. }
  66. page_z, _ := c.GetInt("page_z")
  67. if page_z < 1 {
  68. page_z = conf.Page_size
  69. }
  70. T_name := c.GetString("T_name")
  71. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  72. var cnt int
  73. List, cnt := InfoCollection.Read_UserInfoCollection_List(User_r.T_uuid, T_name, AdminMap, page, page_z)
  74. page_size := math.Ceil(float64(cnt) / float64(page_z))
  75. r_jsons.List = List
  76. r_jsons.Page = page
  77. r_jsons.Page_size = int(page_size)
  78. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  79. r_jsons.Num = cnt
  80. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  81. c.ServeJSON()
  82. return
  83. }
  84. // 获取-
  85. func (c *InfoCollectionController) Get() {
  86. // 验证登录 User_is, User_r
  87. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  88. if !User_is {
  89. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  90. c.ServeJSON()
  91. return
  92. }
  93. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  94. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  95. if !is {
  96. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  97. c.ServeJSON()
  98. return
  99. }
  100. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: InfoCollection.InfoCollectionToInfoCollection_R(r, map[string]string{})}
  101. c.ServeJSON()
  102. return
  103. }
  104. // 添加-
  105. func (c *InfoCollectionController) Add() {
  106. // 验证登录 User_is, User_r
  107. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  108. if !User_is {
  109. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  110. c.ServeJSON()
  111. return
  112. }
  113. T_name := c.GetString("T_name")
  114. T_uuid := c.GetString("T_uuid") // 用户uuid
  115. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  116. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  117. var_ := InfoCollection.InfoCollection{
  118. T_uuid: T_uuid,
  119. T_name: T_name,
  120. T_InfoTemplate_class: T_InfoTemplate_class,
  121. T_InfoTemplate_id: T_InfoTemplate_id,
  122. T_status: 1,
  123. T_State: 1,
  124. }
  125. T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_)
  126. if err != nil {
  127. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  128. c.ServeJSON()
  129. return
  130. }
  131. NatsServer.Create_Local_Table(T_InfoCollection_id)
  132. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "添加", var_)
  133. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_InfoCollection_id}
  134. c.ServeJSON()
  135. return
  136. }
  137. // 修改-
  138. func (c *InfoCollectionController) Up() {
  139. // 验证登录 User_is, User_r
  140. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  141. if !User_is {
  142. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  143. c.ServeJSON()
  144. return
  145. }
  146. T_name := c.GetString("T_name")
  147. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  148. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  149. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  150. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  151. if !is {
  152. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  153. c.ServeJSON()
  154. return
  155. }
  156. // .......
  157. clos := make([]string, 0)
  158. if len(T_name) > 0 {
  159. r.T_name = T_name
  160. clos = append(clos, "T_name")
  161. }
  162. if len(T_InfoTemplate_class) > 0 {
  163. r.T_InfoTemplate_class = T_InfoTemplate_class
  164. clos = append(clos, "T_InfoTemplate_class")
  165. }
  166. if len(T_InfoTemplate_id) > 0 {
  167. r.T_InfoTemplate_id = T_InfoTemplate_id
  168. clos = append(clos, "T_InfoTemplate_id")
  169. }
  170. if !InfoCollection.Update_InfoCollection(r, clos...) {
  171. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  172. c.ServeJSON()
  173. return
  174. }
  175. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改", r)
  176. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  177. c.ServeJSON()
  178. return
  179. }
  180. // 删除-
  181. func (c *InfoCollectionController) Del() {
  182. // 验证登录 User_is, User_r
  183. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  184. if !User_is {
  185. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  186. c.ServeJSON()
  187. return
  188. }
  189. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  190. if r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id); is {
  191. if !InfoCollection.Delete_InfoCollection(r) {
  192. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  193. c.ServeJSON()
  194. return
  195. }
  196. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "删除", r)
  197. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  198. c.ServeJSON()
  199. return
  200. }
  201. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  202. c.ServeJSON()
  203. return
  204. }