<?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.gic.haoban.manage.service.dao.mapper.TabHaobanAppOrderMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.TabHaobanAppOrder" id="TabHaobanAppOrderMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
        <result property="orderStatus" column="order_status" jdbcType="INTEGER"/>
        <result property="orderType" column="order_type" jdbcType="INTEGER"/>
        <result property="userNum" column="user_num" jdbcType="INTEGER"/>
        <result property="duration" column="duration" jdbcType="INTEGER"/>
        <result property="beginTime" column="begin_time" jdbcType="TIMESTAMP"/>
        <result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
        <result property="payTime" column="pay_time" jdbcType="TIMESTAMP"/>
        <result property="originPrice" column="origin_price" jdbcType="INTEGER"/>
        <result property="paidPrice" column="paid_price" jdbcType="INTEGER"/>
        <result property="orderUrl" column="order_url" jdbcType="VARCHAR"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="creatorId" column="creator_id" jdbcType="VARCHAR"/>
        <result property="creatorName" column="creator_name" jdbcType="VARCHAR"/>
        <result property="expireTime" column="expire_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanAppOrderMap">
        select
          id, wx_enterprise_id, order_id, order_status, order_type, user_num, duration, begin_time, end_time, pay_time, origin_price, paid_price, order_url, delete_flag, create_time, update_time, creator_id, creator_name,expire_time
        from tab_haoban_app_order
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TabHaobanAppOrderMap">
        select
          id, wx_enterprise_id, order_id, order_status, order_type, user_num, duration, begin_time, end_time, pay_time, origin_price, paid_price, order_url, delete_flag, create_time, update_time, creator_id, creator_name,expire_time
        from tab_haoban_app_order
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="orderId != null">
                and order_id = #{orderId}
            </if>
            <if test="orderStatus != null">
                and order_status = #{orderStatus}
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="userNum != null">
                and user_num = #{userNum}
            </if>
            <if test="duration != null">
                and duration = #{duration}
            </if>
            <if test="beginTime != null">
                and begin_time = #{beginTime}
            </if>
            <if test="endTime != null">
                and end_time = #{endTime}
            </if>
            <if test="payTime != null">
                and pay_time = #{payTime}
            </if>
            <if test="originPrice != null">
                and origin_price = #{originPrice}
            </if>
            <if test="paidPrice != null">
                and paid_price = #{paidPrice}
            </if>
            <if test="orderUrl != null and orderUrl != ''">
                and order_url = #{orderUrl}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="creatorId != null and creatorId != ''">
                and creator_id = #{creatorId}
            </if>
            <if test="creatorName != null and creatorName != ''">
                and creator_name = #{creatorName}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_app_order
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="orderId != null">
                and order_id = #{orderId}
            </if>
            <if test="orderStatus != null">
                and order_status = #{orderStatus}
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="userNum != null">
                and user_num = #{userNum}
            </if>
            <if test="duration != null">
                and duration = #{duration}
            </if>
            <if test="beginTime != null">
                and begin_time = #{beginTime}
            </if>
            <if test="endTime != null">
                and end_time = #{endTime}
            </if>
            <if test="payTime != null">
                and pay_time = #{payTime}
            </if>
            <if test="originPrice != null">
                and origin_price = #{originPrice}
            </if>
            <if test="paidPrice != null">
                and paid_price = #{paidPrice}
            </if>
            <if test="orderUrl != null and orderUrl != ''">
                and order_url = #{orderUrl}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="creatorId != null and creatorId != ''">
                and creator_id = #{creatorId}
            </if>
            <if test="creatorName != null and creatorName != ''">
                and creator_name = #{creatorName}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_app_order(id,wx_enterprise_id, order_id, order_status, order_type, user_num, duration, begin_time, end_time, pay_time, origin_price, paid_price, order_url, delete_flag, create_time, update_time, creator_id, creator_name,expire_time)
        values (#{id},#{wxEnterpriseId}, #{orderId}, #{orderStatus}, #{orderType}, #{userNum}, #{duration}, #{beginTime}, #{endTime}, #{payTime}, #{originPrice}, #{paidPrice}, #{orderUrl}, #{deleteFlag}, #{createTime}, #{updateTime}, #{creatorId}, #{creatorName},#{expireTime})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_app_order(id,wx_enterprise_id, order_id, order_status, order_type, user_num, duration, begin_time, end_time, pay_time, origin_price, paid_price, order_url, delete_flag, create_time, update_time, creator_id, creator_name,expire_time)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.id},#{entity.wxEnterpriseId}, #{entity.orderId}, #{entity.orderStatus}, #{entity.orderType}, #{entity.userNum}, #{entity.duration}, #{entity.beginTime}, #{entity.endTime}, #{entity.payTime}, #{entity.originPrice}, #{entity.paidPrice}, #{entity.orderUrl}, #{entity.deleteFlag}, #{entity.createTime}, #{entity.updateTime}, #{entity.creatorId}, #{entity.creatorName},#{entity.expireTime})
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_app_order
        <set>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
            <if test="orderId != null">
                order_id = #{orderId},
            </if>
            <if test="orderStatus != null">
                order_status = #{orderStatus},
            </if>
            <if test="orderType != null">
                order_type = #{orderType},
            </if>
            <if test="userNum != null">
                user_num = #{userNum},
            </if>
            <if test="duration != null">
                duration = #{duration},
            </if>
            <if test="beginTime != null">
                begin_time = #{beginTime},
            </if>
            <if test="endTime != null">
                end_time = #{endTime},
            </if>
            <if test="payTime != null">
                pay_time = #{payTime},
            </if>
            <if test="originPrice != null">
                origin_price = #{originPrice},
            </if>
            <if test="paidPrice != null">
                paid_price = #{paidPrice},
            </if>
            <if test="orderUrl != null and orderUrl != ''">
                order_url = #{orderUrl},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="creatorId != null and creatorId != ''">
                creator_id = #{creatorId},
            </if>
            <if test="creatorName != null and creatorName != ''">
                creator_name = #{creatorName},
            </if>
            <if test="expireTime != null">
                expire_time = #{expireTime},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <update id="deleteById">
        update tab_haoban_app_order
        set delete_flag = 1,update_time = now()
        where id = #{id}
    </update>
    <select id="getQywxOrderId"  resultType="string">
        SELECT
        order_id
        FROM tab_haoban_app_order WHERE order_id like concat (#{qywxOrderId},'%') and delete_flag=0
        <if test="wxEnterpriseId != null and wxEnterpriseId !='' ">
            and wx_enterprise_id = #{wxEnterpriseId}
        </if>
    </select>

    <select id="getAppOrderPage" resultMap="TabHaobanAppOrderMap">
    select
    id, wx_enterprise_id, order_id, order_status, order_type, user_num, duration, begin_time, end_time, pay_time, origin_price, paid_price, order_url, delete_flag, create_time, update_time, creator_id, creator_name,expire_time
    from tab_haoban_app_order
    where  delete_flag = 0
        <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
            and wx_enterprise_id = #{wxEnterpriseId}
        </if>
        <if test="orderId != null">
            and order_id = #{orderId}
        </if>
        <if test="orderStatus != null">
            and order_status = #{orderStatus}
        </if>
    </select>

    <select id="queryByOrderId" resultMap="TabHaobanAppOrderMap">
        select
            id, wx_enterprise_id, order_id, order_status, order_type, user_num, duration, begin_time, end_time, pay_time, origin_price, paid_price, order_url, delete_flag, create_time, update_time, creator_id, creator_name,expire_time
        from tab_haoban_app_order
        where order_id = #{orderId} and delete_flag = 0
        limit 1
    </select>

</mapper>

