<?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.PsdcWarnMapper">
    <resultMap type="com.psdc.entity.PsdcWarn" id="PsdcWarnMap">
        <result property="warnId" column="warn_id" />
        <result property="userId" column="user_id" />
        <result property="devId" column="dev_id" />
        <result property="warnName" column="warn_name" />
        <result property="warnType" column="warn_type" />
        <result property="warnDesc" column="warn_desc" />
        <result property="warnStatus" column="warn_status" />
        <result property="occurTime" column="occur_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" />
    </resultMap>

    <!-- 通过ID查询单条数据 -->
    <select id="queryById" resultMap="PsdcWarnMap">
        select
            warn_id,user_id,dev_id,warn_name,warn_type,warn_desc,warn_status,occur_time,create_by,create_time,update_by,update_time
        from psdc_warn
        where warn_id = #{warnId}
    </select>

    <!--分页查询指定行数据-->
    <select id="queryAllByLimit" resultMap="PsdcWarnMap">
        select
        warn_id,user_id,dev_id,warn_name,warn_type,warn_desc,warn_status,occur_time,create_by,create_time,update_by,update_time
        from psdc_warn
        <where>
            <if test="warnId != null and warnId != ''">
                and warn_id = #{warnId}
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
            <if test="devId != null and devId != ''">
                and dev_id = #{devId}
            </if>
            <if test="warnName != null and warnName != ''">
                and warn_name = #{warnName}
            </if>
            <if test="warnType != null and warnType != ''">
                and warn_type = #{warnType}
            </if>
            <if test="warnDesc != null and warnDesc != ''">
                and warn_desc = #{warnDesc}
            </if>
            <if test="warnStatus != null and warnStatus != ''">
                and warn_status = #{warnStatus}
            </if>
            <if test="occurTime != null and occurTime != ''">
                and occur_time = #{occurTime}
            </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_warn
        <where>
            <if test="warnId != null and warnId != ''">
                and warn_id = #{warnId}
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
            <if test="devId != null and devId != ''">
                and dev_id = #{devId}
            </if>
            <if test="warnName != null and warnName != ''">
                and warn_name = #{warnName}
            </if>
            <if test="warnType != null and warnType != ''">
                and warn_type = #{warnType}
            </if>
            <if test="warnDesc != null and warnDesc != ''">
                and warn_desc = #{warnDesc}
            </if>
            <if test="warnStatus != null and warnStatus != ''">
                and warn_status = #{warnStatus}
            </if>
            <if test="occurTime != null and occurTime != ''">
                and occur_time = #{occurTime}
            </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_warn(warn_id,user_id,dev_id,warn_name,warn_type,warn_desc,warn_status,occur_time,create_by,create_time,update_by,update_time)
        values (#{warnId},#{userId},#{devId},#{warnName},#{warnType},#{warnDesc},#{warnStatus},#{occurTime},#{createBy},#{createTime},#{updateBy},#{updateTime})
    </insert>


    <!-- 更新数据 -->
    <update id="update">
        update psdc_warn
        <set>
            <if test="warnId != null and warnId != ''">
                warn_id = #{warnId},
            </if>
            <if test="userId != null and userId != ''">
                user_id = #{userId},
            </if>
            <if test="devId != null and devId != ''">
                dev_id = #{devId},
            </if>
            <if test="warnName != null and warnName != ''">
                warn_name = #{warnName},
            </if>
            <if test="warnType != null and warnType != ''">
                warn_type = #{warnType},
            </if>
            <if test="warnDesc != null and warnDesc != ''">
                warn_desc = #{warnDesc},
            </if>
            <if test="warnStatus != null and warnStatus != ''">
                warn_status = #{warnStatus},
            </if>
            <if test="occurTime != null and occurTime != ''">
                occur_time = #{occurTime},
            </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 warn_id = #{warnId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from psdc_warn where warn_id = #{warnId}
    </delete>
</mapper>