<?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="cn.iocoder.yudao.module.jx.payment.mapper.DrivePayMapper">


    <sql id="selectOrderInfoDetailVo">
        select id, name, phone, jlId, userId, state, identity, orderNumber, startPay, jxId, courseId, create_time, payTime
    </sql>

    <insert id="insertPayInfo">
        insert into drive_school_pay (name, phone, sex,age,state, identity, startPay, jlId,jlName, jxId, courseId, createTime, orderNumber, userId, money)
                values (#{name}, #{phone}, #{sex},#{age},#{state}, #{identity}, #{startPay},#{jlId}, #{jlName},#{jxId}, #{courseId}, now(), #{orderNumber}, #{userId}, #{money})
    </insert>

    <update id="updatePayByOrderNumber">
        update drive_school_pay set payTime = now(), state = 1 where orderNumber = #{orderNo}
    </update>

    <!--    <insert id="insertPayInfo">-->
<!--        insert into drive_school_pay (name, phone, state, identity, startPay, jlId, jxId, courseId, createTime, orderNumber, userId)-->
<!--        values (#{name}, #{phone}, #{state}, #{identity}, #{startPay},#{jlId}, #{jxId}, #{courseId}, now(), #{orderNumber}, #{userId})-->
<!--    </insert>-->

    <select id="findPayListAll" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and userId = #{userId}
    </select>

    <select id="findDriveSchoolByJxId" resultType="cn.iocoder.yudao.module.jx.domain.DriveSchoolInfo">
        select * from drive_school_info where deleted = 0 and  id = #{jxId}
    </select>

    <select id="findDriveSchoolCourse" resultType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse">
        select * from drive_school_course where deleted = 0 and id = #{courseId}
    </select>

    <select id="findPayById" resultType="cn.iocoder.yudao.module.jx.payment.entity.PayEntity">
        select * from drive_school_pay where deleted = 0 and id = #{userId}
    </select>

    <select id="findPayByPhoneList" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and phone = #{phone}
    </select>

    <select id="findPayByUserIdList" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and userId = #{userId}
    </select>

    <select id="findPayListAllNumber" resultType="java.lang.Integer">
        select count(*) from drive_school_pay
    </select>

    <select id="findPayListAfternoonNumber" resultType="java.lang.Integer">
        select count(*) from drive_school_pay where deleted = 0 and afternoon = 1
    </select>
    <select id="findPayByUserId" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and userId = #{userId} and jlId is not null
        order by  createTime desc
        limit 1
    </select>
    <select id="findCurrentJlCount" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and jlId = #{jlId}
    </select>

    <select id="findStuCount" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and jlId = #{jlId}
    </select>
    <select id="findPayListByUserId" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and userId = #{userId}
    </select>
    <select id="findPayByUserIdOne" resultType="cn.iocoder.yudao.module.jx.payment.vo.PayVo">
        select * from drive_school_pay where deleted = 0 and userId = #{userId} group by createTime
    </select>


    <select id="selectByUserId" resultType="Integer">
        select jlId from drive_school_pay where deleted = 0 and userId = #{userId} limit 1
    </select>


</mapper>
