<?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.reptileclient.jlifeapp.dao.jz.OrderMapper">
    <resultMap id="BaseResultMap" type="com.reptileclient.jlifeapp.entity.jz.Order">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="user_id" property="userId" jdbcType="INTEGER"/>
        <result column="order_sn" property="orderSn" jdbcType="VARCHAR"/>
        <result column="order_status" property="orderStatus" jdbcType="SMALLINT"/>
        <result column="order_channel" property="orderChannel" jdbcType="INTEGER"/>
        <result column="order_shop_id" property="orderShopId" jdbcType="INTEGER"/>
        <result column="order_date" property="orderDate" jdbcType="VARCHAR"/>
        <result column="aftersale_status" property="aftersaleStatus" jdbcType="SMALLINT"/>
        <result column="consignee" property="consignee" jdbcType="VARCHAR"/>
        <result column="mobile" property="mobile" jdbcType="VARCHAR"/>
        <result column="address" property="address" jdbcType="VARCHAR"/>
        <result column="address_id" property="addressId" jdbcType="INTEGER"/>
        <result column="message" property="message" jdbcType="VARCHAR"/>
        <result column="goods_price" property="goodsPrice" jdbcType="DECIMAL"/>
        <result column="freight_price" property="freightPrice" jdbcType="DECIMAL"/>
        <result column="coupon_price" property="couponPrice" jdbcType="DECIMAL"/>
        <result column="integral_price" property="integralPrice" jdbcType="DECIMAL"/>
        <result column="groupon_price" property="grouponPrice" jdbcType="DECIMAL"/>
        <result column="order_price" property="orderPrice" jdbcType="DECIMAL"/>
        <result column="actual_price" property="actualPrice" jdbcType="DECIMAL"/>
        <result column="pay_id" property="payId" jdbcType="VARCHAR"/>
        <result column="pay_time" property="payTime" jdbcType="TIMESTAMP"/>
        <result column="ship_sn" property="shipSn" jdbcType="VARCHAR"/>
        <result column="ship_channel" property="shipChannel" jdbcType="VARCHAR"/>
        <result column="ship_time" property="shipTime" jdbcType="TIMESTAMP"/>
        <result column="refund_amount" property="refundAmount" jdbcType="DECIMAL"/>
        <result column="refund_type" property="refundType" jdbcType="VARCHAR"/>
        <result column="refund_content" property="refundContent" jdbcType="VARCHAR"/>
        <result column="refund_time" property="refundTime" jdbcType="TIMESTAMP"/>
        <result column="confirm_time" property="confirmTime" jdbcType="TIMESTAMP"/>
        <result column="comments" property="comments" jdbcType="SMALLINT"/>
        <result column="end_time" property="endTime" jdbcType="TIMESTAMP"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="import_time" property="importTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="BIT"/>
        <result column="comment_time" property="commentTime" jdbcType="TIMESTAMP"/>
        <result column="order_service_status" property="orderServiceStatus" jdbcType="SMALLINT"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
        , user_id, order_sn, order_status, order_channel, order_shop_id, order_date, aftersale_status,
    consignee, mobile, address, address_id, message, goods_price, freight_price, coupon_price, 
    integral_price, groupon_price, order_price, actual_price, pay_id, pay_time, ship_sn, 
    ship_channel, ship_time, refund_amount, refund_type, refund_content, refund_time, 
    confirm_time, comments, end_time, create_time, update_time, import_time, deleted, 
    comment_time, order_service_status
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from jz_order
        where id = #{id,jdbcType=INTEGER}
    </select>
    <select id="selectNewOne" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from jz_order
        where order_channel=4
        <if test="shopId != null and shopId !=0">
        and order_shop_id = #{shopId}
       </if>
        order by create_time desc limit 1
    </select>
    <select id="selectByServiceConatctNo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from jz_order
        where 1=1
        <if test="serviceContractNo != null and serviceContractNo !=''">
            and service_contract_no = #{serviceContractNo}
        </if>
        order by create_time desc limit 1
    </select>
    <select id="selectByOrderSn" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from jz_order
        where order_sn = #{orderSn}
        order by id desc limit 1
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from jz_order
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByCreateTime">
        delete
        from jz_order
        where create_time >= #{date} and order_channel=4
    </delete>
    <insert id="insert" parameterType="com.reptileclient.jlifeapp.entity.jz.Order">
        insert into jz_order (id, user_id, order_sn,
                              order_status, order_channel, order_shop_id,
                              order_date,
                              aftersale_status, consignee, mobile,
                              address, address_id, message,
                              goods_price, freight_price, coupon_price,
                              integral_price, groupon_price, order_price,
                              actual_price, pay_id, pay_time,
                              ship_sn, ship_channel, ship_time,
                              refund_amount, refund_type, refund_content,
                              refund_time, confirm_time, comments,
                              end_time, create_time, update_time,
                              import_time, deleted, comment_time,
                              order_service_status,service_contract_no)
        values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{orderSn,jdbcType=VARCHAR},
                #{orderStatus,jdbcType=SMALLINT}, #{orderChannel,jdbcType=INTEGER}, #{orderShopId,jdbcType=INTEGER},
                #{orderDate,jdbcType=VARCHAR},
                #{aftersaleStatus,jdbcType=SMALLINT}, #{consignee,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR},
                #{address,jdbcType=VARCHAR}, #{addressId,jdbcType=INTEGER}, #{message,jdbcType=VARCHAR},
                #{goodsPrice,jdbcType=DECIMAL}, #{freightPrice,jdbcType=DECIMAL}, #{couponPrice,jdbcType=DECIMAL},
                #{integralPrice,jdbcType=DECIMAL}, #{grouponPrice,jdbcType=DECIMAL}, #{orderPrice,jdbcType=DECIMAL},
                #{actualPrice,jdbcType=DECIMAL}, #{payId,jdbcType=VARCHAR}, #{payTime,jdbcType=TIMESTAMP},
                #{shipSn,jdbcType=VARCHAR}, #{shipChannel,jdbcType=VARCHAR}, #{shipTime,jdbcType=TIMESTAMP},
                #{refundAmount,jdbcType=DECIMAL}, #{refundType,jdbcType=VARCHAR}, #{refundContent,jdbcType=VARCHAR},
                #{refundTime,jdbcType=TIMESTAMP}, #{confirmTime,jdbcType=TIMESTAMP}, #{comments,jdbcType=SMALLINT},
                #{endTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
                #{importTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{commentTime,jdbcType=TIMESTAMP},
                #{orderServiceStatus,jdbcType=SMALLINT}),
                #{service_contract_no,jdbcType=VARCHAR}
    </insert>
    <insert id="insertByBatch">
        insert into jz_order (addr_detail, addr_name,
        agreement_no, arrived_flag, begin_time,
        book_order_no, book_trade_no, cancel_flag,
        cancel_type_desc, confirm_flag, deliver_time,
        duration, end_time, finish_flag,
        hm_order_no, item_id, item_name,
        oper_name, modify_flag, payment_no,
        position, remark, servant_id,
        servant_name, servant_phone, servant_remark,
        service_contract_no, service_type, shop_code,
        start_time, station_code, station_name,
        status, use_code, use_remark,
        user_name, user_phone)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.addrDetail,jdbcType=VARCHAR}, #{item.addrName,jdbcType=VARCHAR},
            #{item.agreementNo,jdbcType=VARCHAR}, #{item.arrivedFlag,jdbcType=BIT}, #{item.beginTime,jdbcType=VARCHAR},
            #{item.bookOrderNo,jdbcType=INTEGER}, #{item.bookTradeNo,jdbcType=INTEGER}, #{item.cancelFlag,jdbcType=BIT},
            #{item.cancelTypeDesc,jdbcType=VARCHAR}, #{item.confirmFlag,jdbcType=BIT},
            #{item.deliverTime,jdbcType=TIMESTAMP},
            #{item.duration,jdbcType=INTEGER}, #{item.endTime,jdbcType=VARCHAR}, #{item.finishFlag,jdbcType=BIT},
            #{item.hmOrderNo,jdbcType=VARCHAR}, #{item.itemId,jdbcType=BIGINT}, #{item.itemName,jdbcType=VARCHAR},
            #{item.operName,jdbcType=VARCHAR}, #{item.modifyFlag,jdbcType=BIT}, #{item.paymentNo,jdbcType=VARCHAR},
            #{item.position,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR}, #{item.servantId,jdbcType=INTEGER},
            #{item.servantName,jdbcType=VARCHAR}, #{item.servantPhone,jdbcType=VARCHAR},
            #{item.servantRemark,jdbcType=VARCHAR},
            #{item.serviceContractNo,jdbcType=BIGINT}, #{item.serviceType,jdbcType=INTEGER},
            #{item.shopCode,jdbcType=VARCHAR},
            #{item.startTime,jdbcType=VARCHAR}, #{item.stationCode,jdbcType=VARCHAR},
            #{item.stationName,jdbcType=VARCHAR},
            #{item.status,jdbcType=INTEGER}, #{item.useCode,jdbcType=VARCHAR}, #{item.useRemark,jdbcType=VARCHAR},
            #{item.userName,jdbcType=VARCHAR}, #{item.userPhone,jdbcType=VARCHAR})
        </foreach>
    </insert>
    <insert id="insertSelective" parameterType="com.reptileclient.jlifeapp.entity.jz.Order" useGeneratedKeys="true"
            keyProperty="id">
        insert into jz_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="userId != null">
                user_id,
            </if>
            <if test="orderSn != null">
                order_sn,
            </if>
            <if test="orderStatus != null">
                order_status,
            </if>
            <if test="orderChannel != null">
                order_channel,
            </if>
            <if test="orderShopId != null">
                order_shop_id,
            </if>
            <if test="orderDate != null">
                order_date,
            </if>
            <if test="aftersaleStatus != null">
                aftersale_status,
            </if>
            <if test="consignee != null">
                consignee,
            </if>
            <if test="mobile != null">
                mobile,
            </if>
            <if test="address != null">
                address,
            </if>
            <if test="addressId != null">
                address_id,
            </if>
            <if test="message != null">
                message,
            </if>
            <if test="goodsPrice != null">
                goods_price,
            </if>
            <if test="freightPrice != null">
                freight_price,
            </if>
            <if test="couponPrice != null">
                coupon_price,
            </if>
            <if test="integralPrice != null">
                integral_price,
            </if>
            <if test="grouponPrice != null">
                groupon_price,
            </if>
            <if test="orderPrice != null">
                order_price,
            </if>
            <if test="actualPrice != null">
                actual_price,
            </if>
            <if test="payId != null">
                pay_id,
            </if>
            <if test="payTime != null">
                pay_time,
            </if>
            <if test="shipSn != null">
                ship_sn,
            </if>
            <if test="shipChannel != null">
                ship_channel,
            </if>
            <if test="shipTime != null">
                ship_time,
            </if>
            <if test="refundAmount != null">
                refund_amount,
            </if>
            <if test="refundType != null">
                refund_type,
            </if>
            <if test="refundContent != null">
                refund_content,
            </if>
            <if test="refundTime != null">
                refund_time,
            </if>
            <if test="confirmTime != null">
                confirm_time,
            </if>
            <if test="comments != null">
                comments,
            </if>
            <if test="endTime != null">
                end_time,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="importTime != null">
                import_time,
            </if>
            <if test="deleted != null">
                deleted,
            </if>
            <if test="commentTime != null">
                comment_time,
            </if>
            <if test="orderServiceStatus != null">
                order_service_status,
            </if>
             <if test="serviceContractNo != null">
                service_contract_no,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="userId != null">
                #{userId,jdbcType=INTEGER},
            </if>
            <if test="orderSn != null">
                #{orderSn,jdbcType=VARCHAR},
            </if>
            <if test="orderStatus != null">
                #{orderStatus,jdbcType=SMALLINT},
            </if>
            <if test="orderChannel != null">
                #{orderChannel,jdbcType=INTEGER},
            </if>
            <if test="orderShopId != null">
                #{orderShopId,jdbcType=INTEGER},
            </if>
            <if test="orderDate != null">
                #{orderDate,jdbcType=VARCHAR},
            </if>
            <if test="aftersaleStatus != null">
                #{aftersaleStatus,jdbcType=SMALLINT},
            </if>
            <if test="consignee != null">
                #{consignee,jdbcType=VARCHAR},
            </if>
            <if test="mobile != null">
                #{mobile,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                #{address,jdbcType=VARCHAR},
            </if>
            <if test="addressId != null">
                #{addressId,jdbcType=INTEGER},
            </if>
            <if test="message != null">
                #{message,jdbcType=VARCHAR},
            </if>
            <if test="goodsPrice != null">
                #{goodsPrice,jdbcType=DECIMAL},
            </if>
            <if test="freightPrice != null">
                #{freightPrice,jdbcType=DECIMAL},
            </if>
            <if test="couponPrice != null">
                #{couponPrice,jdbcType=DECIMAL},
            </if>
            <if test="integralPrice != null">
                #{integralPrice,jdbcType=DECIMAL},
            </if>
            <if test="grouponPrice != null">
                #{grouponPrice,jdbcType=DECIMAL},
            </if>
            <if test="orderPrice != null">
                #{orderPrice,jdbcType=DECIMAL},
            </if>
            <if test="actualPrice != null">
                #{actualPrice,jdbcType=DECIMAL},
            </if>
            <if test="payId != null">
                #{payId,jdbcType=VARCHAR},
            </if>
            <if test="payTime != null">
                #{payTime,jdbcType=TIMESTAMP},
            </if>
            <if test="shipSn != null">
                #{shipSn,jdbcType=VARCHAR},
            </if>
            <if test="shipChannel != null">
                #{shipChannel,jdbcType=VARCHAR},
            </if>
            <if test="shipTime != null">
                #{shipTime,jdbcType=TIMESTAMP},
            </if>
            <if test="refundAmount != null">
                #{refundAmount,jdbcType=DECIMAL},
            </if>
            <if test="refundType != null">
                #{refundType,jdbcType=VARCHAR},
            </if>
            <if test="refundContent != null">
                #{refundContent,jdbcType=VARCHAR},
            </if>
            <if test="refundTime != null">
                #{refundTime,jdbcType=TIMESTAMP},
            </if>
            <if test="confirmTime != null">
                #{confirmTime,jdbcType=TIMESTAMP},
            </if>
            <if test="comments != null">
                #{comments,jdbcType=SMALLINT},
            </if>
            <if test="endTime != null">
                #{endTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="importTime != null">
                #{importTime,jdbcType=TIMESTAMP},
            </if>
            <if test="deleted != null">
                #{deleted,jdbcType=BIT},
            </if>
            <if test="commentTime != null">
                #{commentTime,jdbcType=TIMESTAMP},
            </if>
            <if test="orderServiceStatus != null">
                #{orderServiceStatus,jdbcType=SMALLINT},
            </if>
             <if test="serviceContractNo != null">
               #{serviceContractNo,jdbcType=VARCHAR}
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.reptileclient.jlifeapp.entity.jz.Order">
        update jz_order
        <set>
            <if test="userId != null">
                user_id = #{userId,jdbcType=INTEGER},
            </if>
            <if test="orderSn != null">
                order_sn = #{orderSn,jdbcType=VARCHAR},
            </if>
            <if test="orderStatus != null">
                order_status = #{orderStatus,jdbcType=SMALLINT},
            </if>
            <if test="orderChannel != null">
                order_channel = #{orderChannel,jdbcType=INTEGER},
            </if>
            <if test="orderShopId != null">
                order_shop_id = #{orderShopId,jdbcType=INTEGER},
            </if>
            <if test="orderDate != null">
                order_date = #{orderDate,jdbcType=VARCHAR},
            </if>
            <if test="aftersaleStatus != null">
                aftersale_status = #{aftersaleStatus,jdbcType=SMALLINT},
            </if>
            <if test="consignee != null">
                consignee = #{consignee,jdbcType=VARCHAR},
            </if>
            <if test="mobile != null">
                mobile = #{mobile,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                address = #{address,jdbcType=VARCHAR},
            </if>
            <if test="addressId != null">
                address_id = #{addressId,jdbcType=INTEGER},
            </if>
            <if test="message != null">
                message = #{message,jdbcType=VARCHAR},
            </if>
            <if test="goodsPrice != null">
                goods_price = #{goodsPrice,jdbcType=DECIMAL},
            </if>
            <if test="freightPrice != null">
                freight_price = #{freightPrice,jdbcType=DECIMAL},
            </if>
            <if test="couponPrice != null">
                coupon_price = #{couponPrice,jdbcType=DECIMAL},
            </if>
            <if test="integralPrice != null">
                integral_price = #{integralPrice,jdbcType=DECIMAL},
            </if>
            <if test="grouponPrice != null">
                groupon_price = #{grouponPrice,jdbcType=DECIMAL},
            </if>
            <if test="orderPrice != null">
                order_price = #{orderPrice,jdbcType=DECIMAL},
            </if>
            <if test="actualPrice != null">
                actual_price = #{actualPrice,jdbcType=DECIMAL},
            </if>
            <if test="payId != null">
                pay_id = #{payId,jdbcType=VARCHAR},
            </if>
            <if test="payTime != null">
                pay_time = #{payTime,jdbcType=TIMESTAMP},
            </if>
            <if test="shipSn != null">
                ship_sn = #{shipSn,jdbcType=VARCHAR},
            </if>
            <if test="shipChannel != null">
                ship_channel = #{shipChannel,jdbcType=VARCHAR},
            </if>
            <if test="shipTime != null">
                ship_time = #{shipTime,jdbcType=TIMESTAMP},
            </if>
            <if test="refundAmount != null">
                refund_amount = #{refundAmount,jdbcType=DECIMAL},
            </if>
            <if test="refundType != null">
                refund_type = #{refundType,jdbcType=VARCHAR},
            </if>
            <if test="refundContent != null">
                refund_content = #{refundContent,jdbcType=VARCHAR},
            </if>
            <if test="refundTime != null">
                refund_time = #{refundTime,jdbcType=TIMESTAMP},
            </if>
            <if test="confirmTime != null">
                confirm_time = #{confirmTime,jdbcType=TIMESTAMP},
            </if>
            <if test="comments != null">
                comments = #{comments,jdbcType=SMALLINT},
            </if>
            <if test="endTime != null">
                end_time = #{endTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="importTime != null">
                import_time = #{importTime,jdbcType=TIMESTAMP},
            </if>
            <if test="deleted != null">
                deleted = #{deleted,jdbcType=BIT},
            </if>
            <if test="commentTime != null">
                comment_time = #{commentTime,jdbcType=TIMESTAMP},
            </if>
            <if test="orderServiceStatus != null">
                order_service_status = #{orderServiceStatus,jdbcType=SMALLINT},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.reptileclient.jlifeapp.entity.jz.Order">
        update jz_order
        set user_id              = #{userId,jdbcType=INTEGER},
            order_sn             = #{orderSn,jdbcType=VARCHAR},
            order_status         = #{orderStatus,jdbcType=SMALLINT},
            order_channel        = #{orderChannel,jdbcType=INTEGER},
            order_shop_id        = #{orderShopId,jdbcType=INTEGER},
            order_date           = #{orderDate,jdbcType=VARCHAR},
            aftersale_status     = #{aftersaleStatus,jdbcType=SMALLINT},
            consignee            = #{consignee,jdbcType=VARCHAR},
            mobile               = #{mobile,jdbcType=VARCHAR},
            address              = #{address,jdbcType=VARCHAR},
            address_id           = #{addressId,jdbcType=INTEGER},
            message              = #{message,jdbcType=VARCHAR},
            goods_price          = #{goodsPrice,jdbcType=DECIMAL},
            freight_price        = #{freightPrice,jdbcType=DECIMAL},
            coupon_price         = #{couponPrice,jdbcType=DECIMAL},
            integral_price       = #{integralPrice,jdbcType=DECIMAL},
            groupon_price        = #{grouponPrice,jdbcType=DECIMAL},
            order_price          = #{orderPrice,jdbcType=DECIMAL},
            actual_price         = #{actualPrice,jdbcType=DECIMAL},
            pay_id               = #{payId,jdbcType=VARCHAR},
            pay_time             = #{payTime,jdbcType=TIMESTAMP},
            ship_sn              = #{shipSn,jdbcType=VARCHAR},
            ship_channel         = #{shipChannel,jdbcType=VARCHAR},
            ship_time            = #{shipTime,jdbcType=TIMESTAMP},
            refund_amount        = #{refundAmount,jdbcType=DECIMAL},
            refund_type          = #{refundType,jdbcType=VARCHAR},
            refund_content       = #{refundContent,jdbcType=VARCHAR},
            refund_time          = #{refundTime,jdbcType=TIMESTAMP},
            confirm_time         = #{confirmTime,jdbcType=TIMESTAMP},
            comments             = #{comments,jdbcType=SMALLINT},
            end_time             = #{endTime,jdbcType=TIMESTAMP},
            create_time          = #{createTime,jdbcType=TIMESTAMP},
            update_time          = #{updateTime,jdbcType=TIMESTAMP},
            import_time          = #{importTime,jdbcType=TIMESTAMP},
            deleted              = #{deleted,jdbcType=BIT},
            comment_time         = #{commentTime,jdbcType=TIMESTAMP},
            order_service_status = #{orderServiceStatus,jdbcType=SMALLINT}
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateStatusByPrimaryKey" parameterType="com.reptileclient.jlifeapp.entity.jz.Order">
        update jz_order
        set order_status = #{orderStatus,jdbcType=SMALLINT}
        and
        update_time = #{updateTime,jdbcType=TIMESTAMP} 
        where id = #{id,jdbcType=INTEGER}
    </update>
</mapper>