Certificate.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/Certificate"
  7. "ColdVerify_server/models/System"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "math"
  10. )
  11. type CertificateController struct {
  12. beego.Controller
  13. }
  14. // 列表-
  15. func (c *CertificateController) List() {
  16. // 验证登录 User_is, User_r
  17. _, User_is := Account.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) Get() {
  59. // 验证登录 User_is, User_r
  60. _, User_is := Account.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. if _, is := Certificate.Read_Certificate(T_sn); !is {
  68. c.Data["json"] = lib.JSONS{Code: 202, Msg: "证书不存在!"}
  69. c.ServeJSON()
  70. return
  71. }
  72. r, err := Certificate.Read_CertificatePdf_Newest(T_sn)
  73. if err != nil {
  74. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  75. c.ServeJSON()
  76. return
  77. }
  78. if len(r) == 0 {
  79. c.Data["json"] = lib.JSONS{Code: 202, Msg: "证书不存在!"}
  80. c.ServeJSON()
  81. return
  82. }
  83. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Certificate.CertificatePdfToCertificatePdf_R(r[0])}
  84. c.ServeJSON()
  85. return
  86. }
  87. // 添加-
  88. func (c *CertificateController) Add() {
  89. // 验证登录 User_is, User_r
  90. user_r, User_is := Account.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. T_sn := c.GetString("T_sn")
  97. var_ := Certificate.Certificate{
  98. T_sn: T_sn,
  99. T_State: 1,
  100. }
  101. if _, is := Certificate.Read_Certificate(T_sn); is {
  102. c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复添加!"}
  103. c.ServeJSON()
  104. return
  105. }
  106. Id, is := Certificate.Add_Certificate(var_)
  107. if !is {
  108. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  109. c.ServeJSON()
  110. return
  111. }
  112. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "添加", var_)
  113. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  114. c.ServeJSON()
  115. return
  116. }
  117. // 删除-
  118. func (c *CertificateController) Del() {
  119. // 验证登录 User_is, User_r
  120. user_r, User_is := Account.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. Id, err := c.GetInt("Id")
  127. if err != nil {
  128. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  129. c.ServeJSON()
  130. return
  131. }
  132. if r, is := Certificate.Read_Certificate_ById(Id); is {
  133. if !Certificate.Delete_Certificate_(r) {
  134. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  135. c.ServeJSON()
  136. return
  137. }
  138. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "删除", r)
  139. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  140. c.ServeJSON()
  141. return
  142. }
  143. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  144. c.ServeJSON()
  145. return
  146. }
  147. // 列表-
  148. func (c *CertificateController) Pdf_List() {
  149. // 验证登录 User_is, User_r
  150. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  151. if !User_is {
  152. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  153. c.ServeJSON()
  154. return
  155. }
  156. var r_jsons lib.R_JSONS
  157. page, _ := c.GetInt("page")
  158. if page < 1 {
  159. page = 1
  160. }
  161. page_z, _ := c.GetInt("page_z")
  162. if page_z < 1 {
  163. page_z = conf.Page_size
  164. }
  165. T_Certificate_sn := c.GetString("T_Certificate_sn")
  166. var cnt int64
  167. List, cnt := Certificate.Read_CertificatePdf_List(T_Certificate_sn, page, page_z)
  168. page_size := math.Ceil(float64(cnt) / float64(page_z))
  169. r_jsons.List = List
  170. r_jsons.Page = page
  171. r_jsons.Page_size = int(page_size)
  172. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  173. r_jsons.Num = int(cnt)
  174. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  175. c.ServeJSON()
  176. return
  177. }
  178. // 添加-
  179. func (c *CertificateController) Pdf_Add() {
  180. // 验证登录 User_is, User_r
  181. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  182. if !User_is {
  183. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  184. c.ServeJSON()
  185. return
  186. }
  187. T_Certificate_sn := c.GetString("T_Certificate_sn")
  188. T_release_time := c.GetString("T_release_time")
  189. T_failure_time := c.GetString("T_failure_time")
  190. T_pdf := c.GetString("T_pdf")
  191. if !lib.IsDateStr(T_release_time) {
  192. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  193. c.ServeJSON()
  194. return
  195. }
  196. if !lib.IsDateStr(T_failure_time) {
  197. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  198. c.ServeJSON()
  199. return
  200. }
  201. var_ := Certificate.CertificatePdf{
  202. T_Certificate_sn: T_Certificate_sn,
  203. T_release_time: T_release_time,
  204. T_failure_time: T_failure_time,
  205. T_pdf: T_pdf,
  206. T_State: 1,
  207. }
  208. if _, err := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time); err == nil {
  209. c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复添加!"}
  210. c.ServeJSON()
  211. return
  212. }
  213. Id, is := Certificate.Add_CertificatePdf(var_)
  214. if !is {
  215. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  216. c.ServeJSON()
  217. return
  218. }
  219. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "添加", var_)
  220. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  221. c.ServeJSON()
  222. return
  223. }
  224. // 修改-
  225. func (c *CertificateController) Pdf_Up() {
  226. // 验证登录 User_is, User_r
  227. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  228. if !User_is {
  229. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  230. c.ServeJSON()
  231. return
  232. }
  233. Id, err := c.GetInt("Id")
  234. if err != nil {
  235. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  236. c.ServeJSON()
  237. return
  238. }
  239. T_Certificate_sn := c.GetString("T_Certificate_sn")
  240. T_release_time := c.GetString("T_release_time")
  241. T_failure_time := c.GetString("T_failure_time")
  242. T_pdf := c.GetString("T_pdf")
  243. if !lib.IsDateStr(T_release_time) {
  244. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  245. c.ServeJSON()
  246. return
  247. }
  248. if !lib.IsDateStr(T_failure_time) {
  249. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  250. c.ServeJSON()
  251. return
  252. }
  253. r, is := Certificate.Read_CertificatePdf_ById(Id)
  254. if !is {
  255. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  256. c.ServeJSON()
  257. return
  258. }
  259. _, err = Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time)
  260. if err == nil && r.T_failure_time != T_failure_time && r.T_release_time != T_release_time {
  261. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据已存在!"}
  262. c.ServeJSON()
  263. return
  264. }
  265. if len(T_release_time) > 0 {
  266. r.T_release_time = T_release_time
  267. }
  268. if len(T_failure_time) > 0 {
  269. r.T_failure_time = T_failure_time
  270. }
  271. if len(T_pdf) > 0 {
  272. r.T_pdf = T_pdf
  273. }
  274. if !Certificate.Update_CertificatePdf(r, "T_release_time", "T_failure_time", "T_pdf") {
  275. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  276. c.ServeJSON()
  277. return
  278. }
  279. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "修改", r)
  280. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  281. c.ServeJSON()
  282. return
  283. }
  284. // 删除-
  285. func (c *CertificateController) Pdf_Del() {
  286. // 验证登录 User_is, User_r
  287. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  288. if !User_is {
  289. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  290. c.ServeJSON()
  291. return
  292. }
  293. Id, err := c.GetInt("Id")
  294. if err != nil {
  295. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  296. c.ServeJSON()
  297. return
  298. }
  299. if r, is := Certificate.Read_CertificatePdf_ById(Id); is {
  300. if !Certificate.Delete_CertificatePdf_(r) {
  301. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  302. c.ServeJSON()
  303. return
  304. }
  305. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "删除", r)
  306. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  307. c.ServeJSON()
  308. return
  309. }
  310. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  311. c.ServeJSON()
  312. return
  313. }