package net.wicp.tams.app.duckula.controller.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import net.wicp.tams.app.duckula.controller.bean.models.SysRole;
import net.wicp.tams.app.duckula.controller.bean.models.SysRoleExample;

public interface SysRoleMapper extends BaseMapper<SysRole> {

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	long countByExample(SysRoleExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	int deleteByExample(SysRoleExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	@Delete({ "delete from sys_role", "where id = #{id,jdbcType=BIGINT}" })
	int deleteByPrimaryKey(Long id);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	@Insert({ "insert into sys_role (id, name, ", "status, remark, ", "is_super)",
			"values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
			"#{status,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, ", "#{isSuper,jdbcType=VARCHAR})" })
	int insert(SysRole record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	int insertSelective(SysRole record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	List<SysRole> selectByExample(SysRoleExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	@Select({ "select", "id, name, status, remark, is_super", "from sys_role", "where id = #{id,jdbcType=BIGINT}" })
	@ResultMap("net.wicp.tams.app.duckula.controller.dao.SysRoleMapper.BaseResultMap")
	SysRole selectByPrimaryKey(Long id);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	int updateByExampleSelective(@Param("record") SysRole record, @Param("example") SysRoleExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	int updateByExample(@Param("record") SysRole record, @Param("example") SysRoleExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	int updateByPrimaryKeySelective(SysRole record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table sys_role
	 * @mbg.generated
	 */
	@Update({ "update sys_role", "set name = #{name,jdbcType=VARCHAR},", "status = #{status,jdbcType=VARCHAR},",
			"remark = #{remark,jdbcType=VARCHAR},", "is_super = #{isSuper,jdbcType=VARCHAR}",
			"where id = #{id,jdbcType=BIGINT}" })
	int updateByPrimaryKey(SysRole record);

	/***
	 * 自定义,如果没有加tenant_id字段而又在po里出现tenatnId会报错：Could not process result for mapping:
	 * ResultMapping{property='null', column='tenant_id'
	 * 
	 * @param assignValue
	 * @return
	 */
	@Select({ "select", "cr.*", "from sys_role cr,sys_role_assign ca",
			"where cr.id=ca.role_id and ca.assign_type='STAFF' and ca.assign_value= #{staffId,jdbcType=BIGINT}" })
	@ResultMap("net.wicp.tams.app.duckula.controller.dao.SysRoleMapper.BaseResultMap")
	List<SysRole> findRolesByStaff(long staffId);
}