package com.qmth.sop.business.service.impl;

import com.qmth.sop.business.entity.SysUser;
import com.qmth.sop.business.service.SsoService;
import com.qmth.sop.business.service.SysConfigService;
import com.qmth.sop.business.sync.RtzfApiUtils;
import com.qmth.sop.business.sync.been.rtzf.LoginTypeEnum;
import com.qmth.sop.common.contant.SystemConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: sso单点登录服务实现类
 * @Author: CaoZixuan
 * @Date: 2023-11-22
 */
@Service
public class SsoServiceImpl implements SsoService {
    @Resource
    private RtzfApiUtils rtzfApiUtils;
    @Resource
    private SysConfigService sysConfigService;

    @Override
    public String rtzfSsoLogin(SysUser requestUser) {
        String tenantId = "30002";
        String ssoUrl = sysConfigService.findByConfigKey(SystemConstant.RTZF_OSS_LOGIN_URL).getConfigValue();
        String token = rtzfApiUtils.getRtzfToken(requestUser, LoginTypeEnum.SSO_LOGIN);

        String eg = "https://xxx.xxx.xxx/tenant/xxxx/xxxx/login?tenantId=xxxxx&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXJyZW50VGltZU1pbGxpcyI6IjE2OTAxNjI1OTUyNzAiLCJleHAiOjE2OTAxOTg1OTUsImFjY291bnQiOiJUTUMifQ.mCnhQFUouL-LXdQg_xc279HlyeAovGotItitPf_vO3k";
        return ssoUrl +
                SystemConstant.GET_UNKNOWN +
                SystemConstant.RTZF_TENANT_ID + SystemConstant.GET_EQUAL + tenantId +
                SystemConstant.GET_SYMBOL +
                SystemConstant.TOKEN + SystemConstant.GET_EQUAL + token;
    }
}
