package cn.cslg.report.service.business;

import cn.cslg.report.common.utils.Response;

import cn.cslg.report.entity.asso.AssoReportReferences;

import cn.cslg.report.mapper.AssoReportReferencesMapper;
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;

@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
@SuppressWarnings({"all"})
public class AssoReportReferencesService extends ServiceImpl<AssoReportReferencesMapper, AssoReportReferences> {
    /**
     * @function 增加报告参考资料和文件关联表
     * @param ReportReferencesID 报告参考资料id
     * @param fileID 文件id
     * @return 增加是否成功
     */
    public String add(int ReportReferencesID, List<Integer> fileID){
        List<AssoReportReferences> list=new ArrayList<>();
        fileID.forEach(item ->{
            AssoReportReferences assoReportReferences=new AssoReportReferences();
            assoReportReferences.setReportReferencesID(ReportReferencesID);
            assoReportReferences.setFileID(item);
            list.add(assoReportReferences);
        });
        this.saveBatch(list);
        return Response.success();
    }

    /**
     * @function 根据其他参考资料的id查询报告参考资料和文件关联表
     * @param ReportReferencesID
     * @return
     */
    public List<AssoReportReferences> select(int ReportReferencesID){
        LambdaQueryWrapper<AssoReportReferences> wrapper =new LambdaQueryWrapper<>();
        wrapper.eq(AssoReportReferences::getReportReferencesID,ReportReferencesID);
        return this.list(wrapper);

    }

}
