| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 | package controllersimport (	"ColdVerify_server/conf"	"ColdVerify_server/lib"	"ColdVerify_server/models/Account"	"ColdVerify_server/models/Certificate"	"ColdVerify_server/models/Device"	"ColdVerify_server/models/System"	"ColdVerify_server/models/Task"	beego "github.com/beego/beego/v2/server/web"	"math")type CertificateController struct {	beego.Controller}// 列表-func (c *CertificateController) List() {	// 验证登录 User_is, User_r	_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, 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")	T_Certificate_sn := c.GetString("T_Certificate_sn")	T_layout_no := c.GetString("T_layout_no")	Time_start := c.GetString("Time_start")	Time_end := c.GetString("Time_end")	T_release_time_sort, _ := c.GetInt("T_release_time_sort") // 1 升序 2 降序	T_failure_time_sort, _ := c.GetInt("T_failure_time_sort") // 1 升序 2 降序	T_layout_no_sort, _ := c.GetInt("T_layout_no_sort")       // 1 升序 2 降序	if len(Time_start) > 0 && !lib.IsDateStr(Time_start) {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}		c.ServeJSON()		return	}	if len(Time_end) > 0 && !lib.IsDateStr(Time_end) {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}		c.ServeJSON()		return	}	var cnt int	List, cnt := Certificate.Read_Certificate_List(T_Certificate_sn, T_layout_no, Time_start, Time_end, T_release_time_sort, T_failure_time_sort, T_layout_no_sort, 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) ListWithoutDeviceList() {	// 验证登录 User_is, User_r	_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	T_task_id := c.GetString("T_task_id")	task, is := Task.Read_Task(T_task_id)	if !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "任务id错误!"}		c.ServeJSON()		return	}	var r_jsons lib.R_JSONS	var list []Certificate.Certificate_	var cnt int	certificateList, _ := Certificate.Read_Certificate_List("", "", "", "", 0, 0, 0, 0, 9999)	DeviceList, _ := Device.Read_DeviceClassList_OrderList(task.T_class, "", "", "", 0, 9999)	var deviceMap = make(map[string]struct{})	for _, v := range DeviceList {		deviceMap[v.T_id] = struct{}{}	}	for _, certificate := range certificateList {		if _, ok := deviceMap[certificate.T_layout_no]; ok {			continue		}		list = append(list, certificate)		cnt += 1	}	r_jsons.List = list	r_jsons.Num = cnt	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}	c.ServeJSON()	return}// 删除-func (c *CertificateController) Get() {	// 验证登录 User_is, User_r	_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	T_layout_no := c.GetString("T_layout_no")	if _, is := Certificate.Read_Certificate(T_layout_no); !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号不存在!"}		c.ServeJSON()		return	}	r, err := Certificate.Read_CertificatePdf_Newest(T_layout_no)	if err != nil {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}		c.ServeJSON()		return	}	if len(r) == 0 {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "证书不存在!"}		c.ServeJSON()		return	}	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Certificate.CertificatePdfToCertificatePdf_R(r[0])}	c.ServeJSON()	return}// 添加-func (c *CertificateController) Add() {	// 验证登录 User_is, User_r	user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	T_layout_no := c.GetString("T_layout_no")	var_ := Certificate.Certificate{		T_layout_no: T_layout_no,		T_State:     1,	}	if _, is := Certificate.Read_Certificate(T_layout_no); is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}		c.ServeJSON()		return	}	Id, is := Certificate.Add_Certificate(var_)	if !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}		c.ServeJSON()		return	}	System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "添加", var_)	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}	c.ServeJSON()	return}// 添加-func (c *CertificateController) Edit() {	// 验证登录 User_is, User_r	user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	Id, err := c.GetInt("Id")	if err != nil {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}		c.ServeJSON()		return	}	r, is := Certificate.Read_Certificate_ById(Id)	if !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}		c.ServeJSON()		return	}	old_T_layout_no := r.T_layout_no	T_layout_no := c.GetString("T_layout_no")	if _, is = Certificate.Read_Certificate(T_layout_no); is && r.T_layout_no != T_layout_no {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}		c.ServeJSON()		return	}	r.T_layout_no = T_layout_no	is = Certificate.Update_Certificate(r, "T_layout_no")	if !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}		c.ServeJSON()		return	}	pdfList, _ := Certificate.Read_CertificatePdf_List(old_T_layout_no, 0, 9999)	for _, pdf := range pdfList {		// 修改pdf		var_ := Certificate.CertificatePdf{			Id:          pdf.Id,			T_layout_no: T_layout_no,		}		if !Certificate.Update_CertificatePdf(var_, "T_layout_no") {			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!", Data: Id}	c.ServeJSON()	return}// 删除-func (c *CertificateController) Del() {	// 验证登录 User_is, User_r	user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	Id, err := c.GetInt("Id")	if err != nil {		c.Data["json"] = lib.JSONS{Code: 202, 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	}	c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}	c.ServeJSON()	return}// 列表-func (c *CertificateController) Pdf_List() {	// 验证登录 User_is, User_r	_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, 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")	T_layout_no := c.GetString("T_layout_no")	var cnt int64	List, cnt := Certificate.Read_CertificatePdf_List(T_layout_no, 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 := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	T_layout_no := c.GetString("T_layout_no")           // 布局编号	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 len(T_layout_no) == 0 {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号不能为空"}		c.ServeJSON()		return	}	if !lib.IsDateStr(T_release_time) {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}		c.ServeJSON()		return	}	if !lib.IsDateStr(T_failure_time) {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}		c.ServeJSON()		return	}	var_ := Certificate.CertificatePdf{		T_layout_no:      T_layout_no,		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 _, err := Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time); err == nil {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "证书编号重复!"}		c.ServeJSON()		return	}	Id, is := Certificate.Add_CertificatePdf(var_)	if !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}		c.ServeJSON()		return	}	System.Add_UserLogs_T(user_r.T_uuid, "校准证书Pdf", "添加", var_)	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 := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	Id, err := c.GetInt("Id")	if err != nil {		c.Data["json"] = lib.JSONS{Code: 202, 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: 202, Msg: "时间格式错误!"}		c.ServeJSON()		return	}	if !lib.IsDateStr(T_failure_time) {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}		c.ServeJSON()		return	}	r, is := Certificate.Read_CertificatePdf_ById(Id)	if !is {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}		c.ServeJSON()		return	}	_, err = Certificate.Read_CertificatePdf(T_Certificate_sn, T_release_time, T_failure_time)	if err == nil && r.T_failure_time != T_failure_time && r.T_release_time != T_release_time {		c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据已存在!"}		c.ServeJSON()		return	}	if len(T_Certificate_sn) > 0 {		r.T_Certificate_sn = T_Certificate_sn	}	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_Certificate_sn", "T_release_time", "T_failure_time", "T_pdf") {		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}// 删除-func (c *CertificateController) Pdf_Del() {	// 验证登录 User_is, User_r	user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))	if !User_is {		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}		c.ServeJSON()		return	}	Id, err := c.GetInt("Id")	if err != nil {		c.Data["json"] = lib.JSONS{Code: 202, 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	}	c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}	c.ServeJSON()	return}
 |