<?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.sqx.modules.goods.dao.GoodsRuleMapper">

    <insert id="insertGoodsRule" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.sqx.modules.goods.entity.GoodsRule">
        INSERT INTO goods_rule (create_time, rule_name, shop_id) values (#{createTime}, #{ruleName}, #{shopId})
    </insert>

    <select id="selectRuleByShopId" resultType="com.sqx.modules.goods.entity.GoodsRule">
        select gr.*, gs.shop_name as shopName from goods_rule gr left join goods_shop gs on gr.shop_id = gs.shop_id where 1 = 1
        <if test="shopId!=null">
            and gr.shop_id = #{shopId}
        </if>
        <if test="shopName!=null and shopName!=''">
            and gs.shop_name like concat('%',#{shopName},'%')
        </if>
        order by create_time desc
    </select>

</mapper>