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

	<!-- 可根据自己的需求，是否要使用 -->
	<resultMap type="io.renren.modules.app.entity.SqwxzqEntity"
		id="sqwxzqMap">
		<result property="sqdbh" column="sqdbh" />
		<result property="sqrq" column="sqrq" />
		<result property="sqdwbm" column="sqdwbm" />
		<result property="dhbm" column="dhbm" />
		<result property="sqje" column="sqje" />
		<result property="lx" column="lx" />
		<result property="wxbw" column="wxbw" />
		<result property="zfy" column="zfy" />
		<result property="zhs" column="zhs" />
		<result property="dwyj" column="dwyj" />
		<result property="gwhyj" column="gwhyj" />
		<result property="pzdwyj" column="pzdwyj" />
		<result property="jbrxm" column="jbrxm" />
		<result property="jbrdh" column="jbrdh" />
		<result property="bz" column="bz" />
		<result property="czybm" column="czybm" />
		<result property="czyxm" column="czyxm" />
		<result property="gzdbm" column="gzdbm" />
		<result property="shrbm" column="shrbm" />
		<result property="shrxm" column="shrxm" />
		<result property="shrq" column="shrq" />
		<result property="sfsh" column="sfsh" />
		<result property="sfjz" column="sfjz" />
		<result property="cbwdbm" column="cbwdbm" />
		<result property="sffp" column="sffp" />
		<result property="fprbm" column="fprbm" />
		<result property="fprxm" column="fprxm" />
		<result property="fprq" column="fprq" />
		<result property="fpfs" column="fpfs" />
		<result property="djbh" column="djbh" />
		<result property="jsdbh" column="jsdbh" />
		<result property="sfjs" column="sfjs" />
		<result property="sqdw" column="sqdw" />
	</resultMap>

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

		select
		distinct s.sqdbh,s.sqdw,s.sqrq,q.xqmc,x.xmmc,x.xmbm,sqje,
		s.sfsh,s.wxbw,s.zfy,s.zhs,s.jbrxm,s.jbrdh,s.dwyj,s.gwhyj,s.bz,s.shrxm,s.shrq,s.spje,s.pzdwyj,s.ysje,s.xzbflx,s.xzwxlx,s.wxdzt,s.fjid,s.sgdw,s.dsfsj
		from sqwxzq s,zhxx z,xm x,xqxx q
		where s.xmbm=x.xmbm
		and
		x.xqbm=q.xqbm
		<if test=" sqdbh!=null and sqdbh!='' ">
			and s.sqdbh like CONCAT(#{sqdbh},"%")
		</if>
		<if test=" dhbm!=null and dhbm!='' ">
			and s.dhbm like CONCAT(#{dhbm},"%")
		</if>
		<if test=" sfsh!=null and sfsh!='' ">
			and s.sfsh like CONCAT(#{sfsh},"%")
		</if>
		<if test=" xqbm!=null and xqbm!='' ">
			and q.xqbm like CONCAT(#{xqbm},"%")
		</if>
		<if test=" xmbm!=null and xmbm!='' ">
			and x.xmbm like CONCAT(#{xmbm},"%")
		</if>
		<if test=" sqdw!=null and sqdw!='' ">
			and s.sqdw like CONCAT(#{sqdw},"%")
		</if>
		<if test=" beginrq!=null and beginrq!='' and endrq!=null and endrq!='' ">
			and s.sqrq between #{beginrq} and #{endrq}
		</if>
		order by s.sqdbh desc
	</select>
	<select id="queryByCount" parameterType="java.lang.String"
		resultType="java.lang.String">
		select max(substr(sqdbh,15,4)) from sqwxzq where
		substr(lrrq,1,7)=substr(#{date},1,7)
	</select>
	<select id="query" parameterType="io.renren.modules.app.entity.SqwxzqEntity"
		resultType="io.renren.modules.app.entity.SqwxzqEntity">

		select * from sqwxzq where sfsh in ('0','2') and sfjz = '0' and sffp =
		'0'

		<if test=" sqdbh!=null and sqdbh!='' ">
			and sqdbh like CONCAT(#{sqdbh},"%")
		</if>
	</select>
	<select id="querys" parameterType="io.renren.modules.app.entity.SqwxzqEntity"
		resultType="io.renren.modules.app.entity.SqwxzqEntity">

		select * from sqwxzq where sfsh in ('0','2') and sfjz = '0'
		and sffp = '0'
	</select>
	<select id="querykjqj" parameterType="io.renren.modules.app.entity.SqwxzqEntity"
		resultType="io.renren.modules.app.entity.SqwxzqEntity">

		SELECT x.dqkjqj FROM sqwxzq s
		LEFT JOIN xtcs x ON s.gzdbm = x.gzdbm
		<if test=" sqdbh!=null and sqdbh!='' ">
			and s.sqdbh like CONCAT(#{sqdbh},"%")
		</if>
	</select>
	<select id="querydjbh" parameterType="io.renren.modules.app.entity.SqwxzqEntity"
		resultType="int">

		select COUNT(*)+1 from ywpz where gzdbm='0001' and
		djlx='21'
	</select>

	<select id="querym" parameterType="io.renren.modules.app.entity.SqwxzqEntity"
		resultType="io.renren.modules.app.entity.SqwxzqEntity">

		select * from sqwxzq where 1=1

		<if test=" sqdbh!=null and sqdbh!='' ">
			and sqdbh like CONCAT(#{sqdbh},"%")
		</if>
		<if test=" sqrq!=null and sqrq!='' ">
			and sqrq like CONCAT(#{sqrq},"%")
		</if>
		<if test=" sqdwbm!=null and sqdwbm!='' ">
			and sqdwbm like CONCAT(#{sqdwbm},"%")
		</if>
		<if test=" dhbm!=null and dhbm!='' ">
			and dhbm like CONCAT(#{dhbm},"%")
		</if>
		<if test=" sqje!=null and sqje!='' ">
			and sqje like CONCAT(#{sqje},"%")
		</if>
		<if test=" lx!=null and lx!='' ">
			and lx like CONCAT(#{lx},"%")
		</if>
		<if test=" wxbw!=null and wxbw!='' ">
			and wxbw like CONCAT(#{wxbw},"%")
		</if>
		<if test=" zfy!=null and zfy!='' ">
			and zfy like CONCAT(#{zfy},"%")
		</if>
		<if test=" zhs!=null and zhs!='' ">
			and zhs like CONCAT(#{zhs},"%")
		</if>
		<if test=" dwyj!=null and dwyj!='' ">
			and dwyj like CONCAT(#{dwyj},"%")
		</if>
		<if test=" gwhyj!=null and gwhyj!='' ">
			and gwhyj like CONCAT(#{gwhyj},"%")
		</if>
		<if test=" pzdwyj!=null and pzdwyj!='' ">
			and pzdwyj like CONCAT(#{pzdwyj},"%")
		</if>
		<if test=" jbrxm!=null and jbrxm!='' ">
			and jbrxm like CONCAT(#{jbrxm},"%")
		</if>
		<if test=" jbrdh!=null and jbrdh!='' ">
			and jbrdh like CONCAT(#{jbrdh},"%")
		</if>
		<if test=" bz!=null and bz!='' ">
			and bz like CONCAT(#{bz},"%")
		</if>
		<if test=" czybm!=null and czybm!='' ">
			and czybm like CONCAT(#{czybm},"%")
		</if>
		<if test=" czyxm!=null and czyxm!='' ">
			and czyxm like CONCAT(#{czyxm},"%")
		</if>
		<if test=" gzdbm!=null and gzdbm!='' ">
			and gzdbm like CONCAT(#{gzdbm},"%")
		</if>
		<if test=" shrbm!=null and shrbm!='' ">
			and shrbm like CONCAT(#{shrbm},"%")
		</if>
		<if test=" shrxm!=null and shrxm!='' ">
			and shrxm like CONCAT(#{shrxm},"%")
		</if>
		<if test=" shrq!=null and shrq!='' ">
			and shrq like CONCAT(#{shrq},"%")
		</if>
		<if test=" sfsh!=null and sfsh!='' ">
			and sfsh like CONCAT(#{sfsh},"%")
		</if>
		<if test=" sfjz!=null and sfjz!='' ">
			and sfjz like CONCAT(#{sfjz},"%")
		</if>
		<if test=" cbwdbm!=null and cbwdbm!='' ">
			and cbwdbm like CONCAT(#{cbwdbm},"%")
		</if>
		<if test=" sffp!=null and sffp!='' ">
			and sffp like CONCAT(#{sffp},"%")
		</if>
		<if test=" fprbm!=null and fprbm!='' ">
			and fprbm like CONCAT(#{fprbm},"%")
		</if>
		<if test=" fprxm!=null and fprxm!='' ">
			and fprxm like CONCAT(#{fprxm},"%")
		</if>
		<if test=" fprq!=null and fprq!='' ">
			and fprq like CONCAT(#{fprq},"%")
		</if>
		<if test=" fpfs!=null and fpfs!='' ">
			and fpfs like CONCAT(#{fpfs},"%")
		</if>
		<if test=" djbh!=null and djbh!='' ">
			and djbh like CONCAT(#{djbh},"%")
		</if>
		<if test=" jsdbh!=null and jsdbh!='' ">
			and jsdbh like CONCAT(#{jsdbh},"%")
		</if>
		<if test=" sfjs!=null and sfjs!='' ">
			and sfjs like CONCAT(#{sfjs},"%")
		</if>
		<if test=" sqdw!=null and sqdw!='' ">
			and sqdw like CONCAT(#{sqdw},"%")
		</if>
	</select>

	<select id="selectdjbh" resultType="io.renren.modules.app.entity.XlkEntity">
		select
		s.sqdbh,s.sqrq,s.sqdw,z.dhmc,s.wxbw from sqwxzq s,zhxx z where
		s.dhbm=z.dhbm and sfsh in(0,2)
	</select>

	<select id="selectsqdjxx" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.SqwxzqEntity">
		select
		s.sqdbh,s.sqrq,s.sqdw,a.xqmc,x.xmmc,z.dhmc,s.wxbw,
		s.sqje,s.sfsh,s.zfy,s.zhs,s.dwyj,s.gwhyj,s.jbrxm,s.jbrdh,s.bz,s.shrxm,s.shrq
		from sqwxzq s,s.pzdwyj
		zhxx z,xm x,xqxx a where s.dhbm=z.dhbm and
		z.xmbm=x.xmbm
		and
		x.xqbm=a.xqbm and s.sqdbh=#{id}
	</select>

	<select id="selectxmbyxq" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.XlkEntity">
		select xmbm,xmmc from xm where xqbm=#{id}
	</select>

	<select id="selectlzbyxm" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.XlkEntity">
		select dhbm,dhmc from zhxx where xmbm=#{id}
	</select>

	<select id="selectwxxmxx" resultType="io.renren.modules.app.entity.WxxmxxEntity">
		select * from wxxmxx where
		1=1
	</select>
	<select id="selectwxxmxxbymc" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.WxxmxxEntity">
		select * from wxxmxx where wxxmmc=#{id}
	</select>
	<insert id="inserts" parameterType="io.renren.modules.app.entity.SqwxzqEntity">
		INSERT INTO sqwxzq(
		sqdbh, <!-- 行政区划级别 -->
		sqrq, <!-- 行政区划编码 -->
		sqdwbm, <!-- 农村城市类型 -->
		dhbm, <!-- 行政个数 -->
		sqje, <!-- 辖区面积 -->
		lx, <!-- 户籍人口 -->
		wxbw, <!-- 户籍户数 -->
		zfw, <!-- 常住人口 -->
		zhs, <!-- 服务面积 -->
		dwyj, <!-- 服务户数 -->
		gwhyj, <!-- 服务人口 -->
		pzdwyj, <!-- 清扫总面积 -->
		jbrxm, <!-- 主次道路面积 -->
		jbrdh, <!-- 主次道路机械化清扫面积 -->
		bz, <!-- 主次道路机械化清扫面积 -->
		czyxm, <!-- 主次道路机械化清扫面积 -->
		gzdbm, <!-- 主次道路机械化清扫面积 -->
		shrbm, <!-- 主次道路机械化清扫面积 -->
		shrxm, <!-- 主次道路机械化清扫面积 -->
		shrq, <!-- 主次道路机械化清扫面积 -->
		sfsh, <!-- 主次道路机械化清扫面积 -->
		sfjz, <!-- 主次道路机械化清扫面积 -->
		cbwdbm, <!-- 主次道路机械化清扫面积 -->
		sffp, <!-- 主次道路机械化清扫面积 -->
		fprbm, <!-- 主次道路机械化清扫面积 -->
		fprxm, <!-- 主次道路机械化清扫面积 -->
		fprq, <!-- 主次道路机械化清扫面积 -->
		fpfs, <!-- 主次道路机械化清扫面积 -->
		djbh, <!-- 主次道路机械化清扫面积 -->
		jsdbh, <!-- 主次道路机械化清扫面积 -->
		sfjs, <!-- 主次道路机械化清扫面积 -->
		sqdw, <!-- 主次道路机械化清扫面积 -->
		id, <!-- 主次道路机械化清扫面积 -->
		czybm <!-- 状态 -->
		)
		VALUES
		(#{sqdbh},#{sqrq},#{sqdwbm},#{dhbm},#{sqje},#{lx},#{wxbw},#{zfw},#{zhs},#{dwyj},#{gwhyj},#{pzdwyj},#{jbrxm},#{jbrdh},#{bz},#{czyxm},#{gzdbm},#{shrbm},#{shrxm},#{shrq},#{sfsh},#{sfjz},#{cbwdbm},#{sffp},#{fprbm},#{fprxm},#{fprq},#{fpfs},#{djbh},#{jsdbh},#{sfjs},#{sqdw},#{id},#{czybm})
	</insert>
	<insert id="insertwxjlb" parameterType="io.renren.modules.app.entity.WxjlbEntity">
		insert into
		wxjlb(id,sqdbh,dhbm,fybm,sqje)
		values(#{id},#{sqdbh},#{dhbm},#{fybm},#{sqje})
	</insert>

	<insert id="insertsqwxz" parameterType="io.renren.modules.app.entity.SqwxzqEntity">
		insert into
		sqwxzq(id,sqdbh,sqrq,dhbm,sqje,wxbw,zfy,zhs,dwyj,gwhyj,pzdwyj,jbrxm,jbrdh,bz,sqdw,lrrq,czybm,czyxm,gzdbm,cbwdbm,xmbm,ysje,xzbflx,xzwxlx,fjid,wxdzt,sgdw,dsfsj)
		values(#{id},#{sqdbh},#{sqrq},#{dhbm},#{sqje},#{wxbw},#{zfy},#{zhs},#{dwyj},#{gwhyj},#{pzdwyj},#{jbrxm},#{jbrdh},#{bz},#{sqdw},#{lrrq},#{czybm},#{czyxm},'0001','0001',#{xmbm},#{ysje},#{xzbflx},#{xzwxlx},#{fjid},'1',#{sgdw},#{dsfsj})
	</insert>

	<select id="selectwxxmxxbysqdh" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.WxjlbEntity">
		select
		j.sqdbh,j.id,j.fybm,j.sqje,w.wxxmmc,w.bz,j.dhbm,z.dhmc,x.xmmc from wxjlb
		j,wxxmxx
		w,zhxx z,xm x
		where
		j.fybm=w.wxxmbm and j.dhbm=z.dhbm and z.xmbm=x.xmbm and
		j.sqdbh=#{id}
	</select>
	<update id="updatesqdj" parameterType="io.renren.modules.app.entity.SqwxzqEntity">
		update sqwxzq set
		sqrq=#{sqrq},xmbm=#{xmbm},sqje=#{sqje},wxbw=#{wxbw},zfy=#{zfy},zhs=#{zhs},dwyj=#{dwyj},gwhyj=#{gwhyj},jbrxm=#{jbrxm},jbrdh=#{jbrdh},bz=#{bz},sqdw=#{sqdw},ysje=#{ysje},xzwxlx=#{xzwxlx}
		where sqdbh=#{sqdbh}
	</update>
	<update id="updatewxjlb" parameterType="io.renren.modules.app.entity.WxjlbEntity">
		update wxjlb set
		dhbm=#{dhbm},fybm=#{fybm},sqje=#{sqje} where id=#{id}
	</update>
	<delete id="deletesqdj" parameterType="java.lang.String">
		delete from sqwxzq where
		sqdbh=#{id}
	</delete>
	<delete id="deletewxjlb" parameterType="java.lang.String">
		delete from wxjlb where
		sqdbh=#{id}
	</delete>
	<delete id="deletewxjlbbyid" parameterType="java.lang.String">
		delete from wxjlb
		where
		id=#{id}
	</delete>

	<select id="getWjqljById" parameterType="java.lang.String"
		resultType="java.lang.String">
		select wjqlj from fjb where id=#{id}
	</select>

	<insert id="insertFjb" parameterType="io.renren.modules.app.entity.FjEntity">
		insert into
		fjb(id,wjmc,wjtype,wjqlj,wjsize,createtime,creatid,wjzl)
		values(#{id},#{wjmc},#{wjtype},#{wjqlj},#{wjsize},#{createtime},#{creatid},#{wjzl})
	</insert>
	
	<select id="selectwjdxbyfjid" parameterType="java.lang.String"
		resultType="io.renren.modules.app.entity.FjEntity">
		select * from fjb where id=#{id}
	</select>
	
	<select id="queryByxm" parameterType="java.lang.String"
		resultType="java.lang.String">
		select xmmc from xm where xmbm in(select xmbm from zhxx where dhbm in (select dhbm from wxjlb where sqdbh=#{sqdbh}))
	</select>
</mapper>