<?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.seer.teach.teacher.module.mapper.KnowledgePointsMapper">

    <select id="getKnowIdsByConditions" resultType="java.lang.Integer">
        SELECT DISTINCT kp.id
        FROM teacher_knowledge_point kp
        inner JOIN teacher_unit_know_mapping ukm ON kp.id = ukm.knowledge_point_id
        inner JOIN teacher_units u ON ukm.unit_id = u.id
        inner JOIN teacher_material m ON u.material_id = m.id
        WHERE 1=1 and kp.deleted = 0 AND u.deleted = 0 AND m.deleted = 0 and ukm.deleted = 0
        <if test="param.materialId != null ">AND m.id = #{param.materialId}</if>
        <if test="param.gradeId != null ">AND m.grade_id = #{param.gradeId}</if>
        <if test="param.knowId != null ">AND kp.id = #{param.knowId}</if>
        <if test="param.knowName != null ">AND kp.knowledge_point_name like concat(#{param.knowName},'%')</if>
        <if test="param.versionId != null ">AND m.version_id = #{param.versionId}</if>
        <if test="param.subjectId != null">AND kp.subject_id = #{param.subjectId}</if>
        <if test="param.gradeType != null">AND kp.grade_type = #{param.gradeType}</if>
        <if test="param.gradeIds != null and !param.gradeIds.isEmpty()">AND m.grade_id IN<foreach collection="param.gradeIds" item="gradeId" open="(" separator="," close=")">#{gradeId}</foreach></if>
        <if test="param.versionIds != null and !param.versionIds.isEmpty()">AND m.version_id IN<foreach collection="param.versionIds" item="versionId" open="(" separator="," close=")">#{versionId}</foreach></if>
        <if test="param.subjectIds != null and !param.subjectIds.isEmpty()">AND kp.subject_id IN<foreach collection="param.subjectIds" item="subjectId" open="(" separator="," close=")">#{subjectId}</foreach></if>
    </select>

</mapper>