package com.seeyon.apps.src_finereport.sso;

import cn.hutool.log.Log;
import com.seeyon.apps.common.config.ICstConfigApi;
import com.seeyon.apps.common.plugin.vo.ConfigVo;
import com.seeyon.apps.src_finereport.constans.FineReportConstants;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.controller.BaseController;
import com.seeyon.ctp.organization.manager.OrgManager;
import com.seeyon.ctp.util.annotation.Inject;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FineReportesso extends BaseController {

    private static Log log = Log.get(FineReportesso.class);

    @Inject
    private ICstConfigApi cstConfigApi;

    private OrgManager orgManager;
    public void setOrgManager(OrgManager orgManager) {this.orgManager = orgManager; }
    public OrgManager getOrgManager() {
        if (orgManager == null) {orgManager = (OrgManager) AppContext.getBean("orgManager");}return orgManager;
    }

    public ConfigVo getFineReportConfig() {
        return cstConfigApi.getConfig(getPluginId());
    }

    public String getPluginId() {
        return FineReportConstants.getPluginId();
    }

    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ConfigVo configVo = getFineReportConfig();
//        获取当前请求连接中的ticket
        String ticket = request.getParameter("ticket");
        String fineReportUrl = configVo.getParamVal(FineReportConstants.fineReportUrl.name());
        System.out.println(fineReportUrl);
        String url = configVo.getParamVal(FineReportConstants.url.name());
        System.out.println(url);
        if(fineReportUrl != null && fineReportUrl.contains("?")){
            url = url+fineReportUrl+"&ticket="+ticket;
        }else{
            url = url+fineReportUrl+"?ticket="+ticket;
        }
//        跳转前记录跳转链接到log中
        log.info(url);
        response.sendRedirect(url);
        return null;
    }


}
