<?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="cn.roadm.mapper.NullCheckGroupMapper">

    <resultMap id="BaseResultMap" type="cn.roadm.bo.NullCheckGroup">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="value" property="value" jdbcType="VARCHAR"/>
        <result column="gid" property="gid" jdbcType="INTEGER"/>
        <result column="weight" property="weight" jdbcType="INTEGER"/>
        <result column="otype" property="otype" jdbcType="INTEGER"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, value, gid, weight, otype, status, create_time, update_time
    </sql>

    <select id="listPageNullCheckGroup" parameterType="cn.roadm.bo.NullCheckGroup" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sms_null_check_group
        WHERE status = 0
        <if test="gid != null">
            AND gid = #{gid}
        </if>
        <if test="otype != null">
            AND otype = #{otype}
        </if>
        <if test="value != null and value != ''">
            AND value LIKE CONCAT('%', #{value}, '%')
        </if>
        ORDER BY gid ASC, weight DESC, id ASC
        <if test="page != null">
            LIMIT #{page.startIndex}, #{page.pageSize}
        </if>
    </select>

    <select id="getNullCheckGroupById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sms_null_check_group
        WHERE id = #{id} AND status = 0
    </select>

    <insert id="insertNullCheckGroup" parameterType="cn.roadm.bo.NullCheckGroup" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sms_null_check_group (
            value, gid, weight, otype, status, create_time, update_time
        ) VALUES (
            #{value}, #{gid}, #{weight}, #{otype}, #{status}, #{createTime}, #{updateTime}
        )
    </insert>

    <update id="updateNullCheckGroup" parameterType="cn.roadm.bo.NullCheckGroup">
        UPDATE sms_null_check_group
        <set>
            <if test="value != null and value != ''">
                value = #{value},
            </if>
            <if test="gid != null">
                gid = #{gid},
            </if>
            <if test="weight != null">
                weight = #{weight},
            </if>
            <if test="otype != null">
                otype = #{otype},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            update_time = #{updateTime}
        </set>
        WHERE id = #{id}
    </update>

    <update id="deleteNullCheckGroup" parameterType="java.lang.Integer">
        UPDATE sms_null_check_group
        SET status = 1, update_time = NOW()
        WHERE id = #{id}
    </update>

    <select id="getNullCheckGroupsByGid" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sms_null_check_group
        WHERE gid = #{gid} AND status = 0
        ORDER BY weight DESC, id ASC
    </select>

    <select id="getAllGroupNames" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sms_null_check_group
        WHERE gid = 0 AND status = 0
        ORDER BY id ASC
    </select>


</mapper>
