package com.yihu.hos.system.dao;

import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import com.yihu.hos.system.dao.intf.ISystemRoleMenuDao;
import com.yihu.hos.system.model.SystemRoleMenu;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by chenweida on 2016/2/19.
 */
@Repository("systemRoleMenuDao")
public class SystemRoleMenuDao extends SQLGeneralDAO implements ISystemRoleMenuDao {
    @Override
    public List<SystemRoleMenu> getSystemRoleMenuListByRoleId(String roleId) throws Exception {
        return (List<SystemRoleMenu>) super.hibernateTemplate.find("from SystemRoleMenu s where s.roleId=?", roleId);

    }

    @Override
    public SystemRoleMenu getRoleMenuByRoleIdAndMenuId(String roleId, String menuId) throws Exception {
        return (SystemRoleMenu) super.hibernateTemplate.find("from SystemRoleMenu s where s.roleId=? and s.menuId=?", roleId, menuId).get(0);
    }

    @Override
    public void deleteAllByRoleId(String roleId) throws Exception {
        super.hibernateTemplate.bulkUpdate("delete SystemRoleMenu s where s.roleId=?",roleId);
    }
}
