<?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="org.springblade.modules.finance.mapper.OrderConsignMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="orderConsignResultMap" type="org.springblade.modules.finance.entity.OrderConsign">
        <id column="id" property="id"/>
        <result column="order_id" property="orderId"/>
        <result column="goods_id" property="goodsId"/>
        <result column="total_price" property="totalPrice"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="total_num" property="totalNum"/>
        <result column="consign_user_id" property="consignUserId"/>
        <result column="pay_user_id" property="payUserId"/>
        <result column="consign_state" property="consignState"/>
        <result column="consign_price" property="consignPrice"/>
        <result column="create_time" property="createTime"/>
        <result column="pay_time" property="payTime"/>
        <result column="confirm_time" property="confirmTime"/>
    </resultMap>


    <select id="selectOrderConsignPage" resultMap="orderConsignResultMap">
        select * from t_order_consign where is_deleted = 0
    </select>

    <select id="selectUserCount" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        t_order_consign c
        WHERE
        to_days(c.create_time) = to_days(now())
        <if test="userId != null and userId != ''">
            and c.pay_user_id = #{userId}
        </if>
        AND EXISTS (
        SELECT
        1
        FROM
        t_consign t
        WHERE
        t.is_deleted = 0
        and t.id = c.consign_id
        <if test="consignConfigId != null and consignConfigId != ''">
            and t.consign_config_id = #{consignConfigId}
        </if>
        )
    </select>

</mapper>
