<?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.psdc.mapper.PsdcDeviceMapper">
    <resultMap type="com.psdc.entity.PsdcDevice" id="PsdcDeviceMap">
        <result property="deviceId" column="device_id" />
        <result property="userId" column="user_id" />
        <result property="deviceType" column="device_type" />
        <result property="deviceSn" column="device_sn" />
        <result property="deviceName" column="device_name" />
        <result property="hardVersion" column="hard_version" />
        <result property="softVersion" column="soft_version" />
        <result property="deviceAddress" column="device_address" />
        <result property="startTime" column="start_time" />
        <result property="deviceStatus" column="device_status" />
        <result property="photoUrl" column="photo_url" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
    </resultMap>


    <!-- 通过ID查询单条数据 -->
    <select id="queryById" resultMap="PsdcDeviceMap">
        select
            device_id,user_id,device_type,device_sn,device_name,hard_version,soft_version,device_address,start_time,device_status,photo_url,create_by,create_time,update_by,update_time
        from psdc_device
        where device_id = #{deviceId}
    </select>

    <!--分页查询指定行数据-->
    <select id="queryAllByLimit" resultMap="PsdcDeviceMap">
        select
        device_id,user_id,device_type,device_sn,device_name,hard_version,soft_version,device_address,start_time,device_status,photo_url,create_by,create_time,update_by,update_time
        from psdc_device
        <where>
            <if test="deviceId != null and deviceId != ''">
                and device_id = #{deviceId}
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
            <if test="deviceType != null and deviceType != ''">
                and device_type = #{deviceType}
            </if>
            <if test="deviceSn != null and deviceSn != ''">
                and device_sn = #{deviceSn}
            </if>
            <if test="deviceName != null and deviceName != ''">
                and device_name = #{deviceName}
            </if>
            <if test="hardVersion != null and hardVersion != ''">
                and hard_version = #{hardVersion}
            </if>
            <if test="softVersion != null and softVersion != ''">
                and soft_version = #{softVersion}
            </if>
            <if test="deviceAddress != null and deviceAddress != ''">
                and device_address = #{deviceAddress}
            </if>
            <if test="startTime != null and startTime != ''">
                and start_time = #{startTime}
            </if>
            <if test="deviceStatus != null and deviceStatus != ''">
                and device_status = #{deviceStatus}
            </if>
            <if test="photoUrl != null and photoUrl != ''">
                and photo_url = #{photoUrl}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="createTime != null and createTime != ''">
                and create_time = #{createTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="updateTime != null and updateTime != ''">
                and update_time = #{updateTime}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from psdc_device
        <where>
            <if test="deviceId != null and deviceId != ''">
                and device_id = #{deviceId}
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
            <if test="deviceType != null and deviceType != ''">
                and device_type = #{deviceType}
            </if>
            <if test="deviceSn != null and deviceSn != ''">
                and device_sn = #{deviceSn}
            </if>
            <if test="deviceName != null and deviceName != ''">
                and device_name = #{deviceName}
            </if>
            <if test="hardVersion != null and hardVersion != ''">
                and hard_version = #{hardVersion}
            </if>
            <if test="softVersion != null and softVersion != ''">
                and soft_version = #{softVersion}
            </if>
            <if test="deviceAddress != null and deviceAddress != ''">
                and device_address = #{deviceAddress}
            </if>
            <if test="startTime != null and startTime != ''">
                and start_time = #{startTime}
            </if>
            <if test="deviceStatus != null and deviceStatus != ''">
                and device_status = #{deviceStatus}
            </if>
            <if test="photoUrl != null and photoUrl != ''">
                and photo_url = #{photoUrl}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="createTime != null and createTime != ''">
                and create_time = #{createTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="updateTime != null and updateTime != ''">
                and update_time = #{updateTime}
            </if>
        </where>
    </select>

    <!--新增数据-->
    <insert id="insert" >
        insert into psdc_device(user_id,device_type,device_sn,device_name,hard_version,soft_version,device_address,start_time,device_status,photo_url,create_by,create_time,update_by,update_time)
        values (#{userId},#{deviceType},#{deviceSn},#{deviceName},#{hardVersion},#{softVersion},#{deviceAddress},#{startTime},#{deviceStatus},#{photoUrl},#{createBy},#{createTime},#{updateBy},#{updateTime})
    </insert>

    <!-- 更新数据 -->
    <update id="update">
        update psdc_device
        <set>
            <if test="deviceId != null and deviceId != ''">
                device_id = #{deviceId},
            </if>
            <if test="userId != null and userId != ''">
                user_id = #{userId},
            </if>
            <if test="deviceType != null and deviceType != ''">
                device_type = #{deviceType},
            </if>
            <if test="deviceSn != null and deviceSn != ''">
                device_sn = #{deviceSn},
            </if>
            <if test="deviceName != null and deviceName != ''">
                device_name = #{deviceName},
            </if>
            <if test="hardVersion != null and hardVersion != ''">
                hard_version = #{hardVersion},
            </if>
            <if test="softVersion != null and softVersion != ''">
                soft_version = #{softVersion},
            </if>
            <if test="deviceAddress != null and deviceAddress != ''">
                device_address = #{deviceAddress},
            </if>
            <if test="startTime != null and startTime != ''">
                start_time = #{startTime},
            </if>
            <if test="deviceStatus != null and deviceStatus != ''">
                device_status = #{deviceStatus},
            </if>
            <if test="photoUrl != null and photoUrl != ''">
                photo_url = #{photoUrl},
            </if>
            <if test="createBy != null and createBy != ''">
                create_by = #{createBy},
            </if>
            <if test="createTime != null and createTime != ''">
                create_time = #{createTime},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            <if test="updateTime != null and updateTime != ''">
                update_time = #{updateTime},
            </if>
        </set>
        where device_id = #{deviceId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from psdc_device where device_id = #{deviceId}
    </delete>
</mapper>