<?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.timer.api.dao.insure.InsureProductMapper">

    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="cn.timer.api.bean.insure.InsureProduct" id="insureProductMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="planCodeId" column="plan_code_id"/>
        <result property="productCodeId" column="product_code_id"/>
        <result property="type" column="type"/>
        <result property="createTime" column="create_time"/>
        <result property="isDel" column="is_del"/>
        <result property="payType" column="pay_type"/>
    </resultMap>

    <select id="queryObject" resultType="cn.timer.api.bean.insure.InsureProduct">
        select *
        from insure_product
        where id = #{value}
    </select>

    <select id="queryList" resultType="cn.timer.api.bean.insure.InsureProduct">
        select * from insure_product
        <where>
            <if test="name != null and name != ''">AND `name` = #{name}</if>
            <if test="planCodeId != null and planCodeId != ''">AND `plan_code_id` = #{planCodeId}</if>
            <if test="productCodeId != null and productCodeId != ''">AND `product_code_id` = #{productCodeId}</if>
            <if test="type != null and type != ''">AND `type` = #{type}</if>
            <if test="createTime != null and createTime != ''">AND `create_time` = #{createTime}</if>
            <if test="isDel != null and isDel != ''">AND `is_del` = #{isDel}</if>
        </where>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from insure_product
        <where>
            <if test="name != null and name != ''">AND `name` = #{name}</if>
            <if test="planCodeId != null and planCodeId != ''">AND `plan_code_id` = #{planCodeId}</if>
            <if test="productCodeId != null and productCodeId != ''">AND `product_code_id` = #{productCodeId}</if>
            <if test="type != null and type != ''">AND `type` = #{type}</if>
            <if test="createTime != null and createTime != ''">AND `create_time` = #{createTime}</if>
            <if test="isDel != null and isDel != ''">AND `is_del` = #{isDel}</if>
        </where>
    </select>

    <insert id="save" parameterType="cn.timer.api.bean.insure.InsureProduct" useGeneratedKeys="true" keyProperty="id">
        insert into insure_product
        (`name`,
         `plan_code_id`,
         `product_code_id`,
         `type`,
         `create_time`,
         `is_del`)
        values (#{name},
                #{planCodeId},
                #{productCodeId},
                #{type},
                #{createTime},
                #{isDel})
    </insert>

    <insert id="saveSelective" parameterType="cn.timer.api.bean.insure.InsureProduct" useGeneratedKeys="true"
            keyProperty="id">
        insert into insure_product
        (
        <if test="name != null">,`name`</if>
        <if test="planCodeId != null">,`plan_code_id`</if>
        <if test="productCodeId != null">,`product_code_id`</if>
        <if test="type != null">,`type`</if>
        <if test="createTime != null">,`create_time`</if>
        <if test="isDel != null">,`is_del`</if>
        )
        values
        (
        <if test="name != null">,#{name}</if>
        <if test="planCodeId != null">,#{planCodeId}</if>
        <if test="productCodeId != null">,#{productCodeId}</if>
        <if test="type != null">,#{type}</if>
        <if test="createTime != null">,#{createTime}</if>
        <if test="isDel != null">,#{isDel}</if>
        )
    </insert>


    <insert id="saveList" parameterType="cn.timer.api.bean.insure.InsureProduct" useGeneratedKeys="true"
            keyProperty="id">
        insert into insure_product
        (
        `name`,
        `plan_code_id`,
        `product_code_id`,
        `type`,
        `create_time`,
        `is_del`
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.name},
            #{item.planCodeId},
            #{item.productCodeId},
            #{item.type},
            #{item.createTime},
            #{item.isDel}
            )
        </foreach>
    </insert>


    <update id="update" parameterType="cn.timer.api.bean.insure.InsureProduct">
        update insure_product
        <set>
            <if test="name != null">`name` = #{name},</if>
            <if test="planCodeId != null">`plan_code_id` = #{planCodeId},</if>
            <if test="productCodeId != null">`product_code_id` = #{productCodeId},</if>
            <if test="type != null">`type` = #{type},</if>
            <if test="createTime != null">`create_time` = #{createTime},</if>
            <if test="isDel != null">`is_del` = #{isDel}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
        delete
        from insure_product
        where id = #{value}
    </delete>

    <delete id="deleteBatch">
        delete from insure_product where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>