package com.crm.pay.service.impl.pay;

import com.crm.pay.service.FinanceDepositService;
import com.crm.pay.service.TelegraphicPayService;
import com.crm.pay.service.impl.base.BasePayServiceImpl;
import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
import com.crm.rely.backend.model.pojo.table.FinanceDepositTable;
import com.crm.rely.backend.model.pojo.table.SysRemittanceChannelTable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description:
 * @author: houn
 * @create: 2020-05-07 23:45
 */
@Slf4j
@Service
public class TelegraphicPayServiceImpl extends BasePayServiceImpl implements TelegraphicPayService {

    @Autowired
    private FinanceDepositService balanceService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pay(FinanceDepositAddEntity balanceSaveEntity) throws Exception {

        SysRemittanceChannelTable channel = getPayChannel(balanceSaveEntity.getPayType());

        balanceSaveEntity.setCurrency(channel.getCurrency());
        balanceSaveEntity.setTransformCurrency(channel.getTransformCurrency());
        FinanceDepositTable financeDepositTable = balanceService.save(balanceSaveEntity, channel);
    }

    @Override
    public String uploadFile(Long customId, MultipartFile file) throws Exception {
        String middlePath = (customId == null ? "" : customId.toString()) + "/telegraphic/pay";
        String path = saveFile(middlePath, file);

        return path;
    }

}
