<?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.srs.comprehensive.mapper.CphClassGoodMapper">

    <resultMap type="com.srs.comprehensive.domain.Vo.CphClassGoodStuYear" id="CphClassGoodResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="status"    column="status"    />
        <result property="className" column="class_name"/>
        <result property="yearName" column="stu_year_name"/>
        <result property="classCode" column="class_code"/>
        <result property="deptName" column="dept_name"/>
    </resultMap>

    <sql id="selectCphClassGoodVo">
        SELECT ccg.id,ccg.create_by,ccg.`status`,sc.class_name, sy.stu_year_name,sc.class_code,sd.dept_name
        FROM cph_class_good ccg
                 JOIN srs_class sc ON ccg.class_id = sc.class_id
                 JOIN srs_stu_year sy ON ccg.year_id = sy.id
                 JOIN srs_majors sm ON sc.major_id = sm.major_id
                 JOIN sys_dept sd ON sd.dept_id = sm.college_id
        WHERE ccg.del_flag = '0'
    </sql>

    <select id="selectCphClassGoodList" parameterType="CphClassGood" resultMap="CphClassGoodResult">
        <include refid="selectCphClassGoodVo"/>
        <where>
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="yearId != null "> and year_id = #{yearId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectCphClassGoodById" parameterType="Long" resultMap="CphClassGoodResult">
        <include refid="selectCphClassGoodVo"/>
        where id = #{id}
    </select>

    <insert id="insertCphClassGood" parameterType="CphClassGood" useGeneratedKeys="true" keyProperty="id">
        insert into cph_class_good
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="classId != null">class_id,</if>
            <if test="yearId != null">year_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="classId != null">#{classId},</if>
            <if test="yearId != null">#{yearId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateCphClassGood" parameterType="CphClassGood">
        update cph_class_good
        <trim prefix="SET" suffixOverrides=",">
            <if test="classId != null">class_id = #{classId},</if>
            <if test="yearId != null">year_id = #{yearId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphClassGoodById" parameterType="Long">
        delete from cph_class_good where id = #{id}
    </delete>

    <delete id="deleteCphClassGoodByIds" parameterType="String">
        delete from cph_class_good where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>