package com.brilliance.isc.common.api.settle.controller;

import com.brilliance.isc.common.api.settle.service.SettleDetailApiService;
import com.brilliance.isc.common.api.settle.vo.AccountRequestVo;
import com.brilliance.isc.common.api.settle.vo.AccountResponseVo;
import com.brilliance.isc.common.api.settle.vo.SettleDetailRequestVo;
import com.brilliance.isc.common.api.settle.vo.SettleDetailResponseVo;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.setfeg.service.SetfegService;
import com.brilliance.isc.common.setgll.service.SetgllService;
import com.brilliance.isc.common.setgll.vo.SetgllVo;
import com.brilliance.isc.common.vo.BizAmdInfoVo;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.vo.ResponseSet;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;


@Api("账务计算服务")
public abstract class AbstractSettleDetailController<T1 extends BizInfoVo, T2 extends BizAmdInfoVo> {

    @Autowired
    private SettleContext settleContext;

    @Autowired
    private SetfegService setfegService;

    @Autowired
    private SettleDetailApiService settleDetailService;

    @Autowired
    private SetgllService setgllService;

    @ApiOperation("试算账务入口")
    public ResponseSet<SettleDetailResponseVo> calcSettleDetail( SettleDetailRequestVo<T1, T2> settleDetailRequestVo) {
        try {
            settleContext.loadSettleSession(settleDetailRequestVo.getTransName(), settleDetailRequestVo.getUserId(),
                    settleDetailRequestVo.getRec(),
                    settleDetailRequestVo.getPtsList(), settleDetailRequestVo.getSptinr());
            return ResponseSet.simpleSuccess(settleDetailService.calcSettleDetail(settleDetailRequestVo));
        } catch (Exception e) {
            throw e;
        } finally {
            setfegService.clearFeeSet();
            SettleContext.removeUserSession();
        }
    }

    @ApiOperation("获取核心8091接口账户代码")
    public ResponseSet<AccountResponseVo> getCoreAccountCode(AccountRequestVo accountRequestVo) {
        return ResponseSet.simpleSuccess(settleDetailService.getCoreAccountCode(accountRequestVo));
    }

    @ApiOperation("获取账号信息")
    public ResponseSet<SetgllVo> getAcctInfo(SetgllVo setgllVo) {
        return ResponseSet.simpleSuccess(settleDetailService.getAcctInfo(setgllVo));
    }
}
