<?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.YeFseDao">
	<select id="jbh_1" resultType="String">
		select substr(kmjb,#{jbh},1) len from h_zt where ztbm=#{ztbm}
	</select>
    
	<select id="jbh_2" resultType="String">
		 select substr(kmjb,1,1)+substr(kmjb,2,1) len from h_zt where ztbm=#{ztbm}
	</select>
	
	<select id="jbh_3" resultType="String">
		select substr(kmjb,1,1)+substr(kmjb,2,1)+substr(kmjb,3,1)  len from h_zt where ztbm=#{ztbm}
	</select>
	
	<select id="yeFseSelect_1" parameterType="io.renren.modules.app.entity.HPzEntity" resultType="io.renren.modules.app.entity.HPzEntity">
		select kmdm,kmmc, kmsx,
                 sum(jqcye) zjqcye,
                 sum(dqcye) zdqcye,
                 sum(jfje) zjfje,
                 sum(dfje) zdfje,
                 case kmsx when '0' then sum(jqcye)+ sum(jfje) -sum(dfje) else 0 end jqmye,
                 case kmsx when '1' then sum(dqcye)+ sum(dfje)- sum(jfje) else 0 end dqmye,jbh,kmlbbm from (
          select p.km kmdm,k.kmmc,k.kmsx,0  jqcye ,0  dqcye, P.jfje,P.dfje ,'1' zz,k.jbh,k.kmlbbm from h_pz P ,h_km K
            where (p.km=k.km)  and  p.kjqj &gt;= #{qskjqj} and p.kjqj &lt;= #{zzkjqj} and (k.ztbm=#{ztbm}) and (p.ztbm=#{ztbm})
          union all
         select y.hskmdm kmdm ,k.kmmc,k.kmsx, case k.kmsx when '1' then 0 else y.qcye end jqcye,
          case  k.kmsx when '1' then y.qcye else 0 end dqcye ,0  jfje,0  dfje ,'1' zz,k.jbh,k.kmlbbm from h_kmye y,h_km k
            where (y.hskmdm=k.km)  and (y.kjqj=#{qskjqj}) and (k.ztbm=#{ztbm}) and (y.ztbm=#{ztbm})
            ) a
              group by kmdm,kmmc,kmsx,zz order by kmdm
	</select>
	
	<select id="yeFseSelect_2" parameterType="io.renren.modules.app.entity.YeFseEntity" resultType="io.renren.modules.app.entity.YeFseEntity">

	</select>
	
	<select id="yeFseSelect_3" parameterType="io.renren.modules.app.entity.YeFseEntity" resultType="io.renren.modules.app.entity.YeFseEntity">

	</select>
	
	<select id="yeFseSelect_4" parameterType="io.renren.modules.app.entity.YeFseEntity" resultType="io.renren.modules.app.entity.YeFseEntity">

	</select>

	<select id="select_kmlbbm1" parameterType="io.renren.modules.app.entity.HKmlbEntity" resultType="io.renren.modules.app.entity.HKmlbEntity">
		select * from h_kmlb where kmlbbm = #{kmlbbm} and ztbm = #{ztbm}
	</select>
	
	<select id="select_kmlbbm2" parameterType="io.renren.modules.app.entity.HKmlbEntity" resultType="io.renren.modules.app.entity.HKmlbEntity">
		select * from h_kmlb where ztbm = #{ztbm} order by kmlbbm
	</select>
	
	<select id="selectkm" parameterType="io.renren.modules.app.entity.HPzEntity" resultType="io.renren.modules.app.entity.HKmEntity">
		select * from h_km where ztbm=#{ztbm}
	</select>
	
</mapper>