infoCollection.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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: "获取信息采集失败!"}
  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. T_submit_uuid: User_r.T_uuid,
  125. }
  126. T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_)
  127. if err != nil {
  128. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  129. c.ServeJSON()
  130. return
  131. }
  132. NatsServer.Create_Local_Table(T_InfoCollection_id)
  133. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "添加", var_)
  134. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_InfoCollection_id}
  135. c.ServeJSON()
  136. return
  137. }
  138. // 修改-
  139. func (c *InfoCollectionController) Up() {
  140. // 验证登录 User_is, User_r
  141. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  142. if !User_is {
  143. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  144. c.ServeJSON()
  145. return
  146. }
  147. T_name := c.GetString("T_name")
  148. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  149. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  150. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  151. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  152. if !is {
  153. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  154. c.ServeJSON()
  155. return
  156. }
  157. // .......
  158. clos := make([]string, 0)
  159. if len(T_name) > 0 {
  160. r.T_name = T_name
  161. clos = append(clos, "T_name")
  162. }
  163. if len(T_InfoTemplate_class) > 0 {
  164. r.T_InfoTemplate_class = T_InfoTemplate_class
  165. clos = append(clos, "T_InfoTemplate_class")
  166. }
  167. if len(T_InfoTemplate_id) > 0 {
  168. r.T_InfoTemplate_id = T_InfoTemplate_id
  169. clos = append(clos, "T_InfoTemplate_id")
  170. }
  171. if !InfoCollection.Update_InfoCollection(r, clos...) {
  172. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  173. c.ServeJSON()
  174. return
  175. }
  176. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改", r)
  177. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  178. c.ServeJSON()
  179. return
  180. }
  181. // 删除-
  182. func (c *InfoCollectionController) Del() {
  183. // 验证登录 User_is, User_r
  184. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  185. if !User_is {
  186. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  187. c.ServeJSON()
  188. return
  189. }
  190. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  191. if r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id); is {
  192. if !InfoCollection.Delete_InfoCollection(r) {
  193. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  194. c.ServeJSON()
  195. return
  196. }
  197. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "删除", r)
  198. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  199. c.ServeJSON()
  200. return
  201. }
  202. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  203. c.ServeJSON()
  204. return
  205. }