<?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.HZzsyybbDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="io.renren.modules.app.entity.HZzsyybbEntity" id="hZzsyybbMap">
                    <result property="bm" column="bm"/>
                    <result property="mc" column="mc"/>
                    <result property="hc" column="hc"/>
                    <result property="item1" column="item1"/>
                    <result property="item2" column="item2"/>
                    <result property="bz" column="bz"/>
                    <result property="ztbm" column="ztbm"/>
            </resultMap>

    <select id="queryByPage" parameterType="io.renren.modules.app.entity.HZzsyybbEntity"
            resultType="io.renren.modules.app.entity.HZzsyybbEntity">

        select * from h_zzsyybb where 1=1

                    <if test=" bm!=null and bm!='' ">
                and bm like CONCAT(#{bm},"%")
            </if>
                    <if test=" mc!=null and mc!='' ">
                and mc like CONCAT(#{mc},"%")
            </if>
                    <if test=" hc!=null and hc!='' ">
                and hc like CONCAT(#{hc},"%")
            </if>
                    <if test=" item1!=null and item1!='' ">
                and item1 like CONCAT(#{item1},"%")
            </if>
                    <if test=" item2!=null and item2!='' ">
                and item2 like CONCAT(#{item2},"%")
            </if>
                    <if test=" bz!=null and bz!='' ">
                and bz like CONCAT(#{bz},"%")
            </if>
                    <if test=" ztbm!=null and ztbm!='' ">
                and ztbm like CONCAT(#{ztbm},"%")
            </if>
        
    </select>
    
    <update id="updateZZSYYBB" parameterType="io.renren.modules.app.entity.HZzsyybbEntity">
    	update h_zzsyybb set mc = #{mc},hc = #{hc},item1 = #{item1},item2 = #{item2},bz = #{bz},ztbm = #{ztbm} where bm = #{bm}
    </update>

	<select id="selectNC" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(qcye),0) as je from h_kmye where ztbm=#{ztbm} and KJQJ=CONCAT(substring_index(#{kjqj},'-',1),'-01') AND hskmDM like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectQC" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(qcye),0) as je from h_kmye where ztbm=#{ztbm} and KJQJ=#{kjqj} AND hskmDM like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectQM_1" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(qcye),0) as je from h_kmye where ztbm=#{ztbm} and KJQJ=DATE_FORMAT(DATE_ADD(CONCAT(#{kjqj},'-01'),INTERVAL 1 MONTH),'%Y-%m') AND hskmDM like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectQM_else2" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(case k.kmsx when '0' then p.jfje- p.dfje else p.dfje-p.jfje end ),0)  as tempje
        from h_km k,h_pz p where k.ztbm=#{ztbm} and p.ztbm=#{ztbm}  and k.km=p.km and p.kjqj=#{kjqj} and p.km like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectQM_else1" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(qcye),0) as je from h_kmye where ztbm=#{ztbm} and kjqj=#{kjqj}  and hskmdm like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectJF" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		 select ifnull(sum(jfje),0) as je from h_pz where ztbm=#{ztbm} and kjqj =#{kjqj} and  km like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectDF" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(dfje),0) as je from h_pz where ztbm=#{ztbm} and  kjqj =#{kjqj} and km like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectBNJF" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		 select ifnull(sum(jfje),0) as je from h_pz where ztbm=#{ztbm} and  kjqj &lt;=  #{kjqj} and substring_index(kjqj,'-',1)= substring_index(#{kjqj},'-',1) and km like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectBNDF" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		select ifnull(sum(dfje),0) as je from h_pz where ztbm=#{ztbm} and  kjqj &lt;= #{kjqj} and substring_index(kjqj,'-',1)= substring_index(#{kjqj},'-',1) and km like concat(#{kmdm} ,'%')
	</select>
	
	<select id="selectKJQJ" parameterType="io.renren.modules.app.entity.HZzsyybbEntity" resultType="String">
		 select sfjz from h_cwhsqj  where ztbm = #{ztbm} and kjqjmc=#{kjqj}
	</select>
	
</mapper>