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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.persagy.adm.server.custom.common.AdmRequest;
import com.persagy.adm.server.custom.dao.AdmProblemMapper;
import com.persagy.adm.server.custom.entity.BuildingData;
import com.persagy.adm.server.custom.entity.db.AdmProblem;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 离线数据下载-核查问题数据
 */
@Component
@Slf4j
public class FillProblem implements FillData<BuildingData>{

    @Autowired
    AdmProblemMapper problemMapper;

    @Override
    public void fill(AdmRequest admRequest, BuildingData buildingData) {
        log.info("填充任务数据开始");
        String operator = admRequest.getUserId() + ":" + admRequest.getClientId();
        // 问题相关数据
        LambdaQueryWrapper<AdmProblem> queryWrapper = new LambdaQueryWrapper<AdmProblem>()
                .eq(AdmProblem::getGroupCode, admRequest.getGroupCode())
                .eq(AdmProblem::getProjectId, admRequest.getProjectId())
                .eq(AdmProblem::getBuildingId, admRequest.getBuildingId())
                .gt(admRequest.getAdmDownloadTs()!=null && admRequest.getAdmDownloadTs() != 0,AdmProblem::getTs, admRequest.getAdmDownloadTs())
                .ne(StringUtils.isNotBlank(operator),AdmProblem::getModifier,operator);
        List<AdmProblem> problems = problemMapper.selectList(queryWrapper);
        buildingData.setProblems(problems);
        log.info("填充任务结束");
    }
}
