<?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.jianshui.platform.mapper.ProductInfoMapper">
    
    <resultMap type="ProductInfo" id="ProductInfoResult">
        <result property="id"    column="id"    />
        <result property="productCode"    column="product_code"    />
        <result property="productName"    column="product_name"    />
        <result property="taxRate"    column="tax_rate"    />
        <result property="unitPrice"    column="unit_price"    />
        <result property="specification"    column="specification"    />
        <result property="unitOfMeasurement"    column="unit_of_measurement"    />
        <result property="taxCategoryCode"    column="tax_category_code"    />
        <result property="taxCategoryCodeId"    column="tax_category_code_id"    />
        <result property="taxCategoryAbbreviation"    column="tax_category_abbreviation"    />
        <result property="isQualifiedForDiscount"    column="is_qualified_for_discount"    />
        <result property="discountPolicyType"    column="discount_policy_type"    />
        <result property="zeroTaxRateIndicator"    column="zero_tax_rate_indicator"    />
        <result property="status"    column="status"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProductInfoVo">
        select id, product_code, product_name, tax_rate, unit_price, specification, unit_of_measurement, tax_category_code, tax_category_code_id, tax_category_abbreviation, is_qualified_for_discount, discount_policy_type, zero_tax_rate_indicator, status, create_by, create_time, update_by, update_time, remark from product_info
    </sql>

    <select id="selectProductInfoList" parameterType="ProductInfo" resultMap="ProductInfoResult">
        <include refid="selectProductInfoVo"/>
        <where>  
            <if test="productCode != null  and productCode != ''"> and product_code = #{productCode}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="taxRate != null "> and tax_rate = #{taxRate}</if>
            <if test="unitPrice != null "> and unit_price = #{unitPrice}</if>
            <if test="specification != null  and specification != ''"> and specification = #{specification}</if>
            <if test="unitOfMeasurement != null  and unitOfMeasurement != ''"> and unit_of_measurement = #{unitOfMeasurement}</if>
            <if test="taxCategoryCode != null  and taxCategoryCode != ''"> and tax_category_code = #{taxCategoryCode}</if>
            <if test="taxCategoryCodeId != null "> and tax_category_code_id = #{taxCategoryCodeId}</if>
            <if test="taxCategoryAbbreviation != null  and taxCategoryAbbreviation != ''"> and tax_category_abbreviation = #{taxCategoryAbbreviation}</if>
            <if test="isQualifiedForDiscount != null  and isQualifiedForDiscount != ''"> and is_qualified_for_discount = #{isQualifiedForDiscount}</if>
            <if test="discountPolicyType != null  and discountPolicyType != ''"> and discount_policy_type = #{discountPolicyType}</if>
            <if test="zeroTaxRateIndicator != null  and zeroTaxRateIndicator != ''"> and zero_tax_rate_indicator = #{zeroTaxRateIndicator}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectProductInfoById" parameterType="Long" resultMap="ProductInfoResult">
        <include refid="selectProductInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertProductInfo" parameterType="ProductInfo" useGeneratedKeys="true" keyProperty="id">
        insert into product_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productCode != null">product_code,</if>
            <if test="productName != null">product_name,</if>
            <if test="taxRate != null">tax_rate,</if>
            <if test="unitPrice != null">unit_price,</if>
            <if test="specification != null">specification,</if>
            <if test="unitOfMeasurement != null">unit_of_measurement,</if>
            <if test="taxCategoryCode != null">tax_category_code,</if>
            <if test="taxCategoryCodeId != null">tax_category_code_id,</if>
            <if test="taxCategoryAbbreviation != null">tax_category_abbreviation,</if>
            <if test="isQualifiedForDiscount != null">is_qualified_for_discount,</if>
            <if test="discountPolicyType != null">discount_policy_type,</if>
            <if test="zeroTaxRateIndicator != null">zero_tax_rate_indicator,</if>
            <if test="status != null">status,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productCode != null">#{productCode},</if>
            <if test="productName != null">#{productName},</if>
            <if test="taxRate != null">#{taxRate},</if>
            <if test="unitPrice != null">#{unitPrice},</if>
            <if test="specification != null">#{specification},</if>
            <if test="unitOfMeasurement != null">#{unitOfMeasurement},</if>
            <if test="taxCategoryCode != null">#{taxCategoryCode},</if>
            <if test="taxCategoryCodeId != null">#{taxCategoryCodeId},</if>
            <if test="taxCategoryAbbreviation != null">#{taxCategoryAbbreviation},</if>
            <if test="isQualifiedForDiscount != null">#{isQualifiedForDiscount},</if>
            <if test="discountPolicyType != null">#{discountPolicyType},</if>
            <if test="zeroTaxRateIndicator != null">#{zeroTaxRateIndicator},</if>
            <if test="status != null">#{status},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProductInfo" parameterType="ProductInfo">
        update product_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="productCode != null">product_code = #{productCode},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="taxRate != null">tax_rate = #{taxRate},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>
            <if test="specification != null">specification = #{specification},</if>
            <if test="unitOfMeasurement != null">unit_of_measurement = #{unitOfMeasurement},</if>
            <if test="taxCategoryCode != null">tax_category_code = #{taxCategoryCode},</if>
            <if test="taxCategoryCodeId != null">tax_category_code_id = #{taxCategoryCodeId},</if>
            <if test="taxCategoryAbbreviation != null">tax_category_abbreviation = #{taxCategoryAbbreviation},</if>
            <if test="isQualifiedForDiscount != null">is_qualified_for_discount = #{isQualifiedForDiscount},</if>
            <if test="discountPolicyType != null">discount_policy_type = #{discountPolicyType},</if>
            <if test="zeroTaxRateIndicator != null">zero_tax_rate_indicator = #{zeroTaxRateIndicator},</if>
            <if test="status != null">status = #{status},</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="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProductInfoById" parameterType="Long">
        delete from product_info where id = #{id}
    </delete>

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