<?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.OrderInfoMapper">
    
    <resultMap type="OrderInfo" id="OrderInfoResult">
        <result property="id" column="id"/>
        <result property="orderInfoId"    column="order_info_id"    />
        <result property="remark"    column="remark"    />
        <result property="sourceId"    column="source_id"    />
        <result property="workId"    column="work_id"    />
        <result property="status" column="status"/>
        <result property="refundTime" column="refund_time" />
        <result property="money" column="money"/>
    </resultMap>

    <resultMap id="OrderInfoDtoResult" type="OrderInfoDto">
        <result property="orderInfoId" column="order_info_id"/>
        <result property="sourceId" column="source_id"/>
        <result property="workId" column="work_id"/>
        <result property="status" column="status" />
        <result property="city" column="city"/>
        <result property="scenic" column="scenic"/>
        <result property="part" column="part" />
        <result property="workDetail" column="detail"/>
        <result property="workName" column="work_name"/>
        <result property="workAddress" column="work_address"/>
        <result property="workStatus" column="work_status" />
        <result property="userId" column="user_id" />
        <result property="coordinate" column="coordinate" />
        <result property="refundTime" column="refund_time"/>
        <result property="id" column="id"/>
        <result property="nickName" column="nick_name"/>
        <result property="cX" column="c_x"/>
        <result property="cY" column="c_y"/>

    </resultMap>

    <sql id="selectOrderInfoVo">
        select id, order_info_id, remark, source_id, work_id, money, status, refund_time from order_info
    </sql>

    <select id="selectOrderInfoList" parameterType="OrderInfo" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        <where>  
            <if test="sourceId != null "> and source_id = #{sourceId}</if>
            <if test="workId != null "> and work_id = #{workId}</if>
            <if test="status != null "> and status = #{status}</if>

        </where>
    </select>
    
    <select id="selectOrderInfoByOrderInfoId" parameterType="String" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        where order_info_id = #{orderInfoId}
    </select>
    <select id="getOrderInfoDtoList" resultMap="OrderInfoDtoResult" >

        select o.order_info_id, o.source_id, o.work_id, s.city, s.scenic, s.part,w.work_name ,w.detail, w.work_address,w.work_status, o.status, w.user_id, s.coordinate, o.refund_time, o.id, s.c_x, s.c_y
        from order_info o
        left join sys_source s on o.source_id = s.source_id
        left join user_work w on o.work_id = w.work_id
        where o.order_info_id = #{orderInfoId}


    </select>
    <select id="getOrderInfoByOrderInfoId" resultType="java.lang.Long">
        select id
        from order_info
        where order_info_id = #{orderInfoId}
    </select>
    <select id="getOrderInfoByOrderInfoIdAndWorkId" resultMap="OrderInfoResult">
        select *
        from order_info
        where order_info_id = #{orderInfoId} and work_id = #{workId}
    </select>


    <insert id="insertOrderInfo" parameterType="OrderInfo">
        insert into order_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderInfoId != null">order_info_id,</if>
            <if test="remark != null">remark,</if>
            <if test="sourceId != null">source_id,</if>
            <if test="workId != null">work_id,</if>
--             <if test="id != null">id,</if>
            <if test="status != null">status,</if>
            <if test="refundTime != null">refund_time,</if>
            <if test="money != null">money,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderInfoId != null">#{orderInfoId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="workId != null">#{workId},</if>
<!--            <if test="id != null">#{id},</if>-->
            <if test="status != null">#{status},</if>
            <if test="refundTime != null">#{refundTime},</if>
            <if test="money != null">#{money},</if>
         </trim>
    </insert>

    <update id="updateOrderInfo" parameterType="OrderInfo">
        update order_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="remark != null">remark = #{remark},</if>
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="workId != null">work_id = #{workId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="refundTime != null">refund_time = #{refundTime},</if>
            <if test="money != null">money = #{money},</if>
            <if test="orderInfoId != null">order_info_id = #{orderInfoId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderInfoByOrderInfoId" parameterType="Long">
        delete from order_info where order_info_id = #{orderInfoId}
    </delete>

    <delete id="deleteOrderInfoByOrderInfoIds" parameterType="Long">
        delete from order_info where order_info_id in 
        <foreach item="orderInfoId" collection="array" open="(" separator="," close=")">
            #{orderInfoId}
        </foreach>
    </delete>
</mapper>