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

/**
 * 检查核查问题数据是否有更新
 */
@Component
@Slf4j
public class AdmProblemCheckUpdate implements CheckUpdate{

    @Autowired
    AdmProblemMapper problemMapper;

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