package com.persagy.adm.server.backstage.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.persagy.adm.server.algorithm.constant.AdmModelFileStatusEnum;
import com.persagy.adm.server.algorithm.entity.AdmModelFile;
import com.persagy.adm.server.algorithm.service.AdmModelFileService;
import com.persagy.adm.server.backstage.domain.AdmAnalysisModel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 查询需要解析的模型文件数据
 * @author : lijie
 * Update By 2022/1/21 14:25
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class AdmPreFileServiceImpl extends AdmAnalysisServiceBase {

    private final AdmModelFileService admModelFileService;

    @Override
    protected void analysisInternal(AdmAnalysisModel model) {
        // 1.查询状态为3的文件
        List<AdmModelFile> admModelFiles = admModelFileService
                .listByStatus(AdmModelFileStatusEnum.SYNC_DATA_COMPLETED.getValue());
        if (CollUtil.isEmpty(admModelFiles)){
            return;
        }
        model.setAdmModelFiles(admModelFiles);
        this.getNext().analysis(model);
    }

    @Override
    protected void afterAnalysis(AdmAnalysisModel model) {
        if (CollUtil.isNotEmpty(model.getAdmModelFiles())){
            admModelFileService.updateBatchById(model.getAdmModelFiles());
        }
    }
}
