<?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.PinganChannelPoolMapper">

    <select id="listPagePinganChannelPool" parameterType="cn.roadm.bo.PinganChannelPoolItem"
            resultType="cn.roadm.bo.PinganChannelPoolItem">
        select
        p.id,
        p.channelid,
        p.account,
        p.gateType,
        p.realSPNumber,
        p.signName,
        p.spLoadArea,
        p.spUsableArea,
        p.modifyDate,
        p.spType,
        p.modifyFlag,
        p.spId,
        p.attribute
        from  pingan_channel_pool p
        where 1=1 and p.modifyFlag!='C'
        <if test="id!=null and id>0">
            and p.id=#{id}
        </if>
        <if test="channelid!=null and channelid>0">
            and p.channelid=#{channelid}
        </if>
        <if test="account!=null and account!=''">
            and p.account=#{account}
        </if>
        <if test="gateType!=null and gateType!=''">
            and p.gateType=#{gateType}
        </if>
        <if test="realSPNumber!=null and realSPNumber!=''">
            and p.realSPNumber=#{realSPNumber}
        </if>
        <if test="signName!=null and signName!=''">
            and p.signName=#{signName}
        </if>
        <if test="spLoadArea!=null and spLoadArea!=''">
            and p.spLoadArea=#{spLoadArea}
        </if>
        <if test="spUsableArea!=null and spUsableArea!=''">
            and p.spUsableArea=#{spUsableArea}
        </if>
        <if test="spType!=null and spType!=''">
            and p.spType=#{spType}
        </if>
        <if test="modifyFlag!=null and modifyFlag!='C'">
            and p.modifyFlag=#{modifyFlag}
        </if>
        <if test="attribute!=null and attribute!=''">
            and p.attribute=#{attribute}
        </if>
        <if test="modifyDate!=null and modifyDate!=''">
            and p.modifyDate&gt;=str_to_date(#{modifyDate},'%Y-%m-%d')
        </if>
        <if test="spId!=null and spId!=''">
            and p.spId=#{spId}
        </if>
        order by p.modifyDate desc
    </select>

    <insert id="insertPinganChannelPoolItem" parameterType="cn.roadm.bo.PinganChannelPoolItem" keyProperty="id">
        insert into pingan_channel_pool(channelid,account,gateType,realSPNumber,signName,spLoadArea,spUsableArea,modifyDate,spType,modifyFlag,attribute,spId)
        values(#{channelid},#{account},#{gateType},#{realSPNumber},#{signName},#{spLoadArea},#{spUsableArea},now(),#{spType},'A',#{attribute},#{spId});
    </insert>

    <update id="updatePinganChannelPoolItem" parameterType="cn.roadm.bo.PinganChannelPoolItem">
        UPDATE pingan_channel_pool set
        channelid=#{channelid},
        account=#{account},
        realSPNumber=#{realSPNumber},
        signName=#{signName},
        spLoadArea=#{spLoadArea},
        spUsableArea=#{spUsableArea},
        modifyDate=now(),
        spType=#{spType},
        spId=#{spId},
        modifyFlag='U',
        attribute=#{attribute} where id=#{id}
    </update>

    <update id="deletePinganChannelPoolItemById" parameterType="int">
        UPDATE pingan_channel_pool set
        modifyDate=now(),
        modifyFlag='C'
        where id=#{id}
    </update>

    <select id="getPinganChannelPoolItem" parameterType="cn.roadm.bo.PinganChannelPoolItem"
            resultType="cn.roadm.bo.PinganChannelPoolItem">
        select *  from  pingan_channel_pool p
        where 1=1 and p.modifyFlag!='C'
        <if test="id!=null and id>0">
            and p.id=#{id}
        </if>
        <if test="channelid!=null and channelid>0">
            and p.channelid=#{channelid}
        </if>
        <if test="account!=null and account!=''">
            and p.account=#{account}
        </if>
        <if test="gateType!=null and gateType!=''">
            and p.gateType=#{gateType}
        </if>
        <if test="realSPNumber!=null and realSPNumber!=''">
            and p.realSPNumber=#{realSPNumber}
        </if>
        <if test="signName!=null and signName!=''">
            and p.signName=#{signName}
        </if>
        <if test="spLoadArea!=null and spLoadArea!=''">
            and p.spLoadArea=#{spLoadArea}
        </if>
        <if test="spUsableArea!=null and spUsableArea!=''">
            and p.spUsableArea=#{spUsableArea}
        </if>
        <if test="spType!=null and spType!=''">
            and p.spType=#{spType}
        </if>
        <if test="modifyFlag!=null and modifyFlag!='C'">
            and p.modifyFlag=#{modifyFlag}
        </if>
        <if test="attribute!=null and attribute!=''">
            and p.attribute=#{attribute}
        </if>
        <if test="modifyDate!=null and modifyDate!=''">
            and p.modifyDate&gt;=str_to_date(#{modifyDate},'%Y-%m-%d')
        </if>
        <if test="spId!=null and spId!=''">
            and p.spId=#{spId}
        </if>
        limit 1
    </select>
</mapper>
