Certificate.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. T_layout_no := c.GetString("T_layout_no")
  34. Time_start := c.GetString("Time_start")
  35. Time_end := c.GetString("Time_end")
  36. T_release_time_sort, _ := c.GetInt("T_release_time_sort") // 1 升序 2 降序
  37. T_failure_time_sort, _ := c.GetInt("T_failure_time_sort") // 1 升序 2 降序
  38. if len(Time_start) > 0 && !lib.IsDateStr(Time_start) {
  39. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  40. c.ServeJSON()
  41. return
  42. }
  43. if len(Time_end) > 0 && !lib.IsDateStr(Time_end) {
  44. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  45. c.ServeJSON()
  46. return
  47. }
  48. var cnt int
  49. List, cnt := Certificate.Read_Certificate_List(T_sn, T_layout_no, Time_start, Time_end, T_release_time_sort, T_failure_time_sort, page, page_z)
  50. page_size := math.Ceil(float64(cnt) / float64(page_z))
  51. r_jsons.List = List
  52. r_jsons.Page = page
  53. r_jsons.Page_size = int(page_size)
  54. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  55. r_jsons.Num = cnt
  56. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  57. c.ServeJSON()
  58. return
  59. }
  60. // 删除-
  61. func (c *CertificateController) Get() {
  62. // 验证登录 User_is, User_r
  63. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  64. if !User_is {
  65. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  66. c.ServeJSON()
  67. return
  68. }
  69. T_sn := c.GetString("T_sn")
  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. r, err := Certificate.Read_CertificatePdf_Newest(T_sn)
  76. if err != nil {
  77. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  78. c.ServeJSON()
  79. return
  80. }
  81. if len(r) == 0 {
  82. c.Data["json"] = lib.JSONS{Code: 202, Msg: "证书不存在!"}
  83. c.ServeJSON()
  84. return
  85. }
  86. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Certificate.CertificatePdfToCertificatePdf_R(r[0])}
  87. c.ServeJSON()
  88. return
  89. }
  90. // 添加-
  91. func (c *CertificateController) Add() {
  92. // 验证登录 User_is, User_r
  93. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  94. if !User_is {
  95. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  96. c.ServeJSON()
  97. return
  98. }
  99. T_sn := c.GetString("T_sn")
  100. var_ := Certificate.Certificate{
  101. T_sn: T_sn,
  102. T_State: 1,
  103. }
  104. if _, is := Certificate.Read_Certificate(T_sn); is {
  105. c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}
  106. c.ServeJSON()
  107. return
  108. }
  109. Id, is := Certificate.Add_Certificate(var_)
  110. if !is {
  111. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  112. c.ServeJSON()
  113. return
  114. }
  115. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "添加", var_)
  116. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  117. c.ServeJSON()
  118. return
  119. }
  120. // 添加-
  121. func (c *CertificateController) Edit() {
  122. // 验证登录 User_is, User_r
  123. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  124. if !User_is {
  125. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  126. c.ServeJSON()
  127. return
  128. }
  129. Id, err := c.GetInt("Id")
  130. if err != nil {
  131. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  132. c.ServeJSON()
  133. return
  134. }
  135. r, is := Certificate.Read_Certificate_ById(Id)
  136. if !is {
  137. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  138. c.ServeJSON()
  139. return
  140. }
  141. T_sn := c.GetString("T_sn")
  142. if _, is = Certificate.Read_Certificate(T_sn); is && r.T_sn != T_sn {
  143. c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}
  144. c.ServeJSON()
  145. return
  146. }
  147. r.T_sn = T_sn
  148. is = Certificate.Update_Certificate(r, "T_sn")
  149. if !is {
  150. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  151. c.ServeJSON()
  152. return
  153. }
  154. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "编辑", r)
  155. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  156. c.ServeJSON()
  157. return
  158. }
  159. // 删除-
  160. func (c *CertificateController) Del() {
  161. // 验证登录 User_is, User_r
  162. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  163. if !User_is {
  164. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  165. c.ServeJSON()
  166. return
  167. }
  168. Id, err := c.GetInt("Id")
  169. if err != nil {
  170. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  171. c.ServeJSON()
  172. return
  173. }
  174. if r, is := Certificate.Read_Certificate_ById(Id); is {
  175. if !Certificate.Delete_Certificate_(r) {
  176. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  177. c.ServeJSON()
  178. return
  179. }
  180. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "删除", r)
  181. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  182. c.ServeJSON()
  183. return
  184. }
  185. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  186. c.ServeJSON()
  187. return
  188. }
  189. // 列表-
  190. func (c *CertificateController) Pdf_List() {
  191. // 验证登录 User_is, User_r
  192. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  193. if !User_is {
  194. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  195. c.ServeJSON()
  196. return
  197. }
  198. var r_jsons lib.R_JSONS
  199. page, _ := c.GetInt("page")
  200. if page < 1 {
  201. page = 1
  202. }
  203. page_z, _ := c.GetInt("page_z")
  204. if page_z < 1 {
  205. page_z = conf.Page_size
  206. }
  207. T_Certificate_sn := c.GetString("T_Certificate_sn")
  208. var cnt int64
  209. List, cnt := Certificate.Read_CertificatePdf_List(T_Certificate_sn, page, page_z)
  210. page_size := math.Ceil(float64(cnt) / float64(page_z))
  211. r_jsons.List = List
  212. r_jsons.Page = page
  213. r_jsons.Page_size = int(page_size)
  214. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  215. r_jsons.Num = int(cnt)
  216. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  217. c.ServeJSON()
  218. return
  219. }
  220. // 添加-
  221. func (c *CertificateController) Pdf_Add() {
  222. // 验证登录 User_is, User_r
  223. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  224. if !User_is {
  225. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  226. c.ServeJSON()
  227. return
  228. }
  229. T_Certificate_sn := c.GetString("T_Certificate_sn")
  230. T_release_time := c.GetString("T_release_time")
  231. T_failure_time := c.GetString("T_failure_time")
  232. T_pdf := c.GetString("T_pdf")
  233. if !lib.IsDateStr(T_release_time) {
  234. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  235. c.ServeJSON()
  236. return
  237. }
  238. if !lib.IsDateStr(T_failure_time) {
  239. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  240. c.ServeJSON()
  241. return
  242. }
  243. var_ := Certificate.CertificatePdf{
  244. T_Certificate_sn: T_Certificate_sn,
  245. T_release_time: T_release_time,
  246. T_failure_time: T_failure_time,
  247. T_pdf: T_pdf,
  248. T_State: 1,
  249. }
  250. if _, err := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time); err == nil {
  251. c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复添加!"}
  252. c.ServeJSON()
  253. return
  254. }
  255. Id, is := Certificate.Add_CertificatePdf(var_)
  256. if !is {
  257. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  258. c.ServeJSON()
  259. return
  260. }
  261. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "添加", var_)
  262. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  263. c.ServeJSON()
  264. return
  265. }
  266. // 修改-
  267. func (c *CertificateController) Pdf_Up() {
  268. // 验证登录 User_is, User_r
  269. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  270. if !User_is {
  271. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  272. c.ServeJSON()
  273. return
  274. }
  275. Id, err := c.GetInt("Id")
  276. if err != nil {
  277. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  278. c.ServeJSON()
  279. return
  280. }
  281. T_Certificate_sn := c.GetString("T_Certificate_sn")
  282. T_release_time := c.GetString("T_release_time")
  283. T_failure_time := c.GetString("T_failure_time")
  284. T_pdf := c.GetString("T_pdf")
  285. if !lib.IsDateStr(T_release_time) {
  286. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  287. c.ServeJSON()
  288. return
  289. }
  290. if !lib.IsDateStr(T_failure_time) {
  291. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  292. c.ServeJSON()
  293. return
  294. }
  295. r, is := Certificate.Read_CertificatePdf_ById(Id)
  296. if !is {
  297. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  298. c.ServeJSON()
  299. return
  300. }
  301. _, err = Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time)
  302. if err == nil && r.T_failure_time != T_failure_time && r.T_release_time != T_release_time {
  303. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据已存在!"}
  304. c.ServeJSON()
  305. return
  306. }
  307. if len(T_release_time) > 0 {
  308. r.T_release_time = T_release_time
  309. }
  310. if len(T_failure_time) > 0 {
  311. r.T_failure_time = T_failure_time
  312. }
  313. if len(T_pdf) > 0 {
  314. r.T_pdf = T_pdf
  315. }
  316. if !Certificate.Update_CertificatePdf(r, "T_release_time", "T_failure_time", "T_pdf") {
  317. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  318. c.ServeJSON()
  319. return
  320. }
  321. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "修改", r)
  322. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  323. c.ServeJSON()
  324. return
  325. }
  326. // 删除-
  327. func (c *CertificateController) Pdf_Del() {
  328. // 验证登录 User_is, User_r
  329. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  330. if !User_is {
  331. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  332. c.ServeJSON()
  333. return
  334. }
  335. Id, err := c.GetInt("Id")
  336. if err != nil {
  337. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  338. c.ServeJSON()
  339. return
  340. }
  341. if r, is := Certificate.Read_CertificatePdf_ById(Id); is {
  342. if !Certificate.Delete_CertificatePdf_(r) {
  343. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  344. c.ServeJSON()
  345. return
  346. }
  347. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "删除", r)
  348. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  349. c.ServeJSON()
  350. return
  351. }
  352. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  353. c.ServeJSON()
  354. return
  355. }