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