<?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.m2pool.lease.mapper.LeaseOrderInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.m2pool.lease.entity.LeaseOrderInfo">
        <id column="id" property="id" />
        <result column="order_number" property="orderNumber" />
        <result column="user_id" property="userId" />
        <result column="total_price" property="totalPrice" />
        <result column="status" property="status" />
        <result column="address" property="address" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="del" property="del" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, order_number, user_id, total_price, status, address, create_time, update_time, del
    </sql>
    <select id="getOrdersByStatus" resultType="com.m2pool.lease.dto.OrderInfoDto">
        select
            loo.id,
            loo.order_number as orderNumber,
            loo.user_id as userId,
            loo.total_price as totalPrice,
            loo.status,
            loo.create_time as createTime,
            loo.update_time as endTime,
            loo.shop_name as shopName
        from  lease_order_info loo
        <where>
            del = 0 and user_id = #{userId}
            <if test="status != null">
                and status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>
    <select id="getOrdersByStatusForSeller" resultType="com.m2pool.lease.dto.OrderInfoDto">
        select
            loo.id,
            loo.order_number as orderNumber,
            loo.user_id as userId,
            loo.total_price as totalPrice,
            loo.status,
            loo.create_time as createTime,
            loo.update_time as endTime,
            loo.shop_name as shopName
        from  lease_order_info loo
        <where>
            del = 0
            <if test="status != null">
                and status = #{status}
            </if>
            and id IN
            <foreach collection="ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>

        order by create_time desc
    </select>
    <select id="getOrderItemsByMachineId" resultType="com.m2pool.lease.entity.LeaseUserOwnedProduct">

        select
            loo.id as orderItemId,
            loo.user as `user`,
            loo.miner as miner,
            loo.product_machine_id as productMachineId
        from  lease_order_info loo
        where del = 0 and product_machine_id IN
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="getNeedPayOrderList" resultType="com.m2pool.lease.entity.LeaseOrderInfo">
        select
            id,
            order_number as orderNumber,
            user_id as userId,
            total_price as totalPrice,
            status,
            create_time as createTime
        from  lease_order_info
        where del = 0 and status = 7
    </select>
    <select id="getCoinPrice" resultType="java.math.BigDecimal">
        select `value` from ${coin}_price order by id desc limit 1
    </select>


</mapper>
