<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.zichen.xhkq.dao.shiro.SysRoleDao">
<!-- 根据schoolId和RoleName查询SysRole -->
<select id="selectBySchoolIdAndRoleName" parameterType="com.zichen.xhkq.pojo.shiro.SysRole"
resultType="com.zichen.xhkq.pojo.shiro.SysRole">
SELECT * FROM `sys_role` WHERE `school_id`=#{schoolId} AND
`name`=#{name}
</select>
<!-- 查询SysRole的总数 -->
<select id="selectCount" parameterType="com.zichen.xhkq.pojo.shiro.SysRole"
resultType="java.lang.Integer">
SELECT count(*) FROM `sys_role` WHERE `school_id`=#{schoolId}
<if test="name!=null and name!=''">
AND `name` LIKE '%${name}%'
</if>
<choose>
<when
test="startCreatTime!=null and startCreatTime!='' and endCreatTime!=null and endCreatTime!='' and startCreatTime==endCreatTime">
AND `creat_time` >= #{startCreatTime}
</when>
<otherwise>
<if test="startCreatTime!=null and startCreatTime!=''">
AND `creat_time` >=#{startCreatTime}
</if>
<if test="endCreatTime!=null and endCreatTime!=''">
AND `creat_time` <=#{endCreatTime}
</if>
</otherwise>
</choose>
<if test="creatPerson!=null and creatPerson!=''">
AND `creat_person` LIKE '%${creatPerson}%'
</if>
<if test="available!='3'">
AND `available` =#{available}
</if>
<if test="available=='3'">
AND `available` in ('0','1')
</if>
</select>
<!-- 根据schoolId查询SysRole的list -->
<select id="selectListBySchoolId" parameterType="com.zichen.xhkq.pojo.shiro.SysRole"
resultType="com.zichen.xhkq.pojo.shiro.SysRole">
SELECT * FROM `sys_role` WHERE `school_id`=#{schoolId}
</select>
<!-- 根据id删除SysRole -->
<delete id="deleteById" parameterType="com.zichen.xhkq.pojo.shiro.SysRole">
DELETE FROM `sys_role`
WHERE `id`=#{id}
</delete>
<!-- 根据id list批量删除 -->
<delete id="deleteBatch">
DELETE FROM `sys_role` WHERE `id` in
<foreach collection="idList" close=")" open="(" separator=","
item="id">
#{id}
</foreach>
;
</delete>
<!-- 根据id修改SysRole -->
<update id="updateBySysRole" parameterType="com.zichen.xhkq.pojo.shiro.SysRole">
UPDATE `sys_role`
<set>
`creat_time`= NOW(),
<if test="name != null">
`name`=#{name},
</if>
<if test="available != null and available !=''">
`available`=#{available},
</if>
<if test="creatPerson != null">
`creat_person`=#{creatPerson},
</if>
<if test="description != null">
`description`=#{description},
</if>
</set>
WHERE `id`=#{id}
</update>
<!-- 新增角色信息 -->
<insert id="insertSysRole" parameterType="com.zichen.xhkq.pojo.shiro.SysRole">
INSERT INTO `sys_role`(
`id`,`school_id`,`name`,`available`,`creat_time`,`creat_person`,`description`
)
VALUES(
#{id},#{schoolId},#{name},#{available},NOW(),#{creatPerson},#{description}
)
</insert>
<!-- 条件查询SysRole的list -->
<select id="selectListConditions" resultType="com.zichen.xhkq.pojo.shiro.SysRole">
SELECT * FROM `sys_role` WHERE `school_id`=#{schoolId}
<if test="name!=null and name!=''">
AND `name` LIKE '%${name}%'
</if>
<choose>
<when
test="startCreatTime!=null and startCreatTime!='' and endCreatTime!=null and endCreatTime!='' and startCreatTime==endCreatTime">
AND `creat_time` >= #{startCreatTime}
</when>
<otherwise>
<if test="startCreatTime!=null and startCreatTime!=''">
AND `creat_time` >=#{startCreatTime}
</if>
<if test="endCreatTime!=null and endCreatTime!=''">
AND `creat_time` <=#{endCreatTime}
</if>
</otherwise>
</choose>
<if test="creatPerson!=null and creatPerson!=''">
AND `creat_person` LIKE '%${creatPerson}%'
</if>
<if test="available!='3'">
AND `available` =#{available}
</if>
<if test="available=='3'">
AND `available` in ('0','1')
</if>
LIMIT #{startNum},#{pageSize}
</select>
<!-- 通过学校ID和available获取角色列表 -->
<select id="getRoleListBySchoolIdAndAvailable" resultType="com.zichen.xhkq.pojo.shiro.SysRole">
SELECT * FROM `sys_role` WHERE `available` = #{roleAvailable} AND
`school_id`=#{schoolId}
</select>
<!-- 根据角色id修改角色信息的是否可用状态 -->
<update id="updateRoleAvaliableByRoleId">
UPDATE sys_role AS SR SET SR.available = #{available}
WHERE SR.id = #{id};
</update>
<!-- 根据角色ID获取角色信息 -->
<select id="getSysRoleByRoleId" parameterType="java.lang.String"
resultType="com.zichen.xhkq.pojo.shiro.SysRole">
SELECT * FROM sys_role AS SR WHERE SR.id = #{id};
</select>
</mapper>