<?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.ManualServiceSessionsMapper">
    
    <resultMap type="ManualServiceSessions" id="ManualServiceSessionsResult">
        <result property="manualSessionId" column="id"            />
        <result property="sessionId"     column="session_id"    />
        <result property="userId"        column="user_id"       />
        <result property="serviceId"     column="service_id"    />
        <result property="serviceStaff"  column="service_staff" />
        <result property="startTime"     column="start_time"    />
        <result property="endTime"       column="end_time"      />
        <result property="status"        column="status"        />
        <result property="requestTime"   column="request_time"  />
        <result property="acceptTime"    column="accept_time"   />
        <result property="reason"        column="reason"        />
        <result property="rating"        column="rating"        />
        <result property="feedback"      column="feedback"      />
        <result property="createTime"    column="create_time"   />
        <result property="updateTime"    column="update_time"   />
    </resultMap>

    <sql id="selectManualServiceSessionsVo">
        select id, session_id, user_id, service_id, service_staff, start_time, end_time, status, request_time, accept_time, reason, rating, feedback, create_time, update_time from manual_service_sessions
    </sql>

    <select id="selectManualServiceSessionsList" parameterType="ManualServiceSessions" resultMap="ManualServiceSessionsResult">
        <include refid="selectManualServiceSessionsVo"/>
        <where>  
            <if test="sessionId != null "> and session_id = #{sessionId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="serviceStaff != null  and serviceStaff != ''"> and service_staff = #{serviceStaff}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectManualServiceSessionsById" parameterType="Long" resultMap="ManualServiceSessionsResult">
        <include refid="selectManualServiceSessionsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertManualServiceSessions" parameterType="ManualServiceSessions" useGeneratedKeys="true" keyProperty="manualSessionId">
        insert into manual_service_sessions
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sessionId != null">session_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="serviceId != null">service_id,</if>
            <if test="serviceStaff != null">service_staff,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="status != null">status,</if>
            <if test="requestTime != null">request_time,</if>
            <if test="acceptTime != null">accept_time,</if>
            <if test="reason != null">reason,</if>
            <if test="rating != null">rating,</if>
            <if test="feedback != null">feedback,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sessionId != null">#{sessionId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="serviceId != null">#{serviceId},</if>
            <if test="serviceStaff != null">#{serviceStaff},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="status != null">#{status},</if>
            <if test="requestTime != null">#{requestTime},</if>
            <if test="acceptTime != null">#{acceptTime},</if>
            <if test="reason != null">#{reason},</if>
            <if test="rating != null">#{rating},</if>
            <if test="feedback != null">#{feedback},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateManualServiceSessions" parameterType="ManualServiceSessions">
        update manual_service_sessions
        <trim prefix="SET" suffixOverrides=",">
            <if test="sessionId != null">session_id = #{sessionId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="serviceId != null">service_id = #{serviceId},</if>
            <if test="serviceStaff != null">service_staff = #{serviceStaff},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="requestTime != null">request_time = #{requestTime},</if>
            <if test="acceptTime != null">accept_time = #{acceptTime},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="rating != null">rating = #{rating},</if>
            <if test="feedback != null">feedback = #{feedback},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{manualSessionId}
    </update>

    <delete id="deleteManualServiceSessionsById" parameterType="Long">
        delete from manual_service_sessions where id = #{manualSessionId}
    </delete>

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

</mapper>