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

	<!-- 可根据自己的需求，是否要使用 -->
	<resultMap type="io.renren.modules.app.entity.XmEntity" id="xmMap">
		<result property="xmbm" column="xmbm" />
		<result property="xmmc" column="xmmc" />
		<result property="xkzh" column="xkzh" />
		<result property="gczh" column="gczh" />
		<result property="zrht" column="zrht" />
		<result property="gzdbm" column="gzdbm" />
		<result property="kgrq" column="kgrq" />
		<result property="jfrq" column="jfrq" />
		<result property="dlwz" column="dlwz" />
		<result property="bz" column="bz" />
		<result property="dwbm" column="dwbm" />
		<result property="djdj" column="djdj" />
		<result property="lxr" column="lxr" />
		<result property="lxdh" column="lxdh" />
		<result property="sgzh" column="sgzh" />
		<result property="zzzh" column="zzzh" />
		<result property="rfmj" column="rfmj" />
		<result property="jkmj" column="jkmj" />
		<result property="sfrf" column="sfrf" />
		<result property="sfjk" column="sfjk" />
		<result property="xqbm" column="xqbm" />
		<result property="yjje" column="yjje" />
		<result property="sfdz" column="sfdz" />
	</resultMap>

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

		select
		xm.xmbm,
		xm.xmmc,
		xm.xkzh,
		xm.gczh,
		xm.zrht,
		xm.gzdbm,
		xm.kgrq,
		xm.jfrq,
		xm.dlwz,
		xm.bz,
		xm.dwbm,
		xm.djdj,
		xm.lxr,
		xm.lxdh,
		xm.sgzh,
		xm.zzzh,
		xm.rfmj,
		xm.jkmj,
		xm.sfrf,
		xm.sfjk,
		xm.xqbm,
		xm.yjje,
		xm.sfdz,
		(select count(*) from zhxx
		where zhxx.xmbm = xm.xmbm) zhcon from xm where 1=1

		<if test=" xmbm!=null and xmbm!='' ">
			and xmbm like CONCAT(#{xmbm},"%")
		</if>
		<if test=" xmmc!=null and xmmc!='' ">
			and xmmc like CONCAT(#{xmmc},"%")
		</if>
		<if test=" xkzh!=null and xkzh!='' ">
			and xkzh like CONCAT(#{xkzh},"%")
		</if>
		<if test=" gczh!=null and gczh!='' ">
			and gczh like CONCAT(#{gczh},"%")
		</if>
		<if test=" zrht!=null and zrht!='' ">
			and zrht like CONCAT(#{zrht},"%")
		</if>
		<if test=" gzdbm!=null and gzdbm!='' ">
			and gzdbm like CONCAT(#{gzdbm},"%")
		</if>
		<if test=" kgrq!=null and kgrq!='' ">
			and kgrq like CONCAT(#{kgrq},"%")
		</if>
		<if test=" jfrq!=null and jfrq!='' ">
			and jfrq like CONCAT(#{jfrq},"%")
		</if>
		<if test=" dlwz!=null and dlwz!='' ">
			and dlwz like CONCAT(#{dlwz},"%")
		</if>
		<if test=" bz!=null and bz!='' ">
			and bz like CONCAT(#{bz},"%")
		</if>
		<if test=" dwbm!=null and dwbm!='' ">
			and dwbm like CONCAT(#{dwbm},"%")
		</if>
		<if test=" djdj!=null and djdj!='' ">
			and djdj like CONCAT(#{djdj},"%")
		</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=" sgzh!=null and sgzh!='' ">
			and sgzh like CONCAT(#{sgzh},"%")
		</if>
		<if test=" zzzh!=null and zzzh!='' ">
			and zzzh like CONCAT(#{zzzh},"%")
		</if>
		<if test=" rfmj!=null and rfmj!='' ">
			and rfmj like CONCAT(#{rfmj},"%")
		</if>
		<if test=" jkmj!=null and jkmj!='' ">
			and jkmj like CONCAT(#{jkmj},"%")
		</if>
		<if test=" sfrf!=null and sfrf!='' ">
			and sfrf like CONCAT(#{sfrf},"%")
		</if>
		<if test=" sfjk!=null and sfjk!='' ">
			and sfjk like CONCAT(#{sfjk},"%")
		</if>
		<if test=" xqbm!=null and xqbm!='' ">
			and xqbm like CONCAT(#{xqbm},"%")
		</if>
		<if test=" yjje!=null and yjje!='' ">
			and yjje like CONCAT(#{yjje},"%")
		</if>
		<if test=" sfdz!=null and sfdz!='' ">
			and sfdz like CONCAT(#{sfdz},"%")
		</if>
		order by xmbm desc
	</select>

	<select id="selectxqmcxx" resultType="io.renren.modules.app.entity.XqxxEntity">
		select * from xqxx where
		1=1

	</select>

	<select id="selectxlkgj" resultType="io.renren.modules.app.entity.XlkEntity">
		select gzdmc,gzdbm from
		gzdxx where 1=1

	</select>

	<select id="maxkmbm" resultType="io.renren.modules.app.entity.XmEntity">
		select max(km) km from h_km where
		LENGTH(km)=6 and SUBSTR(km FROM 1 FOR 3)='211'
	</select>

	<select id="selectxlkdw" resultType="io.renren.modules.app.entity.XlkEntity">
		select dwmc,dwbm from sfdw
		where 1=1

	</select>

	<select id="selectxlkxq" resultType="io.renren.modules.app.entity.XlkEntity">
		select xqmc,xqbm from xqxx
		where 1=1

	</select>

	<insert id="insertxm" parameterType="io.renren.modules.app.entity.XmEntity">
		insert into xm(
		xmbm,xmmc,xkzh,gczh,zrht,gzdbm,kgrq,jfrq,
		dlwz,bz,dwbm,djdj,lxr,lxdh,sgzh,zzzh,rfmj,jkmj,sfrf,sfjk,xqbm,yjje,sfdz,kfskm
		) values(
		#{xmbm},#{xmmc},#{xkzh},#{gczh},#{zrht},#{gzdbm},#{kgrq},#{jfrq},#{dlwz},#{bz},
		#{dwbm},#{djdj},#{lxr},#{lxdh},#{sgzh},#{zzzh},#{rfmj},#{jkmj},#{sfrf},#{sfjk},#{xqbm},#{yjje},#{sfdz},#{kfskm}
		)
	</insert>

	<select id="queryxmbm" resultType="string">
		SELECT xmbm FROM xm WHERE LENGTH(xmbm)>=8 ORDER BY xmbm DESC LIMIT 1
	</select>

	<insert id="insertkm" parameterType="io.renren.modules.app.entity.HKmEntity">
		insert into
		h_km(km,kmmc,kmlbbm,kmsx,djkm,jbh,ztbm,gzdbm)
		values(#{km},#{kmmc},#{kmlbbm},#{kmsx},#{djkm},#{jbh},#{ztbm},#{gzdbm})
	</insert>
	
	<insert id="insertfzhsye" parameterType="io.renren.modules.app.entity.YwpzEntity">
	insert into fzhsye(gjkjqj,xmbm,djlx,qcye,jffse,dffse,qmye,zqlx)values(#{gjkjqj},#{xmbm},#{djlx},#{qcye},#{jffse},#{dffse},#{qmye},#{zqlx})
	</insert>
	
	<delete id="deletefzhsyexmbm" parameterType="string">
	delete from fzhsye where xmbm=#{id}
	</delete>
	
	<select id="selectmaxkjqj" resultType="string">
		select MAX(gjkjqj) from fzhsye where djlx='01'
	</select>
	
	<select id="selectmaxkjqj2" resultType="string">
		select MAX(gjkjqj) from fzhsye where djlx='21'
	</select>

</mapper>