package cases

// GetKeyList 获取钥匙列表
func (c *CaseController) GetKeyList() {
	caseid := c.GetString("caseid")
	page, _ := c.GetInt("page")
	pageSize, _ := c.GetInt("pagesize")
	num := c.GetString("num")

	if page < 1 {
		page = 1
	}

	list, err := c.dao.GetKeysByCase(caseid, num, page, pageSize)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(list)
}

// AddKeys 新增钥匙
func (c *CaseController) AddKeys() {
	caseid := c.GetString("caseid")
	orgid := c.GetString("orgid")
	beginnum, _ := c.GetInt("beginnum")
	endnum, _ := c.GetInt("endnum")

	err := c.dao.AddKeys(orgid, caseid, beginnum, endnum)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功！")
}

// UnLockKey 解锁
func (c *CaseController) UnLockKey() {
	keyid := c.GetString(":keyid")
	err := c.dao.UnLockKey(keyid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("解锁成功！")
}

// DelKey 删除
func (c *CaseController) DelKey() {
	keyid := c.GetString(":keyid")
	err := c.dao.DelKey(keyid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("删除成功！")
}
