mapping if else

<?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` &gt;= #{startCreatTime}
			</when>
			<otherwise>
				<if test="startCreatTime!=null and startCreatTime!=''">
					AND `creat_time` &gt;=#{startCreatTime}
				</if>
				<if test="endCreatTime!=null and endCreatTime!=''">
					AND `creat_time` &lt;=#{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` &gt;= #{startCreatTime}
			</when>
			<otherwise>
				<if test="startCreatTime!=null and startCreatTime!=''">
					AND `creat_time` &gt;=#{startCreatTime}
				</if>
				<if test="endCreatTime!=null and endCreatTime!=''">
					AND `creat_time` &lt;=#{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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值