package com.ningdatech.carapi.homepage.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.util.NdDateUtils;
import com.ningdatech.carapi.car.datascreen.model.dto.DataScreenParam;
import com.ningdatech.carapi.car.vehicle.mapper.VehicleBaseInfoJoinMapper;
import com.ningdatech.carapi.car.vehicle.mapper.VehicleBaseInfoMapper;
import com.ningdatech.carapi.car.vehicle.model.NdVehicleBaseInfo;
import com.ningdatech.carapi.car.vehicle.model.NdVehicleBaseInfoJoin;
import com.ningdatech.carapi.common.aop.BuildChildrenRegionEntity;
import com.ningdatech.carapi.datascope.aop.XmlDataScope;
import com.ningdatech.carapi.homepage.constant.HomepageConstant;
import com.ningdatech.carapi.homepage.entity.dto.HomepageAbnormalBehaviorPageParamDTO;
import com.ningdatech.carapi.homepage.entity.model.NdDataAccessGps;
import com.ningdatech.carapi.homepage.entity.model.OnlineNumCnt;
import com.ningdatech.carapi.homepage.entity.po.DriverAbnormalBehaviorNumPO;
import com.ningdatech.carapi.homepage.entity.po.VehicleNumPO;
import com.ningdatech.carapi.homepage.mapper.DataAccessGpsMapper;
import com.ningdatech.carapi.homepage.mapper.HomepageMapper;
import com.ningdatech.carapi.homepage.service.IDataAccessGpsService;
import com.ningdatech.carapi.homepage.service.IHomepageService;
import com.ningdatech.carapi.scheduler.mapper.VehicleOnlineStatusDayMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
 * @author zpf
 * @description
 * @since 2024/09/20 17:10
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class DataAccessGpsServiceImpl extends ServiceImpl<DataAccessGpsMapper, NdDataAccessGps> implements IDataAccessGpsService {

    @Override
    public Long getMaxBizId() {
        List<Long> list = baseMapper.selectList(Wrappers.lambdaQuery(NdDataAccessGps.class).select(NdDataAccessGps::getBizId))
                .stream().map(d -> {
                    String bizId = d.getBizId();
                    return Long.parseLong(bizId);
                }).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(list)){
            return list.stream().max(Long::compare).get();
        }
        return null;
    }
}
