Certificate.go 8.2 KB

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