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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.dict.impl.FileModuleDict;
import com.sunxung.factoring.entity.salescontractmanagement.SalesContractReturnBond;
import com.sunxung.factoring.entity.sys.FileStorage;
import com.sunxung.factoring.mapper.salescontractmanagement.SalesContractReturnBondMapper;
import com.sunxung.factoring.service.project.BusinessProcessingLogService;
import com.sunxung.factoring.service.salescontractmanagement.ISalesContractReturnBondService;
import com.sunxung.factoring.service.salescontractmanagement.SalesContractService;
import com.sunxung.factoring.service.sys.ISysAttachmentRefService;
import com.sunxung.factoring.service.sys.dto.AttachmentDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Yafan Wang
 * @Date 2023/3/8 11:15
 */
@Service("sales_contract_return_bondService")
public class SalesContractReturnBondServiceImpl extends ServiceImpl<SalesContractReturnBondMapper, SalesContractReturnBond> implements ISalesContractReturnBondService {

    @Autowired
    private ISysAttachmentRefService iSysAttachmentRefService;

    @Autowired
    private BusinessProcessingLogService processingLogService;

    @Autowired
    private SalesContractService salesContractService;

    @Override
    public SalesContractReturnBond getView(Long id) {
        //获取历史
        SalesContractReturnBond contractReturnBond = getOne(new QueryWrapper<SalesContractReturnBond>().eq("sales_contract_management_id", id));
        AttachmentDto attachmentDto = AttachmentDto.builder()
                .setEntityId(contractReturnBond.getId())
                .setChildEnum(FileModuleDict.ChildEnum.SALES_CONTRACT_RETURN_BOND_FILE)
                .build();
        List<FileStorage> voucherFiles = iSysAttachmentRefService.getFiles(attachmentDto);
        contractReturnBond.setVoucherFiles(voucherFiles);
        return contractReturnBond;
    }

}
