<?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.sim.mapper.SimMapper">

    <resultMap type="Sim" id="SimResult">
        <result property="simId" column="sim_id"/>
        <result property="seatId" column="seat_id"/>
        <result property="simType" column="sim_type"/>
        <result property="simState" column="sim_state"/>
        <result property="simSn" column="sim_sn"/>
        <result property="simNum" column="sim_num"/>
        <result property="lastSentTime" column="last_sent_time"/>
        <result property="lastReceivedTime" column="last_received_time"/>
        <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="remark" column="remark"/>
    </resultMap>

    <sql id="selectSimVo">
        select sim_id,
               seat_id,
               sim_type,
               sim_state,
               sim_sn,
               sim_num,
               last_sent_time,
               last_received_time,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from mx_sim
    </sql>

    <select id="selectSimList" parameterType="Sim" resultMap="SimResult">
        <include refid="selectSimVo"/>
        <where>
            <if test="seatId != null ">and seat_id = #{seatId}</if>
            <if test="simType != null  and simType != ''">and sim_type = #{simType}</if>
            <if test="simState != null  and simState != ''">and sim_state = #{simState}</if>
            <if test="simSn != null  and simSn != ''">and sim_sn = #{simSn}</if>
            <if test="simNum != null  and simNum != ''">and sim_num = #{simNum}</if>
            <if test="lastSentTime != null ">and last_sent_time = #{lastSentTime}</if>
            <if test="lastReceivedTime != null ">and last_received_time = #{lastReceivedTime}</if>
        </where>
    </select>

    <select id="selectSimBySimId" parameterType="Long" resultMap="SimResult">
        <include refid="selectSimVo"/>
        where sim_id = #{simId}
    </select>

    <insert id="insertSim" parameterType="Sim" useGeneratedKeys="true" keyProperty="simId">
        <selectKey keyProperty="simId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into mx_sim
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="seatId != null">seat_id,</if>
            <if test="simType != null and simType != ''">sim_type,</if>
            <if test="simState != null and simState != ''">sim_state,</if>
            <if test="simSn != null and simSn != ''">sim_sn,</if>
            <if test="simNum != null and simNum != ''">sim_num,</if>
            <if test="lastSentTime != null">last_sent_time,</if>
            <if test="lastReceivedTime != null">last_received_time,</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="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="seatId != null">#{seatId},</if>
            <if test="simType != null and simType != ''">#{simType},</if>
            <if test="simState != null and simState != ''">#{simState},</if>
            <if test="simSn != null and simSn != ''">#{simSn},</if>
            <if test="simNum != null and simNum != ''">#{simNum},</if>
            <if test="lastSentTime != null">#{lastSentTime},</if>
            <if test="lastReceivedTime != null">#{lastReceivedTime},</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="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateSim" parameterType="Sim">
        update mx_sim
        <trim prefix="SET" suffixOverrides=",">
            <if test="seatId != null">seat_id = #{seatId},</if>
            <if test="simType != null and simType != ''">sim_type = #{simType},</if>
            <if test="simState != null and simState != ''">sim_state = #{simState},</if>
            <if test="simSn != null and simSn != ''">sim_sn = #{simSn},</if>
            <if test="simNum != null and simNum != ''">sim_num = #{simNum},</if>
            <if test="lastSentTime != null">last_sent_time = #{lastSentTime},</if>
            <if test="lastReceivedTime != null">last_received_time = #{lastReceivedTime},</if>
            <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="remark != null">remark = #{remark},</if>
        </trim>
        where sim_id = #{simId}
    </update>

    <delete id="deleteSimBySimId" parameterType="Long">
        delete
        from mx_sim
        where sim_id = #{simId}
    </delete>

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