package com.hxhq;

import com.hxhq.common.ad.ADProperties;
import com.hxhq.common.ad.JdkADAuthUtil;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.common.security.annotation.EnableCustomConfig;
import com.hxhq.common.security.annotation.EnableRyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * 系统模块
 * 
 * @author hxhq
 */
@EnableCustomConfig
@EnableRyFeignClients
@SpringBootApplication
@ComponentScan({"com.hxhq.*"})
public class HxhqIntegrationApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(HxhqIntegrationApplication.class, args);
        System.out.println("数据对接模块启动成功");


        // 1. 配置AD基础信息（替换为你的实际配置）
        ADProperties adConfig = new ADProperties();
        adConfig.setServerHost("172.21.10.1");
        adConfig.setServerPort(389);
        adConfig.setBaseDn("DC=glpcd,DC=com");
        adConfig.setUseSsl(false);
        adConfig.setConnectTimeout(5000);
        adConfig.getReadOnly().setUsername("adcon");
        adConfig.getReadOnly().setPassword("JYL@it323");

        // 2. 初始化工具类（★核心★：传入只读账号，替换为你的实际只读账号/密码）
        JdkADAuthUtil adAuthUtil = new JdkADAuthUtil(adConfig);

        // 3. 测试账号
        String existUsername = "ELNtest01";       // 存在的账号
        String nonExistUsername = "test_not_exists"; // 不存在的账号
        String testPassword = "Abcd1234";        // 测试账号密码

        // 4. 测试接口2：验证账号是否存在（无需用户密码）
        AjaxResult exists = adAuthUtil.checkAccountExists(existUsername);
        System.out.println("===== 验证账号[" + existUsername + "]是否存在：" + (exists.isSuccess() ? "存在" : "不存在") + " =====");

        AjaxResult exists1 = adAuthUtil.checkAccountExists("ELNtest01@glpcd.com");
        System.out.println("===== 验证账号[" + existUsername + "]是否存在：" + (exists1.isSuccess()? "存在" : "不存在") + " =====");

        AjaxResult nonExists = adAuthUtil.checkAccountExists(nonExistUsername);
        System.out.println("===== 验证账号[" + nonExistUsername + "]是否存在：" + (nonExists.isSuccess() ? "存在" : "不存在") + " =====");

        // 5. 测试接口1：账号密码鉴权
        AjaxResult authSuccess = adAuthUtil.validateAccount(existUsername, testPassword);
        System.out.println("===== 账号[" + existUsername + "]鉴权结果：" + (authSuccess.isSuccess() ? "成功" : "失败") + " =====");
        AjaxResult authSuccess1 = adAuthUtil.validateAccount(existUsername+"@glpcd.com", testPassword);
        System.out.println("===== 账号[" + existUsername + "]鉴权结果：" + (authSuccess1.isSuccess() ? "成功" : "失败") + " =====");


        AjaxResult authFail = adAuthUtil.validateAccount(existUsername, "wrong_password");
        System.out.println("===== 账号[" + existUsername + "]错误密码鉴权结果：" + (authFail.isSuccess() ? "成功" : "失败") + " =====");
    }
}
