Certificate.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Certificate"
  6. "ColdVerify_server/models/System"
  7. beego "github.com/beego/beego/v2/server/web"
  8. "math"
  9. "strings"
  10. )
  11. type CertificateController struct {
  12. beego.Controller
  13. }
  14. // 列表-
  15. func (c *CertificateController) List() {
  16. // 验证登录 User_is, User_r
  17. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  18. if !User_is {
  19. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  20. c.ServeJSON()
  21. return
  22. }
  23. var r_jsons lib.R_JSONS
  24. page, _ := c.GetInt("page")
  25. if page < 1 {
  26. page = 1
  27. }
  28. page_z, _ := c.GetInt("page_z")
  29. if page_z < 1 {
  30. page_z = conf.Page_size
  31. }
  32. T_sn := c.GetString("T_sn")
  33. Time_start := c.GetString("Time_start")
  34. Time_end := c.GetString("Time_end")
  35. if len(Time_start) > 0 && !lib.IsDateStr(Time_start) {
  36. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  37. c.ServeJSON()
  38. return
  39. }
  40. if len(Time_end) > 0 && !lib.IsDateStr(Time_end) {
  41. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  42. c.ServeJSON()
  43. return
  44. }
  45. var cnt int
  46. List, cnt := Certificate.Read_Certificate_List(T_sn, Time_start, Time_end, page, page_z)
  47. page_size := math.Ceil(float64(cnt) / float64(page_z))
  48. r_jsons.List = List
  49. r_jsons.Page = page
  50. r_jsons.Page_size = int(page_size)
  51. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  52. r_jsons.Num = cnt
  53. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  54. c.ServeJSON()
  55. return
  56. }
  57. // 添加-
  58. func (c *CertificateController) Add() {
  59. // 验证登录 User_is, User_r
  60. user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  61. if !User_is {
  62. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  63. c.ServeJSON()
  64. return
  65. }
  66. T_sn := c.GetString("T_sn")
  67. var_ := Certificate.Certificate{
  68. T_sn: T_sn,
  69. T_State: 1,
  70. }
  71. if _, is := Certificate.Read_Certificate(T_sn); is {
  72. c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复添加!"}
  73. c.ServeJSON()
  74. return
  75. }
  76. Id, is := Certificate.Add_Certificate(var_)
  77. if !is {
  78. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  79. c.ServeJSON()
  80. return
  81. }
  82. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "添加", var_)
  83. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  84. c.ServeJSON()
  85. return
  86. }
  87. // 删除-
  88. func (c *CertificateController) Del() {
  89. // 验证登录 User_is, User_r
  90. user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  91. if !User_is {
  92. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  93. c.ServeJSON()
  94. return
  95. }
  96. Id, err := c.GetInt("Id")
  97. if err != nil {
  98. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  99. c.ServeJSON()
  100. return
  101. }
  102. if r, is := Certificate.Read_Certificate_ById(Id); is {
  103. if !Certificate.Delete_Certificate_(r) {
  104. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  105. c.ServeJSON()
  106. return
  107. }
  108. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "删除", r)
  109. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  110. c.ServeJSON()
  111. return
  112. }
  113. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  114. c.ServeJSON()
  115. return
  116. }
  117. // 列表-
  118. func (c *CertificateController) Pdf_List() {
  119. // 验证登录 User_is, User_r
  120. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  121. if !User_is {
  122. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  123. c.ServeJSON()
  124. return
  125. }
  126. var r_jsons lib.R_JSONS
  127. page, _ := c.GetInt("page")
  128. if page < 1 {
  129. page = 1
  130. }
  131. page_z, _ := c.GetInt("page_z")
  132. if page_z < 1 {
  133. page_z = conf.Page_size
  134. }
  135. T_Certificate_sn := c.GetString("T_Certificate_sn")
  136. var cnt int64
  137. List, cnt := Certificate.Read_CertificatePdf_List(T_Certificate_sn, page, page_z)
  138. page_size := math.Ceil(float64(cnt) / float64(page_z))
  139. r_jsons.List = List
  140. r_jsons.Page = page
  141. r_jsons.Page_size = int(page_size)
  142. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  143. r_jsons.Num = int(cnt)
  144. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  145. c.ServeJSON()
  146. return
  147. }
  148. // 添加-
  149. func (c *CertificateController) Pdf_Add() {
  150. // 验证登录 User_is, User_r
  151. user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  152. if !User_is {
  153. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  154. c.ServeJSON()
  155. return
  156. }
  157. T_Certificate_sn := c.GetString("T_Certificate_sn")
  158. T_release_time := c.GetString("T_release_time")
  159. T_failure_time := c.GetString("T_failure_time")
  160. T_pdf := c.GetString("T_pdf")
  161. if !lib.IsDateStr(T_release_time) {
  162. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  163. c.ServeJSON()
  164. return
  165. }
  166. if !lib.IsDateStr(T_failure_time) {
  167. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  168. c.ServeJSON()
  169. return
  170. }
  171. var_ := Certificate.CertificatePdf{
  172. T_Certificate_sn: T_Certificate_sn,
  173. T_release_time: T_release_time,
  174. T_failure_time: T_failure_time,
  175. T_pdf: T_pdf,
  176. T_State: 1,
  177. }
  178. if _, err := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time); err == nil {
  179. c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复添加!"}
  180. c.ServeJSON()
  181. return
  182. }
  183. Id, is := Certificate.Add_CertificatePdf(var_)
  184. if !is {
  185. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  186. c.ServeJSON()
  187. return
  188. }
  189. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "添加", var_)
  190. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  191. c.ServeJSON()
  192. return
  193. }
  194. // 修改-
  195. func (c *CertificateController) Pdf_Up() {
  196. // 验证登录 User_is, User_r
  197. user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  198. if !User_is {
  199. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  200. c.ServeJSON()
  201. return
  202. }
  203. Id, err := c.GetInt("Id")
  204. if err != nil {
  205. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  206. c.ServeJSON()
  207. return
  208. }
  209. T_Certificate_sn := c.GetString("T_Certificate_sn")
  210. T_release_time := c.GetString("T_release_time")
  211. T_failure_time := c.GetString("T_failure_time")
  212. T_pdf := c.GetString("T_pdf")
  213. if !lib.IsDateStr(T_release_time) {
  214. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  215. c.ServeJSON()
  216. return
  217. }
  218. if !lib.IsDateStr(T_failure_time) {
  219. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  220. c.ServeJSON()
  221. return
  222. }
  223. _, err = Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time)
  224. if !strings.Contains(err.Error(), "no row found") || err == nil {
  225. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据已存在!"}
  226. c.ServeJSON()
  227. return
  228. }
  229. r, is := Certificate.Read_CertificatePdf_ById(Id)
  230. if !is {
  231. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  232. c.ServeJSON()
  233. return
  234. }
  235. if len(T_release_time) > 0 {
  236. r.T_release_time = T_release_time
  237. }
  238. if len(T_failure_time) > 0 {
  239. r.T_failure_time = T_failure_time
  240. }
  241. if len(T_pdf) > 0 {
  242. r.T_pdf = T_pdf
  243. }
  244. if !Certificate.Update_CertificatePdf(r, "T_release_time", "T_failure_time", "T_pdf") {
  245. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  246. c.ServeJSON()
  247. return
  248. }
  249. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "修改", r)
  250. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  251. c.ServeJSON()
  252. return
  253. }
  254. // 删除-
  255. func (c *CertificateController) Pdf_Del() {
  256. // 验证登录 User_is, User_r
  257. user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  258. if !User_is {
  259. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  260. c.ServeJSON()
  261. return
  262. }
  263. Id, err := c.GetInt("Id")
  264. if err != nil {
  265. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  266. c.ServeJSON()
  267. return
  268. }
  269. if r, is := Certificate.Read_CertificatePdf_ById(Id); is {
  270. if !Certificate.Delete_CertificatePdf_(r) {
  271. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  272. c.ServeJSON()
  273. return
  274. }
  275. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "删除", r)
  276. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  277. c.ServeJSON()
  278. return
  279. }
  280. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  281. c.ServeJSON()
  282. return
  283. }