Certificate.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. T_layout_no := c.GetString("T_layout_no")
  101. var_ := Certificate.Certificate{
  102. T_sn: T_sn,
  103. T_layout_no: T_layout_no,
  104. T_State: 1,
  105. }
  106. if _, is := Certificate.Read_Certificate(T_sn); is {
  107. c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}
  108. c.ServeJSON()
  109. return
  110. }
  111. if _, is := Certificate.Read_Certificate_ByT_layout_no(T_layout_no); is {
  112. c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号重复!"}
  113. c.ServeJSON()
  114. return
  115. }
  116. Id, is := Certificate.Add_Certificate(var_)
  117. if !is {
  118. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  119. c.ServeJSON()
  120. return
  121. }
  122. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "添加", var_)
  123. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  124. c.ServeJSON()
  125. return
  126. }
  127. // 添加-
  128. func (c *CertificateController) Edit() {
  129. // 验证登录 User_is, User_r
  130. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  131. if !User_is {
  132. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  133. c.ServeJSON()
  134. return
  135. }
  136. Id, err := c.GetInt("Id")
  137. if err != nil {
  138. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  139. c.ServeJSON()
  140. return
  141. }
  142. r, is := Certificate.Read_Certificate_ById(Id)
  143. if !is {
  144. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  145. c.ServeJSON()
  146. return
  147. }
  148. T_sn := c.GetString("T_sn")
  149. T_layout_no := c.GetString("T_layout_no")
  150. if _, is = Certificate.Read_Certificate(T_sn); is && r.T_sn != T_sn {
  151. c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}
  152. c.ServeJSON()
  153. return
  154. }
  155. if _, is = Certificate.Read_Certificate_ByT_layout_no(T_layout_no); is && r.T_layout_no != T_layout_no {
  156. c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号重复!"}
  157. c.ServeJSON()
  158. return
  159. }
  160. r.T_sn = T_sn
  161. r.T_layout_no = T_layout_no
  162. is = Certificate.Update_Certificate(r, "T_sn", "T_layout_no")
  163. if !is {
  164. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  165. c.ServeJSON()
  166. return
  167. }
  168. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "编辑", r)
  169. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  170. c.ServeJSON()
  171. return
  172. }
  173. // 删除-
  174. func (c *CertificateController) Del() {
  175. // 验证登录 User_is, User_r
  176. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  177. if !User_is {
  178. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  179. c.ServeJSON()
  180. return
  181. }
  182. Id, err := c.GetInt("Id")
  183. if err != nil {
  184. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  185. c.ServeJSON()
  186. return
  187. }
  188. if r, is := Certificate.Read_Certificate_ById(Id); is {
  189. if !Certificate.Delete_Certificate_(r) {
  190. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  191. c.ServeJSON()
  192. return
  193. }
  194. System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "删除", r)
  195. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  196. c.ServeJSON()
  197. return
  198. }
  199. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  200. c.ServeJSON()
  201. return
  202. }
  203. // 列表-
  204. func (c *CertificateController) Pdf_List() {
  205. // 验证登录 User_is, User_r
  206. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  207. if !User_is {
  208. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  209. c.ServeJSON()
  210. return
  211. }
  212. var r_jsons lib.R_JSONS
  213. page, _ := c.GetInt("page")
  214. if page < 1 {
  215. page = 1
  216. }
  217. page_z, _ := c.GetInt("page_z")
  218. if page_z < 1 {
  219. page_z = conf.Page_size
  220. }
  221. T_Certificate_sn := c.GetString("T_Certificate_sn")
  222. var cnt int64
  223. List, cnt := Certificate.Read_CertificatePdf_List(T_Certificate_sn, page, page_z)
  224. page_size := math.Ceil(float64(cnt) / float64(page_z))
  225. r_jsons.List = List
  226. r_jsons.Page = page
  227. r_jsons.Page_size = int(page_size)
  228. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  229. r_jsons.Num = int(cnt)
  230. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  231. c.ServeJSON()
  232. return
  233. }
  234. // 添加-
  235. func (c *CertificateController) Pdf_Add() {
  236. // 验证登录 User_is, User_r
  237. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  238. if !User_is {
  239. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  240. c.ServeJSON()
  241. return
  242. }
  243. T_Certificate_sn := c.GetString("T_Certificate_sn")
  244. T_release_time := c.GetString("T_release_time")
  245. T_failure_time := c.GetString("T_failure_time")
  246. T_pdf := c.GetString("T_pdf")
  247. if !lib.IsDateStr(T_release_time) {
  248. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  249. c.ServeJSON()
  250. return
  251. }
  252. if !lib.IsDateStr(T_failure_time) {
  253. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  254. c.ServeJSON()
  255. return
  256. }
  257. var_ := Certificate.CertificatePdf{
  258. T_Certificate_sn: T_Certificate_sn,
  259. T_release_time: T_release_time,
  260. T_failure_time: T_failure_time,
  261. T_pdf: T_pdf,
  262. T_State: 1,
  263. }
  264. if _, err := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time); err == nil {
  265. c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复添加!"}
  266. c.ServeJSON()
  267. return
  268. }
  269. Id, is := Certificate.Add_CertificatePdf(var_)
  270. if !is {
  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", "添加", var_)
  276. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  277. c.ServeJSON()
  278. return
  279. }
  280. // 修改-
  281. func (c *CertificateController) Pdf_Up() {
  282. // 验证登录 User_is, User_r
  283. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  284. if !User_is {
  285. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  286. c.ServeJSON()
  287. return
  288. }
  289. Id, err := c.GetInt("Id")
  290. if err != nil {
  291. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  292. c.ServeJSON()
  293. return
  294. }
  295. T_Certificate_sn := c.GetString("T_Certificate_sn")
  296. T_release_time := c.GetString("T_release_time")
  297. T_failure_time := c.GetString("T_failure_time")
  298. T_pdf := c.GetString("T_pdf")
  299. if !lib.IsDateStr(T_release_time) {
  300. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  301. c.ServeJSON()
  302. return
  303. }
  304. if !lib.IsDateStr(T_failure_time) {
  305. c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
  306. c.ServeJSON()
  307. return
  308. }
  309. r, is := Certificate.Read_CertificatePdf_ById(Id)
  310. if !is {
  311. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  312. c.ServeJSON()
  313. return
  314. }
  315. _, err = Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time)
  316. if err == nil && r.T_failure_time != T_failure_time && r.T_release_time != T_release_time {
  317. c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据已存在!"}
  318. c.ServeJSON()
  319. return
  320. }
  321. if len(T_release_time) > 0 {
  322. r.T_release_time = T_release_time
  323. }
  324. if len(T_failure_time) > 0 {
  325. r.T_failure_time = T_failure_time
  326. }
  327. if len(T_pdf) > 0 {
  328. r.T_pdf = T_pdf
  329. }
  330. if !Certificate.Update_CertificatePdf(r, "T_release_time", "T_failure_time", "T_pdf") {
  331. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  332. c.ServeJSON()
  333. return
  334. }
  335. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "修改", r)
  336. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  337. c.ServeJSON()
  338. return
  339. }
  340. // 删除-
  341. func (c *CertificateController) Pdf_Del() {
  342. // 验证登录 User_is, User_r
  343. user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  344. if !User_is {
  345. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  346. c.ServeJSON()
  347. return
  348. }
  349. Id, err := c.GetInt("Id")
  350. if err != nil {
  351. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  352. c.ServeJSON()
  353. return
  354. }
  355. if r, is := Certificate.Read_CertificatePdf_ById(Id); is {
  356. if !Certificate.Delete_CertificatePdf_(r) {
  357. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  358. c.ServeJSON()
  359. return
  360. }
  361. System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "删除", r)
  362. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  363. c.ServeJSON()
  364. return
  365. }
  366. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  367. c.ServeJSON()
  368. return
  369. }