<?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.OrderSoundMapper">
    
    <resultMap type="OrderSound" id="OrderSoundResult">
        <result property="id"    column="id"    />
        <result property="oid"    column="oid"    />
        <result property="file"    column="file"    />
        <result property="workerUid"    column="worker_uid"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectOrderSoundVo">
        select id, oid, file, worker_uid, created_at, updated_at from order_sound
    </sql>

    <select id="selectOrderSoundList" parameterType="OrderSound" resultMap="OrderSoundResult">
        <include refid="selectOrderSoundVo"/>
        <where>  
            <if test="ocode != null "> and oid  in  (select b.id from order_data b where  b.order_id like concat('%',#{ocode},'%'))</if>
            <if test="workerUid != null "> and worker_uid = #{workerUid}</if>

        </where>
    </select>
    
    <select id="selectOrderSoundById" parameterType="Integer" resultMap="OrderSoundResult">
        <include refid="selectOrderSoundVo"/>
        where id = #{id}
    </select>

 <select id="selectOrderCallRecordsByOid" parameterType="Integer" resultType="Long">
        <include refid="selectOrderSoundVo"/>
        where oid = #{oid}
    </select>
    
<select id="selectCountOrderSoundByOid" parameterType="Long" resultType="Integer" >
    select count(0) from order_sound where oid= #{oid}
</select>


    <select id="selectOrderSoundByOid" parameterType="Long" resultMap="OrderSoundResult" >
        select * from order_sound where oid= #{oid}
    </select>



    <insert id="insertOrderSound" parameterType="OrderSound" useGeneratedKeys="true" keyProperty="id">
        insert into order_sound
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="oid != null">oid,</if>
            <if test="file != null and file != ''">file,</if>
            <if test="workerUid != null">worker_uid,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="oid != null">#{oid},</if>
            <if test="file != null and file != ''">#{file},</if>
            <if test="workerUid != null">#{workerUid},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateOrderSound" parameterType="OrderSound">
        update order_sound
        <trim prefix="SET" suffixOverrides=",">
            <if test="oid != null">oid = #{oid},</if>
            <if test="file != null and file != ''">file = #{file},</if>
            <if test="workerUid != null">worker_uid = #{workerUid},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderSoundById" parameterType="Integer">
        delete from order_sound where id = #{id}
    </delete>

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