package com.brilliance.isc.common.register.liaccv.common;

import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.common.cbsmod.service.CbsmodService;
import com.brilliance.isc.common.liaccv.vo.LiaccvVo;
import com.brilliance.isc.common.register.liaccv.ILiaccvRegister;
import com.brilliance.isc.common.transaction.help.TransactionHelpService;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.mda.runtime.mda.util.Dates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;

@Component("liaccvSetTransaction")
public class LiaccvRegister implements ILiaccvRegister {

    @Autowired
    private TransactionHelpService transactionHelpService;

    @Autowired
    private CbsmodService cbsmodService;

    @Override
    public void liaccvSetTransaction(LiaccvVo liaccvVo) {
        //注册其他需要参与计算的字段
        transactionHelpService.getLiaallSet().setRec(liaccvVo.getRec());
        transactionHelpService.getLiaallSet().setPtsptas(liaccvVo.getPtsList());
        Cbb cbb = liaccvVo.getCbsMap().get("MAX");
        if (cbb == null) {
            cbb = liaccvVo.getCbsMap().get("NOM1");
        }
        if (cbb != null) {
            liaccvVo.setDoccur(cbb.getCur());
            liaccvVo.setDocamt(cbb.getAmt());
            liaccvVo.setConcur(cbb.getCur());
        }
    }

    /**
     * 获取改变金额的值
     * @return
     */
    public BigDecimal getCcvMaxAmt(String objTyp, String objInr) {
        Date date = Dates.add(Utils.getMaxDate(), -1);
        Cbb cbb = new Cbb();
        cbsmodService.cbsGetBalance(cbb, objTyp, objInr, "MAXSUM", "CCVAMT", date);
        if (cbb != null) {
            return cbb.getAmt();
        }
        return BigDecimal.ZERO;
    }
}
