CarPermanentMapper.xml 15.6 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.com.glsx.dj.customer.mapper.CarPermanentMapper">
	<resultMap id="BaseResultMap" type="cn.com.glsx.dj.customer.model.CarPermanent">
		<id column="id" jdbcType="INTEGER" property="id" />
		<result column="sn" jdbcType="VARCHAR" property="sn" />
		<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
		<result column="name" jdbcType="VARCHAR" property="name" />
		<result column="mobile" jdbcType="VARCHAR" property="mobile" />
		<result column="location" jdbcType="VARCHAR" property="location" />
		<result column="distance" jdbcType="DOUBLE" property="distance" />
		<result column="is_nearest" jdbcType="INTEGER" property="isNearest" />
		<result column="vehicle_id" jdbcType="INTEGER" property="vehicleId" />
		<result column="total_stay_times" jdbcType="INTEGER" property="totalStayTimes" />
		<result column="azimuth" jdbcType="DOUBLE" property="azimuth" />
		<result column="azimuth_desc" jdbcType="VARCHAR" property="azimuthDesc" />
		<result column="province" jdbcType="VARCHAR" property="province" />
		<result column="region" jdbcType="VARCHAR" property="region" />
		<result column="shop_name" jdbcType="VARCHAR" property="shopName" />
		<result column="merchant_code" jdbcType="VARCHAR" property="merchantCode" />
		<result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
		<result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
		<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
		<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
		<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
		<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
		<result column="deleted_flag" jdbcType="CHAR" property="deletedFlag" />
	</resultMap>

	<resultMap id="BaseResultDTOMap" type="cn.com.glsx.dj.customer.dto.CarPermanentDTO">
		<id column="id" jdbcType="INTEGER" property="id" />
		<result column="sn" jdbcType="VARCHAR" property="sn" />
		<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
		<result column="name" jdbcType="VARCHAR" property="name" />
		<result column="mobile" jdbcType="VARCHAR" property="mobile" />
		<result column="location" jdbcType="VARCHAR" property="location" />
		<result column="distance" jdbcType="DOUBLE" property="distance" />
		<result column="is_nearest" jdbcType="INTEGER" property="isNearest" />
		<result column="vehicle_id" jdbcType="INTEGER" property="vehicleId" />
		<result column="total_stay_times" jdbcType="INTEGER" property="totalStayTimes" />
		<result column="azimuth" jdbcType="DOUBLE" property="azimuth" />
		<result column="azimuth_desc" jdbcType="VARCHAR" property="azimuthDesc" />
		<result column="merchant_code" jdbcType="VARCHAR" property="merchantCode" />
		<result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
		<result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
		<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
		<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
		<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
		<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
		<result column="deleted_flag" jdbcType="CHAR" property="deletedFlag" />
		<result column="factory_merchant_name" jdbcType="VARCHAR"
			property="factoryMerchantName" />
		<result column="province_merchant_name" jdbcType="VARCHAR"
			property="provinceMerchantName" />
		<result column="city_merchant_name" jdbcType="VARCHAR"
			property="cityMerchantName" />
		<result column="factory_merchant_id" jdbcType="INTEGER"
			property="factoryMerchantId" />
		<result column="province_merchant_id" jdbcType="INTEGER"
			property="provinceMerchantId" />
		<result column="city_merchant_id" jdbcType="INTEGER" property="cityMerchantId" />
		<result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
		<result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
		<result column="province_name" jdbcType="VARCHAR" property="provinceName" />
		<result column="city_name" jdbcType="VARCHAR" property="cityName" />
		<result column="area_name" jdbcType="VARCHAR" property="areaName" />
	</resultMap>

	<resultMap id="BaseResultVOMap" type="cn.com.glsx.dj.customer.vo.CarPermanentVO">
		<result column="id" jdbcType="INTEGER" property="id" />
		<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
		<result column="distance" jdbcType="DOUBLE" property="distance" />
		<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
		<result column="is_nearest" jdbcType="TIMESTAMP" property="isNearest" />
		<result column="sn" jdbcType="VARCHAR" property="sn" />
	</resultMap>

	<resultMap id="InitPermanentVOMap" type="cn.com.glsx.dj.customer.vo.InitPermanentVO">
		<result column="id" jdbcType="INTEGER" property="id" />
		<result column="location" jdbcType="VARCHAR" property="location" />
		<result column="lat" jdbcType="DOUBLE" property="lat" />
		<result column="lng" jdbcType="DOUBLE" property="lng" />
		<result column="azimuth" jdbcType="DOUBLE" property="azimuth" />
		<result column="azimuth_desc" jdbcType="VARCHAR" property="azimuthDesc" />
	</resultMap>

	<resultMap id="BaseResultHotMap" type="cn.com.glsx.dj.customer.vo.HotPointVO">
		<result column="location" jdbcType="VARCHAR" property="location" />
		<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
		<result column="name" jdbcType="VARCHAR" property="name" />
		<result column="mobile" jdbcType="VARCHAR" property="mobile" />
		<result column="distance" jdbcType="DOUBLE" property="distance" />
	</resultMap>

	<resultMap id="BaseResultPVOMap" type="cn.com.glsx.dj.customer.vo.PermanentVO">
		<result column="id" jdbcType="INTEGER" property="id" />
		<result column="sn" jdbcType="VARCHAR" property="sn" />
		<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
		<result column="name" jdbcType="VARCHAR" property="name" />
		<result column="mobile" jdbcType="VARCHAR" property="mobile" />
		<result column="location" jdbcType="VARCHAR" property="location" />
		<result column="distance" jdbcType="DOUBLE" property="distance" />
		<result column="is_nearest" jdbcType="INTEGER" property="isNearest" />
		<result column="azimuth_desc" jdbcType="VARCHAR" property="azimuthDesc" />
	</resultMap>
	<resultMap id="BaseCarPermanentVOMap"
		type="cn.com.glsx.dj.customer.vo.CarPermanentStatisticsVO">
		<result column="fiveKilometreCount" jdbcType="INTEGER"
			property="fiveKilometreCount" />
		<result column="fiveToTenKilometreCount" jdbcType="INTEGER"
			property="fiveToTenKilometreCount" />
		<result column="tenToTwentyKilometreCount" jdbcType="INTEGER"
			property="tenToTwentyKilometreCount" />
		<result column="twentyKilometreCount" jdbcType="INTEGER"
			property="twentyKilometreCount" />
		<result column="carPermanentCount" jdbcType="INTEGER" property="carPermanentCount" />

		<result column="fivePercentage" jdbcType="DOUBLE" property="fivePercentage" />
		<result column="fiveToTenPercentage" jdbcType="DOUBLE"
			property="fiveToTenPercentage" />
		<result column="tenToTwentyPercentage" jdbcType="DOUBLE"
			property="tenToTwentyPercentage" />
		<result column="twentyPercentage" jdbcType="DOUBLE" property="twentyPercentage" />
	</resultMap>
	<sql id="Base_Column_List">
		id, sn, stand_no, name, mobile, location, distance, is_nearest,
		vehicle_id,
		total_stay_times, azimuth, azimuth_desc, merchant_code,
		pmerchant_name, created_by, created_date, updated_by, updated_date,
		deleted_flag,factory_merchant_name,province_merchant_name,city_merchant_name,factory_merchant_id,province_merchant_id,
		city_merchant_id,merchant_id,merchant_name,province_name,city_name,area_name
	</sql>
	<sql id="vo_Base_Column_List">
		id, stand_no, distance, created_date, is_nearest,sn
	</sql>
	<sql id="baseWhereClause">
		<where>
			<if
				test="record.factoryMerchantName != null and record.factoryMerchantName !=''">
				and factory_merchant_name =
				#{record.factoryMerchantName,jdbcType=VARCHAR}
			</if>
			<if
				test="record.provinceMerchantName != null and record.provinceMerchantName !=''">
				and province_merchant_name =
				#{record.provinceMerchantName,jdbcType=VARCHAR}
			</if>
			<if
				test="record.cityMerchantName != null and record.cityMerchantName !=''">
				and city_merchant_name = #{record.cityMerchantName,jdbcType=VARCHAR}
			</if>
			<if test="record.merchantName != null and record.merchantName !=''">
				and merchant_name LIKE
				CONCAT('%',#{record.merchantName,jdbcType=VARCHAR},'%')
			</if>
			<if test="record.id != null">
				and id = #{record.id,jdbcType=INTEGER}
			</if>
			<if test="record.sn != null and record.sn !=''">
				and sn = #{record.sn,jdbcType=VARCHAR}
			</if>
			<if test="record.standNo != null and record.standNo !=''">
				and stand_no = #{record.standNo,jdbcType=VARCHAR}
			</if>
			<if test="record.name != null and record.name !=''">
				and name = #{record.name,jdbcType=VARCHAR}
			</if>
			<if test="record.mobile != null and record.mobile !=''">
				and mobile = #{record.mobile,jdbcType=VARCHAR}
			</if>
			<if test="record.minDistance != null">
				and distance >= #{record.minDistance,jdbcType=DOUBLE}
			</if>
			<if test="record.maxDistance != null">
				and distance &lt;= #{record.maxDistance,jdbcType=DOUBLE}
			</if>
			<if test="record.factoryMerchantId != null">
				and factory_merchant_id = #{record.factoryMerchantId,jdbcType=INTEGER}
			</if>
			<if test="record.provinceMerchantId != null">
				and province_merchant_id =
				#{record.provinceMerchantId,jdbcType=INTEGER}
			</if>
			<if test="record.cityMerchantId != null">
				and city_merchant_id = #{record.cityMerchantId,jdbcType=INTEGER}
			</if>
			<if test="record.merchantId != null">
				and merchant_id = #{record.merchantId,jdbcType=INTEGER}
			</if>
			<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
				and merchant_id in
				<foreach item="merchantId" index="index" collection="record.merchantIds"
					open="(" separator="," close=")">
					#{merchantId}
				</foreach>
			</if>
			and deleted_flag = 'N'
			and is_nearest = 1
		</where>
	</sql>

	<select id="listBasic" parameterType="cn.com.glsx.dj.customer.dto.CarPermanentDTO"
		resultMap="BaseResultDTOMap">
		select
		<include refid="Base_Column_List"></include>
		from dj_car_permanent
		<include refid="baseWhereClause" />
		order by distance asc
	</select>

	<select id="carPermanentVOList" resultMap="BaseResultVOMap">
		SELECT
		<include refid="vo_Base_Column_List" />
		FROM dj_car_permanent WHERE is_nearest = 1 and deleted_flag = 'N'
		<if test="merchantId != null">
			and MERCHANT_ID = #{merchantId}
		</if>
	</select>

	<select id="carPermanentVOListByPage" resultMap="BaseResultVOMap">
		SELECT
		<include refid="vo_Base_Column_List" />
		FROM dj_car_permanent WHERE is_nearest = 1 and deleted_flag = 'N'
		<if test="merchantId != null">
			and MERCHANT_ID = #{merchantId}
		</if>
		and id > #{id}
		limit #{pageSize}
	</select>

	<select id="queryPermanent" resultMap="BaseResultPVOMap"
		parameterType="cn.com.glsx.dj.customer.dto.CarPermanentDTO">
		select
		id,
		sn,
		stand_no,
		name,
		mobile,
		location,
		distance,
		is_nearest,
		azimuth_desc
		FROM dj_car_permanent
		<include refid="baseWhereClause" />
		order by distance asc
	</select>

	<select id="queryHotPoint" resultMap="BaseResultHotMap"
		parameterType="cn.com.glsx.dj.customer.dto.CarPermanentDTO">
		select
		location,
		name,
		mobile,
		stand_no,
		distance
		FROM dj_car_permanent
		WHERE 1=1
		<if
			test="record.factoryMerchantName != null and record.factoryMerchantName !=''">
			and factory_merchant_name =
			#{record.factoryMerchantName,jdbcType=VARCHAR}
		</if>
		<if
			test="record.provinceMerchantName != null and record.provinceMerchantName !=''">
			and province_merchant_name =
			#{record.provinceMerchantName,jdbcType=VARCHAR}
		</if>
		<if test="record.cityMerchantName != null and record.cityMerchantName !=''">
			and city_merchant_name = #{record.cityMerchantName,jdbcType=VARCHAR}
		</if>
		<if test="record.merchantName != null and record.merchantName !=''">
			and and merchant_name LIKE
			CONCAT('%',#{record.merchantName,jdbcType=VARCHAR},'%')
		</if>
		<if test="record.factoryMerchantId != null">
			and factory_merchant_id = #{record.factoryMerchantId,jdbcType=INTEGER}
		</if>
		<if test="record.provinceMerchantId != null">
			and province_merchant_id = #{record.provinceMerchantId,jdbcType=INTEGER}
		</if>
		<if test="record.cityMerchantId != null">
			and city_merchant_id = #{record.cityMerchantId,jdbcType=INTEGER}
		</if>
		<if test="record.isNearest != null">
			AND is_nearest = #{record.isNearest,jdbcType=INTEGER}
		</if>
		<if test="record.minDistance != null">
			AND distance >= #{record.minDistance,jdbcType=DOUBLE}
		</if>
		<if test="record.maxDistance != null">
			AND distance &lt;= #{record.maxDistance,jdbcType=DOUBLE}
		</if>
		<if test="record.merchantId != null">
			AND merchant_id = #{record.merchantId,jdbcType=INTEGER}
		</if>
		<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
			and merchant_id in
			<foreach item="merchantId" index="index" collection="record.merchantIds"
				open="(" separator="," close=")">
				#{merchantId}
			</foreach>
		</if>
		and deleted_flag = 'N'
		order by created_date DESC
	</select>

	<delete id="deleteByStandNo" parameterType="java.lang.String">
		delete from dj_car_permanent where stand_no = #{standNo}
	</delete>
	
	<delete id="deleteBySn" parameterType="java.lang.String">
		delete from dj_car_permanent where sn = #{sn}
	</delete>

	<update id="updateByStandNo" parameterType="cn.com.glsx.dj.customer.model.CarPermanent">
		update dj_car_permanent
		set is_nearest = #{record.isNearest, jdbcType=INTEGER},
		where stand_no = #{record.standNo}
	</update>

	<select id="initPermanent" resultMap="InitPermanentVOMap">
		SELECT
		p.id,
		p.location,
		m.lat,
		m.lng,
		p.azimuth,
		p.azimuth_desc
		FROM dj_car_permanent p LEFT JOIN dj_system_merchant m ON
		p.merchant_id=m.merchant_id
		WHERE p.azimuth_desc is null
	</select>

	<select id="queryCarPermanentByMerchantId" parameterType="java.lang.Integer"
		resultMap="BaseCarPermanentVOMap">
        <![CDATA[  SELECT
        sum(case when 0<=distance and distance <5 then 1 ELSE 0 end) AS fiveKilometreCount,
        sum(case when 5<=distance and distance<10 then 1 ELSE 0 end) AS fiveToTenKilometreCount,
        sum(case when 10<=distance AND distance<=20 then 1 ELSE 0 end) AS tenToTwentyKilometreCount,
        sum(case when distance>20 THEN 1 ELSE 0 end) AS twentyKilometreCount,
        sum(1) AS carPermanentCount,
        CAST(sum(case when 0<=distance and distance <5 then 1 ELSE 0 end)/sum(1)*100 as decimal(18,2)) AS fivePercentage,
        CAST(sum(case when 5<=distance and distance<10 then 1 ELSE 0 end)/sum(1)*100 as decimal(18,2)) AS fiveToTenPercentage,
        CAST(sum(case when 10<=distance AND distance<=20 then 1 ELSE 0 end)/sum(1)*100 as decimal(18,2)) AS tenToTwentyPercentage,
        CAST(sum(case when distance>20 THEN 1 ELSE 0 end)/sum(1)*100 as decimal(18,2)) AS twentyPercentage
        FROM dj_customer_portrait WHERE DELETED_FLAG = 'N' AND distance is NOT NULL]]>
		<if test="merchantId != null">
			and MERCHANT_ID = #{merchantId, jdbcType=INTEGER}
		</if>
	</select>


	<select id="getLastPermanent" resultMap="BaseResultDTOMap"
		parameterType="cn.com.glsx.dj.customer.dto.CarPermanentDTO">
		select
		<include refid="Base_Column_List" />
		FROM dj_car_permanent
		WHERE 1=1
		<if test="sn!=null and sn!= ''">
			and sn=#{sn,jdbcType=VARCHAR}
		</if>
		<if test="standNo != null and standNo != ''">
			and stand_no=#{standNo,jdbcType=VARCHAR}
		</if>
		and is_nearest=1 limit 0,1
	</select>
</mapper>