wlzboy
2025-10-26 5c5cddb1c2ee0d19adddebaf3a3a10a6d93fd2ad
ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
@@ -39,7 +39,25 @@
            <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>
            <!-- 部门过滤:自动查找传入部门所属的分公司(parent_id=100) -->
            <if test="deptId != null">
                and v.dept_id = (
                    <!-- 如果传入的就是分公司(parent_id=100),直接返回 -->
                    select case
                        when exists(select 1 from sys_dept where dept_id = #{deptId} and parent_id = 100) then #{deptId}
                        else (
                            <!-- 否则从 ancestors 中查找分公司ID -->
                            select d.dept_id
                            from sys_dept d
                            where d.parent_id = 100
                            and FIND_IN_SET(d.dept_id, (
                                select ancestors from sys_dept where dept_id = #{deptId}
                            ))
                            limit 1
                        )
                    end
                )
            </if>
            <!-- 任务车辆选择必须过滤:只显示car_id和dept_id都不为空的车辆 -->
            and v.car_id is not null and v.car_id != ''
            and v.dept_id is not null