UfoProductPoolMapper.xml 2.1 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.UfoProductPoolMapper">

    <resultMap id="productPool" type="com.yoho.ufo.model.goodsmanage.ProductPool">
    </resultMap>

    <sql id="queryColumns">
        pool.id, pool.pool_name, pool.create_time, COUNT(pool_detail.product_id) AS productNum
    </sql>

    <insert id="insertProductPool" parameterType="com.yoho.ufo.model.goodsmanage.ProductPool" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        insert into product_pool(id, pool_name, create_time, pool_type)
        values (#{id}, #{poolName}, #{createTime}, #{poolType})
    </insert>




    <update id="updateProductPool" parameterType="com.yoho.ufo.model.goodsmanage.ProductPool">
        update product_pool set pool_name = #{productPool.poolName}
        where id = #{productPool.id}
    </update>

    <select id="selectOneById" resultMap="productPool">
        select id, pool_name
        from product_pool where id = #{id}
    </select>


    <sql id="queryParam">
        <where>
            <if test="productPool.id != null">
                pool.id = #{productPool.id}
            </if>
            <if test="productPool.poolName != null and productPool.poolName != ''">
                and pool.pool_name like concat('%', #{productPool.poolName}, '%')
            </if>
        </where>
    </sql>

    <sql id="queryTable">
        FROM product_pool pool
        LEFT JOIN product_pool_detail pool_detail
        ON pool.id = pool_detail.pool_id
    </sql>

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

    <select id="getProductPoolPageList" resultMap="productPool">
        select <include refid="queryColumns"/>
        <include refid="queryTable"/>
        <include refid="queryParam"/>
        GROUP BY pool_detail.pool_id
        ORDER BY pool.create_time DESC
        limit #{page.startIndex}, #{page.pageSize}
    </select>

</mapper>