<?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.iamberry.wechat.service.mapper.IntegralProductMapper">
    <resultMap  id="BaseResultMap" type="IntegralProduct" >
        <result    column="integral_product_id"    property="integralProductId" />
        <result    column="integral_product_name"    property="integralProductName" />
        <result    column="integral_product_img"    property="integralProductImg" />
        <result    column="integral_product_desc"    property="integralProductDesc" />
        <result    column="integral_product_type"    property="integralProductType" />
        <result    column="integral_product_num"    property="integralProductNum" />
        <result    column="integral_product_remaining_num"    property="integralProductRemainingNum" />
        <result    column="integral_product_imagetext"    property="integralProductImagetext" />
        <result    column="integral_product_status"    property="integralProductStatus" />
        <result    column="integral_product_create_time"    property="integralProductCreateTime" />
        <result    column="integral_product_update_time"    property="integralProductUpdateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.integral_product_id,
        t.integral_product_name,
        t.integral_product_img,
        t.integral_product_desc,
        t.integral_product_type,
        t.integral_product_num,
        t.integral_product_remaining_num,
        t.integral_product_imagetext,
        t.integral_product_status,
        t.integral_product_create_time,
        t.integral_product_update_time
    </sql>
    <select id="getIntegralProductList" resultType="IntegralProduct" parameterType="IntegralProduct" >
        select
            t.integral_product_id,
            t.integral_product_name,
            t.integral_product_img,
            t.integral_product_desc,
            t.integral_product_type,
            t.integral_product_num,
            t.integral_product_remaining_num,
            t.integral_product_status,
            t.integral_product_create_time,
            t.integral_product_update_time,
            pc.convert_id,
            pc.integral_product_id,
            pc.convert_dfbi,
            pc.convert_is_mailing,
            pc.convert_is_mailing,
            pc.convert_dfbi,
            pc.convert_dfbi,
            pc.convert_is_pay,
            pc.convert_price,
            pc.coupon_id,
            ct.coupon_type AS  couponType,
            ct.coupon_reduce AS  couponReduce
        from tb_iamberry_integral_product t
        LEFT JOIN tb_iamberry_integral_product_convert pc ON t.integral_product_id = pc.integral_product_id
        LEFT JOIN tb_iamberry_coupon_type ct ON pc.coupon_id = ct.coupon_id
        <where>
            <if test="integralProductId != null ">
                AND t.integral_product_id = #{integralProductId}
            </if >
            <if test="integralProductName != null and integralProductName != ''">
                AND t.integral_product_name  like  CONCAT ('%',#{integralProductName},'%')
            </if >
            <if test="integralProductImg != null and integralProductImg != ''">
                AND t.integral_product_img = #{integralProductImg}
            </if >
            <if test="integralProductDesc != null and integralProductDesc != ''">
                AND t.integral_product_desc = #{integralProductDesc}
            </if >
            <if test="integralProductType != null ">
                AND t.integral_product_type = #{integralProductType}
            </if >
            <if test="integralProductNum != null ">
                AND t.integral_product_num = #{integralProductNum}
            </if >
            <if test="integralProductRemainingNum != null ">
                AND t.integral_product_remaining_num = #{integralProductRemainingNum}
            </if >
            <if test="integralProductImagetext != null and integralProductImagetext != ''">
                AND t.integral_product_imagetext = #{integralProductImagetext}
            </if >
            <if test="integralProductStatus != null ">
                AND t.integral_product_status = #{integralProductStatus}
            </if >
        </where>
    </select>
    <select id="getIntegralProductById" resultMap="BaseResultMap" parameterType="Integer" >
        select
            <include refid="Base_List" />,
            pc.convert_id,
            pc.integral_product_id,
            pc.convert_dfbi,
            pc.convert_is_mailing,
            pc.convert_is_mailing,
            pc.convert_dfbi,
            pc.convert_dfbi,
            pc.convert_is_pay,
            pc.convert_price,
            pc.coupon_id,
            ct.coupon_type AS  couponType,
            ct.coupon_reduce AS  couponReduce
        from tb_iamberry_integral_product t
        LEFT JOIN tb_iamberry_integral_product_convert pc ON t.integral_product_id = pc.integral_product_id
        LEFT JOIN tb_iamberry_coupon_type ct ON pc.coupon_id = ct.coupon_id
        where t.integral_product_id= #{integralProductId}
    </select>
    <insert id="save" parameterType="IntegralProduct" >
        insert into
        tb_iamberry_integral_product
        (
        integral_product_id,
        integral_product_name,
        integral_product_img,
        integral_product_desc,
        integral_product_type,
        integral_product_num,
        integral_product_remaining_num,
        integral_product_imagetext,
        integral_product_status
        )
        values
        (
        #{integralProductId},
        #{integralProductName},
        #{integralProductImg},
        #{integralProductDesc},
        #{integralProductType},
        #{integralProductNum},
        #{integralProductRemainingNum},
        #{integralProductImagetext},
        #{integralProductStatus}
        )
    </insert>
    <update id="update" parameterType="IntegralProduct" >
        update
        tb_iamberry_integral_product
        <set >
            <if test="integralProductId != null ">
                integral_product_id = #{integralProductId},
            </if >
            <if test="integralProductName != null and integralProductName != ''">
                integral_product_name = #{integralProductName},
            </if >
            <if test="integralProductImg != null and integralProductImg != ''">
                integral_product_img = #{integralProductImg},
            </if >
            <if test="integralProductDesc != null and integralProductDesc != ''">
                integral_product_desc = #{integralProductDesc},
            </if >
            <if test="integralProductType != null ">
                integral_product_type = #{integralProductType},
            </if >
            <if test="integralProductNum != null ">
                integral_product_num = #{integralProductNum},
            </if >
            <if test="integralProductRemainingNum != null ">
                integral_product_remaining_num = #{integralProductRemainingNum},
            </if >
            <if test="integralProductImagetext != null and integralProductImagetext != ''">
                integral_product_imagetext = #{integralProductImagetext},
            </if >
            <if test="integralProductStatus != null ">
                integral_product_status = #{integralProductStatus},
            </if >
        </set >
        where integral_product_id= #{integralProductId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete
        tb_iamberry_integral_product
        where integral_product_id=#{integralProductId}
    </delete>
</mapper>