<?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.younike.system.mapper.OrderGoodsMapper">

    <resultMap type="OrderGoods" id="OrderGoodsResult">
        <result property="orderId"    column="order_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="cateId"    column="cate_id"    />
        <result property="serverId"    column="server_id"    />
        <result property="goodsCounts"    column="goods_counts"    />
        <result property="addCounts"    column="add_counts"    />
        <result property="price"    column="price"    />
        <result property="singleTime"    column="single_time"    />
        <result property="coin"    column="coin"    />
        <result property="name"    column="name"    />
        <result property="goodsUnit"    column="goods_unit"    />
        <result property="otherUnit"    column="other_unit"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="loginIp"    column="login_ip"    />
        <result property="loginDate"    column="login_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <result property="publishId"    column="publish_id"    />
        <result property="goodsSpecificationId"    column="goods_specification_id"    />
    </resultMap>

    <sql id="selectOrderGoodsVo">
        select order_id, goods_id, cate_id, server_id, goods_counts, add_counts, price, single_time, coin, name, goods_unit,other_unit, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, column1, column2, column3, publish_id, goods_specification_id from order_goods
    </sql>

    <select id="selectOrderGoodsList" parameterType="OrderGoods" resultMap="OrderGoodsResult">
        <include refid="selectOrderGoodsVo"/>
        <where>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="serverId != null "> and server_id = #{serverId}</if>
            <if test="goodsCounts != null "> and goods_counts = #{goodsCounts}</if>
            <if test="addCounts != null  and addCounts != ''"> and add_counts = #{addCounts}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="singleTime != null "> and single_time = #{singleTime}</if>
            <if test="coin != null "> and coin = #{coin}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="goodsUnit != null  and goodsUnit != ''"> and goods_unit = #{goodsUnit}</if>
            <if test="otherUnit != null  and otherUnit != ''"> and other_unit = #{otherUnit}</if>
            <if test="loginIp != null  and loginIp != ''"> and login_ip = #{loginIp}</if>
            <if test="loginDate != null "> and login_date = #{loginDate}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
            <if test="publishId != null "> and publish_id = #{publishId}</if>
        </where>
    </select>

    <select id="selectOrderGoodsByOrderId" parameterType="Long" resultMap="OrderGoodsResult">
        <include refid="selectOrderGoodsVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertOrderGoods" parameterType="OrderGoods">
        insert into order_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="serverId != null">server_id,</if>
            <if test="goodsCounts != null">goods_counts,</if>
            <if test="addCounts != null">add_counts,</if>
            <if test="price != null">price,</if>
            <if test="singleTime != null">single_time,</if>
            <if test="coin != null">coin,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="goodsUnit != null">goods_unit,</if>
            <if test="otherUnit != null">other_unit,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="loginIp != null">login_ip,</if>
            <if test="loginDate != null">login_date,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
            <if test="publishId != null">publish_id,</if>
            <if test="goodsSpecificationId != null">goods_specification_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="serverId != null">#{serverId},</if>
            <if test="goodsCounts != null">#{goodsCounts},</if>
            <if test="addCounts != null">#{addCounts},</if>
            <if test="price != null">#{price},</if>
            <if test="singleTime != null">#{singleTime},</if>
            <if test="coin != null">#{coin},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="goodsUnit != null">#{goodsUnit},</if>
            <if test="otherUnit != null">#{otherUnit},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="loginIp != null">#{loginIp},</if>
            <if test="loginDate != null">#{loginDate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
            <if test="publishId != null">#{publishId},</if>
            <if test="goodsSpecificationId != null">#{goodsSpecificationId},</if>
         </trim>
    </insert>

    <update id="updateOrderGoods" parameterType="OrderGoods">
        update order_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="serverId != null">server_id = #{serverId},</if>
            <if test="goodsCounts != null">goods_counts = #{goodsCounts},</if>
            <if test="addCounts != null">add_counts = #{addCounts},</if>
            <if test="price != null">price = #{price},</if>
            <if test="singleTime != null">single_time = #{singleTime},</if>
            <if test="coin != null">coin = #{coin},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="goodsUnit != null">goods_unit = #{goodsUnit},</if>
            <if test="otherUnit != null">other_unit = #{otherUnit},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="loginIp != null">login_ip = #{loginIp},</if>
            <if test="loginDate != null">login_date = #{loginDate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
            <if test="publishId != null">publish_id = #{publishId},</if>
            <if test="goodsSpecificationId != null">goods_specification_id = #{goodsSpecificationId},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteOrderGoodsByOrderId" parameterType="Long">
        delete from order_goods where order_id = #{orderId}
    </delete>

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