<?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.frequency.orderoperatorhistory.mapper.OrderOperatorHistoryMapper">

    <resultMap type="com.ruoyi.frequency.orderoperatorhistory.entity.OrderOperatorHistory" id="OrderOperatorHistoryResult">
        <result property="id"    column="id"    />
        <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="delFlag"    column="del_flag"    />
        <result property="orderId"    column="order_id"    />
        <result property="type"    column="type"    />
        <result property="content"    column="content"    />
        <result property="userId"    column="user_id"    />
        <result property="userType"    column="user_type"    />
        <result property="ports"    column="ports"    />
        <association property="userInfo"    column="user_id" javaType="com.ruoyi.vo.UserInfo" resultMap="userInfo" />
    </resultMap>

    <resultMap id="userInfo" type="com.ruoyi.vo.UserInfo">
        <id     property="userId"    column="user_id"     />
        <result property="userType"  column="user_type"   />
        <result property="idNo"  column="id_no"   />
        <result property="nickname"  column="nickname"   />
        <result property="avatar" column="avatar"   />
        <result property="mobile" column="mobile"   />
    </resultMap>
    
    
    <sql id="selectOrderOperatorHistoryVo">
        select
            t.id ,
            t.create_by ,
            t.create_time ,
            t.update_by ,
            t.update_time ,
            t.del_flag ,
            t.order_id ,
            t.type,
            t.content ,
            t.user_id ,
            t.user_type,
            t.ports
        from t_order_operator_history AS t

    </sql>

    <select id="selectOrderOperatorHistoryList" parameterType="com.ruoyi.frequency.orderoperatorhistory.entity.OrderOperatorHistory" resultMap="OrderOperatorHistoryResult">
        <include refid="selectOrderOperatorHistoryVo"/>
        <where> AND t.del_flag != 2
            <if test="orderId != null "> and t.order_id = #{orderId}</if>
            <if test="type != null  and type != ''"> and t.type = #{type}</if>
            <if test="content != null  and content != ''"> and t.content = #{content}</if>
            <if test="userId != null "> and t.user_id = #{userId}</if>
            <if test="userType != null "> and t.user_type = #{userType}</if>
            <if test="delFlag != null and delFlag != ''"> and t.del_flag = #{delFlag}</if>
            <if test="ports != null and ports != ''"> and t.ports = #{ports}</if>
            <if test="beginTime != null ">
                and  t.create_time >= #{beginTime}

            </if>
            <if test="endTime != null ">
                and  t.create_time &lt; #{endTime}
            </if>
        </where>
        order by t.create_time desc
    </select>

    <select id="selectOrderOperatorHistoryById" parameterType="Long" resultMap="OrderOperatorHistoryResult">
        <include refid="selectOrderOperatorHistoryVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertOrderOperatorHistory" parameterType="com.ruoyi.frequency.orderoperatorhistory.entity.OrderOperatorHistory">
        insert into t_order_operator_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="delFlag != null">del_flag,</if>
            <if test="orderId != null">order_id,</if>
            <if test="type != null">type,</if>
            <if test="content != null">content,</if>
            <if test="userId != null">user_id,</if>
            <if test="userType != null">user_type,</if>
            <if test="ports != null">ports,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="delFlag != null">#{delFlag},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="type != null">#{type},</if>
            <if test="content != null">#{content},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userType != null">#{userType},</if>
            <if test="ports != null">#{ports},</if>
        </trim>
    </insert>

    <update id="updateOrderOperatorHistory" parameterType="com.ruoyi.frequency.orderoperatorhistory.entity.OrderOperatorHistory">
        update t_order_operator_history
        <trim prefix="SET" suffixOverrides=",">
            <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="delFlag != null">del_flag = #{delFlag},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="content != null">content = #{content},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="ports != null">ports = #{ports},</if>
        </trim>
        where id = #{id}
    </update>

</mapper>