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

import java.util.List;

/**
 * 离线数据下载-CAD图纸数据
 */
@Component
@Slf4j
public class FillCad implements FillData<BuildingData>{
    @Autowired
    AdmCadMapper admCadMapper;
    @Override
    public void fill(AdmRequest admRequest, BuildingData buildingData) {
        log.info("填充CAD图纸数据开始");
        Long admDownloadTs = buildingData.getAdmDownloadTs();
        List<AdmCad> admCads = admCadMapper.selectList(new LambdaQueryWrapper<AdmCad>()
                .eq(AdmCad::getGroupCode,admRequest.getGroupCode())
                .eq(AdmCad::getProjectId,admRequest.getProjectId())
                .eq(AdmCad::getBuildingId,admRequest.getBuildingId())
                .gt(admDownloadTs != null && admDownloadTs != 0,AdmCad::getTs,admDownloadTs));
        buildingData.setAdmCads(admCads);
        log.info("填充CAD图纸数据开始");
    }
}
