<?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.iocoder.mall.order.biz.dao.order.OrderLogisticsMapper">

    <sql id="FIELDS">
        id, area_no, `name`, mobile, address, logistics, logistics_no, create_time, update_time
    </sql>

    <!--
        插入数据
    -->
    <insert id="insert" parameterType="OrderLogisticsDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO `order_logistics` (
            area_no, `name`, mobile, address, logistics, logistics_no, create_time, update_time
        ) VALUES (
             #{areaNo}, #{name}, #{mobile}, #{address},
             #{logistics}, #{logisticsNo}, #{createTime}, #{updateTime}
        )
    </insert>

    <!--
        可更新字段
    -->
    <sql id="updateFieldSql" >
        <set>
            <if test="areaNo != null">
                , area_no = #{areaNo}
            </if>
            <if test="name != null">
                , `name` = #{name}
            </if>
            <if test="mobile != null">
                , mobile = #{mobile}
            </if>
            <if test="address != null">
                , address = #{address}
            </if>
            <if test="logistics != null">
                , logistics = #{logistics}
            </if>
            <if test="logisticsNo != null">
                , logistics_no = #{logisticsNo}
            </if>
        </set>
    </sql>

    <!--
        更新 - 根据id
    -->
    <update id="updateById">
        UPDATE `order_logistics`
        <include refid="updateFieldSql" />
        WHERE id = #{id}
    </update>

    <!--
        查询 - 根据 ids
    -->
    <select id="selectByIds" resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDO">
        SELECT
        <include refid="FIELDS" />
        FROM `order_logistics`
        WHERE `id`
        IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>

    <!--
        查询 - 根据 ids
    -->
    <select id="selectById" resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDO">
        SELECT
        <include refid="FIELDS" />
        FROM `order_logistics`
        WHERE `id` = #{id}
        LIMIT 1
    </select>
</mapper>
