UfoProductDetailsMapper.xml 2.85 KB
<?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.yoho.ufo.dal.UfoProductDetailsMapper">

    <resultMap id="productDetails" type="com.yoho.ufo.model.goodsmanage.ProductDetails">
    </resultMap>

    <sql id="queryColumns">
        product.id, product.product_code, product.product_name, product.product_code, brand.brand_name, 
        CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, product.del_status, pool_detail.order_by
    </sql>

    <select id="queryProductIdsByProductIds" parameterType="java.util.Set" resultType="integer">
        select id from product
        where del_status = 0 and id in
        <foreach collection="set" index="index" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

    <sql id="queryParam">
        WHERE pool_detail.pool_id = #{productDetails.poolId}
        <if test="productDetails.productCode != null and productDetails.productCode != ''">
            and product.product_code like concat('%',#{productDetails.productCode}, '%')
        </if>
        <if test="productDetails.id != null and productDetails.id != ''">
            and product.id like #{productDetails.id}
        </if>
        <if test="productDetails.productName != null and productDetails.productName != ''">
            and product.product_name like concat('%', #{productDetails.productName}, '%')
        </if>
        <if test="productDetails.brandName != null and productDetails.brandName != ''">
            and brand.brand_name like concat('%', #{productDetails.brandName}, '%')
        </if>
        <if test="productDetails.sortName != null and productDetails.sortName != ''">
            and (sort1.sort_name like concat('%', #{productDetails.sortName}, '%') or sort2.sort_name like concat('%', #{productDetails.sortName}, '%'))
        </if>
    </sql>

    <sql id="queryTable">
        FROM product_pool pool
        LEFT JOIN product_pool_detail pool_detail
        ON pool.id = pool_detail.pool_id
        LEFT JOIN product
        ON pool_detail.product_id = product.id
        LEFT JOIN brand
        ON product.brand_id = brand.id
        LEFT JOIN product_sort sort1
        ON product.mid_sort_id = sort1.id
        LEFT JOIN product_sort sort2
        ON product.max_sort_id = sort2.id
    </sql>

    <select id="selectProductDetailsCount" resultType="integer">
        SELECT COUNT(*)
        <include refid="queryTable"/>
        <include refid="queryParam"/>
    </select>

    <select id="getProductDetailsPageList" resultMap="productDetails">
        select <include refid="queryColumns"/>
        <include refid="queryTable"/>
        <include refid="queryParam"/> 
        order by pool_detail.order_by desc 
        limit #{page.startIndex}, #{page.pageSize}
    </select>

</mapper>