HomeMapper.xml 13.3 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.reports.mapper.HomeMapper">
  <resultMap type="cn.com.glsx.dj.reports.dto.EffectiveInsureOrderDTO" id="EffectiveMap">
  	<result column="name" jdbcType="VARCHAR" property="name"/>
  	<result column="phone" jdbcType="VARCHAR" property="phone"/>
  	<result column="stand_no" jdbcType="VARCHAR" property="standNo"/>
  	<result column="success_date" jdbcType="TIMESTAMP" property="successDate"/>
  </resultMap>
  
  <resultMap id="homeStatisticVo" type="cn.com.glsx.dj.reports.vo.HomeStatisticVO">
     <result column="number" property="number" jdbcType="INTEGER" />
     <result column="date" property="date" jdbcType="VARCHAR" />
  </resultMap>
  
  <resultMap id="orderChannelCodeVO" type="cn.com.glsx.dj.reports.vo.ChannelCodeVO">
     <result column="channel_code" property="channelCode" jdbcType="VARCHAR" />
  </resultMap>
  
  <resultMap id="shopDataListVOMap" type="cn.com.glsx.dj.reports.vo.ShopDataListVO">
    <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
    <result column="ydhCount" jdbcType="INTEGER" property="ydhCount" />
    <result column="gzqCount" jdbcType="INTEGER" property="gzqCount" />
    <result column="gpsCount" jdbcType="INTEGER" property="gpsCount" />
    <result column="jlyCount" jdbcType="INTEGER" property="jlyCount" />
    <result column="hsjCount" jdbcType="INTEGER" property="hsjCount" />
    <result column="allCount" jdbcType="INTEGER" property="allCount"/>
  </resultMap>
  
  <select id="getOrderChannelCode" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="orderChannelCodeVO">
  	select dvi.channel_code
    from dj_insure_order dvi
    where dvi.deleted_flag = 'N' 
    and dvi.channel_code IS NOT NULL
    and dvi.insurance_status = 1
    <if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
	
	group by dvi.channel_code
  </select>
  
  <!-- 新增保单数 -->
  <select id="incrInsurances" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultType="int">
    SELECT COUNT(dvi.id) FROM dj_insure_order dvi 
    WHERE 1 = 1 
    and dvi.insurance_status=1
    and dvi.success_date IS NOT NULL
    <if test="record.channelCode != null and record.channelCode !=''">
		and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
	</if>
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
  </select>
  
  <!-- 根绝时间范围查询新增保单数 -->
  <select id="getInsuranceByTimeRange" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="homeStatisticVo" >
  	SELECT COUNT(dvi.id) AS number,
    <choose>
    	<when test="record.timeRange == 1 or record.timeRange == 2">
        	DATE_FORMAT(dvi.success_date, '%H') AS date
        </when>
       	<otherwise>  
       		DATE_FORMAT(dvi.success_date, '%Y-%m-%d') AS date
        </otherwise>
    </choose> 
    FROM dj_insure_order dvi 
    WHERE 1 = 1 
   	and dvi.insurance_status = 1
   	and dvi.success_date IS NOT NULL
    <if test="record.channelCode != null and record.channelCode !=''">
		and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
	</if>
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
    <choose>
        <when test="record.timeRange == 1 or record.timeRange == 2">
            GROUP BY DATE_FORMAT(dvi.success_date, '%H')
        </when>
        <otherwise>  
        	GROUP BY DATE_FORMAT(dvi.success_date, '%Y-%m-%d')
        </otherwise>
    </choose>     
  </select>
  
  <select id="getIncrAppBindingByTimeRange" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="homeStatisticVo" >
	SELECT COUNT(db.id) AS number,
    <choose>
    	<when test="record.timeRange == 1 or record.timeRange == 2">
    		DATE_FORMAT(db.updated_date, '%H') AS date
    	</when>
    	<otherwise>
    		DATE_FORMAT(db.updated_date, '%Y-%m-%d') AS date
    	</otherwise>
    </choose>
    FROM dj_app_binding db left join dj_insure_order dvi on db.sn = dvi.sub_device_sn 
    WHERE 1 = 1 
    and db.bind_status=1
    and dvi.insurance_status = 1
    and dvi.success_date IS NOT NULL
    <if test="record.channelCode != null and record.channelCode !=''">
		and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
	</if>
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		and db.updated_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
    <choose>
    	<when test="record.timeRange == 1 or record.timeRange == 2">
    		GROUP BY DATE_FORMAT(db.updated_date, '%H')
    	</when>
    	<otherwise>
    		GROUP BY DATE_FORMAT(db.updated_date, '%Y-%m-%d')
    	</otherwise>
    </choose>
  </select>
  
  <!-- 新增绑定数 -->
  <select id="incrBinding" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultType="int">
  	SELECT COUNT(dvi.id) FROM dj_app_binding db left join dj_insure_order dvi on db.sn = dvi.sub_device_sn 
    WHERE 1 = 1 
    and db.bind_status=1
    and dvi.insurance_status = 1
    and dvi.success_date IS NOT NULL
    <if test="record.channelCode != null and record.channelCode !=''">
		and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
	</if>
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		and db.updated_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
  </select>

  <!-- 所有激活的设备 -->
  <select id="totalActiveDevice"   parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO"  resultType="int">	
	SELECT COUNT(dti.sn) from dj_insure_device dti
    LEFT JOIN dj_insure_order dvi ON dti.vehicle_id = dvi.vehicle_id
    WHERE dti.is_active=1
    and dvi.insurance_status =1
	AND dvi.deleted_flag='N' and dti.deleted_flag='N'
    <if test="record.channelCode != null and record.channelCode !=''">
		and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
	</if>
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
  </select>

  <!-- 激活且在线的设备 -->
  <select id="onlineActiveDevice"   parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO"  resultType="int">
	SELECT COUNT(ddl.sn) from dj_insure_device dti
    LEFT JOIN dj_device_login ddl ON ddl.sn=dti.sn
    LEFT JOIN dj_insure_order dvi ON dti.vehicle_id = dvi.vehicle_id
    WHERE dti.is_active=1
    and dvi.insurance_status=1
    and ddl.last_gprs_time &gt;= date_add(NOW(), interval -3 day) 
    and ddl.last_gprs_time &lt;= NOW()
	and dvi.deleted_flag='N'
    <if test="record.channelCode != null and record.channelCode !=''">
		and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
	</if>
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and dvi.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
  </select>
  
  
  <select id="incrDataCount" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="shopDataListVOMap">
  	SELECT 
	SUM(CASE WHEN d.device_type='2' THEN 1 ELSE 0 END) ydhCount,
	SUM(CASE WHEN d.device_type='8' THEN 1 WHEN d.device_type='4' THEN 1 ELSE 0 END) gpsCount,
	SUM(CASE WHEN d.device_type='6' THEN 1 ELSE 0 END) jlyCount,
	SUM(CASE WHEN d.device_type='12134' THEN 1 ELSE 0 END) hsjCount,
	COUNT(o.id) AS allCount
 	FROM dj_insure_order o LEFT JOIN dj_insure_device d ON o.sub_device_sn = d.sn
	WHERE o.insurance_status=1
	AND d.sn IS NOT NULL
	AND d.device_type in('2','6','8','12134','4')
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		AND o.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and o.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
  </select>
  
  <select id="incrShopDataList" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="shopDataListVOMap">
  	select * from(
  	SELECT 
	(SELECT m.merchant_name FROM dj_system_merchant m WHERE m.merchant_id=o.merchant_id) AS merchant_name,
	SUM(CASE WHEN d.device_type='2' THEN 1 ELSE 0 END) ydhCount,
	SUM(CASE WHEN d.device_type='8' THEN 1 WHEN d.device_type='4' THEN 1 ELSE 0 END) gpsCount,
	SUM(CASE WHEN d.device_type='6' THEN 1 ELSE 0 END) jlyCount,
	SUM(CASE WHEN d.device_type='12134' THEN 1 ELSE 0 END) hsjCount,
	COUNT(o.id) AS allCount
 	FROM dj_insure_order o LEFT JOIN dj_insure_device d ON o.sub_device_sn = d.sn
	WHERE o.insurance_status=1
	AND d.sn IS NOT NULL
	AND d.device_type in('2','6','8','12134','4')
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		AND o.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and o.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
	GROUP BY o.merchant_id
	)tp where allCount>0
  </select>
  
  <select id="incrDataMixList" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="shopDataListVOMap">
  	SELECT * FROM(
	SELECT 
	(SELECT m.merchant_name FROM dj_system_merchant m WHERE m.merchant_id=o.merchant_id) AS merchant_name,
	SUM(CASE WHEN d.device_type='2' THEN 1 ELSE 0 END) ydhCount,
	SUM(CASE WHEN d.device_type='8' THEN 1 WHEN d.device_type='4' THEN 1 ELSE 0 END) gpsCount,
	SUM(CASE WHEN d.device_type='6' THEN 1 ELSE 0 END) jlyCount,
	SUM(CASE WHEN d.device_type='12134' THEN 1 ELSE 0 END) hsjCount,
	COUNT(o.id) AS allCount 
	FROM dj_insure_order o LEFT JOIN dj_insure_device d ON o.sub_device_sn = d.sn
	WHERE o.insurance_status=1
	AND d.sn IS NOT NULL
	AND d.device_type in('2','6','8','12134','4')
	<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
		AND o.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
	</if>
	<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
        and o.merchant_id in
        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        #{merchantId}
	    </foreach>
	</if>
	GROUP BY o.merchant_id
	) tp 
	<choose>
  		<when test="record.dimension != null and record.dimension==5">
            ORDER BY allCount DESC
        </when>
    	<when test="record.dimension != null and record.dimension==4">
            ORDER BY ydhCount DESC
        </when>
        <when test="record.dimension != null and record.dimension==3">
            ORDER BY gpsCount DESC
        </when>
        <when test="record.dimension != null and record.dimension==2">
            ORDER BY jlyCount DESC
        </when>
        <otherwise>
            ORDER BY allCount DESC
        </otherwise>
    </choose>
	LIMIT 0,5
  </select>

</mapper>