<?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.mmc.csf.release.dao.FlyerTrainingDao">

    <insert id="insertPilotRegistrationInfo" parameterType="com.mmc.csf.release.entity.PilotRegistrationDO"
            useGeneratedKeys="true" keyProperty="id">
        INSERT INTO pilot_registration(id, apply_user_id, `name`, city, telephone, driving_license, province,
                                       uav_license, industry_app_auth, remark)
        VALUES (#{id}, #{applyUserId}, #{name}, #{city}, #{telephone}, #{drivingLicense}, #{province}, #{uavLicense},
                #{industryAppAuth}, #{remark})
    </insert>
    <select id="selectAllLicenses" resultType="com.mmc.csf.release.flyer.vo.DronePilotLicenseVO">
        select id,
               parent_id,
               license_type,
               create_time,
               description
        FROM drone_pilot_license
        where is_deleted = 0
    </select>
    <select id="listIndustryFlightSkills" resultType="com.mmc.csf.release.entity.FlightSkillsDO">
        select id,
               skills_name
        from flight_skills
    </select>
    <select id="countCurriculumInfoList" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM
        curriculum_info ci INNER JOIN curriculum_video cv ON ci.id = cv.curriculum_info_id
        <where>
            and ci.is_deleted = 0
            <if test="licenseId != null">
                and ci.drone_pilot_license_id = #{licenseId}
            </if>
            <if test="flightSkillsId != null">
                and ci.flight_skills = #{flightSkillsId}
            </if>
        </where>
    </select>
    <select id="listPageCurriculumInfo" resultType="com.mmc.csf.release.entity.CurriculumInfoDO">
        SELECT
            ci.id,
            ci.curriculum_name,
            ci.supplier_id,
            ci.curriculum_price,
            ci.curriculum_desc,
            ci.is_free free,
            ci.drone_pilot_license_id,
            ci.flight_skills,
            cv.curriculum_url videoUrl
        from curriculum_info ci INNER JOIN curriculum_video cv ON ci.id = cv.curriculum_info_id
        <where>
            and ci.is_deleted = 0
            <if test="licenseId != null">
                and drone_pilot_license_id = #{licenseId}
            </if>
            <if test="flightSkillsId != null">
                and flight_skills = #{flightSkillsId}
            </if>
        </where>
        order by ci.create_time desc
        LIMIT #{pageNo},#{pageSize}
    </select>
    <select id="selectLicensesCurriculum" resultType="com.mmc.csf.release.entity.CurriculumInfoDO">
        SELECT ci.id,
               ci.curriculum_name,
               ci.supplier_id,
               ci.curriculum_price,
               ci.curriculum_desc,
               ci.is_free        free,
               ci.drone_pilot_license_id,
               ci.flight_skills,
               cv.curriculum_url videoUrl
        from curriculum_info ci
                 INNER JOIN curriculum_video cv ON ci.id = cv.curriculum_info_id
        where ci.drone_pilot_license_id is not null
    </select>
    <select id="selectSkillCurriculum" resultType="com.mmc.csf.release.entity.CurriculumInfoDO">
        SELECT ci.id,
               ci.curriculum_name,
               ci.supplier_id,
               ci.curriculum_price,
               ci.curriculum_desc,
               ci.is_free        free,
               ci.drone_pilot_license_id,
               ci.flight_skills,
               cv.curriculum_url videoUrl
        from curriculum_info ci
                 INNER JOIN curriculum_video cv ON ci.id = cv.curriculum_info_id
        where ci.flight_skills is not null
    </select>
</mapper>