<?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.ruoyi.materialClass.mapper.MaterialClassMasterMapper">

    <resultMap type="MaterialClassMaster" id="MaterialClassMastResult">
        <result property="classMastId"    column="class_mast_id"    />
        <result property="id"    column="id"    />
        <result property="classMastType"    column="class_mast_type"    />
        <result property="classNameMast"    column="class_name_mast"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="deptId"    column="dept_id"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="classCount"    column="class_count"    />
    </resultMap>

    <resultMap id="MaterialClassMastMaterialClassSubResult" type="MaterialClassMaster" extends="MaterialClassMastResult">
        <collection property="materialClassSubList" notNullColumn="sub_class_sub_id" javaType="java.util.List" resultMap="MaterialClassSubResult" />
    </resultMap>

    <resultMap type="MaterialClassSub" id="MaterialClassSubResult">
        <result property="classSubId"    column="sub_class_sub_id"    />
        <result property="classMastId"    column="sub_class_mast_id"    />
        <result property="classMastType"    column="class_mast_type"    />
        <result property="classNameSub"    column="sub_class_name_sub"    />
        <result property="createBy"    column="sub_create_by"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateBy"    column="sub_update_by"    />
        <result property="updateTime"    column="sub_update_time"    />
        <result property="remark"    column="sub_remark"    />
        <result property="deptId"    column="sub_dept_id"    />
        <result property="createUserId"    column="sub_create_user_id"    />
        <result property="updateUserId"    column="sub_update_user_id"    />
        <result property="id"    column="sub_id"    />
    </resultMap>

    <sql id="selectMaterialClassMastVo">
        select class_mast_id, id, class_mast_type, class_name_mast, create_by, create_time, update_by, update_time,
        remark, dept_id, create_user_id, update_user_id,(select count(1) from material_class_sub b where a.id=b.mast_id ) class_count from material_class_master a
    </sql>

    <select id="selectMaterialClassMastList" parameterType="MaterialClassMaster" resultMap="MaterialClassMastResult">
        <include refid="selectMaterialClassMastVo"/>
        <where>
            <if test="classMastId != null  and classMastId != ''"> and class_mast_id = #{classMastId}</if>
            <if test="classMastType != null  and classMastType != ''"> and class_mast_type = #{classMastType}</if>
            <if test="classNameMast != null  and classNameMast != ''"> and class_name_mast = #{classNameMast}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
        </where>
    </select>

    <select id="selectMaterialClassMastByClassMastId" parameterType="String" resultMap="MaterialClassMastMaterialClassSubResult">
            select a.class_mast_id, a.id, a.class_mast_type, a.class_name_mast, a.create_by, a.create_time, a.update_by, a.update_time, a.remark, a.dept_id, a.create_user_id, a.update_user_id,
 b.class_sub_id as sub_class_sub_id, b.class_mast_id as sub_class_mast_id, b.class_name_sub as sub_class_name_sub, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark, b.dept_id as sub_dept_id, b.create_user_id as sub_create_user_id, b.update_user_id as sub_update_user_id, b.id as sub_id
            from material_class_master a
            left join material_class_sub b on b.mast_id = a.id
            where a.id = #{classMastId}
    </select>




</mapper>