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.AdmJobSpaceMapper;
import com.persagy.adm.server.custom.entity.db.AdmJobSpace;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 检查任务数据是否有更新
 */
@Component
@Slf4j
public class AdmJobSpaceCheckUpdate implements CheckUpdate{
    @Autowired
    private AdmJobSpaceMapper jobSpaceMapper;

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