<?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="cn.superdesk.uniorder.dao.mapper.sys.role.SysRoleMapper">
	<resultMap id="BaseResultMap" type="cn.superdesk.uniorder.dao.entity.sys.role.SysRole">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
		<result column="remarks" property="remarks" jdbcType="VARCHAR"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
		<result column="update_user_id" property="updateUserId" jdbcType="BIGINT"/>
		<result column="issystem" property="issystem" jdbcType="TINYINT"/>
		<result column="avic_code" property="avicCode" jdbcType="VARCHAR"/>
	</resultMap>

	<resultMap id="ViewResultMap" type="cn.superdesk.uniorder.dto.vo.sys.role.ViewRole">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
		<result column="remarks" property="remarks" jdbcType="VARCHAR"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
		<result column="update_user_id" property="updateUserId" jdbcType="BIGINT"/>
		<collection property="menus" ofType="cn.superdesk.uniorder.dto.vo.sys.role.ViewRoleMenu" javaType="java.util.List"
		            column="id" select="GetMenusById">
		</collection>
	</resultMap>

	<select id="findAll" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List"/>
		from sys_role
		<where>
			<if test="roleName != null and roleName != '' ">
				and role_name like CONCAT('%',#{roleName,jdbcType=VARCHAR},'%')
			</if>
		</where>
	</select>
	<select id="findByAvicCode" resultMap="BaseResultMap" parameterType="java.lang.String">
		select
		<include refid="Base_Column_List"/>
		from sys_role
		where avic_code = #{avicCode,jdbcType=VARCHAR}
	</select>

	<sql id="Base_Column_List">
    id, role_name, remarks, create_time, create_user_id, update_time, update_user_id,issystem, avic_code
  </sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
		select
		<include refid="Base_Column_List"/>
		from sys_role
		where id = #{id,jdbcType=BIGINT}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from sys_role
    where id = #{id,jdbcType=BIGINT}
  </delete>
	<insert id="insert" parameterType="cn.superdesk.uniorder.dao.entity.sys.role.SysRole">
		<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into sys_role (role_name, remarks, create_time,
		create_user_id, update_time, update_user_id,
		issystem, avic_code)
		values (#{roleName,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
		#{createUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=BIGINT},
		#{issystem,jdbcType=TINYINT}, #{avicCode,jdbcType=VARCHAR})
	</insert>
	<insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.sys.role.SysRole">
		<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into sys_role
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="roleName != null">
				role_name,
			</if>
			<if test="remarks != null">
				remarks,
			</if>
			<if test="createTime != null">
				create_time,
			</if>
			<if test="createUserId != null">
				create_user_id,
			</if>
			<if test="updateTime != null">
				update_time,
			</if>
			<if test="updateUserId != null">
				update_user_id,
			</if>
			<if test="issystem != null">
				issystem,
			</if>
			<if test="avicCode != null">
				avic_code,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="roleName != null">
				#{roleName,jdbcType=VARCHAR},
			</if>
			<if test="remarks != null">
				#{remarks,jdbcType=VARCHAR},
			</if>
			<if test="createTime != null">
				#{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="createUserId != null">
				#{createUserId,jdbcType=BIGINT},
			</if>
			<if test="updateTime != null">
				#{updateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="updateUserId != null">
				#{updateUserId,jdbcType=BIGINT},
			</if>
			<if test="issystem != null">
				#{issystem,jdbcType=TINYINT},
			</if>
			<if test="avicCode != null">
				#{avicCode,jdbcType=VARCHAR},
			</if>
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective" parameterType="cn.superdesk.uniorder.dao.entity.sys.role.SysRole">
		update sys_role
		<set>
			<if test="roleName != null">
				role_name = #{roleName,jdbcType=VARCHAR},
			</if>
			<if test="remarks != null">
				remarks = #{remarks,jdbcType=VARCHAR},
			</if>
			<if test="createTime != null">
				create_time = #{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="createUserId != null">
				create_user_id = #{createUserId,jdbcType=BIGINT},
			</if>
			<if test="updateTime != null">
				update_time = #{updateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="updateUserId != null">
				update_user_id = #{updateUserId,jdbcType=BIGINT},
			</if>
			<if test="issystem != null">
				issystem = #{issystem,jdbcType=TINYINT},
			</if>
			<if test="avicCode != null">
				avic_code = #{avicCode,jdbcType=VARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=BIGINT}
	</update>
	<update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.sys.role.SysRole">
    update sys_role
    set role_name = #{roleName,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user_id = #{createUserId,jdbcType=BIGINT},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_user_id = #{updateUserId,jdbcType=BIGINT},
      issystem = #{issystem,jdbcType=TINYINT},
      avic_code = #{avicCode,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>