CommonMapper.xml 4.03 KB
<?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="cn.runsa.crmapp.common.mapper.CommonMapper">
	<select id="selectChannelId" resultType="java.util.HashMap">
		select
		b.CHL_ID
		from crm_account_set_wxgzh a,crm_account_set_channel b
		where a.ACT_ID=b.ACT_ID
		and b.SCENE=#{SCENE,jdbcType=VARCHAR}
		and a.GZH_ID=#{GZH_ID,jdbcType=VARCHAR}
	</select>

	<select id="selectChannelIdByActId" resultType="java.lang.Integer">
		select CHL_ID
		from crm_account_set_channel
		where  ACT_ID=#{ACT_ID} limit 0,1
	</select>

	<select id="selectProvince" resultType="java.util.HashMap">
		select prId as id,prName as name,prSort as sort
		from mtProvince
		where
		coId=#{pid,jdbcType=VARCHAR}
	</select>

	<select id="selectCity" resultType="java.util.HashMap">
		select ciId as id,ciName as name,ciSort as sort
		from mtCity
		where
		prId=#{pid,jdbcType=VARCHAR}
	</select>

	<select id="selectCityByName" resultType="java.util.HashMap">
		select ciId as id,ciName as name,ciSort as sort
		from mtCity
		where
		ciName
		like CONCAT('%','#{name,jdbcType=VARCHAR}','%')
	</select>

	<select id="selectTown" resultType="java.util.HashMap">
		select diId as id,diName as name,diSort as sort
		from mtDistrict
		where
		ciId=#{pid,jdbcType=VARCHAR}
	</select>

	<select id="selectArea" resultType="java.util.HashMap">
		select CBD_ID as id,CBD_NAME as name
		from crm_district
		<where>
			<if test="province !=null and province != '' ">
				PROVINCE = #{province, jdbcType=INTEGER}
			</if>
			<if test="province !=null and province != '' ">
				CITY = #{city, jdbcType=INTEGER}
			</if>
			<if test="province !=null and province != '' ">
				COUNTY = #{county, jdbcType=INTEGER}
			</if>
		</where>
	</select>

	<select id="selectGzhBrand" resultType="java.util.HashMap">
		select a.brId,a.brName from mtbrand a
		INNER JOIN crm_account_set_brand b
		on a.brId=b.BND_ID
		INNER JOIN crm_site_group c on b.ACT_ID=c.ACT_ID
		INNER JOIN crm_site_group_wxgzh d on
		c.GRP_ID=d.GRP_ID
		where d.GZH_ID=#{gzhId,jdbcType=VARCHAR}
	</select>

	<select id="getNearbyStores" resultType="map">
		SELECT distinct
		a.siId,a.siCode,a.siName,a.ptAddr,a.ptTphone,st_distance(point(IFNULL(a.siNavLat,0),IFNULL(a.siNavLng,0)),point(#{latitude},#{longitude}))*111195
		AS distance,a.siNavLat,a.siNavLng
		FROM
		mtSite a LEFT JOIN vdistrict b on a.diId = b.diId
		LEFT JOIN
		crm_account_set_site c on
		a.siId=c.SIT_ID
		WHERE a.siId in
		(select SIT_ID from crm_account_set_site where GRP_ID in 
		(select GRP_ID from crm_site_group_wxgzh where GZH_ID = #{gzhId,jdbcType=VARCHAR}))
		<if test="city=null">
			AND a.siNavLat is not null
			AND a.siNavLng is not null
			AND a.siNavLat &gt; #{ringRegion.minLat}
			AND a.siNavLat &lt; #{ringRegion.maxLat}
			AND a.siNavLng &gt; #{ringRegion.minLng}
			AND a.siNavLng &lt; #{ringRegion.maxLng}
		</if>
		<if test="city!=null">
			AND b.`ciId` in
			<foreach collection="city" open="(" close=")" separator="," item="it">
				#{it}
			</foreach>
		</if>
		<if test="brand!=null">
			AND c.`BND_ID` in
			<foreach collection="brand" open="(" close=")" separator="," item="it">
				#{it}
			</foreach>
		</if>
		<if test="siteName!=null">
			AND a.`siName` like CONCAT('%',#{siteName,jdbcType=VARCHAR},'%')
		</if>
		AND a.`ptValid` = 1
		ORDER BY distance ASC
		LIMIT
		#{start} ,#{size}
	</select>
	
	<select id="selectAll" resultType="java.util.HashMap">
		select distinct ciId,ciName,prId,prName 
		from vdistrict
		order by convert(prName using gbk) asc
	</select>
	
	<select id="nearlySiteAndCity" resultType="map">
		SELECT t1.siId,t1.siName,t3.prName,t3.ciName,t3.diName,
		st_distance(point(t1.siNavLat,t1.siNavLng),point(#{latitude},#{longitude}))*111195 as distance
		FROM `mtsite` t1 
		LEFT JOIN vdistrict t3 ON t1.diId = t3.diId
		WHERE t1.`ptValid` = 1
		AND t1.siId in
		(select SIT_ID from crm_account_set_site where GRP_ID in 
		(select GRP_ID from crm_site_group_wxgzh where GZH_ID = #{gzhId,jdbcType=VARCHAR}))
		ORDER BY distance ASC LIMIT 0,1
	</select>
</mapper>