TrialDriveReportMapper.xml 5.28 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.admin.modules.mapper.TrialDriveReportMapper">
    <resultMap id="BaseResultMap"
               type="cn.com.glsx.admin.modules.model.export.TrialDriveReportExport">
        <result column="shopCode" jdbcType="VARCHAR" property="shopCode"/>
        <result column="shopName" jdbcType="VARCHAR" property="shopName"/>
        <result column="vehicleTypeName" jdbcType="VARCHAR" property="vehicleTypeName"/>
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="vin" jdbcType="VARCHAR" property="vin"/>
        <result column="statDate" jdbcType="VARCHAR" property="statDate"/>
        <result column="cnt" jdbcType="INTEGER" property="cnt"/>
        <result column="dayCount" jdbcType="INTEGER" property="dayCount"/>
        <result column="cnttotal" jdbcType="INTEGER" property="cnttotal"/>
    </resultMap>

    <resultMap id="PageBaseMap"
               type="cn.com.glsx.admin.modules.model.export.TrialDriveReportExport">
        <result column="shopCode" jdbcType="VARCHAR" property="shopCode"/>
        <result column="shopName" jdbcType="VARCHAR" property="shopName"/>
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="vin" jdbcType="VARCHAR" property="vin"/>
        <result column="vehicleTypeName" jdbcType="VARCHAR" property="vehicleTypeName"/>
    </resultMap>

    <select id="getTestDrivePageList"
            parameterType="cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch"
            resultMap="PageBaseMap">
        SELECT distinct
        tu.account shopCode,
        tu.username shopName,
        tefs.sn,
        tefs.vin,
        tv.model_name vehicleTypeName
        from t_electric_fence_sns tefs
        inner join t_electric_fence tef on tef.id = tefs.fence_id
        left join t_user tu on tu.id = tef.created_by
        left join t_vehicle tv on tv.vin = tefs.vin
        where tefs.fence_id = tef.id
        and tef.biz_fence_type = 12 and tu.del_flag = 0
        <if test="keywords != null and keywords!='' ">
            and (
            tu.account like '%${keywords}%'
            or tu.username like '%${keywords}%'
            )
        </if>
        <if test="userIdList != null">
            and tu.id IN
            <foreach collection="userIdList" item="userId" index="index" open="(" close=")" separator=",">
                #{userId}
            </foreach>
        </if>
        <if test="splitList != null">
            and tv.model_name IN
            <foreach collection="splitList" item="vehicleTypeName" index="index" open="(" close=")" separator=",">
                #{vehicleTypeName}
            </foreach>
        </if>
        order by tu.account
    </select>

    <select id="getEffectiveTestDriveData"
            parameterType="cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch"
            resultMap="BaseResultMap">
        SELECT tall.shopCode, tall.shopName, tall.vehicleTypeName, tall.sn, tall.vin, left(tall.statDate,7)
        statDate, tall.cnt, day(tall.statDate) dayCount , sum(cnt) cnttotal FROM
        (select tu.account shopCode, tu.username shopName, tv.model_name vehicleTypeName,
        tefdd.sn, tv.vin, DATE_FORMAT(tefdd.journey_time,'%Y-%m-%d') statDate, sum(case when tefdd.percent >= 80
        then 1 else 0
        end) cnt
        from t_electric_fence_drive tefdd
        left join t_electric_fence tef on tef.id = tefdd.fence_id
        left join t_vehicle_device tvv on tvv.sn = tefdd.sn
        left join t_vehicle tv on tv.id = tvv.vehicle_id
        left join t_user tu on tu.id = tef.created_by
        <where>
            <choose>
                <when test="year != null and year != '' and month != null and month != '' ">
                    left(tefdd.journey_time,7) = CONCAT(#{year,jdbcType=VARCHAR},'-',#{month,jdbcType=VARCHAR})
                </when>
                <otherwise>
                    <if test="year != null and year != '' ">
                        left(tefdd.journey_time,4) = #{year,jdbcType=VARCHAR}
                    </if>
                    <if test="month != null and month != '' ">
                        right(left(tefdd.journey_time,7),2) = #{month,jdbcType=VARCHAR}
                    </if>
                </otherwise>
            </choose>

            <if test="keywords !=null and keywords != ''">
                and (
                tu.account like '%${keywords}%'
                or tu.username like '%${keywords}%'
                )
            </if>
            <if test="sn !=null and sn != ''">
                and tefdd.sn = #{sn,jdbcType=VARCHAR}
            </if>
            <if test="splitList != null">
                and tv.model_name IN
                <foreach collection="splitList" item="vehicleTypeName" index="index" open="(" close=")" separator=",">
                    #{vehicleTypeName}
                </foreach>
            </if>
        </where>
        GROUP BY tefdd.sn,tefdd.fence_id,statDate order by tu.account) tall GROUP BY tall.shopCode, tall.sn,
        tall.statDate ORDER BY tall.shopCode
    </select>

    <select id="getYearWithData" resultType="java.lang.String">
      select distinct left(journey_time,4) from t_electric_fence_drive
    </select>
</mapper>