<?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.tofly.watermeter.custom.mapper.statisticanalysis.WaterStatisticsMapper">

    <!--    <select id="getWaterTrend" resultType="hashmap">-->
    <!--        select nvl(sum(CBSL),0) as sum,(-->
    <!--        case when SBKJ <![CDATA[ <= ]]> 25 then 'DN15-DN25'-->
    <!--        when 40 <![CDATA[ <= ]]> SBKJ and SBKJ <![CDATA[ <= ]]> 60 then 'DN40-DN60'-->
    <!--        when 80 <![CDATA[ <= ]]> SBKJ and SBKJ <![CDATA[ <= ]]> 150 then 'DN80-DN150'-->
    <!--        when SBKJ >= 200 then '>=dn200'-->
    <!--        else '其他' end) as SBKJ-->
    <!--        from TF_YWPN_QFCBQFMXLS_W-->
    <!--        where CBPQ = #{cbpq}-->
    <!--        <if test="queryDate != null and queryDate != '' ">-->
    <!--            and to_char(CBRQ,'yyyy-mm') = #{queryDate}-->
    <!--        </if>-->
    <!--        group by CBPQ,-->
    <!--        case when SBKJ <![CDATA[ <= ]]> 25 then 'DN15-DN25'-->
    <!--        when 40 <![CDATA[ <= ]]> SBKJ and SBKJ <![CDATA[ <= ]]> 60 then 'DN40-DN60'-->
    <!--        when 80 <![CDATA[ <= ]]> SBKJ and SBKJ <![CDATA[ <= ]]> 150 then 'DN80-DN150'-->
    <!--        when SBKJ >= 200 then '>=dn200'-->
    <!--        else '其他' end-->
    <!--    </select>-->
<!--
    &lt;!&ndash;    from TF_YWPN_QFCBQFMXLS_W&ndash;&gt;
    <select id="getWaterTrend" resultType="hashmap">
        select CBPQ,to_char(CBRQ,'yyyy-mm') cbsj,sum(CBSL) ysl
        from TF_YWPN_QFCBQFMXLS_W
        where to_char(CBRQ,'yyyy-mm') between #{startDate} and #{endDate}
          and CBPQ = #{cbpq}
        group by to_char(CBRQ,'yyyy-mm'),CBPQ
        order by CBPQ,cbsj
    </select>-->
    <!-- 6.24 抄表数据存储调整 -->
    <select id="getWaterTrend" resultType="hashmap">
        select pq.QYBM CBPQ,to_char(cb.CBRQ,'yyyy-mm') cbsj,sum(cb.CBSL) ysl
        from TF_YWPN_YHBINGQY_W pq
            left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = pq.YHBH
        where pq.QYBM = #{cbpq}
          and to_char(cb.CBRQ,'yyyy-mm') between #{startDate} and #{endDate}
        group by pq.QYBM,to_char(cb.CBRQ,'yyyy-mm')
        order by cbsj
    </select>

    <!-- 6.25 修改sql TF_YWPN_QFCBQFMXLS_W替换 -->
    <select id="getWaterInquire" resultType="hashmap">
        select to_char(CBRQ,'yyyy-mm') as yearMonth,SUM(CBSL) as water
        from TF_YWPN_QFCBYWLS_W
        where YHBH = #{yhbh}
          and to_char(CBRQ,'yyyy-mm') between #{start} and #{end}
        group by CBRQ
        order by CBRQ
    </select>

    <!--    TF_YWPN_QFCBQFMXLS_W -->
    <!--    select CBPQ,CBB cbqyd,to_char(CBRQ,'yyyy-mm') cbsj,sum(CBSL) ysl
        from  TF_YWPN_QFCBQFMX_W
        where to_char(CBRQ,'yyyy-mm') between #{startDate} and #{endDate}
        and CBPQ = #{cbpq}
        group by to_char(CBRQ,'yyyy-mm'),CBPQ,CBB
        order by CBPQ,cbsj,cbqyd-->

<!--    <select id="getWaterTrendByQyd" resultType="hashmap" >
        select CBB cbqyd,to_char(CBRQ,'yyyy-mm') cbsj,sum(CBSL) ysl
        from  TF_YWPN_QFCBQFMXLS_W
        where to_char(CBRQ,'yyyy-mm') between #{startDate} and #{endDate}
          and CBPQ = #{cbpq}
        group by to_char(CBRQ,'yyyy-mm'),CBB
        order by cbqyd,cbsj
    </select>
    6.24 抄表数据表调整 sql语句调整
    -->
    <select id="getWaterTrendByQyd" resultType="hashmap" >
        select pq.QYDBM cbqyd,to_char(cb.CBRQ,'yyyy-mm') cbsj,sum(cb.CBSL) ysl
        from  TF_YWPN_YHBINGQY_W pq left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = pq.YHBH
        where pq.QYBM = #{cbpq}
          and to_char(cb.CBRQ,'yyyy-mm') between #{startDate} and #{endDate}
        group by to_char(cb.CBRQ,'yyyy-mm'),pq.QYDBM
        order by cbqyd,cbsj
    </select>

    <!--<select id="getWaterTrendDetail" resultType="hashmap" >
        select CBPQ,CBB cbqyd,sum(CBSL) ysl
        from TF_YWPN_QFCBQFMXLS_W
        where to_char(CBRQ,'yyyy-mm') = #{queryDate} and CBPQ = #{cbpq}
        group by CBPQ,CBB
        order by CBB
    </select>
        6.24 抄表数据表调整 sql语句调整
-->
    <select id="getWaterTrendDetail" resultType="hashmap" >
        select pq.QYBM cbpq,pq.QYDBM cbqyd,sum(cb.CBSL) ysl
        from TF_YWPN_YHBINGQY_W pq left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = pq.YHBH
        where pq.QYBM = #{cbpq} and to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
        group by pq.QYBM,pq.QYDBM
        order by pq.QYDBM
    </select>

    <!-- 6.24 抄表数据库表调整  -->
    <select id="getWaterTrendWaterDetail" resultType="hashmap" >
        select pq.YHBH yhbh,pq.QYBM cbpq,pq.QYDBM cbqyd,yh.YHXM,yh.YHDZ,yh.SBBH,yh.SBKJ,yh.SBCJ,yh.LXDH,
               yh.LXSJ,yh.YSXZ,yh.XZXF,cb.CBRQ,cb.SCDS,cb.CBSL,cb.KHLB,cb.SJHB,cb.SJSL,cb.SJTB
        from TF_YWPN_YHBINGQY_W pq
                 left join TF_YWPN_QFKHJBXX_W yh on yh.YHBH = pq.YHBH
                 left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = yh.YHBH
        where pq.QYBM = #{cbpq} and pq.QYDBM = #{cbqyd} and to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
        order by pq.YHBH
    </select>
    <!--
     select * from TF_YWPN_QFCBQFMXLS_W
        where CBPQ = '1' and CBB = '2' and to_char(CBRQ,'yyyy-mm') = '2021-04'
        order by YHBH
    -->
    <!-- 同样因为TF_YWPN_QFCBQFMXLS_W表字段问题，暂时只能查询MX表 6.11 -->
    <!--    <select id="getYWaterAnalysisByPqAndYearMonth" resultType="hashmap" >
            select YHBH,AUDIT_RESULT pass
            from TF_YWPN_QFCBQFMX_W
            where CBPQ = #{cbpq} and to_char(CBRQ,'yyyy-mm') = #{queryDate};
        </select>
        6.15 修改 先关联查询质检表 0为合格 1为不合格 确定为异常抄表 再去lx表关联用户及时间查询
        -->
<!--    <select id="getYWaterAnalysisByPqAndYearMonth" resultType="hashmap" >
        select cb.YHBH yhbh,rz.IS_QUALIFIED pass from TF_YWPN_QFCBQFMXLS_W cb
               left join (select CLIENT_NUMBER,IS_QUALIFIED from TF_YWPN_ZLRZ_W
                    where to_char(DISPATCH_TIME,'yyyy-,mm') = #{queryDate}) rz on rz.CLIENT_NUMBER = cb.YHBH
        where cb.CBPQ = #{cbpq} and to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
    </select>
    6.23 因抄表业务调整 再次修改水量相关查询统计
    -->
    <select id="getYWaterAnalysisByPqAndYearMonth" resultType="hashmap" >
        select yh.QYBM qybm,count(cb.ID) schs,count(yc.ID) noPass,round(count(cb.ID) - count(yc.ID)) pass
        from TF_YWPN_YHBINGQY_W yh
            left join TF_YWPN_QFCBYWLS_W cb on yh.YHBH = cb.YHBH
            left join TF_YWPN_QFCBYCSL_W yc on yc.KHID = cb.ID
        where yh.QYBM = #{cbpq}
          and  cb.CWRQ = #{queryDate}
        group by yh.QYBM
    </select>

    <!-- 同样因为 TF_YWPN_QFCBQFMXLS_W 表字段问题，暂时智能查询MX TF_YWPN_QFCBQFMX_W 表 6.11 -->
    <!-- 6.15 修改查询关联方式 -->
<!--    <select id="getWaterAnalysisDetail" resultType="hashmap" >
        select * from
            (select cb.*,nvl(ls.lsjl,0) lsjl,nvl(rz.IS_QUALIFIED,0) isPass,tb.CBSL tbsl,hb.CBSL hbsl
            from TF_YWPN_QFCBQFMXLS_W cb
                left join (select CLIENT_NUMBER,IS_QUALIFIED IS_QUALIFIED from TF_YWPN_ZLRZ_W
                    where to_char(DISPATCH_TIME,'yyyy-,mm') = #{queryDate}) rz on rz.CLIENT_NUMBER = cb.YHBH
                left join (select CLIENT_NUMBER,count(*) lsjl from TF_YWPN_ZLRZ_W
                    group by CLIENT_NUMBER ) ls on ls.CLIENT_NUMBER = cb.YHBH
                left join (select YHBH,CBSL from TF_YWPN_QFCBQFMXLS_W where to_char(CBRQ,'yyyy-mm') =
                    to_char(add_months(to_date(#{queryDate},'yyyy-mm'),-1) , 'yyyy-mm')) hb on hb.YHBH = cb.YHBH
                left join (select YHBH,CBSL from TF_YWPN_QFCBQFMXLS_W where to_char(CBRQ,'yyyy-mm') =
                    to_char(add_months(to_date(#{queryDate},'yyyy-mm'),-12) , 'yyyy-mm')) tb on tb.YHBH = cb.YHBH
             where cb.CBPQ = #{cbpq} and to_char(cb.CBRQ,'yyyy-mm') = #{queryDate} ) temp where isPass = #{isPass}
    </select>-->
    <!-- 6.24 因抄表业务表调整 再次修改水量相关查询统计 -->
    <select id="getWaterAnalysisDetail" resultType="hashmap" >
        select * from (
            select pq.YHBH yhbh,pq.QYBM cbpq,pq.QYDBM cbqyd,kh.YHXM yhxm,kh.SBKJ,kh.YSXZ,kh.XZXF,kh.SBCJ,kh.LXSJ,kh.LXDH,kh.SBBH,
                   kh.YHDZ,kh.AZRQ,cb.SCDS,cb.BCDS, cb.CBRQ,cb.CBSL,cb.KHLB,cb.QYSL,cb.SJSL,cb.SJTB||'%' as SJTB,cb.SJHB||'%' as SJHB,
                   (case when yc.ID is null then 1 else 0 end) isPass,nvl(ls.lsjl,0) lsjl
            from TF_YWPN_YHBINGQY_W pq
                left join TF_YWPN_QFKHJBXX_W kh on pq.YHBH = kh.YHBH
                left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = kh.YHBH
                left join  TF_YWPN_QFCBYCSL_W yc on yc.KHID = cb.ID
                left join (select CLIENT_NUMBER,count(*) lsjl from TF_YWPN_ZLRZ_W
                group by CLIENT_NUMBER ) ls on ls.CLIENT_NUMBER = cb.YHBH
            where pq.QYBM = #{cbpq} and to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
            ) temp where isPass = #{isPass}
    </select>

    <!--    <select id="getWaterAnalysisDetail" resultType="hashmap" >
            select cb.*,rz.IS_QUALIFIED isPass,tb.CBSL tbsl,hb.CBSL hbsl from TF_YWPN_QFCBQFMXLS_W cb
                   left join (select CLIENT_NUMBER,IS_QUALIFIED from TF_YWPN_ZLRZ_W where
                        to_char(DISPATCH_TIME,'yyyy-,mm') = #{queryDate}) rz on rz.CLIENT_NUMBER = cb.YHBH
                   left join (select * from TF_YWPN_QFCBQFMXLS_W where to_char(CBRQ,'yyyy-mm') =
                        to_char(add_months(to_date(#{queryDate},'yyyy-mm'),-1) , 'yyyy-mm')) tb on tb.YHBH = cb.YHBH
                   left join (select * from TF_YWPN_QFCBQFMXLS_W where to_char(CBRQ,'yyyy-mm') =
                        to_char(add_months(to_date(#{queryDate},'yyyy-mm'),-12) , 'yyyy-mm')) hb on hb.YHBH = cb.YHBH
            where cb.CBPQ = #{cbpq} and to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
              and isPass = #{isPass}
        </select>-->

<!--
    nvl(round( (t.CBSL - l.CBSL) * 100 / l.CBSL,2),0) sjbl
    优化cbsl 抄表数量为0的条件判断 修复除数为0错误问题
-->
<!--    <select id="getMonthReadMeterData" resultType="com.tofly.watermeter.custom.bo.MonthReadMeterDataBO" >
        select * from
        (select distinct t.YHBH,nvl(t.CBPQ,0) cbpq,
        nvl(t.SBKJ,0) sbkj,
        nvl(t.YSXZ,0) ysxz,
        nvl(t.CBSL,0) dysl,
        nvl(l.CBSL,0) sysl,
        decode(l.CBSL,0,100,round((t.CBSL - l.CBSL) * 100 / l.CBSL,2)) sjbl
        from TF_YWPN_QFCBQFMXLS_W t
        left join (select YHBH,CBSL from TF_YWPN_QFCBQFMXLS_W where to_char(CBRQ,'yyyy-mm') =
        to_char(add_months(to_date(#{queryDate},'yyyy-mm'),-1) , 'yyyy-mm')) l on l.YHBH = t.YHBH
        where to_char(CBRQ,'yyyy-mm') = #{queryDate}
        <choose>
            <when test="upOrDown.equals('down')">
                and round(t.CBSL - l.CBSL) <![CDATA[ < ]]> '0' order by sjbl
            </when>
            <when test="upOrDown.equals('up')">
                and round(t.CBSL - l.CBSL) > '0' order by sjbl desc
            </when>
        </choose>
        ) where ROWNUM <![CDATA[ <= ]]> #{numberParam}
    </select>
    6.25 数据库表调整 修改sql
    -->
    <select id="getMonthReadMeterData" resultType="com.tofly.watermeter.custom.bo.MonthReadMeterDataBO" >
        select * from
        (select distinct pq.YHBH yhbh,
        nvl(pq.QYBM,0) cbpq,
        nvl(kh.SBKJ,0) sbkj,
        nvl(kh.YSXZ,0) ysxz,
        nvl(cb.CBSL,0) dysl,
        nvl(cb.QYSL,0) sysl,
        decode(cb.CBSL,0,100,round(cb.SJSL * 100 / cb.CBSL,2)) sjbl
        from TF_YWPN_YHBINGQY_W pq
        left join TF_YWPN_QFKHJBXX_W kh on kh.YHBH = pq.YHBH
        left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = pq.YHBH
        where to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
        <choose>
            <when test="upOrDown.equals('down')">
                and cb.SJSL <![CDATA[ < ]]> '0' order by sjbl
            </when>
            <when test="upOrDown.equals('up')">
                and cb.SJSL > '0' order by sjbl desc
            </when>
        </choose>
        ) where ROWNUM <![CDATA[ <= ]]> #{numberParam}
    </select>

    <!-- TF_YWPN_QFCBYWLS_W 普表与远传表水量信息表 -->
    <select id="getYoYWaterByKHBH" resultType="hashmap" >
        select nvl(CBSL,0) dysl,to_char(CBRQ,'yyyy-mm') cbrq,CWRQ cwrq,nvl(SJTB,0) sjtb
        from TF_YWPN_QFCBYWLS_W where YHBH = #{khbh} and CBRQ between to_date(#{startDate},'yyyy-mm') and to_date( #{endDate},'yyyy-mm')
    </select>

    <select id="getMoMWaterByKHBH" resultType="hashmap" >
        select to_char(CBRQ,'yyyy-mm') cbrq,CWRQ cwrq,nvl(CBSL,0) dysl ,nvl(SJHB,0) sjhb from TF_YWPN_QFCBYWLS_W
        where YHBH = #{khbh} and to_char(CBRQ,'yyyy-mm') between #{startDate} and #{endDate}

    </select>

    <select id="getFuzzyQueryUsers" resultType="hashmap" >
        select YHBH,YHXM,LXDH,LXSJ,YHDZ,SBKJ,SBBH,SBCJ,SBLX,YSXZ,XZXF
        from TF_YWPN_QFKHJBXX_W
        where YHBH like '%'||#{yhbh}||'%' or YHXM like '%'||#{yhbh}||'%'
    </select>
    
    <!--<select id="getWaterFluctuationDetail" resultType="hashmap" >
        select cb.*,hb.CBSL sysl
        from TF_YWPN_QFCBQFMXLS_W cb
        left join (select YHBH,CBSL from TF_YWPN_QFCBQFMXLS_W where to_char(CBRQ,'yyyy-mm') =
        to_char(add_months(to_date(#{queryDate},'yyyy-mm'),-1) , 'yyyy-mm')) hb on hb.YHBH = cb.YHBH
        where to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
        and cb.YHBH in
        <if test="khbh != null and khbh != '' ">
            <foreach collection="khbh.split(',')" item="yhbh" open="(" separator="," close=")">
                #{yhbh}
            </foreach>
        </if>
    </select>
    6.25 数据库表调整 修改sql
    -->
    <select id="getWaterFluctuationDetail" resultType="hashmap" >
        select distinct pq.YHBH yhbh,kh.YHXM yhxm,pq.QYBM cbpq,pq.QYDBM cbqyd,kh.YSXZ ysxz,kh.XZXF xzxf,kh.SBKJ sbkj,
        kh.SBCJ sbcj,cb.SCDS scds,cb.BCDS bcds,cb.CBRQ cbrq,cb.CBSL cbsl,cb.KHLB khlb,cb.QYSL qysl,
        cb.SJSL sjsl,cb.SJTB sjtb,cb.SJHB sjhb
        from TF_YWPN_YHBINGQY_W pq
        left join TF_YWPN_QFKHJBXX_W kh on kh.YHBH = pq.YHBH
        left join TF_YWPN_QFCBYWLS_W cb on cb.YHBH = pq.YHBH
        where to_char(cb.CBRQ,'yyyy-mm') = #{queryDate}
        and pq.YHBH in
        <if test="khbh != null and khbh != '' ">
            <foreach collection="khbh.split(',')" item="yhbh" open="(" separator="," close=")">
                #{yhbh}
            </foreach>
        </if>
    </select>

    <select id="getCWRQMaxTime" resultType="String" >
        SELECT MAX(CWRQ) cwrq FROM TF_YWPN_QFCBYWLS_W
    </select>

    <select id="getMaxId" resultType="Long" >
        SELECT MAX(ID) id FROM TF_YWPN_QFCBYWLS_W
    </select>


    <insert id="insertWaterQuantity" parameterType="java.util.List">
        INSERT INTO TF_YWPN_QFCBYWLS_W (ID,YHBH, CWRQ, CBRQ,CBSL,KHLB,CREATE_TIME,QYSL,SJSL,SJTB,SJHB,FRONT_ZERO,FRONT_LIFT,FIRST_CB,FRONT_EQUAL)
        select id, yhbh, cwrq, cbrq, cbsl, khlb, createTime,qysl, (nvl(cbsl,0)-nvl(qysl,0)) as sjsl
             ,nvl(decode(yearavg,0,'',round((cbsl-yearavg)/yearavg*100,2)),yearavg) as sjtb
             ,nvl(decode(monthavg,0,'',round((cbsl-monthavg)/monthavg*100,2)),monthavg) as sjtb
             ,FRONT_ZERO,FRONT_LIFT,FIRST_CB,FRONT_EQUAL
        from (
        <foreach collection="list" item="info" index="index" separator="union all">
            SELECT * FROM(
            select #{info.id} id,#{info.yhbh}
                yhbh,#{info.cwrq} cwrq,#{info.cbrq} cbrq,#{info.cbsl} cbsl,#{info.khlb}
                khlb,#{info.createTime} createTime
                ,(select Max(CBSL) from TF_YWPN_QFCBYWLS_W w where w.YHBH = #{info.yhbh} and w.CWRQ =#{info.scwrq} ) as
                qysl
            <choose>
                <when test="info.yearMonth != null and info.yearMonth >= 20210101 ">
                ,(SELECT sum(CBSL)/3 FROM TF_YWPN_QFCBYWLS_W w WHERE w.YHBH = #{info.yhbh} and w.CWRQ IN
                <foreach collection="info.years" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach>
                ) yearavg
                </when>
                <otherwise>
                ,0 as yearavg
                </otherwise>
            </choose>
            FROM DUAL
            ),
            <![CDATA[
            (
                SELECT  sum(CBSLAVG)/3 as monthavg,
            (CASE WHEN sum(FCBSL) =0 THEN 1 ELSE 0 END  ) as FRONT_ZERO,
            (CASE WHEN sum(sign(decode(SJSL,null,0,SJSL))) = 11 THEN 1 WHEN sum(sign(decode(SJSL,null,0,SJSL))) = -11 THEN 2 ELSE 0 END) FRONT_LIFT ,
            (CASE WHEN  count(CBSL)>0 THEN 0 ELSE 1 END ) FIRST_CB ,
            decode(sign(sum(EQUAL)),0,1,0) as  FRONT_EQUAL
            FROM (
            SELECT CBSL,SJSL,CBRQ,decode(sign(CBRQ-ADD_MONTHS(trunc( #{info.cbrq}, 'mm'),-5)),1,CBSL,0) FCBSL,
            decode(sign(CBRQ-ADD_MONTHS(trunc( #{info.cbrq}, 'mm'),-1)),1,SJSL,0) EQUAL,decode(sign(CBRQ-ADD_MONTHS(trunc( #{info.cbrq}, 'mm'),-3)),1,SJSL,0) CBSLAVG
            FROM TF_YWPN_QFCBYWLS_W z WHERE z.YHBH = #{info.yhbh} and z.CBRQ>ADD_MONTHS(trunc( #{info.cbrq}, 'mm'),-11) and  z.CBRQ <  #{info.cbrq} order by CBRQ desc
            ) tab
                )
            ]]>
        </foreach>
        )tb


    </insert>

    <insert id="insertQfcbycslData" >
        INSERT INTO TF_YWPN_QFCBYCSL_W (ID,YCYY,KHID)
        SELECT qfcbycsl_Seq.nextval,yc,id FROM (
        SELECT s.id,
        (CASE
            <![CDATA[
             WHEN q.xz = 1 and ((q.sbkj <= 25  and (s.CBSL>50 or (s.CBSL=0 and s.QYSL>0)))
        or  (q.sbkj > 25 and ( abs(decode(s.SJTB,null,0,s.SJTB))>50 or abs(decode(s.SJHB,null,0,s.SJHB))>50 ))) THEN 1
        WHEN q.xz = 0 and( (q.sbkj <= 25 and ( abs(decode(s.SJTB,null,0,s.SJTB))>50 or abs(decode(s.SJHB,null,0,s.SJHB))>50) )
        or  ((q.sbkj >=40 or q.sbkj<=50 ) and ( abs(decode(s.SJTB,null,0,s.SJTB))>40 or abs(decode(s.SJHB,null,0,s.SJHB))>40))
        or  (q.sbkj >=80  and ( abs(decode(s.SJTB,null,0,s.SJTB))>30 or abs(decode(s.SJHB,null,0,s.SJHB))>30))) THEN 2
        WHEN s.FRONT_ZERO = 0 and s.CBSL = 0 THEN 3
        WHEN  (s.FRONT_LIFT =1 and s.SJSL>0 ) or (s.FRONT_LIFT =2 and s.SJSL<0 ) THEN 5
        WHEN s.FIRST_CB =1 THEN 6
        WHEN s.FRONT_EQUAL = 0 and s.SJSL = 0 THEN 7
        ELSE 0 END) yc
        FROM TF_YWPN_QFCBYWLS_W s LEFT JOIN (
        SELECT YHBH, SBKJ,(case WHEN  YSXZ = '10000' or  YSXZ = '10004' or YSXZ = '10060' or YSXZ = '10020'  or YSXZ = '10024' or YSXZ = '10027' or YSXZ = '10033' THEN 1 ELSE 0 END) xz
        FROM TF_YWPN_QFKHJBXX_W ) q on (s.YHBH = q.YHBH) WHERE CWRQ = #{cwrq}) tb where yc > 0
        ]]>
    </insert>

    <delete id="deleteQfcbywlsCwrq">
        DELETE FROM TF_YWPN_QFCBYWLS_W WHERE CWRQ  = #{cwrq}
    </delete>

</mapper>
