<?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.hm.HmBookTradeOrderMapper">
    <resultMap id="BaseResultMap" type="com.reptileclient.jlifeapp.entity.hm.HmBookTradeOrder">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="addr_detail" property="addrDetail" jdbcType="VARCHAR"/>
        <result column="addr_name" property="addrName" jdbcType="VARCHAR"/>
        <result column="agreement_no" property="agreementNo" jdbcType="VARCHAR"/>
        <result column="arrived_flag" property="arrivedFlag" jdbcType="BIT"/>
        <result column="begin_time" property="beginTime" jdbcType="VARCHAR"/>
        <result column="book_order_no" property="bookOrderNo" jdbcType="INTEGER"/>
        <result column="book_trade_no" property="bookTradeNo" jdbcType="INTEGER"/>
        <result column="cancel_flag" property="cancelFlag" jdbcType="BIT"/>
        <result column="cancel_type_desc" property="cancelTypeDesc" jdbcType="VARCHAR"/>
        <result column="confirm_flag" property="confirmFlag" jdbcType="BIT"/>
        <result column="deliver_time" property="deliverTime" jdbcType="TIMESTAMP"/>
        <result column="duration" property="duration" jdbcType="INTEGER"/>
        <result column="end_time" property="endTime" jdbcType="VARCHAR"/>
        <result column="finish_flag" property="finishFlag" jdbcType="BIT"/>
        <result column="hm_order_no" property="hmOrderNo" jdbcType="VARCHAR"/>
        <result column="item_id" property="itemId" jdbcType="BIGINT"/>
        <result column="item_name" property="itemName" jdbcType="VARCHAR"/>
        <result column="oper_name" property="operName" jdbcType="VARCHAR"/>
        <result column="modify_flag" property="modifyFlag" jdbcType="BIT"/>
        <result column="payment_no" property="paymentNo" jdbcType="VARCHAR"/>
        <result column="position" property="position" jdbcType="VARCHAR"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
        <result column="servant_id" property="servantId" jdbcType="INTEGER"/>
        <result column="servant_name" property="servantName" jdbcType="VARCHAR"/>
        <result column="servant_phone" property="servantPhone" jdbcType="VARCHAR"/>
        <result column="servant_remark" property="servantRemark" jdbcType="VARCHAR"/>
        <result column="service_contract_no" property="serviceContractNo" jdbcType="BIGINT"/>
        <result column="service_type" property="serviceType" jdbcType="INTEGER"/>
        <result column="shop_code" property="shopCode" jdbcType="VARCHAR"/>
        <result column="start_time" property="startTime" jdbcType="VARCHAR"/>
        <result column="station_code" property="stationCode" jdbcType="VARCHAR"/>
        <result column="station_name" property="stationName" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="use_code" property="useCode" jdbcType="VARCHAR"/>
        <result column="use_remark" property="useRemark" jdbcType="VARCHAR"/>
        <result column="user_name" property="userName" jdbcType="VARCHAR"/>
        <result column="user_phone" property="userPhone" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
                ,
        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,
        create_time,
        update_time
    </sql>
    <select id="selectEncrypt" resultMap="BaseResultMap">
        select id,user_phone,book_trade_no  from hm_book_trade_order where user_phone like '%**%'
    </select>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from hm_book_trade_order
        where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByBookTradeNo" resultMap="BaseResultMap" parameterType="Integer">
        select
        <include refid="Base_Column_List"/>
        from hm_book_trade_order
        where book_trade_no = #{bookTradeNo,jdbcType=BIGINT}
    </select>
    <select id="selectNewOne" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hm_book_trade_order
                where 1 = 1
        <if test="stationCode != null and stationCode != ''">
            and station_code = #{stationCode}
        </if>
        order by start_time desc
        limit 1
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from hm_book_trade_order
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <delete id="deleteByStartTime">
        delete
        from hm_book_trade_order
        where start_time >= #{date}
    </delete>
    <delete id="deleteByUserPhone">
        delete
        from hm_book_trade_order
        where user_phone = #{userPhone}
    </delete>

    <delete id="deleteByServantPhone">
        delete
        from hm_book_trade_order
        where servant_phone = #{servantPhone} and substring(begin_time,1,10)=DATE_FORMAT(now(), '%Y-%m-%d')
    </delete>
    <delete id="deleteDistinctData">
        delete from `hm_book_trade_order` where id in (
            select id from (
                select id,row_number() over(partition by book_trade_no order by id  desc) cnt from `hm_book_trade_order`
                  where 1=1
                <if test="dateTime != null">
                    and start_time >= #{dateTime}
                </if>
              ) a where a.cnt>1
        )
    </delete>

<!--    <delete id="deleteDistinctData">-->
<!--        DELETE-->
<!--        FROM `hm_book_trade_order`-->
<!--                WHERE book_trade_no IN-->
<!--                      (SELECT book_trade_no-->
<!--                       FROM (SELECT book_trade_no-->
<!--                             FROM hm_book_trade_order-->
<!--                             GROUP BY book_trade_no-->
<!--                             HAVING COUNT(book_trade_no) > 1) a)-->
<!--                  AND id NOT IN-->
<!--                      (SELECT *-->
<!--                       FROM (SELECT MAX(id)-->
<!--                             FROM `hm_book_trade_order`-->
<!--                             GROUP BY book_trade_no-->
<!--                             HAVING COUNT(book_trade_no) > 1) b)-->
<!--        <if test="dateTime != null">-->
<!--            and start_time >= #{dateTime}-->
<!--        </if>-->
<!--    </delete>-->
    <delete id="deleteByBetWeenTime">
        delete from hm_book_trade_order where id  in (select * from (select min(id) from hm_book_trade_order group by book_trade_no having count(1) > 1)h);
    </delete>

    <insert id="insert" parameterType="com.reptileclient.jlifeapp.entity.hm.HmBookTradeOrder">
        insert into hm_book_trade_order (id, 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, create_time,
                                         update_time)
        values (#{id,jdbcType=BIGINT}, #{addrDetail,jdbcType=VARCHAR}, #{addrName,jdbcType=VARCHAR},
                #{agreementNo,jdbcType=VARCHAR}, #{arrivedFlag,jdbcType=BIT}, #{beginTime,jdbcType=VARCHAR},
                #{bookOrderNo,jdbcType=INTEGER}, #{bookTradeNo,jdbcType=INTEGER}, #{cancelFlag,jdbcType=BIT},
                #{cancelTypeDesc,jdbcType=VARCHAR}, #{confirmFlag,jdbcType=BIT}, #{deliverTime,jdbcType=TIMESTAMP},
                #{duration,jdbcType=INTEGER}, #{endTime,jdbcType=VARCHAR}, #{finishFlag,jdbcType=BIT},
                #{hmOrderNo,jdbcType=VARCHAR}, #{itemId,jdbcType=BIGINT}, #{itemName,jdbcType=VARCHAR},
                #{operName,jdbcType=VARCHAR}, #{modifyFlag,jdbcType=BIT}, #{paymentNo,jdbcType=VARCHAR},
                #{position,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{servantId,jdbcType=INTEGER},
                #{servantName,jdbcType=VARCHAR}, #{servantPhone,jdbcType=VARCHAR}, #{servantRemark,jdbcType=VARCHAR},
                #{serviceContractNo,jdbcType=BIGINT}, #{serviceType,jdbcType=INTEGER}, #{shopCode,jdbcType=VARCHAR},
                #{startTime,jdbcType=VARCHAR}, #{stationCode,jdbcType=VARCHAR}, #{stationName,jdbcType=VARCHAR},
                #{status,jdbcType=INTEGER}, #{useCode,jdbcType=VARCHAR}, #{useRemark,jdbcType=VARCHAR},
                #{userName,jdbcType=VARCHAR}, #{userPhone,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
                #{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.reptileclient.jlifeapp.entity.hm.HmBookTradeOrder">
        insert into hm_book_trade_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="addrDetail != null">
                addr_detail,
            </if>
            <if test="addrName != null">
                addr_name,
            </if>
            <if test="agreementNo != null">
                agreement_no,
            </if>
            <if test="arrivedFlag != null">
                arrived_flag,
            </if>
            <if test="beginTime != null">
                begin_time,
            </if>
            <if test="bookOrderNo != null">
                book_order_no,
            </if>
            <if test="bookTradeNo != null">
                book_trade_no,
            </if>
            <if test="cancelFlag != null">
                cancel_flag,
            </if>
            <if test="cancelTypeDesc != null">
                cancel_type_desc,
            </if>
            <if test="confirmFlag != null">
                confirm_flag,
            </if>
            <if test="deliverTime != null">
                deliver_time,
            </if>
            <if test="duration != null">
                duration,
            </if>
            <if test="endTime != null">
                end_time,
            </if>
            <if test="finishFlag != null">
                finish_flag,
            </if>
            <if test="hmOrderNo != null">
                hm_order_no,
            </if>
            <if test="itemId != null">
                item_id,
            </if>
            <if test="itemName != null">
                item_name,
            </if>
            <if test="operName != null">
                oper_name,
            </if>
            <if test="modifyFlag != null">
                modify_flag,
            </if>
            <if test="paymentNo != null">
                payment_no,
            </if>
            <if test="position != null">
                position,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="servantId != null">
                servant_id,
            </if>
            <if test="servantName != null">
                servant_name,
            </if>
            <if test="servantPhone != null">
                servant_phone,
            </if>
            <if test="servantRemark != null">
                servant_remark,
            </if>
            <if test="serviceContractNo != null">
                service_contract_no,
            </if>
            <if test="serviceType != null">
                service_type,
            </if>
            <if test="shopCode != null">
                shop_code,
            </if>
            <if test="startTime != null">
                start_time,
            </if>
            <if test="stationCode != null">
                station_code,
            </if>
            <if test="stationName != null">
                station_name,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="useCode != null">
                use_code,
            </if>
            <if test="useRemark != null">
                use_remark,
            </if>
            <if test="userName != null">
                user_name,
            </if>
            <if test="userPhone != null">
                user_phone,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="addrDetail != null">
                #{addrDetail,jdbcType=VARCHAR},
            </if>
            <if test="addrName != null">
                #{addrName,jdbcType=VARCHAR},
            </if>
            <if test="agreementNo != null">
                #{agreementNo,jdbcType=VARCHAR},
            </if>
            <if test="arrivedFlag != null">
                #{arrivedFlag,jdbcType=BIT},
            </if>
            <if test="beginTime != null">
                #{beginTime,jdbcType=VARCHAR},
            </if>
            <if test="bookOrderNo != null">
                #{bookOrderNo,jdbcType=INTEGER},
            </if>
            <if test="bookTradeNo != null">
                #{bookTradeNo,jdbcType=INTEGER},
            </if>
            <if test="cancelFlag != null">
                #{cancelFlag,jdbcType=BIT},
            </if>
            <if test="cancelTypeDesc != null">
                #{cancelTypeDesc,jdbcType=VARCHAR},
            </if>
            <if test="confirmFlag != null">
                #{confirmFlag,jdbcType=BIT},
            </if>
            <if test="deliverTime != null">
                #{deliverTime,jdbcType=TIMESTAMP},
            </if>
            <if test="duration != null">
                #{duration,jdbcType=INTEGER},
            </if>
            <if test="endTime != null">
                #{endTime,jdbcType=VARCHAR},
            </if>
            <if test="finishFlag != null">
                #{finishFlag,jdbcType=BIT},
            </if>
            <if test="hmOrderNo != null">
                #{hmOrderNo,jdbcType=VARCHAR},
            </if>
            <if test="itemId != null">
                #{itemId,jdbcType=BIGINT},
            </if>
            <if test="itemName != null">
                #{itemName,jdbcType=VARCHAR},
            </if>
            <if test="operName != null">
                #{operName,jdbcType=VARCHAR},
            </if>
            <if test="modifyFlag != null">
                #{modifyFlag,jdbcType=BIT},
            </if>
            <if test="paymentNo != null">
                #{paymentNo,jdbcType=VARCHAR},
            </if>
            <if test="position != null">
                #{position,jdbcType=VARCHAR},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="servantId != null">
                #{servantId,jdbcType=INTEGER},
            </if>
            <if test="servantName != null">
                #{servantName,jdbcType=VARCHAR},
            </if>
            <if test="servantPhone != null">
                #{servantPhone,jdbcType=VARCHAR},
            </if>
            <if test="servantRemark != null">
                #{servantRemark,jdbcType=VARCHAR},
            </if>
            <if test="serviceContractNo != null">
                #{serviceContractNo,jdbcType=BIGINT},
            </if>
            <if test="serviceType != null">
                #{serviceType,jdbcType=INTEGER},
            </if>
            <if test="shopCode != null">
                #{shopCode,jdbcType=VARCHAR},
            </if>
            <if test="startTime != null">
                #{startTime,jdbcType=VARCHAR},
            </if>
            <if test="stationCode != null">
                #{stationCode,jdbcType=VARCHAR},
            </if>
            <if test="stationName != null">
                #{stationName,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="useCode != null">
                #{useCode,jdbcType=VARCHAR},
            </if>
            <if test="useRemark != null">
                #{useRemark,jdbcType=VARCHAR},
            </if>
            <if test="userName != null">
                #{userName,jdbcType=VARCHAR},
            </if>
            <if test="userPhone != null">
                #{userPhone,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>
    <insert id="insertByBatch">
        insert into hm_book_trade_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="insertOrUpdateByBatch">
        insert into hm_book_trade_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>
        ON DUPLICATE KEY UPDATE
        `status` = VALUES(`status`),servantName = VALUES(servantName),servantPhone = VALUES(servantPhone)
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.reptileclient.jlifeapp.entity.hm.HmBookTradeOrder">
        update hm_book_trade_order
        <set>
            <if test="addrDetail != null">
                addr_detail = #{addrDetail,jdbcType=VARCHAR},
            </if>
            <if test="addrName != null">
                addr_name = #{addrName,jdbcType=VARCHAR},
            </if>
            <if test="agreementNo != null">
                agreement_no = #{agreementNo,jdbcType=VARCHAR},
            </if>
            <if test="arrivedFlag != null">
                arrived_flag = #{arrivedFlag,jdbcType=BIT},
            </if>
            <if test="beginTime != null">
                begin_time = #{beginTime,jdbcType=VARCHAR},
            </if>
            <if test="bookOrderNo != null">
                book_order_no = #{bookOrderNo,jdbcType=INTEGER},
            </if>
            <if test="bookTradeNo != null">
                book_trade_no = #{bookTradeNo,jdbcType=INTEGER},
            </if>
            <if test="cancelFlag != null">
                cancel_flag = #{cancelFlag,jdbcType=BIT},
            </if>
            <if test="cancelTypeDesc != null">
                cancel_type_desc = #{cancelTypeDesc,jdbcType=VARCHAR},
            </if>
            <if test="confirmFlag != null">
                confirm_flag = #{confirmFlag,jdbcType=BIT},
            </if>
            <if test="deliverTime != null">
                deliver_time = #{deliverTime,jdbcType=TIMESTAMP},
            </if>
            <if test="duration != null">
                duration = #{duration,jdbcType=INTEGER},
            </if>
            <if test="endTime != null">
                end_time = #{endTime,jdbcType=VARCHAR},
            </if>
            <if test="finishFlag != null">
                finish_flag = #{finishFlag,jdbcType=BIT},
            </if>
            <if test="hmOrderNo != null">
                hm_order_no = #{hmOrderNo,jdbcType=VARCHAR},
            </if>
            <if test="itemId != null">
                item_id = #{itemId,jdbcType=BIGINT},
            </if>
            <if test="itemName != null">
                item_name = #{itemName,jdbcType=VARCHAR},
            </if>
            <if test="operName != null">
                oper_name = #{operName,jdbcType=VARCHAR},
            </if>
            <if test="modifyFlag != null">
                modify_flag = #{modifyFlag,jdbcType=BIT},
            </if>
            <if test="paymentNo != null">
                payment_no = #{paymentNo,jdbcType=VARCHAR},
            </if>
            <if test="position != null">
                position = #{position,jdbcType=VARCHAR},
            </if>
            <if test="remark != null">
                remark = #{remark,jdbcType=VARCHAR},
            </if>
            <if test="servantId != null">
                servant_id = #{servantId,jdbcType=INTEGER},
            </if>
            <if test="servantName != null">
                servant_name = #{servantName,jdbcType=VARCHAR},
            </if>
            <if test="servantPhone != null">
                servant_phone = #{servantPhone,jdbcType=VARCHAR},
            </if>
            <if test="servantRemark != null">
                servant_remark = #{servantRemark,jdbcType=VARCHAR},
            </if>
            <if test="serviceContractNo != null">
                service_contract_no = #{serviceContractNo,jdbcType=BIGINT},
            </if>
            <if test="serviceType != null">
                service_type = #{serviceType,jdbcType=INTEGER},
            </if>
            <if test="shopCode != null">
                shop_code = #{shopCode,jdbcType=VARCHAR},
            </if>
            <if test="startTime != null">
                start_time = #{startTime,jdbcType=VARCHAR},
            </if>
            <if test="stationCode != null">
                station_code = #{stationCode,jdbcType=VARCHAR},
            </if>
            <if test="stationName != null">
                station_name = #{stationName,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
            <if test="useCode != null">
                use_code = #{useCode,jdbcType=VARCHAR},
            </if>
            <if test="useRemark != null">
                use_remark = #{useRemark,jdbcType=VARCHAR},
            </if>
            <if test="userName != null">
                user_name = #{userName,jdbcType=VARCHAR},
            </if>
            <if test="userPhone != null">
                user_phone = #{userPhone,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.reptileclient.jlifeapp.entity.hm.HmBookTradeOrder">
        update hm_book_trade_order
        set addr_detail         = #{addrDetail,jdbcType=VARCHAR},
            addr_name           = #{addrName,jdbcType=VARCHAR},
            agreement_no        = #{agreementNo,jdbcType=VARCHAR},
            arrived_flag        = #{arrivedFlag,jdbcType=BIT},
            begin_time          = #{beginTime,jdbcType=VARCHAR},
            book_order_no       = #{bookOrderNo,jdbcType=INTEGER},
            book_trade_no       = #{bookTradeNo,jdbcType=INTEGER},
            cancel_flag         = #{cancelFlag,jdbcType=BIT},
            cancel_type_desc    = #{cancelTypeDesc,jdbcType=VARCHAR},
            confirm_flag        = #{confirmFlag,jdbcType=BIT},
            deliver_time        = #{deliverTime,jdbcType=TIMESTAMP},
            duration            = #{duration,jdbcType=INTEGER},
            end_time            = #{endTime,jdbcType=VARCHAR},
            finish_flag         = #{finishFlag,jdbcType=BIT},
            hm_order_no         = #{hmOrderNo,jdbcType=VARCHAR},
            item_id             = #{itemId,jdbcType=BIGINT},
            item_name           = #{itemName,jdbcType=VARCHAR},
            oper_name           = #{operName,jdbcType=VARCHAR},
            modify_flag         = #{modifyFlag,jdbcType=BIT},
            payment_no          = #{paymentNo,jdbcType=VARCHAR},
            position            = #{position,jdbcType=VARCHAR},
            remark              = #{remark,jdbcType=VARCHAR},
            servant_id          = #{servantId,jdbcType=INTEGER},
            servant_name        = #{servantName,jdbcType=VARCHAR},
            servant_phone       = #{servantPhone,jdbcType=VARCHAR},
            servant_remark      = #{servantRemark,jdbcType=VARCHAR},
            service_contract_no = #{serviceContractNo,jdbcType=BIGINT},
            service_type        = #{serviceType,jdbcType=INTEGER},
            shop_code           = #{shopCode,jdbcType=VARCHAR},
            start_time          = #{startTime,jdbcType=VARCHAR},
            station_code        = #{stationCode,jdbcType=VARCHAR},
            station_name        = #{stationName,jdbcType=VARCHAR},
            status              = #{status,jdbcType=INTEGER},
            use_code            = #{useCode,jdbcType=VARCHAR},
            use_remark          = #{useRemark,jdbcType=VARCHAR},
            user_name           = #{userName,jdbcType=VARCHAR},
            user_phone          = #{userPhone,jdbcType=VARCHAR},
            create_time         = #{createTime,jdbcType=TIMESTAMP},
            update_time         = #{updateTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=BIGINT}
    </update>

    <delete id="deleteByServiceContraceNo">
        delete from  hm_book_trade_order  where  service_contract_no =#{rightOrderNo,jdbcType=VARCHAR}
    </delete>

    <delete id="deleteByBookTradeNoList">
        delete
        from jlife_reports.trade_order where channel = '盒马'
                                         and  book_trade_no
            in
        <foreach item="item" index="index" collection="subList" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <delete id="deleteWorkerOrderList">
        delete
        from jlife_worker.worker_order_info where channel = '盒马'
                                              and  book_trade_no
            in
        <foreach item="item" index="index" collection="subList" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
    
    <update id="updateHmBookTradeState">
       update hm_book_trade_order
        set   status              = 4,
            update_time         =now()
        where book_trade_no in
        <foreach item="item" index="index" collection="subList" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>
</mapper>
