package com.gci.boot.modules.projects.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gci.boot.modules.gis.entity.TbGisRunningbus;
import com.gci.boot.modules.gis.service.ITbGisRunningbusService;
import com.gci.boot.modules.projects.entity.ProjectVehicleBindLog;
import com.gci.boot.modules.projects.mapper.ProjectVehicleBindLogMapper;
import com.gci.boot.modules.projects.service.IProjectVehicleBindLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * @author lyz
 * @date 2023/10/8 14:15
 */
@Service
public class ProjectVehicleBindLogServiceImpl extends ServiceImpl<ProjectVehicleBindLogMapper, ProjectVehicleBindLog> implements IProjectVehicleBindLogService {
   @Autowired
   private ProjectVehicleBindLogMapper projectVehicleBindLogMapper;
    @Override
    public void addLog(String projectId, String projectName, String plateNumber, Integer bindType, Integer bindSource, String createBy) {
        ProjectVehicleBindLog log = bindLog(projectId,projectName,plateNumber,bindType,bindSource,createBy);
        this.projectVehicleBindLogMapper.insert(log);
    }

    @Override
    public void addBatchLog(String projectId, String projectName, List<String> plateNumbers, Integer bindType, Integer bindSource, String createBy) {
        List<ProjectVehicleBindLog> logs = new ArrayList<>(plateNumbers.size());
        plateNumbers.stream().forEach(plateNumber->{
            ProjectVehicleBindLog log = bindLog(projectId,projectName,plateNumber,bindType,bindSource,createBy);
            logs.add(log);
        });
        this.saveBatch(logs);
    }

    private ProjectVehicleBindLog bindLog(String projectId, String projectName, String plateNumber, Integer bindType, Integer bindSource, String createBy){
        ProjectVehicleBindLog log = new ProjectVehicleBindLog();
        log.setProjectId(projectId);
        log.setProjectName(projectName);
        log.setPlateNumber(plateNumber);
        log.setBindType(bindType);
        log.setBindSource(bindSource);
        log.setCreateTime(new Date());
        log.setCreateBy(createBy);
        return log;
    }
}
