package cn.cslg.report.service.business;

import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.asso.AssoReportFile;

import cn.cslg.report.mapper.AssoReportFileMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class AssoReportFileService extends ServiceImpl<AssoReportFileMapper, AssoReportFile> {


    //添加
    public String addAsso(Integer reportId, List<Integer> fileIds) {
        List<AssoReportFile> assoReportFiles = new ArrayList<>();
        fileIds.forEach(item -> {
            AssoReportFile assoReportFile = new AssoReportFile();
            assoReportFile.setReportId(reportId);
            assoReportFile.setFileId(item);
            assoReportFile.setFileType(0);
            assoReportFiles.add(assoReportFile);
        });
           this.saveBatch(assoReportFiles);
        return Response.success();
    }

    //根据报告Id查询文件Id
    public List<AssoReportFile> queryFileByReportId(List<Integer> reportIds){
        LambdaQueryWrapper<AssoReportFile> wrapper =new LambdaQueryWrapper<>();
        wrapper.in(AssoReportFile::getReportId,reportIds);
        List<AssoReportFile> assoReportFiles =this.list(wrapper);
        return assoReportFiles;
    }
}
