puzhibing
2026-09-30 67d25f3d9eb0124c7aab544bf8f77031d6d8adc3
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TFleetController.java
@@ -15,6 +15,7 @@
import com.ruoyi.other.api.dto.FleetExportDTO;
import com.ruoyi.other.api.dto.FleetImportDTO;
import com.ruoyi.other.api.dto.FleetQueryDTO;
import com.ruoyi.other.service.CompanyAccountAccessService;
import com.ruoyi.other.service.TFleetService;
import com.ruoyi.other.service.TGroupCompanyService;
import io.swagger.annotations.ApiOperation;
@@ -57,6 +58,9 @@
    @Resource
    private TGroupCompanyService groupCompanyService;
    @Resource
    private CompanyAccountAccessService companyAccountAccessService;
    /**
     * 分页查询车队
     */
@@ -68,6 +72,8 @@
                                             @RequestParam(value = "fleetName", required = false) String fleetName,
                                             @RequestParam(value = "companyId", required = false) Integer companyId,
                                             @RequestParam(value = "status", required = false) Integer status) {
        // 公司账号强制按所属公司过滤,覆盖前端传入的公司筛选
        companyId = companyAccountAccessService.resolveCompanyFilter(companyId);
        PageInfo<TFleet> page = new PageInfo<>(current, size);
        fleetService.lambdaQuery()
                .like(StringUtils.hasText(fleetName), TFleet::getFleetName, fleetName)
@@ -89,6 +95,8 @@
    @ApiOperation(value = "添加车队", tags = {"管理后台-车队管理"})
    @Log(title = "【车队管理】添加车队", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody TFleet fleet) {
        // 公司账号新增车队时强制归属本公司
        fleet.setCompanyId(companyAccountAccessService.resolveCompanyFilter(fleet.getCompanyId()));
        if (fleet.getCompanyId() == null) {
            return AjaxResult.error("所属公司不能为空");
        }
@@ -115,6 +123,13 @@
        if (fleet.getId() == null) {
            return AjaxResult.error("车队ID不能为空");
        }
        TFleet existing = fleetService.getById(fleet.getId());
        if (existing == null) {
            return AjaxResult.error("车队不存在或已删除");
        }
        // 公司账号越权校验:只能编辑本公司车队,且不允许改挂到其他公司
        companyAccountAccessService.assertCompanyVisible(existing.getCompanyId());
        fleet.setCompanyId(companyAccountAccessService.resolveCompanyFilter(fleet.getCompanyId()));
        fleetService.updateById(fleet);
        return AjaxResult.success();
    }
@@ -138,6 +153,14 @@
        if (idList.isEmpty()) {
            return AjaxResult.error("车队ID不能为空");
        }
        // 公司账号越权校验:只能删除本公司车队
        List<TFleet> records = fleetService.listByIds(idList);
        if (records == null || records.size() != idList.size()) {
            return AjaxResult.error("部分车队不存在或已删除");
        }
        for (TFleet record : records) {
            companyAccountAccessService.assertCompanyVisible(record.getCompanyId());
        }
        fleetService.deleteFleets(idList);
        return AjaxResult.success();
    }
@@ -153,6 +176,12 @@
        if (id == null) {
            return AjaxResult.error("车队ID不能为空");
        }
        TFleet record = fleetService.getById(id);
        if (record == null) {
            return AjaxResult.error("车队不存在或已删除");
        }
        // 公司账号越权校验:只能操作本公司车队
        companyAccountAccessService.assertCompanyVisible(record.getCompanyId());
        TFleet update = new TFleet();
        update.setId(id);
        update.setStatus(status);
@@ -190,6 +219,11 @@
    @ApiOperation(value = "导出车队", tags = {"管理后台-车队管理"})
    @Log(title = "【车队管理】导出车队", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, @RequestBody(required = false) FleetQueryDTO query) {
        if (query == null) {
            query = new FleetQueryDTO();
        }
        // 公司账号强制按所属公司过滤,覆盖前端传入的公司筛选
        query.setCompanyId(companyAccountAccessService.resolveCompanyFilter(query.getCompanyId()));
        new ExcelUtil<>(FleetExportDTO.class).exportExcel(response, fleetService.selectExportList(query), "车队数据");
    }
@@ -207,6 +241,8 @@
        if (fleet == null) {
            return AjaxResult.error("车队不存在或已删除");
        }
        // 公司账号越权校验:只能查看本公司车队
        companyAccountAccessService.assertCompanyVisible(fleet.getCompanyId());
        if (fleet.getCompanyId() != null) {
            TGroupCompany company = groupCompanyService.getById(fleet.getCompanyId());
            if (company != null) {
@@ -227,6 +263,12 @@
    public AjaxResult<Page<TVinManagement>> vinPage(@RequestParam("id") Integer id,
                                                    @RequestParam(value = "current", defaultValue = "1") Integer current,
                                                    @RequestParam(value = "size", defaultValue = "10") Integer size) {
        TFleet fleet = fleetService.getById(id);
        if (fleet == null) {
            return AjaxResult.error("车队不存在或已删除");
        }
        // 公司账号越权校验:只能查看本公司车队下的VIN
        companyAccountAccessService.assertCompanyVisible(fleet.getCompanyId());
        return AjaxResult.success(fleetService.selectVinPage(id, current, size));
    }