<?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.ruoyi.mall.mapper.MallExpeditingGoodsMapper">
    
    <resultMap type="com.ruoyi.mall.domain.MallExpeditingGoods" id="MallExpeditingGoodsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="goodName"    column="good_name"    />
        <result property="goodPrice"    column="good_price"    />
        <result property="createAt"    column="create_at"    />
    </resultMap>

    <sql id="selectMallExpeditingGoodsVo">
        select id, user_id, user_name, user_phone, good_name, good_price, create_at from mall_expediting_goods
    </sql>

    <select id="selectMallExpeditingGoodsList" parameterType="MallExpeditingGoods" resultMap="MallExpeditingGoodsResult">
        <include refid="selectMallExpeditingGoodsVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null "> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userPhone != null "> and user_phone = #{userPhone}</if>
            <if test="goodName != null  and goodName != ''"> and good_name like concat('%', #{goodName}, '%')</if>
            <if test="goodPrice != null  and goodPrice != ''"> and good_price = #{goodPrice}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
        </where>
    </select>
    
    <select id="selectMallExpeditingGoodsById" parameterType="Long" resultMap="MallExpeditingGoodsResult">
        <include refid="selectMallExpeditingGoodsVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallExpeditingGoods" parameterType="MallExpeditingGoods" useGeneratedKeys="true" keyProperty="id">
        insert into mall_expediting_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="goodName != null">good_name,</if>
            <if test="goodPrice != null">good_price,</if>
            <if test="createAt != null">create_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="goodName != null">#{goodName},</if>
            <if test="goodPrice != null">#{goodPrice},</if>
            <if test="createAt != null">#{createAt},</if>
         </trim>
    </insert>

    <update id="updateMallExpeditingGoods" parameterType="MallExpeditingGoods">
        update mall_expediting_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="goodName != null">good_name = #{goodName},</if>
            <if test="goodPrice != null">good_price = #{goodPrice},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallExpeditingGoodsById" parameterType="Long">
        delete from mall_expediting_goods where id = #{id}
    </delete>

    <delete id="deleteMallExpeditingGoodsByIds" parameterType="String">
        delete from mall_expediting_goods where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>