<?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.FhxxSelectDao">
	<select id="selectFhxx" parameterType="io.renren.modules.app.entity.FhxxSelectEntity"
		resultType="io.renren.modules.app.entity.FhxxSelectEntity">
		SELECT
		fwxx.fwbm,
		zhxx.dhmc,
		xm.xmmc,
		fwxx.cczh,
		fwxx.mphm,
		fwxx.lc,
		fwxx.hx,
		sys_dict.`value`,
		fwxx.ssdj,
		fwxx.mj,
		fwxx.fwje,
		fwxx.gfrq,
		fwxx.xm,
		fwxx.sfzh,
		fwxx.lxdh,
		fwxx.dz,
		fwxx.htbh,
		fwxx.fpbh,
<!--		ifnull((fwxx.grje + fwxx.dwje),'0') jjze,-->
<!--		&lt;!&ndash; 当前余额 &ndash;&gt;-->
<!--		ifnull((fwxx.grje + fwxx.dwje + fwxx.ggsy),'0') dqye,-->
<!--		ifnull(fwxx.grje,'0') grje,-->
<!--		ifnull(fwxx.dwje,'0') dwje,-->
		<!-- fwxx.dqye, -->
		CASE
		WHEN fwxx.sfsc = '0' THEN
		'未售出'
		WHEN fwxx.sfsc = '1' THEN
		'已售出'
		ELSE
		'已销户'
		END sfsc,
		dyxx.dymc,
		fwxx.grjjl,
		fwxx.ggsy,
		ifnull((fwxx.zqje+fwxx.zqje2),0) zqje,
		fwxx.ljlx,
		fwxx.xhje,
		fwxx.xhjx
		FROM
		fwxx,
		dyxx,
		sys_dict,
		zhxx,
		xm
		WHERE
		sys_dict.id = fwxx.hx
	    and fwxx.dhbm=#{dhbm}
		<!-- AND fwxx.dhbm = #{dhbm} -->
		AND fwxx.mh = dyxx.fwdybm
		and fwxx.dhbm=zhxx.dhbm
		and zhxx.xmbm=xm.xmbm
		ORDER BY
		fwxx.fwbm
	</select>
	
	<select id="selectFhxx2" parameterType="io.renren.modules.app.entity.FhxxSelectEntity"
		resultType="io.renren.modules.app.entity.FhxxSelectEntity">
		SELECT
		fwxx.fwbm,
		zhxx.dhmc,
		xm.xmmc,
		fwxx.cczh,
		fwxx.mphm,
		fwxx.lc,
		fwxx.hx,
		sys_dict.`value`,
		fwxx.ssdj,
		fwxx.mj,
		fwxx.fwje,
		fwxx.gfrq,
		fwxx.xm,
		fwxx.sfzh,
		fwxx.lxdh,
		fwxx.dz,
		fwxx.htbh,
		fwxx.fpbh,
<!--		ifnull((fwxx.grje + fwxx.dwje),'0') jjze,-->
<!--		&lt;!&ndash; 当前余额 &ndash;&gt;-->
<!--		ifnull((fwxx.grje + fwxx.dwje + fwxx.ggsy),'0') dqye,-->
<!--		ifnull(fwxx.grje,'0') grje,-->
<!--		ifnull(fwxx.dwje,'0') dwje,-->
		<!-- fwxx.dqye, -->
		CASE
		WHEN fwxx.sfsc = '0' THEN
		'未售出'
		WHEN fwxx.sfsc = '1' THEN
		'已售出'
		ELSE
		'已销户'
		END sfsc,
		dyxx.dymc,
		fwxx.grjjl,
		fwxx.ggsy,
		ifnull((fwxx.zqje+fwxx.zqje2),0) zqje,
		fwxx.ljlx,
		fwxx.xhje,
		fwxx.xhjx
		FROM
		fwxx,
		dyxx,
		sys_dict,
		zhxx,
		xm
		WHERE
		sys_dict.id = fwxx.hx
		
		and fwxx.dhbm in(select dhbm from zhxx where xmbm=#{xmbm})
		
		<!-- AND fwxx.dhbm = #{dhbm} -->
		AND fwxx.mh = dyxx.fwdybm
		and fwxx.dhbm=zhxx.dhbm
		and zhxx.xmbm=xm.xmbm
		ORDER BY
		fwxx.fwbm
	</select>
	
	<select id="selectFhxx3" parameterType="io.renren.modules.app.entity.FhxxSelectEntity"
		resultType="io.renren.modules.app.entity.FhxxSelectEntity">
		SELECT
		fwxx.fwbm,
		zhxx.dhmc,
		xm.xmmc,
		fwxx.cczh,
		fwxx.mphm,
		fwxx.lc,
		fwxx.hx,
		sys_dict.`value`,
		fwxx.ssdj,
		fwxx.mj,
		fwxx.fwje,
		fwxx.gfrq,
		fwxx.xm,
		fwxx.sfzh,
		fwxx.lxdh,
		fwxx.dz,
		fwxx.htbh,
		fwxx.fpbh,
<!--		ifnull((fwxx.grje + fwxx.dwje),'0') jjze,-->
<!--		&lt;!&ndash; 当前余额 &ndash;&gt;-->
<!--		ifnull((fwxx.grje + fwxx.dwje + fwxx.ggsy ),'0') dqye,-->
<!--		ifnull(fwxx.grje,'0') grje,-->
<!--		ifnull(fwxx.dwje,'0') dwje,-->
		<!-- fwxx.dqye, -->
		CASE
		WHEN fwxx.sfsc = '0' THEN
		'未售出'
		WHEN fwxx.sfsc = '1' THEN
		'已售出'
		ELSE
		'已销户'
		END sfsc,
		dyxx.dymc,
		fwxx.grjjl,
		fwxx.ggsy,
		ifnull((fwxx.zqje+fwxx.zqje2),0) zqje,
		fwxx.ljlx,
		fwxx.xhje,
		fwxx.xhjx
		FROM
		fwxx,
		dyxx,
		sys_dict,
		zhxx,
		xm
		WHERE
		sys_dict.id = fwxx.hx
		
		and fwxx.dhbm in(select dhbm from zhxx where xmbm in(select xmbm from xm where xqbm=#{xqbm}))
		
		<!-- AND fwxx.dhbm = #{dhbm} -->
		AND fwxx.mh = dyxx.fwdybm
		and fwxx.dhbm=zhxx.dhbm
		and zhxx.xmbm=xm.xmbm
		ORDER BY
		fwxx.fwbm
	</select>

	<select id="selectIsdw" parameterType="String">
		select count(*) from xm
		where dwbm = #{dwbm}
	</select>

	<delete id="deleteFromSfdw" parameterType="String">
		delete from sfdw where
		dwbm = #{dwbm}
	</delete>
	
	<select id="selectfwyjhs" parameterType="String" resultType="int">
		select count(*) from fwxx where dhbm=#{id} and sfyj='1'
	</select>
	<select id="selectfwyjhs2" parameterType="String" resultType="int">
		select count(*) from fwxx where dhbm in(select dhbm from zhxx where xmbm=#{id}) and sfyj='1'
	</select>
	<select id="selectfwyjhs3" parameterType="String" resultType="int">
		select count(*) from fwxx where dhbm in(select dhbm from zhxx where xmbm in(select xmbm from xm where xqbm=#{id})) and sfyj='1'
	</select>

	<select id="selectgrje" parameterType="String" resultType="io.renren.modules.app.entity.FwxxEntity">
 select ifnull(je,0) grje,fwbm from ywpzmx where (SUBSTR(djbh FROM 1 FOR 2)='03' or SUBSTR(djbh FROM 5 FOR 2)='03' or SUBSTR(djbh FROM 1 FOR 2)='05' or SUBSTR(djbh FROM 5 FOR 2)='05') and dhbm=#{dhbm}
	</select>
	<select id="selectdwje" parameterType="String" resultType="io.renren.modules.app.entity.FwxxEntity">
 select ifnull(je,0) dwje,fwbm from ywpzmx where (SUBSTR(djbh FROM 1 FOR 2)='02' or SUBSTR(djbh FROM 5 FOR 2)='02') and dhbm=#{dhbm}
	</select>
	<select id="selectgrje2" parameterType="String" resultType="io.renren.modules.app.entity.FwxxEntity">
 select ifnull(je,0) grje,fwbm from ywpzmx where (SUBSTR(djbh FROM 1 FOR 2)='03' or SUBSTR(djbh FROM 5 FOR 2)='03' or SUBSTR(djbh FROM 1 FOR 2)='05' or SUBSTR(djbh FROM 5 FOR 2)='05') and dhbm in(select dhbm from zhxx where xmbm=#{xmbm})
	</select>
	<select id="selectdwje2" parameterType="String" resultType="io.renren.modules.app.entity.FwxxEntity">
 select ifnull(je,0) dwje,fwbm from ywpzmx where (SUBSTR(djbh FROM 1 FOR 2)='02' or SUBSTR(djbh FROM 5 FOR 2)='02') and dhbm in(select dhbm from zhxx where xmbm=#{xmbm})
	</select>
	<select id="selectgrje3" parameterType="String" resultType="io.renren.modules.app.entity.FwxxEntity">
 select ifnull(je,0) grje,fwbm from ywpzmx where (SUBSTR(djbh FROM 1 FOR 2)='03' or SUBSTR(djbh FROM 5 FOR 2)='03' or SUBSTR(djbh FROM 1 FOR 2)='05' or SUBSTR(djbh FROM 5 FOR 2)='05') and dhbm in(select dhbm from zhxx where xmbm in(select xmbm from xm where xqbm=#{xqbm}))
	</select>
	<select id="selectdwje3" parameterType="String" resultType="io.renren.modules.app.entity.FwxxEntity">
 select ifnull(je,0) dwje,fwbm from ywpzmx where (SUBSTR(djbh FROM 1 FOR 2)='02' or SUBSTR(djbh FROM 5 FOR 2)='02') and dhbm in(select dhbm from zhxx where xmbm in(select xmbm from xm where xqbm=#{xqbm}))
	</select>
</mapper>