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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.component.util.ConstantConversionUtil;
import com.sunxung.factoring.component.util.ConstantUtil;
import com.sunxung.factoring.dict.impl.FileModuleDict;
import com.sunxung.factoring.entity.settlement.SettlementApproval;
import com.sunxung.factoring.entity.sys.FileStorage;
import com.sunxung.factoring.entity.sys.FileStorageDO;
import com.sunxung.factoring.mapper.settlement.SettlementApprovalMapper;
import com.sunxung.factoring.service.settlement.SettlementApprovalFlowService;
import com.sunxung.factoring.service.settlement.SettlementApprovalService;
import com.sunxung.factoring.service.sys.FileService;
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 liutao
 * @date 2021.10.08
 */
@Service("finance_reviewService")
public class SettlementApprovalFlowServiceImpl extends ServiceImpl<SettlementApprovalMapper, SettlementApproval> implements SettlementApprovalFlowService {

    @Autowired
    private SettlementApprovalService settlementApprovalService;

    @Autowired
    private ISysAttachmentRefService sysAttachmentRefService;

    @Autowired
    private FileService fileService;

    @Override
    public SettlementApproval getView(Long SettlementApprovalId) {
        SettlementApproval settlementApproval = settlementApprovalService.getById(SettlementApprovalId);
        AttachmentDto attachmentDtoAcceptanceFile = AttachmentDto.builder()
                .setEntityId(settlementApproval.getSettlementBasicInfoId())
                .setChildEnum(FileModuleDict.ChildEnum.SETTLEMENT_UPSTREAM_UNSIGNED_FILE)
                .build();
        List<FileStorageDO> fileStorageDOList = fileService.findByBusinessId(settlementApproval.getSettlementBasicInfoId(), FileModuleDict.ChildEnum.SETTLEMENT_UPSTREAM_UNSIGNED_FILE.getCode());
//        List<FileStorage> files = sysAttachmentRefService.getFiles(attachmentDtoAcceptanceFile);
        settlementApproval.setFiles(fileStorageDOList);
        String result;
        switch (settlementApproval.getApprovalConclusion()){
            case ConstantConversionUtil.APPROVAL_RESULT_PASS:
                result = ConstantUtil.APPROVAL;
                break;
            case ConstantConversionUtil.APPROVAL_RESULT_BACK:
                result = ConstantUtil.OVERRULE;
                break;
            default:
                result = "";

        }
        settlementApproval.setResult(result);
        return settlementApproval;
    }
}
