OrderDetailMapper.xml 6.57 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.soss.system.mapper.OrderDetailMapper">
    
    <resultMap type="OrderDetail" id="OrderDetailResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="machineId"    column="machine_id"    />
        <result property="num"    column="num"    />
        <result property="amount"    column="amount"    />
        <result property="realAmount"    column="real_amount"    />
        <result property="specRuleDetail"    column="spec_rule_detail"    />
        <result property="specRuleIds"    column="spec_rule_ids"    />
        <result property="skuId"    column="sku_id"    />
        <result property="goodsCategory"    column="goods_category"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectOrderDetailVo">
        select id, order_id, goods_id, goods_name, machine_id, num, amount, real_amount, spec_rule_detail, spec_rule_ids, sku_id, goods_category, created_at, updated_at from order_detail
    </sql>

    <select id="selectOrderDetailList" parameterType="OrderDetail" resultMap="OrderDetailResult">
        <include refid="selectOrderDetailVo"/>
        <where>  
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="goodsId != null  and goodsId != ''"> and goods_id = #{goodsId}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="machineId != null  and machineId != ''"> and machine_id = #{machineId}</if>
            <if test="num != null  and num != ''"> and num = #{num}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="realAmount != null "> and real_amount = #{realAmount}</if>
            <if test="specRuleDetail != null  and specRuleDetail != ''"> and spec_rule_detail = #{specRuleDetail}</if>
            <if test="specRuleIds != null  and specRuleIds != ''"> and spec_rule_ids = #{specRuleIds}</if>
            <if test="skuId != null  and skuId != ''"> and sku_id = #{skuId}</if>
            <if test="goodsCategory != null  and goodsCategory != ''"> and goods_category = #{goodsCategory}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectOrderDetailById" parameterType="String" resultMap="OrderDetailResult">
        <include refid="selectOrderDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertOrderDetail" parameterType="OrderDetail" useGeneratedKeys="true" keyProperty="id">
        insert into order_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null and orderId != ''">order_id,</if>
            <if test="goodsId != null and goodsId != ''">goods_id,</if>
            <if test="goodsName != null and goodsName != ''">goods_name,</if>
            <if test="machineId != null and machineId != ''">machine_id,</if>
            <if test="num != null and num != ''">num,</if>
            <if test="amount != null">amount,</if>
            <if test="realAmount != null">real_amount,</if>
            <if test="specRuleDetail != null and specRuleDetail != ''">spec_rule_detail,</if>
            <if test="specRuleIds != null and specRuleIds != ''">spec_rule_ids,</if>
            <if test="skuId != null and skuId != ''">sku_id,</if>
            <if test="goodsCategory != null">goods_category,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null and orderId != ''">#{orderId},</if>
            <if test="goodsId != null and goodsId != ''">#{goodsId},</if>
            <if test="goodsName != null and goodsName != ''">#{goodsName},</if>
            <if test="machineId != null and machineId != ''">#{machineId},</if>
            <if test="num != null and num != ''">#{num},</if>
            <if test="amount != null">#{amount},</if>
            <if test="realAmount != null">#{realAmount},</if>
            <if test="specRuleDetail != null and specRuleDetail != ''">#{specRuleDetail},</if>
            <if test="specRuleIds != null and specRuleIds != ''">#{specRuleIds},</if>
            <if test="skuId != null and skuId != ''">#{skuId},</if>
            <if test="goodsCategory != null">#{goodsCategory},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateOrderDetail" parameterType="OrderDetail">
        update order_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
            <if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
            <if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
            <if test="machineId != null and machineId != ''">machine_id = #{machineId},</if>
            <if test="num != null and num != ''">num = #{num},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="realAmount != null">real_amount = #{realAmount},</if>
            <if test="specRuleDetail != null and specRuleDetail != ''">spec_rule_detail = #{specRuleDetail},</if>
            <if test="specRuleIds != null and specRuleIds != ''">spec_rule_ids = #{specRuleIds},</if>
            <if test="skuId != null and skuId != ''">sku_id = #{skuId},</if>
            <if test="goodsCategory != null">goods_category = #{goodsCategory},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderDetailById" parameterType="String">
        delete from order_detail where id = #{id}
    </delete>

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