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

	<!-- 可根据自己的需求，是否要使用 -->
	<resultMap type="io.renren.modules.app.entity.GrbgEntity" id="grbgMap">
		<result property="bgdbh" column="bgdbh" />
		<result property="cczh" column="cczh" />
		<result property="fwbm" column="fwbm" />
		<result property="mphm" column="mphm" />
		<result property="qXm" column="q_xm" />
		<result property="qSfzh" column="q_sfzh" />
		<result property="qLxdh" column="q_lxdh" />
		<result property="hXm" column="h_xm" />
		<result property="hSfzh" column="h_sfzh" />
		<result property="hLxdh" column="h_lxdh" />
		<result property="dqye" column="dqye" />
		<result property="bgrq" column="bgrq" />
		<result property="czyxm" column="czyxm" />
		<result property="czybm" column="czybm" />
		<result property="gzdbm" column="gzdbm" />
		<result property="qDz" column="q_dz" />
		<result property="hDz" column="h_dz" />
		<result property="hCczh" column="h_cczh" />
	</resultMap>

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

		select distinct z.dhmc,g.bgdbh,g.fwbm,g.cczh,g.h_cczh hcczh,g.q_lxdh
		qllxdh,g.h_lxdh hllxdh,g.dqye,g.bgrq,g.q_sfzh qsfzh,g.h_sfzh
		hsfzh,g.q_dz qdz,g.h_dz hdz,f.mh,f.lc,g.mphm,g.q_xm qxm,g.h_xm hxm
		from
		grbg g,fwxx f,zhxx
		z,xm x,xqxx q,wygsxx w where g.fwbm=f.fwbm and
		f.dhbm=z.dhbm and z.xmbm=x.xmbm and x.xqbm=q.xqbm

		<if test=" bgrq!=null and bgrq!='' ">
			and g.bgrq like CONCAT(#{bgrq},"%")
		</if>
		<if test=" dhbm!=null and dhbm!='' ">
			and z.dhbm like CONCAT(#{dhbm},"%")
		</if>
		<if test=" xmbm!=null and xmbm!='' ">
			and x.xmbm like CONCAT(#{xmbm},"%")
		</if>
		<if test=" xqbm!=null and xqbm!='' ">
			and q.xqbm like CONCAT(#{xqbm},"%")
		</if>
		order by g.bgdbh desc
	</select>

	<select id="selectfwxx" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.FwxxEntity">
		select * from fwxx where fwbm=#{id}
	</select>

	<insert id="insertcqbg" parameterType="io.renren.modules.app.entity.GrbgEntity">
		insert into
		grbg(bgdbh,cczh,h_cczh,fwbm,mphm,
		q_xm,q_sfzh,q_lxdh,q_dz,h_xm,
		h_sfzh,h_lxdh,h_dz,dqye,bgrq,czyxm,czybm,gzdbm)
		values(#{bgdbh},#{cczh},#{h_cczh},#{fwbm},
		#{mphm},#{q_xm},#{q_sfzh},#{q_lxdh},#{q_dz},#{h_xm},#{h_sfzh},#{h_lxdh},#{h_dz},#{dqye},#{bgrq},#{czyxm},#{czybm},#{gzdbm})
	</insert>

	<update id="updatefwxx" parameterType="io.renren.modules.app.entity.GrbgEntity">
		update fwxx set
		xm=#{h_xm},sfzh=#{h_sfzh},lxdh=#{h_lxdh},dz=#{h_dz},cczh=#{h_cczh}
		where fwbm=#{fwbm}
	</update>

	<select id="queryByCount" parameterType="java.lang.String"
		resultType="java.lang.String">
		select max(substr(bgdbh,15,4)) from grbg where
		substr(bgrq,1,7)=substr(#{date},1,7)

	</select>


</mapper>