puzhibing
2026-09-30 67d25f3d9eb0124c7aab544bf8f77031d6d8adc3
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TFleetServiceImpl.java
@@ -19,6 +19,7 @@
import com.ruoyi.other.api.vo.FleetOrderAggregateVO;
import com.ruoyi.other.mapper.TChargeAuthorizationMapper;
import com.ruoyi.other.mapper.TFleetMapper;
import com.ruoyi.other.service.CompanyAccountAccessService;
import com.ruoyi.other.service.TFleetService;
import com.ruoyi.other.service.TGroupCompanyService;
import org.springframework.stereotype.Service;
@@ -30,6 +31,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
@@ -66,6 +68,9 @@
    @Resource
    private FleetUnbindClient fleetUnbindClient;
    @Resource
    private CompanyAccountAccessService companyAccountAccessService;
    @Override
    public Page<TVinManagement> selectVinPage(Integer fleetId, Integer current, Integer size) {
@@ -111,6 +116,8 @@
        if (items == null || items.isEmpty()) {
            throw new ServiceException("导入数据不能为空");
        }
        // 公司账号导入车队时强制归属本公司,Excel中的所属公司仅作展示信息
        Integer lockedCompanyId = companyAccountAccessService.getCurrentCompanyId();
        Set<String> fleetNames = new HashSet<>();
        Set<String> companyNames = new HashSet<>();
        int row = 1;
@@ -123,17 +130,19 @@
            if (fleetName.length() > 128) {
                throw new ServiceException("第" + row + "行车队名称不能超过128个字符");
            }
            if (!StringUtils.hasText(item.getCompanyName())) {
            if (lockedCompanyId == null && !StringUtils.hasText(item.getCompanyName())) {
                throw new ServiceException("第" + row + "行所属公司不能为空");
            }
            parseStatus(item.getStatus(), row);
            if (!fleetNames.add(fleetName) || lambdaQuery().eq(TFleet::getFleetName, fleetName).count() > 0) {
                throw new ServiceException("第" + row + "行车队名称已存在或重复");
            }
            companyNames.add(item.getCompanyName().trim());
            if (lockedCompanyId == null && StringUtils.hasText(item.getCompanyName())) {
                companyNames.add(item.getCompanyName().trim());
            }
        }
        // 批量查询公司名称 -> ID
        Map<String, Integer> companyMap = groupCompanyService.lambdaQuery()
        Map<String, Integer> companyMap = companyNames.isEmpty() ? new HashMap<>() : groupCompanyService.lambdaQuery()
                .in(TGroupCompany::getName, companyNames)
                .list()
                .stream()
@@ -141,15 +150,15 @@
        row = 1;
        for (FleetImportDTO item : items) {
            row++;
            String companyName = item.getCompanyName().trim();
            if (!companyMap.containsKey(companyName)) {
            String companyName = item.getCompanyName() == null ? null : item.getCompanyName().trim();
            if (lockedCompanyId == null && (companyName == null || !companyMap.containsKey(companyName))) {
                throw new ServiceException("第" + row + "行所属公司不存在:" + companyName);
            }
        }
        LocalDateTime now = LocalDateTime.now();
        for (FleetImportDTO item : items) {
            TFleet fleet = new TFleet();
            fleet.setCompanyId(companyMap.get(item.getCompanyName().trim()));
            fleet.setCompanyId(lockedCompanyId != null ? lockedCompanyId : companyMap.get(item.getCompanyName().trim()));
            fleet.setFleetName(item.getFleetName().trim());
            fleet.setContactName(trim(item.getContactName()));
            fleet.setContactPhone(trim(item.getContactPhone()));