<?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.com.victorysoft.business.cyyzs.dao.TubularStructureDao">

    <select id="selectList" resultType="cn.com.victorysoft.business.cyyzs.entity.TubularStructureHome">
        select
            gylx,
            sum(case when zjsj <![CDATA[ < ]]> 1 then 1 else 0 end) zjsjxyyn,
            sum(case when zjsj >= 1 and zjsj <![CDATA[ < ]]> 2 then 1 else 0 end) zjsjyen,
            sum(case when zjsj >= 2 and zjsj <![CDATA[ < ]]> 3 then 1 else 0 end) zjsjesn,
            sum(case when zjsj >= 3 and zjsj <![CDATA[ < ]]> 4 then 1 else 0 end) zjsjssn,
            sum(case when zjsj >= 4 and zjsj <![CDATA[ < ]]> 5 then 1 else 0 end) zjsjswn,
            sum(case when zjsj >= 5 then 1 else 0 end) zjsjwnys
        from
            water_tubular_structure
        where
            1 = 1
        <if test="yclx != null and yclx != ''"> </if>
        <if test="dydm != null and dydm != ''"> and dydm = #{dydm}</if>
        <if test="dwdm != null and dwdm != ''"> and dwdm = #{dwdm}</if>
        <if test="cslb != null and cslb != ''"> and cslb = #{cslb}</if>
        group by gylx
    </select>

    <select id="selectDetails" resultType="cn.com.victorysoft.business.cyyzs.entity.TubularStructure">
        select
            a.*,
            (select unitname from sys_unitinfo where unitcode = a.dwdm) dwmc,
            (select blockname from sys_blockinfo where blockcode = a.dydm) dymc,
            (select flag_name from sys_flag where flag_code = a.gylx) gylx_name,
            (select flag_name from sys_flag where flag_code = a.cslb) cslb_name
        from
            water_tubular_structure a
        where
            1 = 1
        <if test="yclx != null and yclx != ''"> </if>
        <if test="dwdm != null and dwdm != ''"> and a.dwdm = #{dwdm}</if>
        <if test="dydm != null and dydm != ''"> and a.dydm = #{dydm}</if>
        <if test="jh != null and jh != ''"> and a.jh = #{jh}</if>
        <if test="gylx != null and gylx != ''"> and a.gylx = #{gylx}</if>
        <if test="fgq != null and fgq != ''"> and a.fgq = #{fgq}</if>
        <if test="cdPsq != null and cdPsq != ''"> and a.cd_psq = #{cdPsq}</if>
        <if test="xjf != null and xjf != ''"> and a.xjf = #{xjf}</if>
    </select>


<!--    <select id="getBarData" resultType="cn.com.victorysoft.business.cyyzs.entity.TubularStructureHome">-->
<!--        select-->
<!--            *-->
<!--        from-->
<!--        (-->
<!--            select-->
<!--                a.flag_code gylx,-->
<!--                nvl(b.zjsjxyyn, 0) zjsjxyyn, nvl(b.zjsjyen, 0) zjsjyen, nvl(b.zjsjesn, 0) zjsjesn, nvl(b.zjsjssn, 0) zjsjssn, nvl(b.zjsjswn, 0) zjsjswn, nvl(b.zjsjwnys, 0) zjsjwnys-->
<!--            from-->
<!--                (select * from sys_flag where category_code = 'GYLX') a-->
<!--            left join (-->
<!--                select-->
<!--                    gylx,-->
<!--                    sum(case when zjsj <![CDATA[ < ]]> 1 then 1 else 0 end) zjsjxyyn,-->
<!--                    sum(case when zjsj >= 1 and zjsj <![CDATA[ < ]]> 2 then 1 else 0 end) zjsjyen,-->
<!--                    sum(case when zjsj >= 2 and zjsj <![CDATA[ < ]]> 3 then 1 else 0 end) zjsjesn,-->
<!--                    sum(case when zjsj >= 3 and zjsj <![CDATA[ < ]]> 4 then 1 else 0 end) zjsjssn,-->
<!--                    sum(case when zjsj >= 4 and zjsj <![CDATA[ < ]]> 5 then 1 else 0 end) zjsjswn,-->
<!--                    sum(case when zjsj >= 5 then 1 else 0 end) zjsjwnys-->
<!--                from-->
<!--                    water_tubular_structure-->
<!--                <if test="yclx != null and yclx != ''"> </if>-->
<!--                <if test="dydm != null and dydm != ''"> and dydm = #{dydm}</if>-->
<!--                <if test="dwdm != null and dwdm != ''"> and dwdm = #{dwdm}</if>-->
<!--                <if test="cslb != null and cslb != ''"> and cslb = #{cslb}</if>-->
<!--                group by gylx-->
<!--            ) b on a.flag_code  = b.gylx-->
<!--        ) a-->
<!--    </select>-->
</mapper>