VehicleMapper.xml 9.34 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.app.modules.mapper.VehicleMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.app.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_type" jdbcType="INTEGER" property="buyType"/>
        <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="sale_manager" jdbcType="VARCHAR" property="saleManager"/>
        <result column="sale_manager_phone" jdbcType="VARCHAR" property="saleManagerPhone"/>
        <result column="validate_status" jdbcType="TINYINT" property="validateStatus"/>
        <result column="vehicle_usages" jdbcType="TINYINT" property="vehicleUsages"/>
        <result column="validate_info" jdbcType="VARCHAR" property="validateInfo"/>
        <result column="registration_date" jdbcType="TIMESTAMP" property="registrationDate"/>
        <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"/>
    </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_type, buy_date, description, remark, serve_type, sale_manager,
        sale_manager_phone, validate_status, vehicle_usages, validate_info, registration_date,
        del_flag, created_date, created_by, updated_date, updated_by
    </sql>

    <select id="vehicleSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO">
        select tv.id as id, tv.vin,
        tv.owner_name ownerName,
        tv.license_plate licensePlate,
        tw.partner_order_no workOrderNo,
        group_concat(td.sn order by td.source desc) as sns,
        group_concat(td.source order by td.source desc) as sources,
        ltvs.accorderIds
        from t_vehicle tv
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
        left join t_device td on td.sn = tvd.sn
        left join t_workorder tw on tw.id = tv.workorder_id
        left join (select content_id, group_concat(accorder_id) accorderIds from t_vehicle_shared
        where receiver_id = #{userId} group by content_id) ltvs on ltvs.content_id = tv.id
        where tv.del_flag = 0 and tvd.del_flag = 0
        and tvd.bind_status = 1
        and tv.created_by is not null
        <if test="term != null and term !=''">
            and (
            tv.owner_name like '%${term}%'
            or tv.vin like '%${term}%'
            or tv.license_plate like '%${term}%'
            or tvd.sn like '%${term}%'
            or tw.partner_order_no like '%${term}%'
            )
        </if>
        group by tv.id
        order by id desc
    </select>

    <select id="manageSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleSharedDTO">
        select tcusd.id as shareId,
        tv.id as vehicleId,
        tv.vin,
        tv.owner_name as ownerName,
        tv.license_plate licensePlate,
        tw.partner_order_no workOrderNo,
        group_concat(td.sn order by td.source desc) as sns,
        group_concat(td.source order by td.source desc) as sources,
        tcusd.enable_status as sharedStatus,
        TIMESTAMPDIFF(MINUTE, now(), tcusd.expiration_date) as sharedDiffMin,
        tcusd.permit_type as permitType,
        ltvs.receiverIds
        from t_vehicle tv
        left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
        left join t_device td on td.sn = tvd.sn
        left join t_workorder tw on tw.id = tv.workorder_id
        left join t_cust_user_shared_data tcusd on tcusd.content_id = tv.id and tcusd.content_type = 0
        left join (select shared_id, group_concat(receiver_id) receiverIds from t_vehicle_shared tvs where tvs.del_flag
        = 0 group by shared_id) ltvs on tcusd.id = ltvs.shared_id
        where tv.del_flag = 0 and tvd.del_flag = 0 and tvd.bind_status = 1
        and tv.created_by is not null
        and tcusd.del_flag = 0
        and tcusd.id is not null
        and (
        tcusd.created_by = #{userId}
        or
        find_in_set(ltvs.receiverIds,#{userId})
        )
        <if test="term != null and term !=''">
            and (
            tv.owner_name like '%${term}%'
            or tv.vin like '%${term}%'
            or tv.license_plate like '%${term}%'
            or tvd.sn like '%${term}%'
            or tw.partner_order_no like '%${term}%'
            )
        </if>
        group by tv.id
        order by tcusd.created_date desc
    </select>

    <select id="countDeviceWithAuth" resultType="java.lang.Integer">
        select count(distinct tv.id)
        from t_vehicle tv
        left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        <where>
            and tv.del_flag = 0
            and tvd.bind_status = 1
            and tvd.del_flag = 0
            <!--            and tv.validate_status = 1-->
            <if test="search.appendSql != null and search.appendSql !=''">
                ${search.appendSql}
            </if>
            <if test="search.settleCondition != null and search.settleCondition !=''">
                ${search.settleCondition}
            </if>
        </where>
    </select>

    <select id="selectVehicleDeviceByVehicleId" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO">
        select tv.id,
               tv.vin,
               tv.owner_name              ownerName,
               tw.partner_order_no        workOrderNo,
               group_concat(tvd.sn)    as sns,
               group_concat(td.source) as sources
        from t_vehicle tv
                 left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
                 left join t_device td on td.sn = tvd.sn
                 left join t_workorder tw on tw.id = tv.workorder_id
        where tv.del_flag = 0
          and tvd.del_flag = 0
          and tvd.bind_status = 1
          and tv.id = #{vehicleId}
        group by tv.id
        order by tv.id desc
    </select>

    <select id="getAllTrackAlarmDataByAuth" resultType="cn.com.glsx.app.modules.model.view.TrackAlarmVO">
        select tv.id            as vehicleId,
               tv.owner_name    as ownerName,
               tv.vin,
               tvd.sn,
               tv.license_plate as licensePlate
        from t_vehicle tv
                 left 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
    </select>

    <select id="getAllDeviceSnByAuth" resultType="String">
        select tvd.sn
        from t_vehicle tv
                 left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        where tv.del_flag = 0
          and tvd.del_flag = 0
          and tvd.bind_status = 1
    </select>
</mapper>