package com.rj;

import com.alibaba.fastjson.JSONObject;
import dev.langchain4j.model.openai.OpenAiChatModel;

import java.util.concurrent.Semaphore;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Author: 李中华  wx: spllzh  email(qq): 28668817@qq.com
 * Date: 2025/8/4 9:55
 **/
public class AppTest {

    private static Semaphore semaphore = new Semaphore(3); // 限制并发数为3
    private static AtomicInteger completedTasks = new AtomicInteger(0);
    
    public static void main(String[] args) {
        System.out.println("==========================================");
        System.out.println("Semaphore测试程序");
        System.out.println("==========================================");
        System.out.println("请选择要运行的测试:");
        System.out.println("1. 基础并发控制测试 (threadPoolTest)");
        System.out.println("2. 资源池场景测试 (testResourcePool)");
        System.out.println("3. 公平性测试 (testSemaphoreFairness)");
        System.out.println("4. 运行所有测试");
        System.out.println("5. 其他测试 (indexof3, parseJson等)");
        System.out.println("==========================================");
        
        // 默认运行基础测试
        System.out.println("运行基础并发控制测试...\n");
        threadPoolTest111();
        
        // 可以取消注释下面的代码来运行其他测试
        // System.out.println("\n运行资源池场景测试...\n");
        // testResourcePool();
        
        // System.out.println("\n运行公平性测试...\n");
        // testSemaphoreFairness();
        
        // 其他测试
        // indexof3();
        // parseJson();
        // parseJsonForMQ();
    }

    /**
     * Semaphore测试方法 - 测试并发控制功能
     * 使用线程池模拟多个任务并发执行，通过Semaphore限制同时执行的任务数量
     */
    public static void threadPoolTest111() {
        System.out.println("==========================================");
        System.out.println("Semaphore并发控制测试开始");
        System.out.println("==========================================");
        System.out.println("Semaphore许可数: " + semaphore.availablePermits());
        System.out.println("总任务数: 10");
        System.out.println("最大并发数: 3");
        System.out.println("==========================================");
        
        // 创建线程池
        ExecutorService executor = Executors.newFixedThreadPool(10);
        long startTime = System.currentTimeMillis();
        
        // 提交10个任务
        for (int i = 1; i <= 10; i++) {
            final int taskId = i;
            executor.submit(() -> {
                try {
                    // 获取许可
                    System.out.println(String.format("[任务%d] 尝试获取许可，当前可用许可数: %d", 
                        taskId, semaphore.availablePermits()));
                    
                    semaphore.acquire(); // 获取许可

                    System.out.println(String.format("[任务%d] ✅ 成功获取许可，开始执行任务", taskId));
                    System.out.println(String.format("[任务%d] 当前可用许可数: %d", 
                        taskId, semaphore.availablePermits()));
                    
                    // 模拟任务执行（2秒）
                    Thread.sleep(8000);
                    
                    System.out.println(String.format("[任务%d] 🎯 任务执行完成", taskId));
                    
                } catch (InterruptedException e) {
                    System.out.println(String.format("[任务%d] ❌ 任务被中断: %s", taskId, e.getMessage()));
                    Thread.currentThread().interrupt();
                } finally {
                    // 释放许可
                    semaphore.release();
                    completedTasks.incrementAndGet();
                    System.out.println(String.format("[任务%d] 🔓 释放许可，当前可用许可数: %d", 
                        taskId, semaphore.availablePermits()));
                }
            });
        }
        
        // 等待所有任务完成
        executor.shutdown();
        try {
            if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
                executor.shutdownNow();
            }
        } catch (InterruptedException e) {
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        }
        
        long endTime = System.currentTimeMillis();
        
        // 输出测试结果
        System.out.println("==========================================");
        System.out.println("Semaphore测试结果统计");
        System.out.println("==========================================");
        System.out.println("总任务数: 10");
        System.out.println("完成任务数: " + completedTasks.get());
        System.out.println("总耗时: " + (endTime - startTime) + "ms");
        System.out.println("最终可用许可数: " + semaphore.availablePermits());
        System.out.println("==========================================");
        
        // 测试Semaphore的其他功能
        testSemaphoreFeatures();
    }
    
    /**
     * 测试Semaphore的其他功能
     */
    private static void testSemaphoreFeatures() {
        System.out.println("\n==========================================");
        System.out.println("Semaphore功能特性测试");
        System.out.println("==========================================");
        
        // 测试tryAcquire - 非阻塞获取许可
        System.out.println("1. 测试tryAcquire()方法:");
        boolean acquired = semaphore.tryAcquire();
        System.out.println("tryAcquire()结果: " + acquired);
        if (acquired) {
            System.out.println("成功获取许可，可用许可数: " + semaphore.availablePermits());
            semaphore.release();
            System.out.println("释放许可后，可用许可数: " + semaphore.availablePermits());
        }
        
        // 测试tryAcquire(timeout) - 带超时的获取许可
        System.out.println("\n2. 测试tryAcquire(timeout)方法:");
        try {
            boolean acquiredWithTimeout = semaphore.tryAcquire(1, TimeUnit.SECONDS);
            System.out.println("tryAcquire(1秒)结果: " + acquiredWithTimeout);
            if (acquiredWithTimeout) {
                semaphore.release();
            }
        } catch (InterruptedException e) {
            System.out.println("tryAcquire(timeout)被中断: " + e.getMessage());
        }
        
        // 测试acquire(permits) - 获取多个许可
        System.out.println("\n3. 测试acquire(permits)方法:");
        try {
            System.out.println("尝试获取2个许可...");
            semaphore.acquire(2);
            System.out.println("成功获取2个许可，可用许可数: " + semaphore.availablePermits());
            semaphore.release(2);
            System.out.println("释放2个许可后，可用许可数: " + semaphore.availablePermits());
        } catch (InterruptedException e) {
            System.out.println("acquire(permits)被中断: " + e.getMessage());
        }
        
        // 测试availablePermits() - 获取可用许可数
        System.out.println("\n4. 当前Semaphore状态:");
        System.out.println("可用许可数: " + semaphore.availablePermits());
        System.out.println("是否有等待的线程: " + semaphore.hasQueuedThreads());
        System.out.println("等待队列长度: " + semaphore.getQueueLength());
        
        System.out.println("==========================================");
        System.out.println("Semaphore功能测试完成");
        System.out.println("==========================================");
    }
    
    /**
     * 测试Semaphore在资源池场景下的应用
     * 模拟数据库连接池的使用
     */
    public static void testResourcePool() {
        System.out.println("\n==========================================");
        System.out.println("Semaphore资源池场景测试");
        System.out.println("==========================================");
        
        // 模拟数据库连接池，最多3个连接
        Semaphore connectionPool = new Semaphore(3);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        
        // 模拟5个客户端同时请求数据库连接
        for (int i = 1; i <= 5; i++) {
            final int clientId = i;
            executor.submit(() -> {
                try {
                    System.out.println(String.format("[客户端%d] 请求数据库连接...", clientId));
                    
                    // 尝试获取连接
                    if (connectionPool.tryAcquire(2, TimeUnit.SECONDS)) {
                        System.out.println(String.format("[客户端%d] ✅ 获得数据库连接，剩余连接数: %d", 
                            clientId, connectionPool.availablePermits()));
                        
                        // 模拟数据库操作
                        Thread.sleep(3000);
                        
                        System.out.println(String.format("[客户端%d] 🎯 数据库操作完成", clientId));
                        
                        // 释放连接
                        connectionPool.release();
                        System.out.println(String.format("[客户端%d] 🔓 释放数据库连接，剩余连接数: %d", 
                            clientId, connectionPool.availablePermits()));
                    } else {
                        System.out.println(String.format("[客户端%d] ❌ 获取数据库连接超时", clientId));
                    }
                } catch (InterruptedException e) {
                    System.out.println(String.format("[客户端%d] ❌ 操作被中断: %s", clientId, e.getMessage()));
                    Thread.currentThread().interrupt();
                }
            });
        }
        
        executor.shutdown();
        try {
            if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                executor.shutdownNow();
            }
        } catch (InterruptedException e) {
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        }
        
        System.out.println("==========================================");
        System.out.println("资源池场景测试完成");
        System.out.println("==========================================");
    }
    
    /**
     * 测试Semaphore的公平性
     */
    public static void testSemaphoreFairness() {
        System.out.println("\n==========================================");
        System.out.println("Semaphore公平性测试");
        System.out.println("==========================================");
        
        // 创建公平的Semaphore
        Semaphore fairSemaphore = new Semaphore(1, true); // 公平模式
        ExecutorService executor = Executors.newFixedThreadPool(3);
        
        // 创建3个线程，每个线程尝试获取许可
        for (int i = 1; i <= 3; i++) {
            final int threadId = i;
            executor.submit(() -> {
                try {
                    System.out.println(String.format("[线程%d] 尝试获取许可...", threadId));
                    fairSemaphore.acquire();
                    System.out.println(String.format("[线程%d] ✅ 获得许可", threadId));
                    
                    // 模拟工作
                    Thread.sleep(1000);
                    
                    System.out.println(String.format("[线程%d] 🎯 工作完成，释放许可", threadId));
                    fairSemaphore.release();
                } catch (InterruptedException e) {
                    System.out.println(String.format("[线程%d] ❌ 被中断: %s", threadId, e.getMessage()));
                    Thread.currentThread().interrupt();
                }
            });
        }
        
        executor.shutdown();
        try {
            if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
                executor.shutdownNow();
            }
        } catch (InterruptedException e) {
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        }
        
        System.out.println("==========================================");
        System.out.println("公平性测试完成");
        System.out.println("==========================================");
    }

    public AppTest( String testName )
    {
        System.out.println( "chatModel Hello World!" );
        // 构建chatmodel对象
        OpenAiChatModel chatModel =  OpenAiChatModel.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .modelName("qwen-plus")
                .logRequests(true) // 输出请求大模型的日志
                .logResponses(true)
                .build();
        String chat = chatModel.chat("2008年奥运会，哪个国际金牌最多？");
        System.out.println(chat);

    }

    public static void indexof3(  )
    {
        System.out.println( "Hello World!" );
        String  ss = "SMART_ASSISTANT_NAMEPLATE-1967863854687916032";
         if (ss.indexOf("SMART_ASSISTANT_NAMEPLATE")>=0){
             System.out.println("ddd:   ");
         }
        System.out.println("ttt:   "+ss.indexOf("SMART_ASSISTANT_NAMEPLATE1"));
    }


    public static void parseJsonForMQ(){

        String jsonNamplate="{\"outputs\":{\"customerFlowId\":\"1919618280323473410\",\"data\":{\"analysisDetail\":{\"purchaseIntention\":{\"familyIncomeLevel\":\"未提及\",\"targetModel\":\"XC90（7座）\",\"carBudget\":\"全款落地价44-47万\",\"financialInstallment\":\"未提及\",\"purchaseCycle\":\"5月前完成购车\",\"preferredConfiguration\":\"B5或B6智逸配置\",\"preferredPowerType\":\"未提及\",\"preferredColor\":\"未提及\",\"purchaseType\":\"未提及\"},\"purchaseConsideration\":{\"comparedVehicles\":\"未提及\",\"concerns\":\"报价与心理预期不符\",\"focusPoints\":\"价格、配置、优惠政策\"},\"consultantProposal\":{\"financialPlan\":\"未提及\",\"consultantQuote\":\"B5车型全款落地近50万，B6暂无车\",\"preferentialPolicies\":\"可申请优惠至47万\"},\"followUpSuggestions\":\"明确客户心理预算，提供详细报价和优惠政策，邀约到店体验试驾以促成成交。\",\"testDriveExperience\":\"未提及\",\"existingVehicle\":{\"licensePlateStatus\":\"未提及\",\"existingCarBrand\":\"未提及\",\"existingCarUsageYears\":\"未提及\"},\"basicInfo\":{\"carUser\":\"未提及\",\"occupation\":\"未提及\",\"educationLevel\":\"未提及\",\"hobbies\":\"未提及\",\"carPurchasePurpose\":\"未提及\",\"familyDailyTravelNumber\":\"未提及\",\"buyerType\":\"个人\",\"customerSource\":\"未提及\",\"purchaseQualification\":\"未提及\",\"homeAddress\":\"瑞丽\"}},\"analysisResult\":\"客户对XC90车型感兴趣，预算全款44-47万左右，希望了解具体报价并对比其他店价格。顾问建议客户到店详谈优惠政策和配置细节。\"},\"analysisScene\":\"3\",\"analysisRecordId\":\"SMART_ASSISTANT_NAMEPLATE-1968176478541664256\",\"version\":2},\"workflow_id\":\"745dc920-8ba0-4e95-8efb-1c8b68f21344\",\"id\":\"d08b3fc9-4986-477d-91d7-b43468ac757a\",\"status\":\"succeeded\"}";
       String jsonstr ="{\"outputs\":{\"customerFlowId\":\"1919618280323473410\",\"data\":{\"analysisDetail\":{\"purchaseIntention\":{\"familyIncomeLevel\":\"未提及\",\"targetModel\":\"XC90（7座）\",\"carBudget\":\"全款落地价44-47万\",\"financialInstallment\":\"未提及\",\"purchaseCycle\":\"5月前完成购车\",\"preferredConfiguration\":\"B5或B6智逸配置\",\"preferredPowerType\":\"未提及\",\"preferredColor\":\"未提及\",\"purchaseType\":\"未提及\"},\"purchaseConsideration\":{\"comparedVehicles\":\"未提及\",\"concerns\":\"报价与心理预期不符\",\"focusPoints\":\"价格、配置、优惠政策\"},\"consultantProposal\":{\"financialPlan\":\"未提及\",\"consultantQuote\":\"B5车型全款落地近50万，B6暂无车\",\"preferentialPolicies\":\"可申请优惠至47万\"},\"followUpSuggestions\":\"明确客户心理预算，提供详细报价和优惠政策，邀约到店体验试驾以促成成交。\",\"testDriveExperience\":\"未提及\",\"existingVehicle\":{\"licensePlateStatus\":\"未提及\",\"existingCarBrand\":\"未提及\",\"existingCarUsageYears\":\"未提及\"},\"basicInfo\":{\"carUser\":\"未提及\",\"occupation\":\"未提及\",\"educationLevel\":\"未提及\",\"hobbies\":\"未提及\",\"carPurchasePurpose\":\"未提及\",\"familyDailyTravelNumber\":\"未提及\",\"buyerType\":\"个人\",\"customerSource\":\"未提及\",\"purchaseQualification\":\"未提及\",\"homeAddress\":\"瑞丽\"}},\"analysisResult\":\"客户对XC90车型感兴趣，预算全款44-47万左右，希望了解具体报价并对比其他店价格。顾问建议客户到店详谈优惠政策和配置细节。\"},\"analysisScene\":\"3\",\"analysisRecordId\":\"SMART_ASSISTANT_NAMEPLATE-1968176478541664256\",\"version\":2},\"workflow_id\":\"745dc920-8ba0-4e95-8efb-1c8b68f21344\",\"id\":\"d08b3fc9-4986-477d-91d7-b43468ac757a\",\"status\":\"succeeded\"}";
         JSONObject analysisResp = JSONObject.parseObject(jsonstr);

        String text = analysisResp.getString("outputs");
        JSONObject outputss = JSONObject.parseObject(text);
        String businessType = outputss.getString("businessType");
        System.out.println("businessType is  : "+businessType);

        String businessId = outputss.getString("businessId");
        System.out.println("businessId is  : "+businessId);


        String aiAnalysisRequestId = outputss.getString("aiAnalysisRequestid") ;
        System.out.println("aiAnalysisRequestId is  : "+aiAnalysisRequestId);

        if (aiAnalysisRequestId.indexOf("CORPUS_PORTRAIT_NAMEPLATE")>=0){
            businessType="CORPUS_PORTRAIT_NAMEPLATE";
        }
        System.out.println("businessType is  : "+businessType);
    }



    public static void parseJson(){
        String jsonPortraint1 = "{\"id\":\"fc32c67a-920f-43e0-9ec8-1c26b31785ee\",\"workflow_id\":\"e0ea47de-9861-45a8-adc6-f46655587419\",\"status\":\"succeeded\",\"outputs\":{\"result\":{\"info\":\"{\\n  \\\"address\\\": \\\"未提及\\\",\\n  \\\"buyCarUse\\\": \\\"未提及\\\",\\n  \\\"actualDriver\\\": \\\"未提及\\\",\\n  \\\"familyStructure\\\": \\\"未提及\\\",\\n  \\\"familyNum\\\": 0,\\n  \\\"familyIncomeMonth\\\": \\\"未提及\\\",\\n  \\\"industry\\\": \\\"未提及\\\",\\n  \\\"occupation\\\": \\\"未提及\\\",\\n  \\\"enterpriseType\\\": \\\"未提及\\\",\\n  \\\"avocation\\\": \\\"未提及\\\",\\n  \\\"educationalLevel\\\": \\\"未提及\\\",\\n  \\\"bookCarDate\\\": \\\"未提及\\\",\\n  \\\"buyType\\\": \\\"首购\\\",\\n  \\\"carBudget\\\": \\\"未提及\\\",\\n  \\\"paymentMethod\\\": \\\"未提及\\\",\\n  \\\"keepVehicleBrand\\\": [\\\"未提及\\\"],\\n  \\\"failBrand\\\": [\\\"未提及\\\"],\\n  \\\"carQuality\\\": \\\"未提及\\\",\\n  \\\"remark\\\": \\\"对话中未提及任何有效信息，无法得出相关结论。\\\"\\n}\",\"entities\":\"{\\n  \\\"brand\\\": \\\"中性\\\",\\n  \\\"design\\\": \\\"中性\\\",\\n  \\\"color\\\": \\\"中性\\\",\\n  \\\"size\\\": \\\"中性\\\",\\n  \\\"space\\\": \\\"中性\\\",\\n  \\\"interior\\\": \\\"中性\\\",\\n  \\\"audio\\\": \\\"中性\\\",\\n  \\\"ivinfo\\\": \\\"中性\\\",\\n  \\\"fsd\\\": \\\"中性\\\",\\n  \\\"mileage\\\": \\\"中性\\\",\\n  \\\"safety\\\": \\\"中性\\\",\\n  \\\"eco\\\": \\\"中性\\\",\\n  \\\"liscense\\\": \\\"中性\\\",\\n  \\\"price\\\": \\\"中性\\\",\\n  \\\"benefit\\\": \\\"中性\\\",\\n  \\\"cost\\\": \\\"中性\\\",\\n  \\\"value\\\": \\\"中性\\\",\\n  \\\"power\\\": \\\"中性\\\",\\n  \\\"control\\\": \\\"中性\\\",\\n  \\\"tradein\\\": \\\"中性\\\",\\n  \\\"finance\\\": \\\"中性\\\",\\n  \\\"warranty\\\": \\\"中性\\\",\\n  \\\"delivery\\\": \\\"中性\\\"\\n}\"},\"communicateDate\":\"Tue May 06 12:55:00 CST 2025\",\"analysisScene\":\"3\",\"analysisRecordId\":\"CORPUS_PORTRAIT_NAMEPLATE-1967954224931184640\",\"businessId\":\"1919618280323473410\",\"businessType\":\"CORPUS_PORTRAIT_NAMEPLATE\"},\"elapsed_time\":9.988657537847757,\"total_tokens\":4720,\"total_steps\":6,\"created_at\":1758031825,\"finished_at\":1758031835,\"aiAnalysisRequestId\":\"CORPUS_PORTRAIT_NAMEPLATE-1967954224931184640\"}" ;
        String jsonNameplate1 ="{\"difyResponse\": {\"status\": \"succeeded\", \"id\": \"cb8de7e4-b96b-4588-bc6a-b9d3f296a814\", \"workflow_id\": \"745dc920-8ba0-4e95-8efb-1c8b68f21344\", \"outputs\": {\"analysisScene\": \"3\", \"customerFlowId\": \"1919618280323473410\", \"analysisRecordId\": \"SMART_ASSISTANT_NAMEPLATE-1967944330802950144\", \"version\": 2, \"data\": {\"analysisResult\": \"\\u5ba2\\u6237\\u5728\\u745e\\u4e3d\\uff0c\\u5bf9XC90 B6\\u667a\\u90387\\u5ea7\\u611f\\u5174\\u8da3\\uff0c\\u9884\\u7b9744\\u4e07\\u5de6\\u53f3\\u5168\\u6b3e\\u843d\\u5730\\uff0c\\u987e\\u95ee\\u62a5\\u4ef747\\u4e07\\uff0c\\u5ba2\\u6237\\u6682\\u672a\\u63a5\\u53d7\\u5e76\\u8ba1\\u5212\\u5bf9\\u6bd4\\u5176\\u4ed6\\u5e97\\u4ef7\\u683c\\u3002\", \"analysisDetail\": {\"basicInfo\": {\"customerSource\": \"\\u672a\\u63d0\\u53ca\", \"occupation\": \"\\u672a\\u63d0\\u53ca\", \"educationLevel\": \"\\u672a\\u63d0\\u53ca\", \"hobbies\": \"\\u672a\\u63d0\\u53ca\", \"homeAddress\": \"\\u5ba2\\u6237\\u5728\\u745e\\u4e3d\", \"carPurchasePurpose\": \"\\u672a\\u63d0\\u53ca\", \"buyerType\": \"\\u4e2a\\u4eba\", \"carUser\": \"\\u672a\\u63d0\\u53ca\", \"purchaseQualification\": \"\\u672a\\u63d0\\u53ca\", \"familyDailyTravelNumber\": \"\\u672a\\u63d0\\u53ca\"}, \"purchaseIntention\": {\"targetModel\": \"XC90 B6\\u667a\\u90387\\u5ea7\", \"preferredColor\": \"\\u672a\\u63d0\\u53ca\", \"preferredConfiguration\": \"\\u672a\\u63d0\\u53ca\", \"preferredPowerType\": \"\\u672a\\u63d0\\u53ca\", \"carBudget\": \"\\u5ba2\\u6237\\u9884\\u7b97\\u5168\\u6b3e\\u843d\\u5730\\u4ef744\\u4e07\\u5de6\\u53f3\", \"financialInstallment\": \"\\u5168\\u6b3e\\u8d2d\\u8f66\", \"familyIncomeLevel\": \"\\u672a\\u63d0\\u53ca\", \"purchaseType\": \"\\u672a\\u63d0\\u53ca\", \"purchaseCycle\": \"5\\u6708\\u524d\\u8d2d\\u8f66\"}, \"purchaseConsideration\": {\"focusPoints\": \"\\u4ef7\\u683c\\u3001\\u8f66\\u578b\\u914d\\u7f6e\", \"concerns\": \"\\u672a\\u63d0\\u53ca\", \"comparedVehicles\": \"\\u672a\\u63d0\\u53ca\"}, \"existingVehicle\": {\"existingCarBrand\": \"\\u672a\\u63d0\\u53ca\", \"existingCarUsageYears\": \"\\u672a\\u63d0\\u53ca\", \"licensePlateStatus\": \"\\u672a\\u63d0\\u53ca\"}, \"consultantProposal\": {\"consultantQuote\": \"\\u987e\\u95ee\\u62a5\\u4ef7\\u5168\\u6b3e\\u843d\\u5730\\u4ef747\\u4e07\\u5de6\\u53f3\", \"financialPlan\": \"\\u672a\\u63d0\\u53ca\", \"preferentialPolicies\": \"\\u672a\\u63d0\\u53ca\"}, \"testDriveExperience\": \"\\u672a\\u63d0\\u53ca\", \"followUpSuggestions\": \"\\u5efa\\u8bae\\u660e\\u786e\\u5ba2\\u6237\\u5173\\u6ce8\\u70b9\\uff0c\\u63d0\\u4f9b\\u66f4\\u8be6\\u7ec6\\u4f18\\u60e0\\u653f\\u7b56\\u53ca\\u5bf9\\u6bd4\\u4fe1\\u606f\\uff0c\\u4ee5\\u4e89\\u53d6\\u5ba2\\u6237\\u8fdb\\u5e97\\u6d3d\\u8c08\\u3002\"}}}}, \"customerFlowId\": \"1919618280323473410\", \"aiAnalysisRequestId\": \"SMART_ASSISTANT_NAMEPLATE-1967944330802950144\"}";

        String jsonStr="{\"outputs\":{\"customerFlowId\":\"1919618280323473410\",\"data\":{\"analysisDetail\":{\"purchaseIntention\":{\"familyIncomeLevel\":\"未提及\",\"targetModel\":\"XC90（7座）\",\"carBudget\":\"全款落地价44-47万\",\"financialInstallment\":\"未提及\",\"purchaseCycle\":\"5月前完成购车\",\"preferredConfiguration\":\"B5或B6智逸配置\",\"preferredPowerType\":\"未提及\",\"preferredColor\":\"未提及\",\"purchaseType\":\"未提及\"},\"purchaseConsideration\":{\"comparedVehicles\":\"未提及\",\"concerns\":\"报价与心理预期不符\",\"focusPoints\":\"价格、配置、优惠政策\"},\"consultantProposal\":{\"financialPlan\":\"未提及\",\"consultantQuote\":\"B5车型全款落地近50万，B6暂无车\",\"preferentialPolicies\":\"可申请优惠至47万\"},\"followUpSuggestions\":\"明确客户心理预算，提供详细报价和优惠政策，邀约到店体验试驾以促成成交。\",\"testDriveExperience\":\"未提及\",\"existingVehicle\":{\"licensePlateStatus\":\"未提及\",\"existingCarBrand\":\"未提及\",\"existingCarUsageYears\":\"未提及\"},\"basicInfo\":{\"carUser\":\"未提及\",\"occupation\":\"未提及\",\"educationLevel\":\"未提及\",\"hobbies\":\"未提及\",\"carPurchasePurpose\":\"未提及\",\"familyDailyTravelNumber\":\"未提及\",\"buyerType\":\"个人\",\"customerSource\":\"未提及\",\"purchaseQualification\":\"未提及\",\"homeAddress\":\"瑞丽\"}},\"analysisResult\":\"客户对XC90车型感兴趣，预算全款44-47万左右，希望了解具体报价并对比其他店价格。顾问建议客户到店详谈优惠政策和配置细节。\"},\"analysisScene\":\"3\",\"analysisRecordId\":\"SMART_ASSISTANT_NAMEPLATE-1968176478541664256\",\"version\":2},\"workflow_id\":\"745dc920-8ba0-4e95-8efb-1c8b68f21344\",\"id\":\"d08b3fc9-4986-477d-91d7-b43468ac757a\",\"status\":\"succeeded\"}";


        JSONObject analysisResp = JSONObject.parseObject(jsonStr);

        String text = analysisResp.getString("outputs");
        JSONObject outputss = JSONObject.parseObject(text);
        String businessType = outputss.getString("businessType");
        System.out.println("businessType is  : "+businessType);

        String businessId = outputss.getString("businessId");
        System.out.println("businessId is  : "+businessId);


        String aiAnalysisRequestId = outputss.getString("aiAnalysisRequestid") ;
        System.out.println("aiAnalysisRequestId is  : "+aiAnalysisRequestId);

        if (aiAnalysisRequestId.indexOf("CORPUS_PORTRAIT_NAMEPLATE")>=0){
            businessType="CORPUS_PORTRAIT_NAMEPLATE";
        }
        System.out.println("businessType is  : "+businessType);
    }
}
