package controllers

import (
	"ColdVerify_local/conf"
	"ColdVerify_local/lib"
	"ColdVerify_local/models/System"
	beego "github.com/beego/beego/v2/server/web"
	"math"
)

type LogsController struct {
	beego.Controller
}

// 自动填写标签数据 标签列表
func (c *LogsController) ListJson() {
	mySlice := []string{ // 20250310
		"外部环境分割线最高温",
		"外部环境分割线最低温",
		"内部环境分割线最低温",
		"内部环境分割线最高温",
		"冰排释冷开始时间",
		"冰排释冷结束时间",
		"冰排释冷分割线最高温",
		"冰排释冷分割线最低温",
		"静态第一次开箱注释",
		"静态第二次开箱注释",
		"静态第三次开箱注释",
		"动态第一次开箱注释",
		"动态第二次开箱注释",
		"动态第三次开箱注释",
		"保温箱温度设定值",
		"保温箱准备开始时间",
		"冰排预冷保温箱准备结束时间",
		"温度自动监测设备放置位置开始时间",
		"温度自动监测设备放置位置结束时间",
	}

	c.Data["json"] = mySlice
	c.ServeJSON() // 使用 ServeJSON
}

// 列表 -
func (c *LogsController) List() {
	var log_jsons lib.LOG_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
	}

	Class_1 := c.GetString("Class_1")

	var cnt int64
	List, cnt := System.Read_Logs_ALL(page, page_z, Class_1)
	page_size := math.Ceil(float64(cnt) / float64(page_z))
	log_jsons.Class_1 = Class_1
	log_jsons.Class_List = System.Read_Logs_Class()
	log_jsons.List = List
	log_jsons.Page = page
	log_jsons.Page_size = int(page_size)
	log_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
	log_jsons.Num = int(cnt)

	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: log_jsons}
	c.ServeJSON()
	return
}

// 列表 -
func (c *LogsController) UserLogs() {
	var log_jsons lib.LOG_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
	}

	Class_1 := c.GetString("Class_1")

	var cnt int64
	List, cnt := System.Read_UserLogs_ALL(page, page_z, Class_1)
	page_size := math.Ceil(float64(cnt) / float64(page_z))
	log_jsons.Class_1 = Class_1
	log_jsons.Class_List = System.Read_UserLogs_Class()
	log_jsons.List = List
	log_jsons.Page = page
	log_jsons.Page_size = int(page_size)
	log_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
	log_jsons.Num = int(cnt)

	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: log_jsons}
	c.ServeJSON()
	return
}

func (c *LogsController) Ping() {
	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
	c.ServeJSON()
	return
}
