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

import com.brilliance.isc.common.bopset.service.JshmodService;
import com.brilliance.isc.common.util.BopUtils;
import com.brilliance.isc.common.context.BopContext;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.jshmod.vo.Jshmod;
import com.brilliance.isc.common.jshmod.vo.JshmodRequest;
import com.brilliance.isc.common.jshmod.vo.JshmodResponse;
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;
import org.springframework.stereotype.Component;

@Api("结售汇申报服务")
@Component
public class AbstractJshController<T extends BizInfoVo> {

    @Autowired
    private JshmodService jshmodService;

    /**
     * 结售汇试算
     *
     * @param jshmodRequest Jshset
     * @return ResponseSet
     */
    @ApiOperation("结售汇试算")
    public ResponseSet<JshmodResponse> calcJshmod(JshmodRequest<T> jshmodRequest) {
        ResponseSet<JshmodResponse> responseSet;
        try {
            BopUtils.loadSettleSession(jshmodRequest);
            BopContext.load(jshmodRequest);
            Jshmod jshmod = jshmodRequest.getJshmod();
            jshmodService.calcJshmod(jshmod);
            JshmodResponse rmbbopResponse = JshmodResponse.builder().jshmod(jshmod).build();
            responseSet = new ResponseSet<>(rmbbopResponse);
        } finally {
            SettleContext.removeUserSession();
            BopContext.remove();
        }
        return responseSet;
    }
}
