<?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.hzs.sale.product.mapper.BdProductExtendMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.sale.product.BdProductExtend">
        <id column="PK_ID" property="pkId" />
        <result column="PK_PRODUCT" property="pkProduct" />
        <result column="IS_PICK_UP" property="isPickUp" />
        <result column="IS_PRIZE" property="isPrize" />
        <result column="IS_BAR_CODE" property="isBarCode" />
        <result column="IS_MERGE" property="isMerge" />
        <result column="IS_GIFT" property="isGift" />
        <result column="IS_PUT_ON" property="isPutOn" />
        <result column="WARNING_QUANTITY" property="warningQuantity" />
    </resultMap>

    <select id="selectByProductId" resultMap="BaseResultMap">
        select * from BD_PRODUCT_EXTEND  where PK_PRODUCT = #{pkProduct} and DEL_FLAG = '0'
    </select>

    <select id="selectByMoveUpSort" resultType="integer">
        select min(ex.SORT) FROM BD_PRODUCT_EXTEND  ex where ex.SORT &gt; (select sort from BD_PRODUCT_EXTEND pe where pe.pk_product = #{pkProduct} ) and  DEL_FLAG = '0'
    </select>

    <update id="updateMoveUpBySort">
        update BD_PRODUCT_EXTEND set sort = sort+1 where sort &gt;= #{sort} and  DEL_FLAG = '0'
    </update>

    <select id="selectByMoveDownSort" resultType="integer">
        select max(ex.SORT) FROM BD_PRODUCT_EXTEND  ex where ex.SORT &lt; (select sort from BD_PRODUCT_EXTEND pe where pe.pk_product = #{pkProduct} ) and  DEL_FLAG = '0'
    </select>

    <update id="updateMoveDownBySort">
        update BD_PRODUCT_EXTEND set sort = sort-1 where sort &lt;= #{sort} and  DEL_FLAG = '0'
    </update>

    <select id="getMaxProductSort" resultType="integer">
        select max(sort) from  BD_PRODUCT_EXTEND where DEL_FLAG = '0'
    </select>

    <!-- 查询产品扩展以及产品信息 -->
    <select id="queryExtendAndProduct" resultType="com.hzs.common.domain.sale.ext.BdProductExtendExt">
        select bpe.*, bp.product_code
        from bd_product_extend bpe
                 inner join bd_product bp
                            on bp.pk_id = bpe.pk_product
        where bpe.del_flag = 0
          and bpe.pk_product = #{pkProduct}
    </select>

</mapper>
