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

import com.brilliance.isc.common.api.bptbck.service.BptbckApiService;
import com.brilliance.isc.common.api.bptbck.vo.BptbckRequest;
import com.brilliance.isc.common.api.bptbck.vo.BptbckResponse;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.vo.ResponseSet;
import com.brilliance.isc.vo.component.bptbck.Bms9011ReqVo;
import com.brilliance.isc.vo.component.bptbck.Bms9011ResVo;
import com.brilliance.isc.vo.component.bptbck.BptbckQueryVo;
import com.brilliance.isc.vo.component.bptbck.Gle4338Vo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 融资还款服务
 * @restApi
 * @param <T>
 */
@Api("融资还款服务")
public abstract class AbstractBptbckController<T extends BizInfoVo> {

    @Autowired
    private SettleContext settleContext;

    @Autowired
    private BptbckApiService bptbckApiService;

    /**
     * 融资还款试算入口
     * @param bptbckRequest
     * @return
     */
    public ResponseSet<BptbckResponse> assertBptbck(BptbckRequest<T> bptbckRequest) {
        try {
            settleContext.loadSettleSession(bptbckRequest.getTransName(), bptbckRequest.getRec().getBranchInr(), "");
            return ResponseSet.simpleSuccess(bptbckApiService.assertBptbck(bptbckRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }

    /**
     * 调用融资还款试算接口
     * @param bptbckRequest
     * @return
     */
    public ResponseSet<BptbckResponse> call6157(BptbckRequest bptbckRequest) {
        try {
            return ResponseSet.simpleSuccess(bptbckApiService.call6157(bptbckRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }

    /**
     * 调用9011接口
     * @param request
     * @return
     */
    public ResponseSet<List<Bms9011ResVo>> call9011(Bms9011ReqVo request) {
        try {
            return ResponseSet.simpleSuccess(bptbckApiService.call9011(request));
        } catch (Exception e) {
            throw e;
        }
    }

    /**
     * 递延分录信息
     * @param bptbckQueryVo
     * @return
     */
    public ResponseSet<List<Gle4338Vo>> calcGle4338(BptbckQueryVo bptbckQueryVo) {
        try {
            settleContext.simpleLoadSettleSession();
            return ResponseSet.simpleSuccess(bptbckApiService.calcGle4338(bptbckQueryVo));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }
}
