<?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.project.benyi.mapper.ByDayFlowStandardMapper">

    <resultMap type="ByDayFlowStandard" id="ByDayFlowStandardResult">
        <result property="id" column="id"/>
        <result property="taskCode" column="task_code"/>
        <result property="standardTitle" column="standard_title"/>
        <result property="standardSort" column="standard_sort"/>
        <result property="unscrambleCount" column="unscramble_count"/>
        <result property="createuser" column="createuser"/>
        <result property="score" column="score"/>
        <result property="createtime" column="createtime"/>
        <result property="updateuser" column="updateuser"/>
        <result property="updatetime" column="updatetime"/>
        <result property="mrz" column="mrz"/>
    </resultMap>

    <sql id="selectByDayFlowStandardVo">
        select id, task_code, standard_title, score, standard_sort,(select count(*) from by_day_flow_unscramble where standard_id=by_day_flow_standard.id) unscramble_count, createuser, createtime, updateuser, updatetime from by_day_flow_standard
    </sql>

    <select id="selectByDayFlowStandardList" parameterType="ByDayFlowStandard" resultMap="ByDayFlowStandardResult">
        <include refid="selectByDayFlowStandardVo"/>
        <where>
            <if test="taskCode != null ">and task_code = #{taskCode}</if>
            <if test="standardTitle != null  and standardTitle != ''">and standard_title like concat('%',
                #{standardTitle}, '%')
            </if>
            <if test="standardSort != null ">and standard_sort = #{standardSort}</if>
            <if test="createuser != null ">and createuser = #{createuser}</if>
            <if test="score != null ">and score = #{score}</if>
            <if test="createtime != null ">and createtime = #{createtime}</if>
            <if test="updateuser != null ">and updateuser = #{updateuser}</if>
            <if test="updatetime != null ">and updatetime = #{updatetime}</if>
        </where>
    </select>

    <select id="selectByDayFlowStandardListAssessment" parameterType="ByDayFlowStandard" resultMap="ByDayFlowStandardResult">
        select a.id, a.task_code, a.standard_title, a.score, a.standard_sort, a.createuser, a.createtime, a.updateuser, a.updatetime,b.value as mrz from by_day_flow_standard a
        left join (select * from by_dayflowassessmentitem where pid=#{id}) b on a.id=b.item
    </select>

    <select id="selectByDayFlowStandardById" parameterType="Long" resultMap="ByDayFlowStandardResult">
        <include refid="selectByDayFlowStandardVo"/>
        where id = #{id}
    </select>

    <insert id="insertByDayFlowStandard" parameterType="ByDayFlowStandard" useGeneratedKeys="true" keyProperty="id">
        insert into by_day_flow_standard
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskCode != null ">task_code,</if>
            <if test="standardTitle != null  and standardTitle != ''">standard_title,</if>
            <if test="standardSort != null ">standard_sort,</if>
            <if test="createuser != null ">createuser,</if>
            <if test="score != null ">score,</if>
            <if test="createtime != null ">createtime,</if>
            <if test="updateuser != null ">updateuser,</if>
            <if test="updatetime != null ">updatetime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskCode != null ">#{taskCode},</if>
            <if test="standardTitle != null  and standardTitle != ''">#{standardTitle},</if>
            <if test="standardSort != null ">#{standardSort},</if>
            <if test="createuser != null ">#{createuser},</if>
            <if test="score != null ">#{score},</if>
            <if test="createtime != null ">#{createtime},</if>
            <if test="updateuser != null ">#{updateuser},</if>
            <if test="updatetime != null ">#{updatetime},</if>
        </trim>
    </insert>

    <update id="updateByDayFlowStandard" parameterType="ByDayFlowStandard">
        update by_day_flow_standard
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskCode != null ">task_code = #{taskCode},</if>
            <if test="standardTitle != null  and standardTitle != ''">standard_title = #{standardTitle},</if>
            <if test="standardSort != null ">standard_sort = #{standardSort},</if>
            <if test="createuser != null ">createuser = #{createuser},</if>
            <if test="score != null ">score = #{score},</if>
            <if test="createtime != null ">createtime = #{createtime},</if>
            <if test="updateuser != null ">updateuser = #{updateuser},</if>
            <if test="updatetime != null ">updatetime = #{updatetime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteByDayFlowStandardById" parameterType="Long">
        delete from by_day_flow_standard where id = #{id}
    </delete>

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

</mapper>