<?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="io.renren.modules.app.dao.Cxtj_FhmxzDao">

	<select id="queryByPage" parameterType="io.renren.modules.app.entity.Cxtj_FhmxzEntity"
		resultType="io.renren.modules.app.entity.Cxtj_FhmxzEntity">
		SELECT djrq,djlx,djbh,jfbj,jflx,dfbj,dflx,ye,ss FROM (
		SELECT STR_TO_DATE('2005-03-10','%Y-%m-%d') djrq,
		'期初余额' djlx ,
		'' djbh,
		0 dfbj,
		0 dflx,
		0 jfbj,
		0 jflx,
		SUM(CASE WHEN ywpzmx.jdf='0' THEN
		ywpzmx.je ELSE -ywpzmx.je END) ye,
		'0' ss
		FROM ywpz,
		ywpzmx
		WHERE
		ywpz.djbh = ywpzmx.djbh AND
		ywpz.djrq &lt;
		STR_TO_DATE('2005-03-10','%Y-%m-%d') AND
		ywpzmx.fwbm = #{fwbm}
		UNION ALL
		SELECT ywpz.djrq,
		CASE WHEN ywpz.djlx='01' THEN '单位缴款'
		WHEN
		ywpz.djlx='02' THEN '单位维修基金分配'
		WHEN ywpz.djlx='03' THEN '个人维修基金'
		WHEN
		ywpz.djlx='04' THEN '公共收益分配'
		WHEN ywpz.djlx='21' THEN '首次拨付分摊'
		WHEN
		ywpz.djlx='22' THEN '余额拨付分摊'
		WHEN ywpz.djlx='23' THEN '维修基金销户'
		WHEN
		ywpz.djlx='05' THEN '个人续缴'
		WHEN ywpz.djlx='07' THEN '个人补缴'
		WHEN
		ywpz.djlx='10' THEN '年度结息'
		WHEN ywpz.djlx='13' THEN '个人退款'
		WHEN
		ywpz.djlx='82' THEN '单位交款分配冲账'
		WHEN ywpz.djlx='83' THEN '个人维修资金冲账'
		WHEN
		ywpz.djlx='84' THEN '公共设施收益分配冲账'
		WHEN ywpz.djlx='85' THEN '个人续缴冲账'
		WHEN
		ywpz.djlx='87' THEN '个人补缴冲账'
		ELSE '未定' END djlx,
		ywpz.djbh,
		CASE WHEN
		jdf='0' THEN ywpzmx.bjje ELSE 0 END dfbj,
		CASE WHEN jdf='0' THEN
		ywpzmx.lxje ELSE 0 END dflx,
		CASE WHEN jdf='1' THEN ywpzmx.bjje ELSE 0
		END jfbj,
		CASE WHEN jdf='1' THEN ywpzmx.lxje ELSE 0 END jflx,
		0 ye,
		'1'
		ss
		FROM ywpz,
		ywpzmx
		WHERE ywpz.djbh = ywpzmx.djbh AND
		ywpz.djrq &gt;=
		STR_TO_DATE('2005-03-10','%Y-%m-%d') AND
		ywpz.djrq &lt;=
		STR_TO_DATE('2017-07-31','%Y-%m-%d') AND
		ywpzmx.fwbm = #{fwbm}
		) a
		ORDER
		BY ss,djrq
	</select>

	<select id="queryKfxm" parameterType="io.renren.modules.app.entity.Cxtj_FhmxzEntity"
		resultType="io.renren.modules.app.entity.Cxtj_FhmxzEntity">
		select xmbm,xmmc from XM t,GZDXX tt where t.gzdbm=tt.gzdbm
		order by t.XMBM
	</select>

	<select id="queryLymc" parameterType="io.renren.modules.app.entity.Cxtj_FhmxzEntity"
		resultType="io.renren.modules.app.entity.Cxtj_FhmxzEntity">
		SELECT t.dhbm,t.dhmc FROM zhxx t,xm t1 WHERE t.xmbm =
		#{xmbm} AND
		t.xmbm=t1.xmbm order by t.DHBM
	</select>

	<select id="queryFwxx" parameterType="io.renren.modules.app.entity.Cxtj_FhmxzEntity"
		resultType="io.renren.modules.app.entity.Cxtj_FhmxzEntity">
		select fwbm,mphm,xm from fwxx where dhbm=#{dhbm} order by
		fwbm
	</select>

	<select id="queryGrjcqkPage" parameterType="io.renren.modules.app.entity.Cxtj_GrjcqkEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcqkEntity">
		SELECT t1.*,t2.dhmc,t3.xmmc,t4.xqmc,ifnull(( ROUND(CASE WHEN
		t1.jsbz='0' THEN t1.mj*t1.grjjl WHEN t1.jsbz='1' THEN t1.zjk*t1.grjjl
		ELSE t1.mj*t1.grjjl END,2)-t1.grje ),'0') qjje,ROUND(CASE WHEN
		t1.jsbz='0' THEN t1.mj*t1.grjjl WHEN t1.jsbz='1' THEN t1.zjk*t1.grjjl
		ELSE t1.mj*t1.grjjl END,2) yjje
		FROM fwxx t1
		LEFT JOIN zhxx t2 ON
		t1.dhbm=t2.dhbm
		LEFT JOIN xm t3 ON t2.xmbm=t3.xmbm
		LEFT JOIN xqxx t4 ON
		t3.xqbm=t4.xqbm
		<where>
			<if test=" xm!=null and xm!='' ">
				and t1.xm like CONCAT("%",#{xm},"%")
			</if>
			<if test=" sfzh!=null and sfzh!='' ">
				and t1.sfzh like CONCAT("%",#{sfzh},"%")
			</if>
		</where>
	</select>

	<select id="queryGrjcHstjPageOne" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
	 <![CDATA[
	 SELECT tt1.*,tt2.qcye FROM
     (SELECT t5.xmbm,
     t5.xmmc,
     SUM(1) hs,
     SUM(t.grjk) grjk,
     SUM(t6.yjyjje) dwyj,
     SUM(t.dwfp) dwfp,
     SUM(t.sy) sy,
     SUM(t.lx) lx,
     SUM(t.zq) zq,
     SUM(t.tk) tk,
     SUM(t.grjk)+SUM(CASE WHEN t6.yjyjje IS NULL THEN 0 ELSE t6.yjyjje END)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) fse,
     SUM(t.grjk)+SUM(CASE WHEN t6.yjyjje IS NULL THEN 0 ELSE t6.yjyjje END)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx) srhj,
     SUM(t.zq)+SUM(t.tk) zchj
     FROM
     (SELECT t2.fwbm,
     SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
     SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
     SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
     SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
     SUM(CASE WHEN t1.djlx='22' THEN t2.bjje ELSE 0 END) zq,
     SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
     FROM ywpz t1
     LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
     WHERE t1.djlx IN ('02','03','04','10','22','23')
     AND t1.djrq >= STR_TO_DATE(#{kssj},'%Y-%m')
     AND t1.djrq <= STR_TO_DATE(#{jssj},'%Y-%m')
     GROUP BY t2.fwbm) t
     LEFT JOIN FWXX t3 ON t3.fwbm=t.fwbm
     LEFT JOIN ZHXX t4 ON t3.dhbm=t4.dhbm
     LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
     LEFT JOIN wxjjyj t6 ON t3.dhbm=t6.yjdhbm
     AND t3.grje<>0
     GROUP BY t5.xmbm,t5.xmmc) tt1
     LEFT JOIN
     (SELECT t5.xmbm,
     t5.xmmc,
     SUM(t.grjk)+SUM(CASE WHEN t6.yjyjje IS NULL THEN 0 ELSE t6.yjyjje END)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) qcye
     FROM
     (SELECT t2.fwbm,
     SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
     SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
     SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
     SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
     SUM(CASE WHEN t1.djlx='22' or t1.djlx='21' THEN t2.bjje ELSE 0 END) zq,
     SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
     FROM ywpz t1
     LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
     WHERE t1.djlx IN ('02','03','04','10','21','22','23')
     AND t1.djrq < STR_TO_DATE(#{kssj},'%Y-%m')
     GROUP BY t2.fwbm) t
     LEFT JOIN FWXX t3 ON t3.fwbm=t.fwbm
     LEFT JOIN ZHXX t4 ON t3.dhbm=t4.dhbm
     LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
     LEFT JOIN wxjjyj t6 ON t3.dhbm=t6.yjdhbm
     AND t3.grje<>0
     GROUP BY t5.xmbm,t5.xmmc) tt2
     ON tt1.xmbm=tt2.xmbm
     ORDER BY tt1.xmbm 
     ]]>
	</select>

	<select id="queryGrjcHstjPageOne2" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
	<![CDATA[
	SELECT tt1.*,tt2.qcye FROM
     (SELECT t5.xmbm,
     t5.xmmc,
     SUM(1) hs,
     SUM(t.grjk) grjk,
      0,
     SUM(t.dwfp) dwfp,
     SUM(t.sy) sy,
     SUM(t.lx) lx,
     SUM(t.zq) zq,
     SUM(t.tk) tk,
     SUM(t.grjk)+0+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) fse,
     SUM(t.grjk)+0+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx) srhj,
     SUM(t.zq)+SUM(t.tk) zchj
     FROM
     (SELECT t2.fwbm,t2.dhbm,
     SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
     sum(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
     SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
     SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
     SUM(CASE WHEN t1.djlx='21' or t1.djlx='22' THEN t2.bjje ELSE 0 END) zq,
     SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
     FROM ywpz t1
     LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
     WHERE t1.djlx IN ('02','03','04','10','21','22','23')
     AND t1.djrq >= STR_TO_DATE(#{kssj},'%Y-%m')
     AND t1.djrq <= STR_TO_DATE(#{jssj},'%Y-%m')
     GROUP BY t2.dhbm) t
     LEFT JOIN ZHXX t4 ON t.dhbm=t4.dhbm
     LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
     GROUP BY t5.xmbm,t5.xmmc) tt1
     LEFT JOIN
     (SELECT t5.xmbm,
     t5.xmmc,
     SUM(t.grjk)+0+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) qcye
     FROM
     (SELECT t2.fwbm,t2.dhbm,
     SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
     SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
     SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
     SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
     SUM(CASE WHEN t1.djlx='22' or t1.djlx='21' THEN t2.bjje ELSE 0 END) zq,
     SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
     FROM ywpz t1
     LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
     WHERE t1.djlx IN ('02','03','04','10','21','22','23')
     AND t1.djrq < STR_TO_DATE(#{kssj},'%Y-%m')
     GROUP BY t2.dhbm) t
     
     LEFT JOIN ZHXX t4 ON t.dhbm=t4.dhbm
     LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
     GROUP BY t5.xmbm,t5.xmmc) tt2
     ON tt1.xmbm=tt2.xmbm
     ORDER BY tt1.xmbm
     ]]>
	</select>

	<select id="queryGrjcHstjPageOneDWYJ" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
		<![CDATA[
		select IFNULL(sum(m.je),0) dwyj from ywpz y,yjmx m where y.djbh=m.djbh and
		y.djlx='01' and y.kjqj>=#{kssj} and y.kjqj<=#{jssj}
		and m.dhbm in(select dhbm from zhxx where xmbm=#{xmbm})
		]]>
	</select>

	<select id="queryGrjcHstjPageOneDWYJQC" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
		<![CDATA[
		select IFNULL(sum(m.je),0) dwyj from ywpz y,yjmx m where y.djbh=m.djbh and y.djlx='01' and y.kjqj<#{kssj} 
and m.dhbm in(select dhbm from zhxx where xmbm=#{xmbm})
		]]>
	</select>
	
	<select id="queryCxtjhs" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
		select count(1) hs from fwxx where dhbm in(select dhbm from zhxx where xmbm=#{xmbm}) and sfyj='1'
	</select>

	<select id="queryGrjcHstjPageTwo" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
	<![CDATA[
	SELECT tt1.*,tt2.qcye FROM
    (SELECT t5.xmmc,
    t4.dhbm,
    t4.dhmc,
    SUM(1) hs,
    SUM(t.grjk) grjk,
    SUM(t6.yjyjje) dwyj,
    SUM(t.dwfp) dwfp,
    SUM(t.sy) sy,
    SUM(t.lx) lx,
    SUM(t.zq) zq,
    SUM(t.tk) tk,
    SUM(t.grjk)+SUM(CASE WHEN t6.yjyjje IS NULL THEN 0 ELSE t6.yjyjje END)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) fse,
    SUM(t.grjk)+SUM(CASE WHEN t6.yjyjje IS NULL THEN 0 ELSE t6.yjyjje END)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx) srhj,
    SUM(t.zq)+SUM(t.tk) zchj
    FROM
    (SELECT t2.fwbm,
    SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
    SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
    SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
    SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
    SUM(CASE WHEN t1.djlx='22' THEN t2.bjje ELSE 0 END) zq,
    SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
    FROM ywpz t1
    LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
    WHERE t1.djlx IN ('02','03','04','10','22','23')
    AND t1.djrq >= STR_TO_DATE(#{kssj},'%Y-%m')
    AND t1.djrq <= STR_TO_DATE(#{jssj},'%Y-%m')
    GROUP BY t2.fwbm) t
    LEFT JOIN FWXX t3 ON t3.fwbm=t.fwbm
    LEFT JOIN ZHXX t4 ON t3.dhbm=t4.dhbm
    LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
    LEFT JOIN wxjjyj t6 ON t3.dhbm=t6.yjdhbm
    AND t3.grje<>0
    GROUP BY t5.xmmc,t4.dhbm,t4.dhmc) tt1
    LEFT JOIN
    (SELECT t5.xmmc,
    t4.dhbm,
    t4.dhmc,
    SUM(t.grjk)+SUM(CASE WHEN t6.yjyjje IS NULL THEN 0 ELSE t6.yjyjje END)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) qcye
    FROM
    (SELECT t2.fwbm,
    SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
    SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
    SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
    SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
    SUM(CASE WHEN t1.djlx='22' THEN t2.bjje ELSE 0 END) zq,
    SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
    FROM ywpz t1
    LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
    WHERE t1.djlx IN ('02','03','04','10','22','23')
    AND t1.djrq < STR_TO_DATE(#{kssj},'%Y-%m')
    GROUP BY t2.fwbm) t
    LEFT JOIN FWXX t3 ON t3.fwbm=t.fwbm
    LEFT JOIN ZHXX t4 ON t3.dhbm=t4.dhbm
    LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
    LEFT JOIN wxjjyj t6 ON t3.dhbm=t6.yjdhbm
    AND t3.grje<>0
    GROUP BY t5.xmmc,t4.dhbm,t4.dhmc) tt2
    ON tt1.dhbm=tt2.dhbm
    ORDER BY tt1.xmmc
    ]]>
	</select>
	
	<select id="queryGrjcHstjPageTwo2" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
	<![CDATA[
	SELECT tt1.*,tt2.qcye FROM
    (SELECT t5.xmmc,
    t4.dhbm,
    t4.dhmc,
    SUM(1) hs,
    SUM(t.grjk) grjk,
    0,
    SUM(t.dwfp) dwfp,
    SUM(t.sy) sy,
    SUM(t.lx) lx,
    SUM(t.zq) zq,
    SUM(t.tk) tk,
    SUM(t.grjk)+0+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) fse,
    SUM(t.grjk)+0+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx) srhj,
    SUM(t.zq)+SUM(t.tk) zchj
    FROM
    (SELECT t2.fwbm,t2.dhbm,
    SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
    SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
    SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
    SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
    SUM(CASE WHEN t1.djlx='22' or t1.djlx='21' THEN t2.bjje ELSE 0 END) zq,
    SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
    FROM ywpz t1
    LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
    WHERE t1.djlx IN ('02','03','04','10','21','22','23')
    AND t1.djrq >= STR_TO_DATE(#{kssj},'%Y-%m')
    AND t1.djrq <= STR_TO_DATE(#{jssj},'%Y-%m')
    GROUP BY t2.dhbm) t
    
    LEFT JOIN ZHXX t4 ON t.dhbm=t4.dhbm
    LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
    
    GROUP BY t5.xmmc,t4.dhbm,t4.dhmc) tt1
    LEFT JOIN
    (SELECT t5.xmmc,
    t4.dhbm,
    t4.dhmc,
    SUM(t.grjk)+0+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) qcye
    FROM
    (SELECT t2.fwbm,t2.dhbm,
    SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
    SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
    SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
    SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
    SUM(CASE WHEN t1.djlx='22' or t1.djlx='21' THEN t2.bjje ELSE 0 END) zq,
    SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
    FROM ywpz t1
    LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
    WHERE t1.djlx IN ('02','03','04','10','21','22','23')
    AND t1.djrq < STR_TO_DATE(#{kssj},'%Y-%m')
    GROUP BY t2.dhbm) t
    
    LEFT JOIN ZHXX t4 ON t.dhbm=t4.dhbm
    LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
   
    GROUP BY t5.xmmc,t4.dhbm,t4.dhmc) tt2
    ON tt1.dhbm=tt2.dhbm
    ORDER BY tt1.xmmc
    ]]>
	</select>
	
	<select id="queryGrjcHstjPageOneDWYJ2" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
		<![CDATA[
		select IFNULL(sum(m.je),0) dwyj from ywpz y,yjmx m where y.djbh=m.djbh and
		y.djlx='01' and y.kjqj>=#{kssj} and y.kjqj<=#{jssj}
		and m.dhbm=#{dhbm}
		]]>
	</select>

	<select id="queryGrjcHstjPageOneDWYJQC2" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
		<![CDATA[
		select IFNULL(sum(m.je),0) dwyj from ywpz y,yjmx m where y.djbh=m.djbh and y.djlx='01' and y.kjqj<#{kssj} 
and m.dhbm=#{dhbm}
		]]>
	</select>
	
	<select id="queryCxtjhs2" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
		select count(1) hs from fwxx where dhbm=#{dhbm} and sfyj='1'
	</select>

	<select id="queryGrjcHstjPageSan" parameterType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcHstjEntity">
	<![CDATA[
	 SELECT tt1.*,tt2.qcye FROM
     (SELECT t5.xmmc,
     t4.dhbm,
     t4.dhmc,
     t6.fwdybm,
     t6.dymc,
     SUM(1) hs,
     SUM(t.grjk) grjk,
     SUM(t.dwfp) dwfp,
     SUM(t.sy) sy,
     SUM(t.lx) lx,
     SUM(t.zq) zq,
     SUM(t.tk) tk,
     SUM(t.grjk)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) fse,
     SUM(t.grjk)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx) srhj,
     SUM(t.zq)+SUM(t.tk) zchj
     FROM
     (SELECT t2.fwbm,
     SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
     SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
     SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
     SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
     SUM(CASE WHEN t1.djlx='22' THEN t2.bjje ELSE 0 END) zq,
     SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
     FROM ywpz t1
     LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
     WHERE t1.djlx IN ('02','03','04','10','22','23')
     AND t1.djrq >= STR_TO_DATE(#{kssj},'%Y-%m')
     AND t1.djrq <= STR_TO_DATE(#{jssj},'%Y-%m')
     GROUP BY t2.fwbm) t
     LEFT JOIN FWXX t3 ON t3.fwbm=t.fwbm
     LEFT JOIN ZHXX t4 ON t3.dhbm=t4.dhbm
     LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
     LEFT JOIN DYXX t6 ON t3.mh=t6.fwdybm
     AND t3.grje<>0
     GROUP BY t5.xmmc,t4.dhbm,t4.dhmc,t6.fwdybm,t6.dymc) tt1
     LEFT JOIN
     (SELECT t5.xmmc,
     t4.dhbm,
     t4.dhmc,
     t6.fwdybm,
     t6.dymc,
     SUM(t.grjk)+SUM(t.dwfp)+SUM(t.sy)+SUM(t.lx)-SUM(t.zq)-SUM(t.tk) qcye
     FROM
     (SELECT t2.fwbm,
     SUM(CASE WHEN t1.djlx='03' THEN t2.bjje ELSE 0 END) grjk,
     SUM(CASE WHEN t1.djlx='02' THEN t2.bjje ELSE 0 END) dwfp,
     SUM(CASE WHEN t1.djlx='04' THEN t2.bjje ELSE 0 END) sy,
     SUM(CASE WHEN t1.djlx='10' THEN t2.lxje ELSE 0 END) lx,
     SUM(CASE WHEN t1.djlx='22' THEN t2.bjje ELSE 0 END) zq,
     SUM(CASE WHEN t1.djlx='23' THEN (t2.bjje+t2.lxje) ELSE 0 END) tk
     FROM ywpz t1
     LEFT JOIN ywpzmx t2 ON t1.djbh=t2.djbh
     WHERE t1.djlx IN ('02','03','04','10','22','23')
     AND t1.djrq < STR_TO_DATE(#{kssj},'%Y-%m')
     GROUP BY t2.fwbm) t
     LEFT JOIN FWXX t3 ON t3.fwbm=t.fwbm
     LEFT JOIN ZHXX t4 ON t3.dhbm=t4.dhbm
     LEFT JOIN XM t5 ON t4.xmbm=t5.xmbm
     LEFT JOIN DYXX t6 ON t3.mh=t6.fwdybm
     AND t3.grje<>0
     GROUP BY t5.xmmc,t4.dhbm,t4.dhmc,t6.fwdybm,t6.dymc) tt2
     ON tt1.dhbm=tt2.dhbm
     ORDER BY tt1.xmmc
    ]]>
	</select>

	<select id="queryGrjcJcybPage" parameterType="io.renren.modules.app.entity.Cxtj_GrjcJcybEntity"
		resultType="io.renren.modules.app.entity.Cxtj_GrjcJcybEntity">
	<![CDATA[
	 SELECT t.xqbm,t.ly,ifnull(t.byje,'0') byje,ifnull(t.ljje,'0') ljje,XQXX.Xqmc FROM
        (SELECT tt1.xqbm,tt1.ly,tt1.ljje,tt2.byje
        FROM
          (SELECT t3.xqbm,SUM(t1.je) ljje,'1、开发商' ly
                 from ywpz y
                 LEFT JOIN YJMX t1 on y.djbh=t1.djbh
                 LEFT JOIN ZHXX t2 ON t1.dhbm=t2.dhbm
                 LEFT JOIN XM t3 ON t2.xmbm=t3.xmbm
                 WHERE date_format(t1.djrq,'%Y-%m')<= #{yfsj} and t3.xqbm is not null
                 and djlx='01'
                 GROUP BY t3.xqbm) tt1
        LEFT JOIN
          (SELECT t3.xqbm,SUM(t1.je) byje,'1、开发商' ly
                 from ywpz y
                 LEFT JOIN YJMX t1 on y.djbh=t1.djbh
                 LEFT JOIN ZHXX t2 ON t1.dhbm=t2.dhbm
                 LEFT JOIN XM t3 ON t2.xmbm=t3.xmbm
                 WHERE t1.je>=0
                 AND date_format(t1.djrq,'%Y-%m') = #{yfsj} and t3.xqbm is not null
                 and djlx='01'
                 GROUP BY t3.xqbm) tt2
        ON tt1.xqbm=tt2.xqbm
        UNION ALL
        SELECT tt3.xqbm,tt3.ly,tt3.ljje,tt4.byje
        FROM
          (SELECT t4.xqbm,SUM(t1.je) ljje,'2、业主' ly
                 FROM YWPZ t1
                 LEFT JOIN YWPZMX t2 ON t1.djbh=t2.djbh
                 LEFT JOIN ZHXX t3 ON t2.dhbm=t3.dhbm
                 LEFT JOIN XM t4 ON t3.xmbm=t4.xmbm
                 WHERE  date_format(t1.djrq,'%Y-%m')<=#{yfsj} and t4.xqbm is not null
                 AND t1.DJLX='03'
                 GROUP BY t4.xqbm) tt3
        LEFT JOIN
          (SELECT t4.xqbm,SUM(t1.je) byje,'2、业主' ly
                 FROM YWPZ t1
                 LEFT JOIN YWPZMX t2 ON t1.djbh=t2.djbh
                 LEFT JOIN ZHXX t3 ON t2.dhbm=t3.dhbm
                 LEFT JOIN XM t4 ON t3.xmbm=t4.xmbm
                 WHERE  date_format(t1.djrq,'%Y-%m')=#{yfsj} and t4.xqbm is not null
                 AND t1.DJLX='03'
                 GROUP BY t4.xqbm) tt4
        ON tt3.xqbm=tt4.xqbm) t
        LEFT JOIN XQXX ON t.xqbm=XQXX.Xqbm
        ORDER BY xqbm,ly
    ]]>
	</select>

	<select id="queryCxtjZzcxPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjZzcxEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjZzcxEntity">
		SELECT t1.yhmc,
		DATE_FORMAT(t.djrq,'%Y-%m') AS yf,
		SUM(t.t_jjje) AS
		jjje,
		SUM(t.t_zqje) AS zqje,
		0 AS qc,
		0 AS qm
		FROM
		(SELECT
		bank_code,djrq,je AS t_jjje,0 AS t_zqje FROM ywpz
		WHERE djlx IN
		('01','02','03','04','05')
		<if test=" yhbm!=null and yhbm!='' ">
			and bank_code= #{yhbm}
		</if>
		UNION ALL
		SELECT bank_code,djrq,0 AS t_jjje,je AS t_zqje FROM ywpz
		WHERE djlx IN ('21','22','23')
		<if test=" yhbm!=null and yhbm!='' ">
			and bank_code= #{yhbm}
		</if>
		) t,yhxx t1
		WHERE t.bank_code=t1.yhbm
		GROUP BY
		t1.yhmc,DATE_FORMAT(t.djrq,'%Y-%m')
		ORDER BY t1.yhmc,yf
	</select>

	<select id="queryCxtjZqcxPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjZqcxEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjZqcxEntity">
		SELECT ywpz.djrq,
		ywpz.djbh,
		CASE WHEN ywpz.djlx='21' THEN '首次拨付分摊'
		WHEN
		ywpz.djlx='22' THEN '余额拨付分摊'
		WHEN ywpz.djlx='23' THEN '业主销户'
		ELSE '未定'
		END djlx,
		ifnull(ywpz.je,'0') je,
		ywpz.bank_code,
		yhxx.yhmc,
		ywpz.jsfs,
		h_jsfs.billname,
		ywpz.czybm,
		ywpz.czyxm
		FROM ywpz,
		h_jsfs,
		yhxx
		WHERE
		h_jsfs.billcode = ywpz.jsfs
		AND ywpz.bank_code= yhxx.yhbm
		<if test=" yhbm!=null and yhbm!='' ">
			AND ywpz.bank_code= #{yhbm}
		</if>
             <![CDATA[
            AND ywpz.djrq   >= DATE_FORMAT(#{kssj},'%Y-%m-%d')
            AND ywpz.djrq   <= DATE_FORMAT(#{jssj},'%Y-%m-%d')
            ]]>
		AND ywpz.djlx IN ('21','22','23')
		ORDER BY ywpz.djrq
	</select>

	<select id="queryCxtjJkcxPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjJkcxEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjJkcxEntity">
		SELECT ywpz.djrq,
		ywpz.djbh,
		CASE ywpz.djlx
		WHEN '01' THEN '单位预交'
		WHEN
		'03' THEN '个人预交'
		WHEN '04' THEN '公共收益'
		WHEN '05' THEN '个人续补缴'
		WHEN '82'
		THEN '冲账'
		WHEN '21' THEN '首次拨付分摊'
		WHEN '22' THEN '余额拨付分摊'
		else '未定' end
		djlx,
		ywpz.je,
		ywpz.bank_code,
		yhxx.yhmc,
		ywpz.jsfs,
		h_jsfs.billname,
		ywpz.czybm,
		ywpz.czyxm
		FROM ywpz,
		h_jsfs,
		yhxx
		WHERE h_jsfs.billcode =
		ywpz.jsfs
		AND ywpz.bank_code= yhxx.yhbm and ywpz.djlx in ('01','03','05')
		<if test=" yhbm!=null and yhbm!='' ">
			AND ywpz.bank_code= #{yhbm}
		</if>
		<if test=" djlx!=null and djlx!='' ">
			AND ywpz.djlx=#{djlx}
		</if>
             <![CDATA[
            AND ywpz.djrq   >= DATE_FORMAT(#{kssj},'%Y-%m-%d')             
            AND ywpz.djrq   <= DATE_FORMAT(#{jssj},'%Y-%m-%d')  
             ]]>
		ORDER BY ywpz.djrq
	</select>

	<select id="queryTyXqPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity">
		select * from XQXX
		<where>
			<if test=" xqbm!=null and xqbm!='' ">
				and xqbm = #{xqbm}
			</if>
		</where>
		order by XQBM
	</select>

	<select id="queryTyXmPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity">
		select * from XM
		<where>
			<if test=" xqbm!=null and xqbm!='' ">
				and xqbm = #{xqbm}
			</if>
		</where>
		order by XMBM
	</select>

	<select id="queryTyLyPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity">
		select * from zhxx
		<where>
			<if test=" xmbm !=null and xmbm !='' ">
				and xmbm = #{xmbm}
			</if>
		</where>
		order by dhbm
	</select>

	<select id="queryTySyxmPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity">
		SELECT * FROM ZDXX WHERE lx ='11' ORDER BY ZDBM
	</select>

	<select id="queryTyHyxxPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjTyEntity">
		SELECT YHBM,YHMC FROM YHXX ORDER BY YHBM
	</select>

	<select id="queryCxtjFwwxqkPage2" parameterType="io.renren.modules.app.entity.Cxtj_CxtjFwwxqkEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjFwwxqkEntity">
		SELECT DISTINCT sqwxzq.sqdbh,
		sqwxzq.sqrq,
		sqwxzq.dhbm,
		xm.xmmc,
		sqwxzq.sqdw,
		sqwxzq.wxbw,
		sqwxzq.zfy,
		sqwxzq.zhs,
		sqwxzq.dwyj,
		sqwxzq.gwhyj,
		sqwxzq.pzdwyj,
		sqwxzq.jbrxm,
		sqwxzq.shrq,
		CASE WHEN
		sqwxzq.sfsh='0' THEN '未审核' WHEN sqwxzq.sfsh='1' THEN '已审核' ELSE
		'退回'
		END sfsh,
		CASE WHEN sqwxzq.sffp='0' THEN '支取未首次分摊' ELSE '支取已首次分摊' END
		sffp,
		<!-- CASE WHEN sqwxzq.sfjz='0' THEN '支取未划拨' ELSE '支取已划拨' END sfjz, -->
		CASE WHEN sqwxzq.sfjs='0' THEN '支取未余额分摊' ELSE '支取已余额分摊' END sfjs
		FROM
		sqwxzq,
		wygsxx,

		xm
		WHERE
		sqwxzq.xmbm = xm.xmbm
		AND
		DATE_FORMAT(sqwxzq.sqrq,'%Y-%m-%d') BETWEEN #{kssj} AND #{jssj}
		AND
		sqwxzq.sfsh = #{sfshtwo}
		AND sqwxzq.sffp = #{sffptwo}
		<!-- AND sqwxzq.sfjz = #{sfjztwo} -->
		AND sqwxzq.sfjs = #{sfjstwo}
		<!-- <if test=" dhbm !=null and dhbm !='' "> and sqwxzq.dhbm = #{dhbm} 
			</if> -->
		<if test=" xmbm !=null and xmbm !='' ">
			and xm.xmbm = #{xmbm}
		</if>
		<if test=" xqbm !=null and xqbm !='' ">
			and xm.xqbm = #{xqbm}
		</if>
	</select>

	<select id="queryCxtjGgsyfpPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjGgsyfpEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjGgsyfpEntity">
		SELECT ywpz.djbh,
		ywpz.djrq,
		ywpz.bank_code,
		yhxx.yhmc,
		ywpz.jsfs,
		ywpz.zph ,
		h_jsfs.billname,
		ywpz.syxm,
		sys_dict.`value` as zdmc,
		ywpz.dhbm,
		zhxx.dhmc,
		ywpz.je
		FROM ywpz,
		h_jsfs,
		yhxx,
		zhxx,
		sys_dict
		WHERE
		h_jsfs.billcode = ywpz.jsfs
		AND ywpz.bank_code = yhxx.yhbm
		AND zhxx.dhbm
		= ywpz.dhbm
		AND sys_dict.id=ywpz.syxm
		AND djlx='04'
		AND SUBSTR(ywpz.djrq,
		1, 10) BETWEEN #{kssj} AND #{jssj}
		<if test=" zdbm !=null and zdbm !='' ">
			AND ywpz.SYXM = #{zdbm}
		</if>
		<if test=" dhbm !=null and dhbm !='' ">
			AND ywpz.Dhbm = #{dhbm}
		</if>
	</select>

	<select id="queryCxtjCqrbgPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjCqrbgEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjCqrbgEntity">
		SELECT fwxx.fwbm,
		fwxx.mphm,
		zhxx.dhmc,
		grbg.cczh,
		grbg.h_cczh
		as hcczh,
		grbg.q_xm as qxm,
		grbg.h_xm as hxm,
		grbg.q_sfzh as qsfzh,
		grbg.h_sfzh as hsfzh,
		grbg.q_lxdh as qlxdh,
		grbg.h_lxdh as hlxdh,
		grbg.bgrq,
		grbg.q_dz as qdz,
		grbg.h_dz as hdz,
		grbg.czyxm,
		grbg.czybm,
		grbg.bgrq
		FROM grbg,
		fwxx,
		zhxx
		WHERE (fwxx.fwbm = grbg.fwbm)
		AND
		(zhxx.dhbm = fwxx.dhbm)
		AND DATE_FORMAT(grbg.bgrq,'%Y-%m-%d') BETWEEN
		#{kssj} AND #{jssj}
	</select>

	<select id="queryCxtjCsbPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjCsbEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjCsbEntity">
		SELECT
		t.XQMC,t.DWBM,t.DWMC,t.XMBM,t.XMMC,t.DHBM,t.DHMC,ifnull(t.ZMJ,'0')
		zmj,ifnull((case when t.dwyjje!=0 then t.dwyjje else t.dwze end),'0')
		yjyjje,ifnull(YJJE,'0')yjje,t.LXR,t.LXDH,t.DZ,(t.yjje-IFNULL((case when t.dwyjje!=0 then t.dwyjje else t.dwze end),0))
		qjje
		FROM (
		SELECT
		t1.DHBM,t1.DHMC,t1.ZMJ,t2.DWBM,t2.DWMC,t2.LXR,t2.LXDH,t2.DZ,t3.XMBM,t3.XMMC,t4.XQMC,(case when t1.dwyjje!=0 then t1.dwyjje else t1.dwze end) dwze,t1.dwyjje,
		t1.YJJE
		FROM zhxx t1
		LEFT JOIN SFDW t2 ON t1.dwbm=t2.dwbm
		LEFT JOIN xm t3
		ON t1.xmbm=t3.xmbm
		LEFT JOIN XQXX t4 ON t3.xqbm=t4.xqbm
		<where>
			<if test=" dwmc !=null and dwmc !='' ">
				and t2.dwmc LIKE CONCAT("%",#{dwmc},"%")
			</if>
			<if test=" xmbm !=null and xmbm !='' ">
				AND t3.xmbm = #{xmbm}
			</if>
			<if test=" xqbm !=null and xqbm !='' ">
				AND t4.xqbm = #{xqbm}
			</if>
		</where>
		) t
		<where>
			<if test=" cslxbm=='0'.toString() ">
				and t.yjje != t.YJYJJE or t.YJYJJE is null
			</if>
			<if test=" cslxbm=='1'.toString() ">
				and t.yjje != t.YJYJJE and t.YJYJJE is not null
			</if>
			<if test=" cslxbm=='2'.toString() ">
				and t.YJYJJE is null
			</if>
		</where>
	</select>

	<select id="queryCxtjFwwxqkPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjCfzhEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjCfzhEntity">
		select t.*,t1.xmmc,t2.wygsmc,t3.gzdmc
		from zhxx t,xm
		t1,wygsxx t2,gzdxx t3
		where t.xmbm=t1.xmbm
		and t.wygsbm=t2.wygsbm
		and
		t.gzdbm=t3.gzdbm
		and t.XMBM = #{xmbm}
		and t.DHMC in (select DHMC from
		ZHXX where XMBM=#{xmbm} group by DHMC
		having(count(*))>1)
		order by DHBM
	</select>

	<select id="queryCxtjFwbgPage" parameterType="io.renren.modules.app.entity.Cxtj_CxtjFwbgEntity"
		resultType="io.renren.modules.app.entity.Cxtj_CxtjFwbgEntity">
		SELECT
		t.*,fwxx.mphm,zhxx.dhmc,xm.xmbm,xm.xmmc,xqxx.xqbm,xqxx.xqmc,sfdw.dwbm,sfdw.dwmc
		FROM
		(
		SELECT * FROM FWGDB
		<where>
			<if test=" gdbh !=null and gdbh !='' ">
				AND Xdhbm = #{gdbh}
			</if>
			<if test=" fzxm !=null and fzxm !='' ">
				AND HZXM = #{fzxm}
			</if>
		</where>
		) t
		LEFT JOIN fwxx ON fwxx.fwbm=t.xfwbm
		LEFT JOIN zhxx ON zhxx.dhbm =
		fwxx.dhbm
		LEFT JOIN xm ON xm.xmbm = zhxx.xmbm
		LEFT JOIN xqxx ON
		xqxx.xqbm = xm.xqbm
		LEFT JOIN sfdw ON sfdw.dwbm=xm.dwbm
	</select>

</mapper>