<?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.SrsAddRecordMapper">
    
    <resultMap type="SrsAddRecord" id="SrsAddRecordResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="applicant"    column="applicant"    />
        <result property="ruleId"    column="rule_id"    />
        <result property="description"    column="description"    />
        <result property="material"    column="material"    />
        <result property="recordScore"    column="record_score"    />
        <result property="stuYearId"    column="stu_year_id"    />
        <result property="statusCode"    column="status_code"    />
        <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"    />
        <result property="iamId"    column="iam_id"    />
    </resultMap>

    <sql id="selectSrsAddRecordVo">
        select id, stu_no,applicant, rule_id, description, material,record_score, stu_year_id,status_code, status, del_flag, create_by, create_time, update_by, update_time from srs_add_record
    </sql>

    <select id="selectSrsAddRecordList" parameterType="SrsAddRecord" resultMap="SrsAddRecordResult">
        <include refid="selectSrsAddRecordVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="ruleId != null "> and rule_id = #{ruleId}</if>
            <if test="applicant != null "> and applicant = #{applicant}</if>
            <if test="stuYearId != null "> and stu_year_id = #{stuYearId}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="material != null  and material != ''"> and material = #{material}</if>
            <if test="statusCode != null  and statusCode != ''"> and status_code = #{statusCode}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="iamId != null "> and iam_id = #{iamId}</if>
        </where>
    </select>

    <select id="getIsExistRecord" resultType="com.srs.comprehensive.domain.SrsAddRecord">
        select * from srs_add_record as a
        where a.rule_id = #{ruleId} and a.stu_year_id = #{stuYearId}
        and stu_no in
        <foreach collection="stuNos" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <select id="listOwnRecord" resultType="com.srs.comprehensive.domain.Vo.CphRecord">
        select a.stu_no,b.`name`,c.stu_year_name,d.rule_name,a.record_score,a.create_time from srs_add_record as a
        left join srs_student as b on a.stu_no = b.stu_no
        left join srs_stu_year as c on a.stu_year_id = c.id
        left join cph_rules as d on a.rule_id = d.rule_id
        where a.stu_no = #{stuNo}
        ORDER BY a.id DESC
    </select>
    
    <select id="selectSrsAddRecordById" parameterType="Long" resultMap="SrsAddRecordResult">
        <include refid="selectSrsAddRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSrsAddRecord" parameterType="SrsAddRecord" useGeneratedKeys="true" keyProperty="id">
        insert into srs_add_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="applicant != null">applicant,</if>
            <if test="ruleId != null">rule_id,</if>
            <if test="description != null">description,</if>
            <if test="material != null">material,</if>
            <if test="recordScore != null">record_score,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="statusCode != null">status_code,</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>
            <if test="iamId != null">iam_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="ruleId != null">#{ruleId},</if>
            <if test="description != null">#{description},</if>
            <if test="material != null">#{material},</if>
            <if test="recordScore != null">#{recordScore},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="statusCode != null">#{statusCode},</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>
            <if test="iamId != null">#{iamId},</if>
         </trim>
    </insert>

    <update id="updateSrsAddRecord" parameterType="SrsAddRecord">
        update srs_add_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="ruleId != null">rule_id = #{ruleId},</if>
            <if test="description != null">description = #{description},</if>
            <if test="material != null">material = #{material},</if>
            <if test="recordScore != null">record_score = #{recordScore},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="statusCode != null">status_code = #{statusCode},</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>
            <if test="iamId != null">iam_id = #{iamId},</if>
        </trim>
        where id = #{id}
    </update>

    <insert id="insertAllAddRecordInt" parameterType="SrsAddRecord">
        insert into srs_add_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="applicant != null">applicant,</if>
            <if test="ruleId != null">rule_id,</if>
            <if test="description != null">description,</if>
            <if test="material != null">material,</if>
            <if test="recordScore != null">record_score,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="statusCode != null">status_code,</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="applicant != null">#{applicant},</if>
            <if test="ruleId != null">#{ruleId},</if>
            <if test="description != null">#{description},</if>
            <if test="material != null">#{material},</if>
            <if test="recordScore != null">#{recordScore},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="statusCode != null">#{statusCode},</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>

    <delete id="deleteSrsAddRecordById" parameterType="Long">
        delete from srs_add_record where id = #{id}
    </delete>

    <delete id="deleteSrsAddRecordByIds" parameterType="String">
        delete from srs_add_record where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
<!--    批量修改-->
    <update id="updateAddRecordDelFlag">
        <foreach collection="array" open="(" separator="," close=")" item="item">
            update srs_add_record
        </foreach>
    </update>

    <update id="updateSrsAddRecordAll" parameterType="java.util.List">
        <foreach collection="updateSrsAddRecord" item="item" index="index" open="" close="" separator=";">
            update srs_add_record
            <set>
                record_score=${item.recordScore}
            </set>
            where id = ${item.id}
        </foreach>
    </update>


</mapper>