<?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="cn.reghao.tnb.content.app.mall.db.mapper.ProductMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert ignore into mall_product
        (`item_id`,`item_url`,`title`,`pic_url`,`price`,`month_sale`,`stock`,`shop_id`,`seller_id`)
        values 
        (#{itemId},#{itemUrl},#{title},#{picUrl},#{price},#{monthSale},#{stock},#{shopId},#{sellerId})
    </insert>

    <update id="updateStockMinus">
        update mall_product
        set stock=stock-#{num}
        where item_id=#{itemId}
    </update>
    <update id="updateStockPlus">
        update mall_product
        set stock=stock+#{num}
        where item_id=#{itemId}
    </update>

    <select id="findAll" resultType="cn.reghao.tnb.content.app.mall.model.po.Product">
        select *
        from mall_product
        order by id desc
        limit 12
    </select>
    <select id="findByItemId" resultType="cn.reghao.tnb.content.app.mall.model.po.Product">
        select *
        from mall_product
        where item_id=#{itemId}
    </select>
</mapper>