<?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.CphIdeologyScoreMapper">
    
    <resultMap type="CphIdeologyScore" id="CphIdeologyScoreResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="score"    column="score"    />
        <result property="stuYearId"    column="stu_year_id"    />
        <result property="description"    column="description"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCphIdeologyScoreVo">
        select i.id, i.stu_no, i.score, i.stu_year_id, i.description, i.status, i.del_flag, i.create_by, i.create_time, i.update_by, i.update_time, s.name, sy.stu_year_name, sc.class_name, m.major_name, d.dept_name
        from cph_ideology_score i
        left join srs_student s on i.stu_no = s.stu_no
        left join srs_stu_year sy on i.stu_year_id = sy.id
        left join srs_class sc on s.class_id = sc.class_id
        left join srs_majors m on sc.major_id = m.major_id
        left join sys_dept d on m.college_id = d.dept_id
    </sql>

    <select id="selectCphIdeologyScoreList" parameterType="CphIdeologyScore" resultMap="CphIdeologyScoreResult">
        <include refid="selectCphIdeologyScoreVo"/>
        <where>  
            <if test="stuNo != null  and stuNo != ''"> and i.stu_no = #{stuNo}</if>
            <if test="score != null "> and i.score = #{score}</if>
            <if test="stuYearId != null "> and i.stu_year_id = #{stuYearId}</if>
            <if test="description != null  and description != ''"> and i.description = #{description}</if>
            <if test="status != null  and status != ''"> and i.status = #{status}</if>
            <if test="classId != null "> and s.class_id = #{classId}</if>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="majorId != null "> and m.major_id = #{majorId}</if>
        </where>
    </select>
    
    <select id="selectCphIdeologyScoreById" parameterType="Long" resultMap="CphIdeologyScoreResult">
        <include refid="selectCphIdeologyScoreVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCphIdeologyScore" parameterType="CphIdeologyScore" useGeneratedKeys="true" keyProperty="id">
        insert into cph_ideology_score
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="score != null">score,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="description != null">description,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="score != null">#{score},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="description != null">#{description},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCphIdeologyScore" parameterType="CphIdeologyScore">
        update cph_ideology_score
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="score != null">score = #{score},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="description != null">description = #{description},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphIdeologyScoreById" parameterType="Long">
        delete from cph_ideology_score where id = #{id}
    </delete>

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