package controllers

import (
	"encoding/json"
	"fmt"
	ywtlog "hello/models/ywtlog"
	"hello/services"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
)

// CMS API
type SinopharmController struct {
	beego.Controller
}

func (c *SinopharmController) URLMapping() {
	c.Mapping("GetSinopharmInfo", c.GetSinopharmInfo)
}

// @router /sinopharm/getSinopharmInfo [get]
func (c *SinopharmController) GetSinopharmInfo() {
	id, err := c.GetInt("id", 0)
	if err != nil {
		logs.Info("代码有问题")
	}
	userId, err := c.GetInt("userId", 0)
	if err != nil {
		logs.Info("代码有问题")
	}
	logs.Info("id:", id)
	logs.Info("userId:", userId)

	// 链接数据库，获取对象
	// 查找列表
	services.QuerySinopharmList()

	// 通过ID查找对象
	var user ywtlog.SinopharmApi
	user = services.FindSinopharmById(id)
	backValue, err := json.Marshal(user)
	if err != nil {
		fmt.Println(err)
		return
	}
	c.Ctx.WriteString(string(backValue))
	return
}
