package cn.iocoder.yudao.module.bpm.service.oa;

import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.infra.api.file.dto.FileCreateReqDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能描述
 *
 * @author: yj
 * @date: 2024年02月09日 15:49
 */
@Service
@Validated
public class BpmOABaseService {

    @Resource
    private FileApi fileApi;
    /**
     * 通过url更新附件的归属的实例ID
     * @param processInstanceId
     * @param fileItems
     */
    public void uploadBpmFileProcessInstanceId(String processInstanceId, List<UploadUserFile> fileItems ) {
        List<String> urls = fileItems.stream()
                .map(UploadUserFile::getUrl)
                .collect(Collectors.toList());
        FileCreateReqDTO createReqDTO = new FileCreateReqDTO() ;
        createReqDTO.setProcessInstanceId(processInstanceId) ;
        createReqDTO.setUrls(urls) ;
        fileApi.uploadBpmFileProcessInstanceId(createReqDTO) ;
    }
}
