| | |
| | | |
| | | <resultMap type="com.ruoyi.system.domain.VehicleInfo" id="VehicleInfoResult"> |
| | | <id property="vehicleId" column="vehicle_id" /> |
| | | <result property="carId" column="car_id" /> |
| | | <result property="deviceId" column="device_id" /> |
| | | <result property="vehicleNo" column="vehicle_no" /> |
| | | <result property="vehicleType" column="vehicle_type" /> |
| | |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | <result property="remark" column="remark" /> |
| | | <!-- 多个分公司关联 --> |
| | | <collection property="deptIds" ofType="Long" |
| | | select="selectVehicleDeptIds" |
| | | column="vehicle_id"/> |
| | | <collection property="deptNames" ofType="String" |
| | | select="selectVehicleDeptNames" |
| | | column="vehicle_id"/> |
| | | </resultMap> |
| | | |
| | | <sql id="selectVehicleInfoVo"> |
| | | select v.vehicle_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand, v.vehicle_model, v.status, v.platform_code, v.dept_id, d.dept_name, v.create_by, v.create_time, v.update_by, v.update_time, v.remark |
| | | select v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand, v.vehicle_model, v.status, v.platform_code, v.dept_id, d.dept_name, v.create_by, v.create_time, v.update_by, v.update_time, v.remark |
| | | from tb_vehicle_info v |
| | | left join sys_dept d on v.dept_id = d.dept_id |
| | | </sql> |
| | | |
| | | <!-- 查询车辆关联的所有分公司ID --> |
| | | <select id="selectVehicleDeptIds" resultType="Long"> |
| | | SELECT dept_id FROM tb_vehicle_dept WHERE vehicle_id = #{vehicle_id} |
| | | </select> |
| | | |
| | | <!-- 查询车辆关联的所有分公司名称 --> |
| | | <select id="selectVehicleDeptNames" resultType="String"> |
| | | SELECT d.dept_name |
| | | FROM tb_vehicle_dept vd |
| | | LEFT JOIN sys_dept d ON vd.dept_id = d.dept_id |
| | | WHERE vd.vehicle_id = #{vehicle_id} |
| | | </select> |
| | | |
| | | <select id="selectVehicleInfoList" parameterType="VehicleInfo" resultMap="VehicleInfoResult"> |
| | | <include refid="selectVehicleInfoVo"/> |
| | |
| | | <if test="vehicleModel != null and vehicleModel != ''"> and v.vehicle_model = #{vehicleModel}</if> |
| | | <if test="status != null and status != ''"> and v.status = #{status}</if> |
| | | <if test="platformCode != null and platformCode != ''"> and v.platform_code = #{platformCode}</if> |
| | | <if test="deptId != null"> and v.dept_id = #{deptId}</if> |
| | | <!-- 部门过滤:根据分公司ID查询车辆(通过关联表) --> |
| | | <if test="deptId != null"> |
| | | and EXISTS ( |
| | | SELECT 1 FROM tb_vehicle_dept vd |
| | | WHERE vd.vehicle_id = v.vehicle_id |
| | | AND vd.dept_id = #{deptId} |
| | | ) |
| | | </if> |
| | | <!-- 任务车辆选择必须过滤:只显示car_id和dept_id都不为空的车辆 --> |
| | | and v.car_id is not null and v.car_id != '' |
| | | and v.dept_id is not null |
| | | and v.status=0 |
| | | |
| | | </where> |
| | | </select> |
| | | |
| | |
| | | <include refid="selectVehicleInfoVo"/> |
| | | where v.vehicle_no = #{plateNumber} |
| | | </select> |
| | | |
| | | <select id="selectVehicleInfoByVehicleNo" parameterType="String" resultMap="VehicleInfoResult"> |
| | | <include refid="selectVehicleInfoVo"/> |
| | | where v.vehicle_no = #{vehicleNo} |
| | | </select> |
| | | |
| | | <insert id="insertVehicleInfo" parameterType="VehicleInfo" useGeneratedKeys="true" keyProperty="vehicleId"> |
| | | insert into tb_vehicle_info |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="carId != null">car_id,</if> |
| | | <if test="deviceId != null">device_id,</if> |
| | | <if test="vehicleNo != null">vehicle_no,</if> |
| | | <if test="vehicleType != null">vehicle_type,</if> |
| | |
| | | <if test="remark != null">remark,</if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="carId != null">#{carId},</if> |
| | | <if test="deviceId != null">#{deviceId},</if> |
| | | <if test="vehicleNo != null">#{vehicleNo},</if> |
| | | <if test="vehicleType != null">#{vehicleType},</if> |
| | |
| | | <update id="updateVehicleInfo" parameterType="VehicleInfo"> |
| | | update tb_vehicle_info |
| | | <trim prefix="SET" suffixOverrides=","> |
| | | <if test="carId != null">car_id = #{carId},</if> |
| | | <if test="deviceId != null">device_id = #{deviceId},</if> |
| | | <if test="vehicleNo != null">vehicle_no = #{vehicleNo},</if> |
| | | <if test="vehicleType != null">vehicle_type = #{vehicleType},</if> |
| | |
| | | ORDER BY uv.bind_time DESC |
| | | LIMIT 1 |
| | | </select> |
| | | |
| | | <!-- 批量插入车辆-分公司关联 --> |
| | | <insert id="batchInsertVehicleDept"> |
| | | INSERT INTO tb_vehicle_dept (vehicle_id, dept_id, order_class, create_by, create_time) |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.vehicleId}, #{item.deptId}, #{item.orderClass}, #{item.createBy}, NOW()) |
| | | </foreach> |
| | | ON DUPLICATE KEY UPDATE |
| | | order_class = VALUES(order_class), |
| | | update_by = VALUES(create_by), |
| | | update_time = NOW() |
| | | </insert> |
| | | |
| | | <!-- 删除车辆的所有分公司关联 --> |
| | | <delete id="deleteVehicleDeptByVehicleId"> |
| | | DELETE FROM tb_vehicle_dept WHERE vehicle_id = #{vehicleId} |
| | | </delete> |
| | | </mapper> |