package com.hotent.uc.manager.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiV2UserCreateRequest;
import com.dingtalk.api.request.OapiV2UserGetbymobileRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiV2UserCreateResponse;
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
import com.hotent.base.cache.annotation.Cacheable;
import com.hotent.base.cache.annotation.FirstCache;
import com.hotent.base.cache.annotation.SecondaryCache;
import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import com.hotent.base.util.UniqueIdUtil;
import com.hotent.uc.dao.*;
import com.hotent.uc.manager.*;
import com.hotent.uc.model.*;
import com.hotent.uc.util.Constant;
import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 用户与外部通讯录关系表 服务实现类
 *
 * @company 广州宏天软件股份有限公司
 * @author pangquan
 * @since 2020-10-30
 */
@Service
public class DIngTokenManagerImpl extends BaseManagerImpl<DIngUserDao, OrgExternalUser> implements DingTokenManager {

    @Value("${dingSetting.appkey}")
    private String clientId;//钉钉应用key
    @Value("${dingSetting.appSecret}")
    private String appSecret;//钉钉应用密钥

    @Override
    @Cacheable(value ="dingApiToken",key = "#orgId+'_'+#agentId+'_'+#tokenType",firstCache = @FirstCache(timeUnit = TimeUnit.SECONDS,expireTime=300),
            secondaryCache = @SecondaryCache( timeUnit = TimeUnit.SECONDS,expireTime = 300))
    public String saveDingToken(String orgId, String agentId, String token,String tokenType) {

        return token;
    }

    @Override
    @Cacheable(value ="dingApiToken",key = "#orgId+'_'+#agentId+'_'+#tokenType",firstCache = @FirstCache(timeUnit = TimeUnit.SECONDS,expireTime=300),
            secondaryCache = @SecondaryCache( timeUnit = TimeUnit.SECONDS,expireTime = 300))
    public String getDingToken(String orgId, String agentId, String tokenType) {
        return null;
    }
}
