<?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.mosty.base.manager.mapper.TbJcglKhtjMapper">
    <select id="getCount" resultType="int">
        <if test='orglevel == "3"'>
            select count(DISTINCT(ssxgajid)) from tb_jcgl_khtj where xt_sjzt = '1'
        </if>
        <if test='orglevel == "4"'>
            select count(DISTINCT(ssbmid)) from tb_jcgl_khtj where xt_sjzt = '1'
        </if>
        and xt_scbz = '0'
        <if test="bmdmList != null and bmdmList != ''">
            and ssbmdm like concat(#{bmdmList},'%')
        </if>

        <if test="kssj != null and kssj != ''">
            and date_format(tjrq,'%Y-%m-%d') >= #{kssj}
        </if>
        <if test="jssj != null and jssj != ''">
            and date_format(tjrq,'%Y-%m-%d') &lt;= #{jssj}
        </if>
    </select>


    <select id="getStatistics" resultType="java.util.Map">
        select
        <if test='searchType == "01"'>
            IFNULL(sum(ybb),0) ybb,IFNULL(sum(sjbb),0) sjbb,IFNULL(sum(wbb),0) wbb,IFNULL(sum(bbf),0) bbf,IFNULL(sum(bbkf),0) bbkf,IFNULL(sum(zsbb),0) zsbb
        </if>
        <if test='searchType == "02"'>
            IFNULL(sum(yxl),0) yxl,IFNULL(sum(sjxl),0) sjxl,IFNULL(sum(wxl),0) wxl,IFNULL(sum(xlf),0) xlf,IFNULL(sum(zsxl),0) zsxl,IFNULL(sum(xlkf),0) xlkf
        </if>
        <if test='searchType == "03"'>
            IFNULL(sum(yqs),0) yqs,IFNULL(sum(sjqs),0) sjqs,IFNULL(sum(wqs),0) wqs,IFNULL(sum(qsf),0) qsf,IFNULL(sum(qskf),0) qskf,IFNULL(sum(qskf),0) qskf
        </if>

        <if test='searchType == "04"'>
            IFNULL(sum(ycr),0) ycr,IFNULL(sum(sjcr),0) sjcr,IFNULL(sum(wcr),0) wcr,IFNULL(sum(crf),0) crf,IFNULL(sum(zscr),0) zscr,IFNULL(sum(crkf),0) crkf
        </if>
        <if test='searchType == "05"'>
            IFNULL(sum(ycc),0) ycc,IFNULL(sum(sjcc),0) sjcc,IFNULL(sum(wcc),0) wcc,IFNULL(sum(ccf),0) ccf,IFNULL(sum(zscc),0) zscc,IFNULL(sum(cckf),0) cckf
        </if>
        <if test='searchType == "06"'>
            IFNULL(sum(yxlsc),0) yxlsc,IFNULL(sum(sjxlsc),0) sjxlsc,IFNULL(sum(wxlsc),0) wxlsc,IFNULL(sum(xlscf),0) xlscf,IFNULL(sum(zsxlsc),0) zsxlsc,IFNULL(sum(xlsckf),0) xlsckf
        </if>
        <if test='searchType == "07"'>
            IFNULL(sum(yxllc),0) yxllc,IFNULL(sum(sjxllc),0) sjxllc,IFNULL(sum(wxllc),0) wxllc,IFNULL(sum(xllcf),0) xllcf,IFNULL(sum(zsxllc),0) zsxllc,IFNULL(sum(xllckf),0) xllckf
        </if>
        <if test='searchType == "08"'>
            IFNULL(sum(ycw),0) ycw,IFNULL(sum(sjcw),0) sjcw,IFNULL(sum(wcw),0) wcw,IFNULL(sum(cwf),0) cwf,IFNULL(sum(zscw),0) zscw,IFNULL(sum(cwkf),0) cwkf
        </if>
        ,IFNULL(sum(sxkf),0) sxkf
        from tb_jcgl_khtj where xt_sjzt = '1'
        and xt_scbz = '0'
        <if test="bmdmList != null and bmdmList != ''">
            and ssbmdm like concat(#{bmdmList},'%')
        </if>
        <if test="time != null and time != ''">
            and date_format(tjrq,'%Y-%m-%d') = #{time}
        </if>
    </select>

    <select id="getList" resultType="com.mosty.base.model.vo.jcgl.TbJcglKhtjVo">
        <if test='orglevel == "3"'>
            select ssxgajdm ssbmdm,ssxgaj ssbm, "3" orglevel,
        </if>
        <if test='orglevel == "4"'>
            select ssbmdm,ssbm, "4" orglevel,
        </if>
        <if test='searchType == "01"'>
            sum(ybb) ybb,sum(sjbb) sjbb,sum(wbb) wbb,sum(bbf) bbf,sum(zsbb) zsbb,sum(bbkf) bbkf
        </if>
        <if test='searchType == "02"'>
            sum(yxl) yxl,sum(sjxl) sjxl,sum(wxl) wxl,sum(xlf) xlf,sum(zsxl) zsxl,sum(xlkf) xlkf
        </if>
        <if test='searchType == "03"'>
            sum(yqs) yqs,sum(sjqs) sjqs,sum(wqs) wqs,sum(qsf) qsf,sum(zsqs) zsqs,sum(qskf) qskf
        </if>

        <if test='searchType == "04"'>
            sum(ycr) ycr,sum(sjcr) sjcr,sum(wcr) wcr,sum(crf) crf,sum(zscr) zscr,sum(crkf) crkf
        </if>

        <if test='searchType == "05"'>
            sum(ycc) ycc,sum(sjcc) sjcc,sum(wcc) wcc,sum(ccf) ccf,sum(zscc) zscc,sum(cckf) cckf
        </if>

        <if test='searchType == "06"'>
            sum(yxlsc) yxlsc,sum(sjxlsc) sjxlsc,sum(wxlsc) wxlsc,sum(xlscf) xlscf,sum(zsxlsc) zsxlsc,sum(xlsckf) xlsckf
        </if>

        <if test='searchType == "07"'>
            sum(yxllc) yxllc,sum(sjxllc) sjxllc,sum(wxllc) wxllc,sum(xllcf) xllcf,sum(zsxllc) zsxllc,sum(xllckf) xllckf
        </if>
        <if test='searchType == "08"'>
            sum(ycw) ycw,sum(sjcw) sjcw,sum(wcw) wcw,sum(cwf) cwf,sum(zscw) zscw,sum(cwkf) cwkf
        </if>


        <if test='searchType != "01" and searchType != "02" and searchType != "03" and searchType != "04" and searchType != "05" and searchType != "06" and searchType != "07"  and searchType != "08"'>
            sum(ybb) ybb,sum(sjbb) sjbb,sum(wbb) wbb,sum(bbf) bbf,sum(zsbb) zsbb,sum(bbkf) bbkf,
            sum(yxl) yxl,sum(sjxl) sjxl,sum(wxl) wxl,sum(xlf) xlf,sum(zsxl) zsxl,sum(xlkf) xlkf,
            sum(yqs) yqs,sum(sjqs) sjqs,sum(wqs) wqs,sum(qsf) qsf,sum(zsqs) zsqs,sum(qskf) qskf,
            sum(ycr) ycr,sum(sjcr) sjcr,sum(wcr) wcr,sum(crf) crf,sum(zscr) zscr,sum(crkf) crkf,
            sum(ycc) ycc,sum(sjcc) sjcc,sum(wcc) wcc,sum(ccf) ccf,sum(zscc) zscc,sum(cckf) cckf,
            sum(yxlsc) yxlsc,sum(sjxlsc) sjxlsc,sum(wxlsc) wxlsc,sum(xlscf) xlscf,sum(zsxlsc) zsxlsc,sum(xlsckf) xlsckf,
            sum(yxllc) yxllc,sum(sjxllc) sjxllc,sum(wxllc) wxllc,sum(xllcf) xllcf,sum(zsxllc) zsxllc,sum(xllckf) xllckf,
            sum(ycw) ycw,sum(sjcw) sjcw,sum(wcw) wcw,sum(cwf) cwf,sum(zscw) zscw,sum(cwkf) cwkf
        </if>
        ,sum(sxkf) sxkf  from tb_jcgl_khtj where xt_sjzt = '1'
        and xt_scbz = '0'
        <if test="bmdmList != null and bmdmList != ''">
            and ssbmdm like concat(#{bmdmList},'%')
        </if>
        <if test="kssj != null and kssj != ''">
            and date_format(tjrq,'%Y-%m-%d') >= #{kssj}
        </if>
        <if test="jssj != null and jssj != ''">
            and date_format(tjrq,'%Y-%m-%d') &lt;= #{jssj}
        </if>
        <if test='orglevel == "3"'>
            group by ssxgajdm,ssxgaj order by ssxgajdm
        </if>
        <if test='orglevel == "4"'>
            group by ssbmdm,ssbm order by ssbmdm
        </if>
        limit #{pageIndex},#{pageSize}
    </select>

    <select  id="getFxbm" resultType="com.mosty.base.model.vo.jcgl.TbJcglKhtjVo">
            <if test='orglevel == "3"'>
                select distinct ssxgajdm ssbmdm,ssxgaj ssbm, "3" orglevel
            </if>
            <if test='orglevel == "4"'>
                select distinct ssbmdm,ssbm, "4" orglevel
            </if>
            from tb_jcgl_khtj where xt_sjzt = '1'
            and xt_scbz = '0'
            <if test="bmdmList != null and bmdmList != ''">
                and ssbmdm like concat(#{bmdmList},'%')
            </if>
            <if test="kssj != null and kssj != ''">
                and date_format(tjrq,'%Y-%m-%d') >= #{kssj}
            </if>
            <if test="jssj != null and jssj != ''">
                and date_format(tjrq,'%Y-%m-%d') &lt;= #{jssj}
            </if>
    </select>
</mapper>