package handler

import (
	"cicv-data-closedloop/common/config/c_db"
	"cicv-data-closedloop/common/config/c_log"
	"cicv-data-closedloop/common/entity"
	"github.com/gin-gonic/gin"
	"net/http"
)

type testStruct struct {
	Id   int    `db:"id"`
	Name string `db:"name"`
}

// Hello 测试接口
// @Tags 此标记的所有接口均用于测试
// @Summary 测试
// @Description 该接口用于测试使用
// @Param param query int true "Id"     参数 :@Param 参数名 位置(query 或者 path或者 body) 类型 是否必需 注释
// @Produce json
// @Success 200 {object} entity.HttpResult
// @Router /test/hello [get]
func Hello(c *gin.Context) {
	// 获取请求参数
	param := c.Query("param")
	c_log.GlobalLogger.Info("接受到请求参数:", param)
	var tests []testStruct
	// 查询数据库
	var testSql string
	if err := c_db.MysqlDb.Select(&tests, testSql); err != nil {
		c_log.GlobalLogger.Error("数据库查询报错:", err)
		c.JSON(http.StatusInternalServerError, entity.DefaultFailHttpResult)
		return
	}
	c_log.GlobalLogger.Info("数据库查询成功:", tests)

	c.JSON(http.StatusOK, entity.DefaultSuccessHttpResult)
}