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

import com.brilliance.isc.common.api.diary.service.DiaryApiService;
import com.brilliance.isc.common.api.diary.vo.DiaryRequestVo;
import com.brilliance.isc.common.api.diary.vo.DiaryResponseVo;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.trndia.vo.DiaVo;
import com.brilliance.isc.common.vo.BizAmdInfoVo;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.vo.ResponseSet;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AbstractDiaryController<T1 extends BizInfoVo, T2 extends BizAmdInfoVo> {

    @Autowired
    private SettleContext settleContext;

    @Autowired
    private DiaryApiService diaryApiService;

    @ApiOperation("试算费用入口")
    public ResponseSet<DiaryResponseVo> calcDiaries(DiaryRequestVo<T1, T2> diaryRequestVo) {
        try {
            settleContext.loadSettleSession(diaryRequestVo.getTransName(), diaryRequestVo.getUserId(),
                    diaryRequestVo.getRec(),
                    diaryRequestVo.getPtsList());
            DiaryResponseVo diaryResponseVo = diaryApiService.calcDiaries(diaryRequestVo);
            return ResponseSet.simpleSuccess(diaryResponseVo);
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }

    @ApiOperation("计算备忘录状态")
    public ResponseSet<String> calculateDiamodflg(DiaVo diaVo) {
        return ResponseSet.simpleSuccess(diaryApiService.calculateDiamodflg(diaVo));
    }


}
