<?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.leromro.core.mapper.SecondOrdersMapper">
    <insert id="insertList" parameterType="java.util.List">
        INSERT INTO l_second_order (
        second_order_id,
        main_order_id,
        volunteer_id,
        service_category,
        service_type,
        service_subject,
        service_one_price,
        work_start_time,
        work_number,
        service_duration,
        address_id,
        work_date,
        create_time,
        create_by,
        update_time,
        update_by,
        order_status,
        remark
        ) VALUES
        <foreach collection="list" item="secondOrder" separator=",">
            <if test="secondOrder != null">
                (
                #{secondOrder.secondOrderId},
                 #{secondOrder.mainOrderId},
                #{secondOrder.volunteerId},
                #{secondOrder.serviceCategory},
                #{secondOrder.serviceType},
                #{secondOrder.serviceSubject},
                #{secondOrder.serviceOnePrice},
                #{secondOrder.workStartTime},
                #{secondOrder.workNumber},
                #{secondOrder.serviceDuration},
                #{secondOrder.addressId},
                #{secondOrder.workDate},
                #{secondOrder.createTime},
                #{secondOrder.createBy},
                #{secondOrder.updateTime},
                #{secondOrder.updateBy},
                #{secondOrder.orderStatus},
                #{secondOrder.remark}
                )
            </if>
        </foreach>
    </insert>

    <!--  <resultMap type="LVolunteerOrder" id="LVolunteerOrderResult">
          <result property="id"    column="id"    />
          <result property="orderId"    column="order_id"    />
          <result property="volunteerId"    column="volunteer_id"    />
          <result property="serviceCategory"    column="service_category"    />
          <result property="serviceType"    column="service_type"    />
          <result property="serviceSubject"    column="service_subject"    />
          <result property="workDate"    column="work_date"    />
          <result property="workStartTime"    column="work_start_time"    />
          <result property="workEndTime"    column="work_end_time"    />
          <result property="workNumber"    column="work_number"    />
          <result property="hours"    column="hours"    />
          <result property="addressId"    column="address_id"    />
          <result property="score"    column="score"    />
          <result property="remark"    column="remark"    />
          <result property="createTime"    column="create_time"    />
          <result property="createBy"    column="create_by"    />
          <result property="updateTime"    column="update_time"    />
          <result property="updateBy"    column="update_by"    />
          <result property="remake"    column="remake"    />
      </resultMap>

      <sql id="selectLVolunteerOrderVo">
          select id, order_id, volunteer_id, service_category, service_type, service_subject, work_date, work_start_time, work_end_time, work_number, hours, address_id, score, remark, create_time, create_by, update_time, update_by, remake from l_volunteer_order
      </sql>

      <select id="selectLVolunteerOrderList" parameterType="LVolunteerOrder" resultMap="LVolunteerOrderResult">
          <include refid="selectLVolunteerOrderVo"/>
          <where>
              <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
              <if test="volunteerId != null "> and volunteer_id = #{volunteerId}</if>
              <if test="serviceCategory != null "> and service_category = #{serviceCategory}</if>
              <if test="serviceType != null "> and service_type = #{serviceType}</if>
              <if test="serviceSubject != null "> and service_subject = #{serviceSubject}</if>
              <if test="workDate != null "> and work_date = #{workDate}</if>
              <if test="workStartTime != null "> and work_start_time = #{workStartTime}</if>
              <if test="workEndTime != null "> and work_end_time = #{workEndTime}</if>
              <if test="workNumber != null "> and work_number = #{workNumber}</if>
              <if test="hours != null "> and hours = #{hours}</if>
              <if test="addressId != null "> and address_id = #{addressId}</if>
              <if test="score != null "> and score = #{score}</if>
              <if test="remake != null  and remake != ''"> and remake = #{remake}</if>
          </where>
      </select>

      <select id="selectLVolunteerOrderById" parameterType="Long" resultMap="LVolunteerOrderResult">
          <include refid="selectLVolunteerOrderVo"/>
          where id = #{id}
      </select>

      <insert id="insertLVolunteerOrder" parameterType="LVolunteerOrder" useGeneratedKeys="true" keyProperty="id">
          insert into l_volunteer_order
          <trim prefix="(" suffix=")" suffixOverrides=",">
              <if test="orderId != null">order_id,</if>
              <if test="volunteerId != null">volunteer_id,</if>
              <if test="serviceCategory != null">service_category,</if>
              <if test="serviceType != null">service_type,</if>
              <if test="serviceSubject != null">service_subject,</if>
              <if test="workDate != null">work_date,</if>
              <if test="workStartTime != null">work_start_time,</if>
              <if test="workEndTime != null">work_end_time,</if>
              <if test="workNumber != null">work_number,</if>
              <if test="hours != null">hours,</if>
              <if test="addressId != null">address_id,</if>
              <if test="score != null">score,</if>
              <if test="remark != null">remark,</if>
              <if test="createTime != null">create_time,</if>
              <if test="createBy != null">create_by,</if>
              <if test="updateTime != null">update_time,</if>
              <if test="updateBy != null">update_by,</if>
              <if test="remake != null">remake,</if>
           </trim>
          <trim prefix="values (" suffix=")" suffixOverrides=",">
              <if test="orderId != null">#{orderId},</if>
              <if test="volunteerId != null">#{volunteerId},</if>
              <if test="serviceCategory != null">#{serviceCategory},</if>
              <if test="serviceType != null">#{serviceType},</if>
              <if test="serviceSubject != null">#{serviceSubject},</if>
              <if test="workDate != null">#{workDate},</if>
              <if test="workStartTime != null">#{workStartTime},</if>
              <if test="workEndTime != null">#{workEndTime},</if>
              <if test="workNumber != null">#{workNumber},</if>
              <if test="hours != null">#{hours},</if>
              <if test="addressId != null">#{addressId},</if>
              <if test="score != null">#{score},</if>
              <if test="remark != null">#{remark},</if>
              <if test="createTime != null">#{createTime},</if>
              <if test="createBy != null">#{createBy},</if>
              <if test="updateTime != null">#{updateTime},</if>
              <if test="updateBy != null">#{updateBy},</if>
              <if test="remake != null">#{remake},</if>
           </trim>
      </insert>

      <update id="updateLVolunteerOrder" parameterType="LVolunteerOrder">
          update l_volunteer_order
          <trim prefix="SET" suffixOverrides=",">
              <if test="orderId != null">order_id = #{orderId},</if>
              <if test="volunteerId != null">volunteer_id = #{volunteerId},</if>
              <if test="serviceCategory != null">service_category = #{serviceCategory},</if>
              <if test="serviceType != null">service_type = #{serviceType},</if>
              <if test="serviceSubject != null">service_subject = #{serviceSubject},</if>
              <if test="workDate != null">work_date = #{workDate},</if>
              <if test="workStartTime != null">work_start_time = #{workStartTime},</if>
              <if test="workEndTime != null">work_end_time = #{workEndTime},</if>
              <if test="workNumber != null">work_number = #{workNumber},</if>
              <if test="hours != null">hours = #{hours},</if>
              <if test="addressId != null">address_id = #{addressId},</if>
              <if test="score != null">score = #{score},</if>
              <if test="remark != null">remark = #{remark},</if>
              <if test="createTime != null">create_time = #{createTime},</if>
              <if test="createBy != null">create_by = #{createBy},</if>
              <if test="updateTime != null">update_time = #{updateTime},</if>
              <if test="updateBy != null">update_by = #{updateBy},</if>
              <if test="remake != null">remake = #{remake},</if>
          </trim>
          where id = #{id}
      </update>

      <delete id="deleteLVolunteerOrderById" parameterType="Long">
          delete from l_volunteer_order where id = #{id}
      </delete>

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

    <select id="selectVolunteerOrder" resultType="com.leromro.core.domain.vo.VolunteerOrdersVO">
        select lso.second_order_id ,lso.score ,lso.remark ,lso.second_order_id ,lso.order_status as orderStatus,lso.service_one_price as serviceOnePrice,la.user_id,
        la.address as address ,la.name as name,(select avatar from sys_user su where su.user_id = la.user_id ) as avatar
        from l_second_order lso left join l_address la on lso.address_id = la.address_id
        <where>
            <if test="userId != null">and volunteer_id = #{userId}</if>
            <if test="orderStatus != null ">and order_status = #{orderStatus}</if>
        </where>
    </select>

</mapper>