package com.muyu.car.gateway.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.car.domain.api.req.VehicleConnectionReq;
import com.muyu.car.domain.model.MqttServerModel;
import com.muyu.car.domain.model.VehicleInformation;
import com.muyu.car.gateway.service.VehicleInformationService;
import com.muyu.car.mapper.VehicleInformationMapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：蓬叁
 * @Package：com.muyu.car.gateway.service.impl
 * @Project：cloud-server-8
 * @name：VehicleInformationServiceImpl
 * @Date：2024/10/6 下午2:41
 */
@Log4j2
@Service
public class VehicleInformationServiceImpl implements VehicleInformationService{

    @Autowired private VehicleInformationMapper vehicleInformationMapper;

    @Override
    public MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq) {
        log.info("车辆连接请求:[{}]",vehicleConnectionReq);
        vehicleConnectionReq.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce());

        List<String> selectVehicle =vehicleInformationMapper.selectVehicleVin(vehicleConnectionReq.getVehicleVin());
        if(selectVehicle.isEmpty()) {
            vehicleInformationMapper.addVehicleConnection(vehicleConnectionReq);
            log.info("车辆预上线成功");
        }else {
            log.info("车辆无法重复预上线");
        }

        return new MqttServerModel("tcp://121.199.172.3:1883","vehicle");
    }

}
