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

	<!-- 可根据自己的需求，是否要使用 -->
	<resultMap type="io.renren.modules.app.entity.SfdwEntity" id="sfdwMap">
		<result property="dwbm" column="dwbm" />
		<result property="dwmc" column="dwmc" />
		<result property="lxr" column="lxr" />
		<result property="lxdh" column="lxdh" />
		<result property="gslb" column="gslb" />
		<result property="zzdj" column="zzdj" />
		<result property="zsh" column="zsh" />
		<result property="zshfrq" column="zshfrq" />
		<result property="zsyxq" column="zsyxq" />
		<result property="hrdb" column="hrdb" />
		<result property="zczj" column="zczj" />
		<result property="nsrq" column="nsrq" />
		<result property="nsqk" column="nsqk" />
		<result property="kfyh" column="kfyh" />
		<result property="yxzh" column="yxzh" />
		<result property="dz" column="dz" />
		<result property="gzdbm" column="gzdbm" />
		<result property="zckje" column="zckje" />
	</resultMap>

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

		select sfdw.dwbm,
		sfdw.dwmc,
		sfdw.lxr,
		sfdw.lxdh,
		sfdw.gslb,
		sfdw.zzdj,
		sfdw.zsh,
		sfdw.zshfrq,
		sfdw.zsyxq,
		sfdw.hrdb,
		sfdw.zczj,
		sfdw.nsrq,
		sfdw.nsqk,
		sfdw.kfyh,
		sfdw.yxzh,
		sfdw.dz,
		sfdw.gzdbm,
		sfdw.zckje,
		ifnull((SELECT count(*) from xm where sfdw.dwbm = xm.dwbm),'0') xmcon from sfdw
		where 1=1

		<if test=" dwbm!=null and dwbm!='' ">
			and dwbm like CONCAT(#{dwbm},"%")
		</if>
		<if test=" dwmc!=null and dwmc!='' ">
			and dwmc like CONCAT(#{dwmc},"%")
		</if>
		<if test=" lxr!=null and lxr!='' ">
			and lxr like CONCAT(#{lxr},"%")
		</if>
		<if test=" lxdh!=null and lxdh!='' ">
			and lxdh like CONCAT(#{lxdh},"%")
		</if>
		<if test=" gslb!=null and gslb!='' ">
			and gslb like CONCAT(#{gslb},"%")
		</if>
		<if test=" zzdj!=null and zzdj!='' ">
			and zzdj like CONCAT(#{zzdj},"%")
		</if>
		<if test=" zsh!=null and zsh!='' ">
			and zsh like CONCAT(#{zsh},"%")
		</if>
		<if test=" zshfrq!=null and zshfrq!='' ">
			and zshfrq like CONCAT(#{zshfrq},"%")
		</if>
		<if test=" zsyxq!=null and zsyxq!='' ">
			and zsyxq like CONCAT(#{zsyxq},"%")
		</if>
		<if test=" hrdb!=null and hrdb!='' ">
			and hrdb like CONCAT(#{hrdb},"%")
		</if>
		<if test=" zczj!=null and zczj!='' ">
			and zczj like CONCAT(#{zczj},"%")
		</if>
		<if test=" nsrq!=null and nsrq!='' ">
			and nsrq like CONCAT(#{nsrq},"%")
		</if>
		<if test=" nsqk!=null and nsqk!='' ">
			and nsqk like CONCAT(#{nsqk},"%")
		</if>
		<if test=" kfyh!=null and kfyh!='' ">
			and kfyh like CONCAT(#{kfyh},"%")
		</if>
		<if test=" yxzh!=null and yxzh!='' ">
			and yxzh like CONCAT(#{yxzh},"%")
		</if>
		<if test=" dz!=null and dz!='' ">
			and dz like CONCAT(#{dz},"%")
		</if>
		<if test=" gzdbm!=null and gzdbm!='' ">
			and gzdbm like CONCAT(#{gzdbm},"%")
		</if>
		<if test=" zckje!=null and zckje!='' ">
			and zckje like CONCAT(#{zckje},"%")
		</if>
		order by dwbm desc
	</select>

	<select id="querydwbm" resultType="string">
		SELECT dwbm FROM sfdw WHERE LENGTH(dwbm)>=8 ORDER BY dwbm DESC LIMIT 1
	</select>


</mapper>