<?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.younike.system.mapper.SysCodeMapper">

    <resultMap type="SysCode" id="SysCodeResult">
        <result property="codeId"    column="Code_Id"    />
        <result property="codeValue"    column="Code_Value"    />
        <result property="decodeId"    column="Decode_Id"    />
        <result property="decodeValue"    column="Decode_Value"    />
        <result property="comment"    column="Comment"    />
    </resultMap>

    <sql id="selectSysCodeVo">
        select Code_Id, Code_Value, Decode_Id, Decode_Value, Comment from sys_code
    </sql>

    <select id="selectSysCodeList" parameterType="SysCode" resultMap="SysCodeResult">
        <include refid="selectSysCodeVo"/>
        <where>
            <if test="codeValue != null  and codeValue != ''"> and Code_Value = #{codeValue}</if>
            <if test="decodeValue != null  and decodeValue != ''"> and Decode_Value = #{decodeValue}</if>
            <if test="comment != null  and comment != ''"> and Comment = #{comment}</if>
        </where>
    </select>

    <select id="selectSysCodeByCodeId" parameterType="String" resultMap="SysCodeResult">
        <include refid="selectSysCodeVo"/>
        where Code_Id = #{codeId}
    </select>

    <insert id="insertSysCode" parameterType="SysCode">
        insert into sys_code
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="codeId != null">Code_Id,</if>
            <if test="codeValue != null">Code_Value,</if>
            <if test="decodeId != null">Decode_Id,</if>
            <if test="decodeValue != null">Decode_Value,</if>
            <if test="comment != null">Comment,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="codeId != null">#{codeId},</if>
            <if test="codeValue != null">#{codeValue},</if>
            <if test="decodeId != null">#{decodeId},</if>
            <if test="decodeValue != null">#{decodeValue},</if>
            <if test="comment != null">#{comment},</if>
        </trim>
    </insert>

    <update id="updateSysCode" parameterType="SysCode">
        update sys_code
        <trim prefix="SET" suffixOverrides=",">
            <if test="codeValue != null">Code_Value = #{codeValue},</if>
            <if test="decodeId != null">Decode_Id = #{decodeId},</if>
            <if test="decodeValue != null">Decode_Value = #{decodeValue},</if>
            <if test="comment != null">Comment = #{comment},</if>
        </trim>
        where Code_Id = #{codeId}
    </update>

    <delete id="deleteSysCodeByCodeId" parameterType="String">
        delete from sys_code where Code_Id = #{codeId}
    </delete>

    <delete id="deleteSysCodeByCodeIds" parameterType="String">
        delete from sys_code where Code_Id in
        <foreach item="codeId" collection="array" open="(" separator="," close=")">
            #{codeId}
        </foreach>
    </delete>
</mapper>
