package com.brilliance.isc.common.bopset.controller;

import com.brilliance.isc.bo.model.Cfabop;
import com.brilliance.isc.bo.model.Cfagit;
import com.brilliance.isc.common.bopset.service.CfabopService;
import com.brilliance.isc.common.bopset.service.CfagitService;
import com.brilliance.isc.common.context.SettleContext;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author yangxd
 * @version 1.0
 * @description: 资本项目报送入口
 * @data 2023/7/7 16:35
 */
@Api("资本项目报送服务")
public class AbstractCfabopController<T1 extends BizInfoVo, T2 extends BizAmdInfoVo> {

    @Autowired
    private CfagitService cfagitService;

    @Autowired
    private CfabopService cfabopService;



    @Autowired
    private SettleContext settleContext;

    Logger logger = LoggerFactory.getLogger(AbstractCfabopController.class);

    @ApiOperation("资本项目前端数据交互（试算）")
    public ResponseSet<Cfagit> mappingCfaData(Cfagit<T1, T2>  cfagit) {
        try {
            settleContext.loadSettleSession(cfagit.getTransName(), cfagit.getUserId(), cfagit.getRec(), cfagit.getPtsList());
            return ResponseSet.simpleSuccess(cfagitService.cfaMappingData(cfagit));
        } catch (Exception ex) {
            logger.error("资本项目报送异常",ex);
            throw ex;
        } finally {
            SettleContext.removeUserSession();
        }
    }

    @ApiOperation("二期-资本项目前端数据交互（试算）")
    public ResponseSet<Cfabop> calCfabopData(Cfabop<T1, T2>  cfabop) {
        try {
            cfabop.reset();
            settleContext.loadSettleSession(cfabop.getTransName(), cfabop.getUserId(), cfabop.getRec(), cfabop.getPtsList());
            cfabopService.calCfaData(cfabop);
            return ResponseSet.simpleSuccess(cfabop);
        } catch (Exception ex) {
            logger.error("资本项目报送异常",ex);
            throw ex;
        } finally {
            //SettleContext.removeUserSession();
        }
    }

}
