package com.persagy.adm.server.custom.service.impl.check_update;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.persagy.adm.server.custom.dao.AdmPipeMapper;
import com.persagy.adm.server.custom.entity.db.AdmPipe;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 检查管道数据是否有更新
 */
@Component
@Slf4j
public class AdmPipeCheckUpdate implements CheckUpdate{

    @Autowired
    private AdmPipeMapper pipeMapper;

    @Override
    public boolean doCheck(CheckUpdateContext hasUpdateReq) {
        log.info("检查管道数据是否有更新");
        return pipeMapper.selectOne(new LambdaQueryWrapper<AdmPipe>().select(AdmPipe::getId).eq(AdmPipe::getProjectId, hasUpdateReq.getProjectId()).gt(AdmPipe::getTs, hasUpdateReq.getDownloadAdmTs()).last("limit 1")) != null;
    }
}
