<?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.lyms.platform.permission.dao.master.MasterUserRoleMapsMapper">
<resultMap id="UserRoleMapsResultMap" type="com.lyms.platform.permission.model.UserRoleMaps">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="role_id" property="roleId" jdbcType="INTEGER" />
<result column="yn" property="yn" jdbcType="INTEGER" />
<result column="expirTime" property="expirTime" jdbcType="TIMESTAMP" />
</resultMap>
<insert id="addUserRoleMaps" parameterType="com.lyms.platform.permission.model.UserRoleMaps">
<selectKey order="AFTER" keyProperty="id" resultType="java.lang.Integer">SELECT LAST_INSERT_ID()</selectKey>
insert into user_role_maps (user_id,role_id,yn,expirTime
<if test="id != null and id >= 0">
,id
</if>
) values (#{userId},#{roleId},#{yn},#{expirTime}
<if test="id != null and id >= 0">
,#{id}
</if>)
</insert>
<select id="queryUserRoleList" parameterType="com.lyms.platform.permission.model.UserRoleMaps" resultType="java.lang.Integer">
select DISTINCT role_id from user_role_maps
<include refid="UserRoleMapsCondition" />
<include refid="orderAndLimit" />
</select>
<update id="updateUserRoleMaps" parameterType="com.lyms.platform.permission.model.UserRoleMaps">
update user_role_maps <set><if test="userId != null and userId >= 0">
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="roleId != null and roleId >= 0">
role_id = #{roleId,jdbcType=INTEGER},
</if>
<if test="yn != null and yn >= 0">
yn = #{yn,jdbcType=INTEGER},
</if>
<if test="expirTime != null">
expirTime = #{expirTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteUserRoleMaps" parameterType="java.lang.Integer">
delete from user_role_maps where id = #{id,jdbcType=INTEGER}
</delete>
<select id="getUserRoleMaps" resultMap="UserRoleMapsResultMap" parameterType="java.lang.Integer">
select id,user_id,role_id,yn,expirTime
from user_role_maps where id = #{id,jdbcType=INTEGER}
</select>
<sql id="orderAndLimit">
<if test="sort != null and sort != '' ">
order by ${sort}
<if test="need != null">
limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
</if>
</if>
</sql>
<sql id="UserRoleMapsCondition">
<where>
1 = 1
<if test="id != null and id >= 0">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="userId != null and userId >= 0">
and user_id = #{userId,jdbcType=INTEGER}
</if>
<if test="roleId != null and roleId >= 0">
and role_id = #{roleId,jdbcType=INTEGER}
</if>
<if test="yn != null and yn >= 0">
and yn = #{yn,jdbcType=INTEGER}
</if>
<if test="expirTime != null">
and expirTime = #{expirTime,jdbcType=TIMESTAMP}
</if>
</where>
</sql>
<select id="queryUserRoleMaps" resultMap="UserRoleMapsResultMap" parameterType="com.lyms.platform.permission.model.UserRoleMapsQuery">
select id,user_id,role_id,yn,expirTime
from user_role_maps
<include refid="UserRoleMapsCondition" />
<include refid="orderAndLimit" />
</select>
<select id="queryUserRoleMapsCount" resultType="int" parameterType="com.lyms.platform.permission.model.UserRoleMapsQuery">
select count(1) from user_role_maps
<include refid="UserRoleMapsCondition" />
</select>
<select id="queryUserRoleName" resultType="java.lang.String" parameterType="java.lang.Integer">
select b.name from user_role_maps a ,roles b where a.yn=1 and a.user_id=#{id,jdbcType=INTEGER} and a.role_id=b.id and b.yn=1
</select>
</mapper>