<?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.system.mapper.score.ScoreDataMapper">
    
    <resultMap type="ScoreData" id="ScoreDataResult">
        <result property="scoreId"    column="score_id"    />
        <result property="scoreTitle"    column="score_title"    />
        <result property="scoreTime"    column="score_time"    />
        <result property="scoreClassId"    column="score_class_id"    />
        <result property="scoreClassName"    column="score_class_name"    />
        <result property="privacyType"    column="privacy_type"    />
        <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"    />
    </resultMap>

    <resultMap id="ScoreDataScoreDataDetailsResult" type="ScoreData" extends="ScoreDataResult">
        <collection property="scoreDataDetailsList" notNullColumn="sub_score_details_id" javaType="java.util.List" resultMap="ScoreDataDetailsResult" />
    </resultMap>

    <resultMap type="ScoreDataDetails" id="ScoreDataDetailsResult">
        <result property="scoreDetailsId"    column="sub_score_details_id"    />
        <result property="scoreId"    column="sub_score_id"    />
        <result property="scoreSort"    column="sub_score_sort"    />
        <result property="scoreDataName"    column="sub_score_data_name"    />
        <result property="scoreDataNameId"    column="sub_score_data_name_id"    />
        <result property="yuwen"    column="sub_yuwen"    />
        <result property="shuxue"    column="sub_shuxue"    />
        <result property="yingyu"    column="sub_yingyu"    />
        <result property="wuli"    column="sub_wuli"    />
        <result property="huaxue"    column="sub_huaxue"    />
        <result property="shengwu"    column="sub_shengwu"    />
        <result property="zhengzhi"    column="sub_zhengzhi"    />
        <result property="lishi"    column="sub_lishi"    />
        <result property="dili"    column="sub_dili"    />
        <result property="tiyu"    column="sub_tiyu"    />
        <result property="wenzong"    column="sub_wenzong"    />
        <result property="lizong"    column="sub_lizong"    />
        <result property="zhengcefen"    column="sub_zhengcefen"    />
        <result property="zongfen"    column="sub_zongfen"    />
        <result property="detailsType"    column="sub_details_type"    />
        <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"    />
    </resultMap>

    <sql id="selectScoreDataVo">
        select score_id, score_title, score_time, score_class_id, score_class_name, privacy_type, create_by, create_time, update_by, update_time, remark from score_data
    </sql>

    <select id="selectScoreDataList" parameterType="ScoreData" resultMap="ScoreDataResult">
        select a.score_id, a.score_title, a.score_time, a.score_class_id, a.score_class_name, a.privacy_type, a.create_by, a.create_time, a.update_by, a.update_time, a.remark

        from score_data a

        <where>  
            <if test="scoreTitle != null  and scoreTitle != ''"> and a.score_title = #{scoreTitle}</if>
            <if test="scoreTime != null "> and a.score_time = #{scoreTime}</if>
            <if test="scoreClassName != null  and scoreClassName != ''"> and a.score_class_name like concat('%', #{scoreClassName}, '%')</if>
            <if test="privacyType != null  and privacyType != ''"> and a.privacy_type = #{privacyType}</if>
            <if test="scoreClassId != null  and scoreClassId != ''"> and find_in_set(a.score_class_id,#{scoreClassId})</if>
        </where>
        order by score_time DESC
    </select>
    
    <select id="selectScoreDataByScoreId" parameterType="Long" resultMap="ScoreDataScoreDataDetailsResult">
        select a.score_id, a.score_title, a.score_time, a.score_class_id, a.score_class_name, a.privacy_type, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
 b.score_details_id as sub_score_details_id, b.score_id as sub_score_id,b.zongfen as sub_zongfen, b.score_sort as sub_score_sort, b.details_type as sub_details_type, b.score_data_name as sub_score_data_name, b.yuwen as sub_yuwen, b.shuxue as sub_shuxue, b.yingyu as sub_yingyu, b.wuli as sub_wuli, b.huaxue as sub_huaxue, b.shengwu as sub_shengwu, b.zhengzhi as sub_zhengzhi, b.lishi as sub_lishi, b.dili as sub_dili, b.tiyu as sub_tiyu, b.wenzong as sub_wenzong, b.lizong as sub_lizong, b.zhengcefen as sub_zhengcefen, 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
        from score_data a
        left join score_data_details b on b.score_id = a.score_id
        where a.score_id = #{scoreId}
    </select>

    <select id="selectScoreDataForParents" parameterType="ScoreData" resultMap="ScoreDataScoreDataDetailsResult">
        select a.score_id, a.score_title, a.score_time, a.score_class_id, a.score_class_name, a.privacy_type, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
 b.score_details_id as sub_score_details_id, b.score_id as sub_score_id,b.zongfen as sub_zongfen, b.score_sort as sub_score_sort, b.details_type as sub_details_type, b.score_data_name as sub_score_data_name, b.yuwen as sub_yuwen, b.shuxue as sub_shuxue, b.yingyu as sub_yingyu, b.wuli as sub_wuli, b.huaxue as sub_huaxue, b.shengwu as sub_shengwu, b.zhengzhi as sub_zhengzhi, b.lishi as sub_lishi, b.dili as sub_dili, b.tiyu as sub_tiyu, b.wenzong as sub_wenzong, b.lizong as sub_lizong, b.zhengcefen as sub_zhengcefen, 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
        from score_data a
        left join score_data_details b on b.score_id = a.score_id
        where a.score_id = #{scoreId} and  find_in_set(b.score_data_name_id,#{params.stdId})
    </select>

    <select id="selectScoreIdByScoreClassId" parameterType="string" resultMap="ScoreDataResult">
SELECT
		score_id
	FROM
		score_data
WHERE
	score_class_id = #{scoreClassId} order by score_time DESC limit 1

    </select>
    <select id="selectScoreDataByScoreClassId" parameterType="string" resultMap="ScoreDataDetailsResult">
        select
 b.score_details_id as sub_score_details_id, b.score_id as sub_score_id,b.zongfen as sub_zongfen, b.score_sort as sub_score_sort, b.details_type as sub_details_type, b.score_data_name as sub_score_data_name, b.yuwen as sub_yuwen, b.shuxue as sub_shuxue, b.yingyu as sub_yingyu, b.wuli as sub_wuli, b.huaxue as sub_huaxue, b.shengwu as sub_shengwu, b.zhengzhi as sub_zhengzhi, b.lishi as sub_lishi, b.dili as sub_dili, b.tiyu as sub_tiyu, b.wenzong as sub_wenzong, b.lizong as sub_lizong, b.zhengcefen as sub_zhengcefen, 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
        from
         score_data_details b
WHERE
	b.score_id = (
	SELECT
		score_id
	FROM
		score_data
WHERE
	score_class_id = #{scoreClassId} order by score_time DESC limit 1)
	order by b.score_sort

    </select>
    <select id="selectDetailsCountByScoreId" resultType="java.lang.Integer">
        select ifnull(count(0),0) from score_data_details where score_id = #{scoreId}
    </select>

    <insert id="insertScoreData" parameterType="ScoreData" useGeneratedKeys="true" keyProperty="scoreId">
        insert into score_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scoreTitle != null">score_title,</if>
            <if test="scoreTime != null">score_time,</if>
            <if test="scoreClassId != null">score_class_id,</if>
            <if test="scoreClassName != null">score_class_name,</if>
            <if test="privacyType != null">privacy_type,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="scoreTitle != null">#{scoreTitle},</if>
            <if test="scoreTime != null">#{scoreTime},</if>
            <if test="scoreClassId != null">#{scoreClassId},</if>
            <if test="scoreClassName != null">#{scoreClassName},</if>
            <if test="privacyType != null">#{privacyType},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateScoreData" parameterType="ScoreData">
        update score_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="scoreTitle != null">score_title = #{scoreTitle},</if>
            <if test="scoreTime != null">score_time = #{scoreTime},</if>
            <if test="scoreClassId != null">score_class_id = #{scoreClassId},</if>
            <if test="scoreClassName != null">score_class_name = #{scoreClassName},</if>
            <if test="privacyType != null">privacy_type = #{privacyType},</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="remark != null">remark = #{remark},</if>
        </trim>
        where score_id = #{scoreId}
    </update>

    <delete id="deleteScoreDataByScoreId" parameterType="Long">
        delete from score_data where score_id = #{scoreId}
    </delete>

    <delete id="deleteScoreDataByScoreIds" parameterType="String">
        delete from score_data where score_id in 
        <foreach item="scoreId" collection="array" open="(" separator="," close=")">
            #{scoreId}
        </foreach>
    </delete>
    
    <delete id="deleteScoreDataDetailsByScoreIds" parameterType="String">
        delete from score_data_details where score_id in 
        <foreach item="scoreId" collection="array" open="(" separator="," close=")">
            #{scoreId}
        </foreach>
    </delete>

    <delete id="deleteScoreDataDetailsByScoreId" parameterType="Long">
        delete from score_data_details where score_id = #{scoreId}
    </delete>

    <insert id="batchScoreDataDetails">
        insert into score_data_details( score_details_id, score_id, score_sort, score_data_name,score_data_name_id, yuwen, shuxue, yingyu, wuli, huaxue, shengwu, zhengzhi, lishi, dili, tiyu, wenzong, lizong, zhengcefen,zongfen, details_type,create_by, create_time, update_by, update_time, remark) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.scoreDetailsId}, #{item.scoreId}, #{item.scoreSort}, #{item.scoreDataName},#{item.scoreDataNameId}, #{item.yuwen}, #{item.shuxue}, #{item.yingyu}, #{item.wuli}, #{item.huaxue}, #{item.shengwu}, #{item.zhengzhi}, #{item.lishi}, #{item.dili}, #{item.tiyu}, #{item.wenzong}, #{item.lizong}, #{item.zhengcefen},#{item.zongfen},#{item.detailsType}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark})
        </foreach>
    </insert>
</mapper>