<?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.care.mapper.CareScoresMapper">
    
    <resultMap type="CareScores" id="CareScoresResult">
        <result property="scoreId"    column="score_id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="userId"    column="user_id"    />
        <result property="assess"    column="assess"    />
        <result property="reason"    column="reason"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCareScoresVo">
        select score_id, apply_id, user_id, assess, reason, del_flag, create_by, create_time, update_by, update_time, remark from care_scores
    </sql>

    <select id="selectCareScoresList" parameterType="CareScores" resultMap="CareScoresResult">
        <include refid="selectCareScoresVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="assess != null  and assess != ''"> and assess = #{assess}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
        </where>
    </select>
    
    <select id="selectCareScoresByScoreId" parameterType="Long" resultMap="CareScoresResult">
        <include refid="selectCareScoresVo"/>
        where score_id = #{scoreId}
    </select>

    <insert id="insertCareScores" parameterType="CareScores" useGeneratedKeys="true" keyProperty="scoreId">
        insert into care_scores
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="userId != null and userId != ''">user_id,</if>
            <if test="assess != null and assess != ''">assess,</if>
            <if test="reason != null">reason,</if>
            <if test="delFlag != null">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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="userId != null and userId != ''">#{userId},</if>
            <if test="assess != null and assess != ''">#{assess},</if>
            <if test="reason != null">#{reason},</if>
            <if test="delFlag != null">#{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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCareScores" parameterType="CareScores">
        update care_scores
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="userId != null and userId != ''">user_id = #{userId},</if>
            <if test="assess != null and assess != ''">assess = #{assess},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="delFlag != null">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="remark != null">remark = #{remark},</if>
        </trim>
        where score_id = #{scoreId}
    </update>

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

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