Certificate.go 7.9 KB

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