|
@@ -0,0 +1,312 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "bzd_server/conf"
|
|
|
+ "bzd_server/lib"
|
|
|
+ "bzd_server/models/Certificate"
|
|
|
+ "bzd_server/models/System"
|
|
|
+ beego "github.com/beego/beego/v2/server/web"
|
|
|
+ "math"
|
|
|
+)
|
|
|
+
|
|
|
+type CertificateController struct {
|
|
|
+ beego.Controller
|
|
|
+}
|
|
|
+
|
|
|
+// 列表-
|
|
|
+func (c *CertificateController) List() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var r_jsons lib.R_JSONS
|
|
|
+ page, _ := c.GetInt("page")
|
|
|
+ if page < 1 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ page_z, _ := c.GetInt("page_z")
|
|
|
+ if page_z < 1 {
|
|
|
+ page_z = conf.Page_size
|
|
|
+ }
|
|
|
+
|
|
|
+ T_sn := c.GetString("T_sn")
|
|
|
+ Time_start := c.GetString("Time_start")
|
|
|
+ Time_end := c.GetString("Time_end")
|
|
|
+
|
|
|
+ if len(Time_start) > 0 && !lib.IsDateStr(Time_start) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "时间格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(Time_end) > 0 && !lib.IsDateStr(Time_end) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "时间格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var cnt int
|
|
|
+ List, cnt := Certificate.Read_Certificate_List(T_sn, Time_start, Time_end, page, page_z)
|
|
|
+ page_size := math.Ceil(float64(cnt) / float64(page_z))
|
|
|
+ r_jsons.List = List
|
|
|
+ r_jsons.Page = page
|
|
|
+ r_jsons.Page_size = int(page_size)
|
|
|
+ r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
|
|
|
+ r_jsons.Num = cnt
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 添加-
|
|
|
+func (c *CertificateController) Add() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ T_sn := c.GetString("T_sn")
|
|
|
+
|
|
|
+ var_ := Certificate.Certificate{
|
|
|
+ T_sn: T_sn,
|
|
|
+ T_State: 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, is := Certificate.Read_Certificate(T_sn); is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "重复添加!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Id, is := Certificate.Add_Certificate(var_)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "添加", var_)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
|
|
|
+ c.ServeJSON()
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 删除-
|
|
|
+func (c *CertificateController) Del() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Id, err := c.GetInt("Id")
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if r, is := Certificate.Read_Certificate_ById(Id); is {
|
|
|
+ if !Certificate.Delete_Certificate_(r) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "删除", r)
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 列表-
|
|
|
+func (c *CertificateController) Pdf_List() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var r_jsons lib.R_JSONS
|
|
|
+ page, _ := c.GetInt("page")
|
|
|
+ if page < 1 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ page_z, _ := c.GetInt("page_z")
|
|
|
+ if page_z < 1 {
|
|
|
+ page_z = conf.Page_size
|
|
|
+ }
|
|
|
+
|
|
|
+ T_Certificate_sn := c.GetString("T_Certificate_sn")
|
|
|
+
|
|
|
+ var cnt int64
|
|
|
+ List, cnt := Certificate.Read_CertificatePdf_List(T_Certificate_sn, page, page_z)
|
|
|
+ page_size := math.Ceil(float64(cnt) / float64(page_z))
|
|
|
+ r_jsons.List = List
|
|
|
+ r_jsons.Page = page
|
|
|
+ r_jsons.Page_size = int(page_size)
|
|
|
+ r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
|
|
|
+ r_jsons.Num = int(cnt)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 添加-
|
|
|
+func (c *CertificateController) Pdf_Add() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ T_Certificate_sn := c.GetString("T_Certificate_sn")
|
|
|
+ T_release_time := c.GetString("T_release_time")
|
|
|
+ T_failure_time := c.GetString("T_failure_time")
|
|
|
+ T_pdf := c.GetString("T_pdf")
|
|
|
+
|
|
|
+ if !lib.IsDateStr(T_release_time) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "时间格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if !lib.IsDateStr(T_failure_time) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "时间格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var_ := Certificate.CertificatePdf{
|
|
|
+ T_Certificate_sn: T_Certificate_sn,
|
|
|
+ T_release_time: T_release_time,
|
|
|
+ T_failure_time: T_failure_time,
|
|
|
+ T_pdf: T_pdf,
|
|
|
+ T_State: 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, is := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time); is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "重复添加!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Id, is := Certificate.Add_CertificatePdf(var_)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf管理", "添加", var_)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
|
|
|
+ c.ServeJSON()
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 修改-
|
|
|
+func (c *CertificateController) Pdf_Up() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err := c.GetInt("Id")
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ T_Certificate_sn := c.GetString("T_Certificate_sn")
|
|
|
+ T_release_time := c.GetString("T_release_time")
|
|
|
+ T_failure_time := c.GetString("T_failure_time")
|
|
|
+ T_pdf := c.GetString("T_pdf")
|
|
|
+
|
|
|
+ if !lib.IsDateStr(T_release_time) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "时间格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if !lib.IsDateStr(T_failure_time) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "时间格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ r, is := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "数据已存在!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(T_release_time) > 0 {
|
|
|
+ r.T_release_time = T_release_time
|
|
|
+ }
|
|
|
+ if len(T_failure_time) > 0 {
|
|
|
+ r.T_failure_time = T_failure_time
|
|
|
+ }
|
|
|
+ if len(T_pdf) > 0 {
|
|
|
+ r.T_pdf = T_pdf
|
|
|
+ }
|
|
|
+ if !Certificate.Update_CertificatePdf(r, "T_release_time", "T_failure_time", "T_pdf") {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf管理", "修改", r)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 删除-
|
|
|
+func (c *CertificateController) Pdf_Del() {
|
|
|
+ // 验证登录 User_is, User_r
|
|
|
+ user_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+ if !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Id, err := c.GetInt("Id")
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if r, is := Certificate.Read_CertificatePdf_ById(Id); is {
|
|
|
+ if !Certificate.Delete_CertificatePdf_(r) {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf管理", "删除", r)
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|