package com.qmth.distributed.print.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
import com.qmth.distributed.print.business.entity.ExamTaskSync;
import com.qmth.distributed.print.business.mapper.ExamTaskSyncMapper;
import com.qmth.distributed.print.business.service.ExamTaskSyncService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 数据同步 服务实现类
 * </p>
 */
@Service
public class ExamTaskSyncServiceImpl extends ServiceImpl<ExamTaskSyncMapper, ExamTaskSync> implements ExamTaskSyncService {

    @Override
    public ExamTaskSync getBySchoolIdAndOrgCodeAndPaperNumber(Long schoolId, Long examId, String orgCode, String paperNumber) {

        QueryWrapper<ExamTaskSync> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ExamTaskSync::getSchoolId, schoolId)
                .eq(ExamTaskSync::getExamId, examId)
                .eq(ExamTaskSync::getPaperNumber, paperNumber);
        if(StringUtils.isNotBlank(orgCode)){
            queryWrapper.lambda().eq(ExamTaskSync::getOrgCode, orgCode);
        } else {
            queryWrapper.lambda().isNull(ExamTaskSync::getOrgCode);
        }
        return this.getOne(queryWrapper);
    }
}
