package com.sunxung.factoring.service.signconfirmation.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.signconfirmation.SignConfirmationApproval;
import com.sunxung.factoring.entity.signconfirmation.SignConfirmationElectronicInfo;
import com.sunxung.factoring.entity.sys.FileStorage;
import com.sunxung.factoring.mapper.signconfirmation.SignConfirmationApprovalMapper;
import com.sunxung.factoring.service.signconfirmation.ISignConfirmationApprovalService;
import com.sunxung.factoring.service.signconfirmation.ISignConfirmationElectronicInfoService;
import com.sunxung.factoring.service.sys.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * --签署确认审核表 服务实现类
 * </p>
 *
 * @author liutao
 * @since 2023-05-16
 */
@Service("legal_approvalService")
public class SignConfirmationApprovalServiceImpl extends ServiceImpl<SignConfirmationApprovalMapper, SignConfirmationApproval> implements ISignConfirmationApprovalService {

    @Autowired
    private ISignConfirmationElectronicInfoService signConfirmationElectronicInfoService;

    @Autowired
    private FileStorageService fileStorageService;

    @Override
    public SignConfirmationApproval getView(Long id) {
        SignConfirmationApproval signConfirmationApproval = getById(id);
        List<SignConfirmationElectronicInfo> signConfirmationElectronicInfos = signConfirmationElectronicInfoService.lambdaQuery()
                .eq(SignConfirmationElectronicInfo::getSignConfirmationId, signConfirmationApproval.getSignConfirmationId()).list();
        List<FileStorage> fileStorages = signConfirmationElectronicInfos.stream().map(r -> {
            FileStorage old = fileStorageService.get(r.getFileId());
            FileStorage fileStorage = fileStorageService.get(r.getBackFileId());
            fileStorage.setOriginalName(old.getOriginalName());
            return fileStorage;
        }).collect(Collectors.toList());
        signConfirmationApproval.setFileStorages(fileStorages);
        return signConfirmationApproval;
    }
}
