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

import com.brilliance.isc.common.api.fee.service.FeeDetailApiService;
import com.brilliance.isc.common.api.fee.vo.FeeDetailRequestVo;
import com.brilliance.isc.common.api.fee.vo.FeeDetailResponseVo;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.setfeg.service.SetfegService;
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 AbstractFeeDetailController<T1 extends BizInfoVo, T2 extends BizAmdInfoVo> {

    @Autowired
    private SettleContext settleContext;

    @Autowired
    private SetfegService setfegService;

    @Autowired
    private FeeDetailApiService feeDetailService;

    @ApiOperation("试算费用入口")
    public ResponseSet<FeeDetailResponseVo> calcFeeDetail(FeeDetailRequestVo<T1, T2> feeDetailRequestVo) {
        try {
            settleContext.loadSettleSession(feeDetailRequestVo.getTransName(), feeDetailRequestVo.getUserId(),
                    feeDetailRequestVo.getRec(),
                    feeDetailRequestVo.getPtsList(), feeDetailRequestVo.getSptinr());
            FeeDetailResponseVo feeDetailResponseVo = feeDetailService.calcFeeDetail(feeDetailRequestVo);
            return ResponseSet.simpleSuccess(feeDetailResponseVo);
        } catch (Exception e) {
            throw e;
        } finally {
            setfegService.clearFeeSet();
            SettleContext.removeUserSession();
        }
    }
}
