package com.yh.saas.plugin.yiliangyiyun.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yh.saas.common.support.util.IdGenerator;
import com.yh.saas.plugin.yiliangyiyun.entity.FuelFillingInfo;
import com.yh.saas.plugin.yiliangyiyun.entity.TrackDetailInfo;
import com.yh.saas.plugin.yiliangyiyun.mapper.TrackDetailInfoMapper;
import com.yh.saas.plugin.yiliangyiyun.service.IFuelFillingInfoService;
import com.yh.saas.plugin.yiliangyiyun.service.ITrackDetailInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 记录轨迹明细 服务实现类
 * </p>
 *
 * @author Gdc
 * @since 2022-06-29
 */
@Service
public class TrackDetailInfoServiceImpl extends ServiceImpl<TrackDetailInfoMapper, TrackDetailInfo> implements ITrackDetailInfoService {

    @Autowired
    private IFuelFillingInfoService fuelFillingInfoService;
    /**
     * 添加轨迹
     * @param trackDetailInfo
     * @return
     */
    @Override
    public String addTrackDetail(TrackDetailInfo trackDetailInfo) {
        //新增主键id
        trackDetailInfo.setId(IdGenerator.generateUUID());
        //查询加油信息
        FuelFillingInfo fuelFillingInfo = fuelFillingInfoService.selectOne(new EntityWrapper<FuelFillingInfo>()
                    .eq("car_no",trackDetailInfo.getCarNo())
                    .eq("delete_flag","0"));
        if(fuelFillingInfo != null){
            trackDetailInfo.setFillingId(fuelFillingInfo.getId());
        }
        this.insert(trackDetailInfo);
        return "OK";
    }

    /**
     * 查看轨迹
     * @param trackDetailInfo
     * @return
     */
    @Override
    public TrackDetailInfo getTrack(TrackDetailInfo trackDetailInfo) {
        TrackDetailInfo trackDetailInfo1 = this.selectOne(new EntityWrapper<TrackDetailInfo>()
                    .eq("filling_id",trackDetailInfo.getFillingId())
                    .eq("delete_flag","0"));
        return trackDetailInfo1;
    }
}
