package com.bs.cm.service.impl;

import com.bs.cm.domain.CmVehicle;
import com.bs.cm.domain.CmVehicleRfid;
import com.bs.cm.mapper.CmVehicleHostMapper;
import com.bs.cm.domain.CmVehicleHost;
import com.bs.cm.service.ICmVehicleHostService;
import com.bs.cm.service.ICmVehicleService;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 车辆主机信息Service业务层处理
 *
 * @author bs
 * @date 2025-01-12
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CmVehicleHostServiceImpl  extends MPJBaseServiceImpl<CmVehicleHostMapper, CmVehicleHost> implements ICmVehicleHostService {
    @Resource
    private ICmVehicleService cmVehicleService;
    @Override
    public List<CmVehicleHost> getVehicleInfo(List<CmVehicleHost> lsData) {
        if (null != lsData && lsData.size() > 0) {
            Map<Long, CmVehicle> vehicleMap = new HashMap<>();
            List<CmVehicle> lsVehicle = cmVehicleService.list();
            if (null != lsVehicle &&lsVehicle.size() > 0) {
                for (CmVehicle vehicle : lsVehicle) {
                    vehicleMap.put(vehicle.getId(), vehicle);
                }
            }
            for (CmVehicleHost host : lsData) {
                if (null != host.getVehicleId()) {
                    CmVehicle vehicle = vehicleMap.get(host.getVehicleId());
                    host.setVehicle(vehicle);
                }
            }
        }
        return lsData;
    }
}
