package cn.cslg.report.service.business;

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

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

import cn.cslg.report.mapper.AssoReferenceFileMapper;
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})
public class AssoReferenceFileService extends ServiceImpl<AssoReferenceFileMapper, AssoReferenceFile> {

    /**
     *@function 增加其他资料和文件关联表 对应实体：AssoReferenceFile
     * @param id 其他参考资料的id
     * @param fileIds 文件id
     * @return
     */
    public String addAsso(Integer id, List<Integer> fileIds) {
        List<AssoReferenceFile> tems = new ArrayList<>();
        fileIds.forEach(item -> {
            AssoReferenceFile tem = new AssoReferenceFile();
            tem.setReferenceId(id);
            tem.setFileId(item);
            tems.add(tem);
        });
        this.saveBatch(tems);
        return Response.success();
    }
}
