VehicleMapper.xml 18.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.admin.modules.mapper.VehicleMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.admin.modules.entity.Vehicle">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="workorder_id" jdbcType="INTEGER" property="workorderId"/>
        <result column="owner_name" jdbcType="VARCHAR" property="ownerName"/>
        <result column="vin" jdbcType="VARCHAR" property="vin"/>
        <result column="owner_sex" jdbcType="VARCHAR" property="ownerSex"/>
        <result column="owner_tel" jdbcType="VARCHAR" property="ownerTel"/>
        <result column="brand_id" jdbcType="INTEGER" property="brandId"/>
        <result column="brand_name" jdbcType="VARCHAR" property="brandName"/>
        <result column="sub_brand_id" jdbcType="INTEGER" property="subBrandId"/>
        <result column="sub_brand_name" jdbcType="VARCHAR" property="subBrandName"/>
        <result column="series_id" jdbcType="INTEGER" property="seriesId"/>
        <result column="series_name" jdbcType="VARCHAR" property="seriesName"/>
        <result column="type_id" jdbcType="INTEGER" property="typeId"/>
        <result column="type_name" jdbcType="VARCHAR" property="typeName"/>
        <result column="model_id" jdbcType="INTEGER" property="modelId"/>
        <result column="model_name" jdbcType="VARCHAR" property="modelName"/>
        <result column="config_id" jdbcType="INTEGER" property="configId"/>
        <result column="config_desc" jdbcType="VARCHAR" property="configDesc"/>
        <result column="color" jdbcType="VARCHAR" property="color"/>
        <result column="inner_color" jdbcType="VARCHAR" property="innerColor"/>
        <result column="license_plate" jdbcType="VARCHAR" property="licensePlate"/>
        <result column="vehicle_type" jdbcType="TINYINT" property="vehicleType"/>
        <result column="engine" jdbcType="VARCHAR" property="engine"/>
        <result column="displacement" jdbcType="VARCHAR" property="displacement"/>
        <result column="mileage" jdbcType="VARCHAR" property="mileage"/>
        <result column="buy_date" jdbcType="DATE" property="buyDate"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="serve_type" jdbcType="TINYINT" property="serveType"/>
        <result column="validate_status" jdbcType="TINYINT" property="validateStatus"/>
        <result column="validate_info" jdbcType="VARCHAR" property="validateInfo"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
        <result column="registration_date" jdbcType="TIMESTAMP" property="registrationDate"/>
        <result column="sale_manager" jdbcType="VARCHAR" property="saleManager"/>
        <result column="sale_manager_phone" jdbcType="VARCHAR" property="saleManagerPhone"/>
        <result column="buy_type" jdbcType="DATE" property="buyType"/>
    </resultMap>

    <resultMap id="TearDownAlarmMap" type="cn.com.glsx.admin.modules.model.export.TearDownModelExport">
        <result column="area" jdbcType="VARCHAR" property="area"/>
        <result column="province" jdbcType="VARCHAR" property="province"/>
        <result column="city" jdbcType="VARCHAR" property="city"/>
        <result column="username" jdbcType="VARCHAR" property="shopName"/>
        <result column="account" jdbcType="VARCHAR" property="shopCode"/>
        <result column="shop_level" jdbcType="INTEGER" property="shopLevel"/>
        <result column="type_name" jdbcType="VARCHAR" property="typeName"/>
        <result column="model_name" jdbcType="VARCHAR" property="modelName"/>
        <result column="config_desc" jdbcType="INTEGER" property="configDesc"/>
        <result column="vin" jdbcType="VARCHAR" property="vin"/>
        <result column="sn" jdbcType="INTEGER" property="sn"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
    </resultMap>

    <resultMap id="VehicleInfoMap" type="cn.com.glsx.admin.modules.model.VehicleInfoPageDTO">
        <result column="id" jdbcType="BIGINT" property="id"/>
        <result column="workorder_id" jdbcType="INTEGER" property="workorderId"/>
        <result column="owner_name" jdbcType="VARCHAR" property="ownerName"/>
        <result column="vin" jdbcType="VARCHAR" property="vin"/>
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="device_type" jdbcType="INTEGER" property="deviceType"/>
        <result column="model_name" jdbcType="VARCHAR" property="modelName"/>
        <result column="vehicle_type" jdbcType="INTEGER" property="vehicleType"/>
        <result column="vehicle_usages" jdbcType="INTEGER" property="vehicleUsages"/>
        <result column="activate_time" jdbcType="TIMESTAMP" property="activateTime"/>
        <result column="freqStatus" jdbcType="INTEGER" property="freqStatus"/>
    </resultMap>

    <resultMap id="VehicleInfoReportExportMap" type="cn.com.glsx.admin.modules.model.export.VehicleInfoReportExport">
        <result column="id" jdbcType="BIGINT" property="id"/>
        <result column="workorder_id" jdbcType="INTEGER" property="workorderId"/>
        <result column="owner_name" jdbcType="VARCHAR" property="ownerName"/>
        <result column="vin" jdbcType="VARCHAR" property="vin"/>
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="device_type" jdbcType="INTEGER" property="deviceType"/>
        <result column="model_name" jdbcType="VARCHAR" property="modelName"/>
        <result column="vehicle_type" jdbcType="INTEGER" property="vehicleType"/>
        <result column="vehicle_usages" jdbcType="VARCHAR" property="vehicleUsages"/>
        <result column="activate_time" jdbcType="TIMESTAMP" property="activateTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, workorder_id, owner_name, vin, owner_sex, owner_tel, brand_id, brand_name, sub_brand_id,sub_brand_name,
        series_id,series_name, type_id,type_name,model_id, model_name, config_id, config_desc, color, inner_color,
        license_plate,vehicle_type, engine, displacement, mileage, buy_date, description, remark, serve_type,
        validate_status, validate_info, del_flag, created_date, created_by, updated_date,updated_by
    </sql>

    <sql id="search_sql_condition">
        <if test="searchKey != null and searchKey != '' ">
            and (
            tu.account like concat('%',#{searchKey},'%')
            or tu.username like concat('%',#{searchKey},'%')
            or tv.vin like concat('%',#{searchKey},'%')
            or tvd.sn like concat('%',#{searchKey},'%')
            or tv.model_name like concat('%',#{searchKey},'%')
            or tv.series_name like concat('%',#{searchKey},'%')
            )
        </if>
    </sql>

    <select id="linkSnsSearch" resultType="cn.com.glsx.admin.modules.model.VehicleLinkSnsDTO">
        select tv.owner_name name, tv.vin, tv.owner_tel userTel, tvd.sn sns
        from t_vehicle tv
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
        left join t_device td on tvd.sn = td.sn
        where tv.del_flag = 0 and tvd.del_flag = 0
        and tvd.bind_status = 1
        <choose>
            <when test="termType == 1">
                and tvd.sn like concat('%',#{term},'%')
            </when>
            <when test="termType == 2">
                and tv.vin like concat('%',#{term},'%')
            </when>
        </choose>
        <if test="shopId != null">
            and tv.created_by = #{shopId}
        </if>
        <if test="deviceSource != null">
            and td.source = #{deviceSource}
        </if>
        <if test="trialType != null">
            and tvd.trial_type = #{trialType}
        </if>
        order by tv.id,tvd.sn
    </select>

    <select id="selectVehicleLinkSnsByUserId" resultType="cn.com.glsx.admin.modules.model.VehicleLinkSnsDTO">
        select tv.owner_name name, tv.vin, tv.owner_tel userTel, tvd.sn sns
        from t_vehicle tv
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
        left join t_device td on tvd.sn = td.sn
        where tv.del_flag = 0 and tvd.del_flag = 0
        and tvd.bind_status = 1
        and tv.created_by = #{userId}
        <if test="trialType != null">
            and tvd.trial_type = #{trialType}
        </if>
        order by tv.id,tvd.sn
    </select>

    <select id="searchTrialDrive" resultType="cn.com.glsx.admin.modules.model.TrialDriveVehiclePageDTO">
        select tv.id tempId,
        tv.vin,
        case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name, '/', series_name) end seriesName,
        case when tv.type_id is null then tv.config_desc else tv.type_name end typeName,
        tv.license_plate licensePlate,
        tv.created_by createdBy,
        tu.username shopName,
        tu.account shopCode,
        ttds.shop_level shopLevel,
        tvd.sn sns,
        tvd.created_date installedTime
        from t_vehicle tv
        inner join t_trial_drive_vehicle ttdv on ttdv.vehicle_id = tv.id
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id and tvd.bind_status = 1 and tvd.del_flag = 0 and tvd.trial_type = 1
        left join t_user tu on tv.created_by = tu.id and tu.del_flag = 0
        left join t_trial_drive_shop ttds on tu.id = ttds.created_by and ttds.del_flag = 0
        where tv.del_flag = 0
        and ttdv.del_flag = 0
        and tvd.trial_type = 1
        <include refid="search_sql_condition"/>
        order by tv.created_date desc
    </select>

    <select id="exportDriveVehicle" resultType="cn.com.glsx.admin.modules.model.export.TrialDriveVehicleExport">
        select tv.vin,
        case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name, '/', series_name) end seriesName,
        case when tv.type_id is null then tv.config_desc else tv.type_name end typeName,
        tv.license_plate licensePlate,
        tv.model_name modelName,
        tv.color,
        tv.inner_color innerColor,
        tv.serve_type serveType,
        tu.username shopName, tu.account shopCode,
        tvd.sn sns
        from t_vehicle tv
        inner join t_trial_drive_vehicle ttdv on ttdv.vehicle_id = tv.id
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id and tvd.bind_status = 1 and tvd.del_flag = 0 and tvd.trial_type = 1
        left join t_user tu on tv.created_by = tu.id and tu.del_flag = 0
        left join t_trial_drive_shop ttds on tu.id = ttds.created_by and ttds.del_flag = 0
        where tv.del_flag = 0
        and ttdv.del_flag = 0
        and tvd.trial_type = 1
        <include refid="search_sql_condition"/>
        order by tv.created_date desc
    </select>

    <select id="searchTearDownAlarmList" resultMap="TearDownAlarmMap">
        SELECT distinct
        ttds.area,
        ttds.province,
        ttds.city,
        tu.username,
        tu.account,
        ttds.shop_level,
        tv.model_name,
        tv.config_desc,
        tv.vin,
        tvd.sn,
        tv.created_by
        FROM t_vehicle tv
        left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        left join t_electric_fence_sns tefs on tefs.sn = tvd.sn
        left join t_trial_drive_shop ttds on ttds.fence_id = tefs.fence_id
        left join t_user tu on tu.id = tv.created_by
        where tv.del_flag = 0 and tvd.del_flag = 0 and tvd.bind_status = 1 and tu.del_flag = 0
        <if test="keywords != null and keywords !=''">
            and (
            tu.username like '%${keywords}%'
            or tu.account like '%${keywords}%'
            or tvd.sn like '%${keywords}%'
            or tv.model_name like '%${keywords}%'
            or tv.series_name like '%${keywords}%'
            )
        </if>
    </select>

    <select id="findVehicleInfoBySn" resultMap="BaseResultMap">
        select
        tv.*
        from t_vehicle tv
        inner join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        where tv.del_flag = 0 and tvd.bind_status = 1 and tvd.del_flag = 0
        <if test="sn != null and sn != ''">
            and tvd.sn = #{sn}
        </if>
    </select>

    <select id="selectVehicleSns" resultType="cn.com.glsx.admin.modules.model.OrgVehicleModel">
        select tvd.id,
        tv.id vid,
        tv.vin,
        tv.owner_name ownerName,
        tvd.sn sns,
        tv.created_by creatorId
        from t_vehicle tv
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
        where tv.del_flag = 0
        and tvd.bind_status = 1
        <if test="userIds != null and userIds.size() > 0">
            and tv.created_by in
            <foreach collection="userIds" separator="," open="(" close=")" item="item">
                #{item}
            </foreach>
        </if>
        <choose>
            <when test="termType == 1">
                and tvd.sn like concat('%',#{term},'%')
            </when>
            <when test="termType == 2">
                and tv.vin like concat('%',#{term},'%')
            </when>
            <when test="termType == 3">
                and tv.owner_name like concat('%',#{term},'%')
            </when>
        </choose>
        order by tv.id desc
    </select>

    <select id="selectById" resultMap="BaseResultMap">
        select *
        from t_vehicle
        where id = #{vehicleId}
          and del_flag = 0
    </select>

    <select id="getVehicleByVin" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_vehicle tv where tv.vin = #{vin} and del_flag = 0
    </select>

    <select id="searchVehicleInfo" parameterType="cn.com.glsx.admin.modules.model.param.VehicleInfoSearch"
            resultMap="VehicleInfoMap">
        select tv.id ,tv.workorder_id ,tv.owner_name ,tv.vin ,td.sn ,
        td.device_type ,tv.model_name ,tv.vehicle_type ,
        tv.vehicle_usages ,td.activate_time,
        ddf.`status` AS freqStatus
        from t_vehicle tv
        left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        left join t_device td on td.sn = tvd.sn
        left join (select * from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn = td.sn
        where tv.del_flag = 0
        and tvd.bind_status = 1
        <if test="keywords != null and keywords !=''">
            and(
            tv.owner_name like '%${keywords}%'
            or tv.vin like '%${keywords}%'
            or td.sn like '%${keywords}%'
            or tv.model_name like '%${keywords}%'
            )
        </if>
        <if test="activateTimeStart != null and activateTimeStart !=''">
            and left(td.activate_time,10) &gt;= #{activateTimeStart}
        </if>
        <if test="activateTimeEnd != null and activateTimeEnd !=''">
            and left(td.activate_time,10) &lt;= #{activateTimeEnd}
        </if>
        <if test="deviceType != null">
            and td.device_type = #{deviceType}
        </if>
        <if test="vehicleType != null">
            and tv.vehicle_type = #{vehicleType}
        </if>
        <if test="vehicleUsages != null">
            and tv.vehicle_usages = #{vehicleUsages}
        </if>
    </select>

    <select id="exportVehicleInfo" parameterType="cn.com.glsx.admin.modules.model.param.VehicleInfoSearch"
            resultMap="VehicleInfoReportExportMap">
        select tv.id ,tv.workorder_id ,tv.owner_name ,tv.vin ,td.sn ,
        td.device_type ,tv.model_name ,tv.vehicle_type ,
        tv.vehicle_usages ,td.activate_time,
        ddf.`status` AS freqStatus
        from t_vehicle tv
        left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        left join t_device td on td.sn = tvd.sn
        left join (select * from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn = td.sn
        where tv.del_flag = 0
        and tvd.bind_status = 1
        <if test="keywords != null and keywords !=''">
            and(
            tv.owner_name like '%${keywords}%'
            or tv.vin like '%${keywords}%'
            or td.sn like '%${keywords}%'
            or tv.model_name like '%${keywords}%'
            )
        </if>
        <if test="activateTimeStart != null and activateTimeStart !=''">
            and left(td.activate_time,10) &gt;= #{activateTimeStart}
        </if>
        <if test="activateTimeEnd != null and activateTimeEnd !=''">
            and left(td.activate_time,10) &lt;= #{activateTimeEnd}
        </if>
        <if test="deviceType != null">
            and td.device_type = #{deviceType}
        </if>
        <if test="vehicleType != null">
            and tv.vehicle_type = #{vehicleType}
        </if>
        <if test="vehicleUsages != null">
            and tv.vehicle_usages = #{vehicleUsages}
        </if>
    </select>

    <select id="listTestDriveVehicle" resultType="cn.com.glsx.admin.modules.model.TestVehicleDTO">
        select
        tv.id ,
        tv.vin ,
        tv.owner_name ,
        GROUP_CONCAT(td.sn) as sns
        from t_vehicle tv
        left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        left join t_device td on td.sn = tvd.sn
        left join t_user tu on tu.id = tv.created_by
        where tv.del_flag = 0
        and tvd.bind_status = 1
        and tvd.trial_type = 0
        and tvd.del_flag = 0
        and td.del_flag = 0
        <if test="sn != null and sn !=''">
            and td.sn like concat('%',#{sn},'%')
        </if>
        <if test="ownerName != null and ownerName !=''">
            and tv.owner_name like concat('%',#{ownerName},'%')
        </if>
        <if test="vin != null and vin !=''">
            and tv.vin = like concat('%',#{vin},'%')
        </if>
        <if test="buyDateStart != null and buyDateStart !=''">
            and tv.buy_date &gt;= #{buyDateStart}
        </if>
        <if test="buyDateEnd != null and buyDateEnd !=''">
            and tv.buy_date &lt;= #{buyDateEnd}
        </if>
        <if test="shopId != null ">
            and tu.id = #{shopId}
        </if>
        GROUP BY tv.vin
    </select>
</mapper>