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

import com.brilliance.isc.common.api.gle.service.GlentryApiService;
import com.brilliance.isc.common.api.gle.vo.GlentryRequest;
import com.brilliance.isc.common.api.gle.vo.GlentryResponse;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.vo.ResponseSet;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 会计结算分录服务
 * @restApi
 * @param <T>
 */
@Api("会计结算分录服务")
public abstract class AbstractGleController<T extends BizInfoVo> {

    @Autowired
    private SettleContext settleContext;

    @Autowired
    private GlentryApiService glentryApiService;

    /**
     * 会计分录试算入口
     * @param glentryRequest
     * @return
     */
    public ResponseSet<GlentryResponse> generateGlentry(GlentryRequest<T> glentryRequest) {
        try {
            settleContext.loadSettleSession(glentryRequest.getTransName(), glentryRequest.getUserId(), glentryRequest.getRec(), glentryRequest.getPtsList());
            return ResponseSet.simpleSuccess(glentryApiService.generateGlentry(glentryRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }
}
