package cases

import "spaceofcheng/services/models/model"

// GetEquipmentList 获取体检设备列表
func (c *CaseController) GetEquipmentList() {
	cases := c.Context.Get("cases").([]model.SysUserCase)
	caseIDs := c.GetCaseIDs(cases)
	page, _ := c.GetInt("page")
	pageSize, _ := c.GetInt("pagesize")

	list, err := c.dao.GetCaseEquipment(caseIDs, page, pageSize)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(list)
}

// GetEquipmentByID 根据ID获取体检设备信息
func (c *CaseController) GetEquipmentByID() {
	id := c.GetString(":id")
	info, err := c.dao.GetCaseEquipmentByID(id)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(info)
}

// SaveCaseEquipment 保存体检设备
func (c *CaseController) SaveCaseEquipment() {
	info := model.SysCaseEquipment{}
	if err := c.ParseForm(&info); err != nil {
		c.ResponseError(err)
	}
	newinfo, err := c.dao.SaveCaseEquipment(info)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(newinfo)
}

// DelCaseEquipment 删除体检设备
func (c *CaseController) DelCaseEquipment() {
	id := c.GetString(":id")
	err := c.dao.DelCaseEquipment(id)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("删除成功！")
}
