package com.muyu.enterprise.service.impl.carImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.enterprise.domain.car.Vehicle;
import com.muyu.enterprise.domain.car.VehicleType;
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
import com.muyu.enterprise.domain.resp.car.VehicleManageResp;
import com.muyu.enterprise.mapper.car.VehicleMapper;
import com.muyu.enterprise.service.car.VehicleService;
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.service.impl
 * @Project：cloud-server
 * @name：VehicleServiceImpl
 * @Date：2024/9/26 22:35
 * @Description: 车辆管理业务层
 */
@Log4j2
@Service
public class VehicleServiceImpl
extends ServiceImpl<VehicleMapper,
        Vehicle> implements VehicleService
{
    @Autowired
    private  VehicleMapper vehicleMapper;

    /**
     * 查询车辆管理列表
     * @param vehicleManageReq 请求对象
     * @return 返回结果
     */
    @Override
    public List<VehicleManageResp> getVehicleList(VehicleManageReq vehicleManageReq) {
        MPJLambdaWrapper<Vehicle> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(Vehicle.class)
                .selectAs(VehicleType::getVehicleTypeName, VehicleManageResp::getVehicleTypeName)
                .leftJoin(VehicleType.class, VehicleType::getVehicleTypeId, Vehicle::getVehicleTypeId)
                .like(
                        StringUtils.isNotEmpty(vehicleManageReq.getLicenceNumber()),
                        Vehicle::getLicenceNumber, vehicleManageReq.getLicenceNumber()
                )
                .like(
                        StringUtils.isNotEmpty(vehicleManageReq.getVehicleVin()),
                        Vehicle::getVehicleVin, vehicleManageReq.getVehicleVin()
                )
                .eq(
                        StringUtils.isNotBlank(vehicleManageReq.getVehicleStatus()),
                        Vehicle::getVehicleStatus, vehicleManageReq.getVehicleStatus()
                );
        List<VehicleManageResp> list = vehicleMapper.selectJoinList(VehicleManageResp.class, wrapper);
        return list;
    }
    /**
     * 通过车辆vin码查询模板id
     * @param vehicleVin 请求对象
     * @return 返回结果
     */
    @Override
    public Long findByVehicleVin(String vehicleVin) {
        Long templateId = vehicleMapper.findByVehicleVin(vehicleVin);
        return templateId;

    }


}
