<?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.jsowell.pile.mapper.PileLicenceInfoMapper">

    <resultMap type="com.jsowell.pile.domain.PileLicenceInfo" id="PileLicenceInfoResult">
        <result property="id"    column="id"    />
        <result property="licenceName"    column="licence_name"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="status"    column="status"    />
        <result property="expireTime"    column="expire_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectPileLicenceInfoVo">
        select id, licence_name, merchant_id, status, expire_time, create_by, create_time, update_by, update_time, del_flag from pile_licence_info
    </sql>

    <select id="selectPileLicenceInfoList" parameterType="com.jsowell.pile.domain.PileLicenceInfo" resultMap="PileLicenceInfoResult">
        <include refid="selectPileLicenceInfoVo"/>
        <where>
            <if test="licenceName != null  and licenceName != ''"> and licence_name like concat('%', #{licenceName}, '%')</if>
            <if test="merchantId != null "> and merchant_id = #{merchantId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="expireTime != null "> and expire_time = #{expireTime}</if>
        </where>
    </select>

    <select id="selectPileLicenceInfoById" parameterType="Long" resultMap="PileLicenceInfoResult">
        <include refid="selectPileLicenceInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertPileLicenceInfo" parameterType="com.jsowell.pile.domain.PileLicenceInfo">
        insert into pile_licence_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="licenceName != null">licence_name,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="status != null">status,</if>
            <if test="expireTime != null">expire_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="licenceName != null">#{licenceName},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="status != null">#{status},</if>
            <if test="expireTime != null">#{expireTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updatePileLicenceInfo" parameterType="com.jsowell.pile.domain.PileLicenceInfo">
        update pile_licence_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="licenceName != null">licence_name = #{licenceName},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="expireTime != null">expire_time = #{expireTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePileLicenceInfoById" parameterType="Long">
        delete from pile_licence_info where id = #{id}
    </delete>

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