MerchantAnalysisService.java 11.5 KB
package com.glsk.service;


import com.glsk.component.HttpUtil;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 门店分析
 */
@Service
@Slf4j
public class MerchantAnalysisService {
    final String HOST_URL = "https://glsx-bi-report.glsx.com.cn/merchant/";

    // 字段描述
    final String BUSINESS_TYPE_DESC = "业务场景:quanyi/yanbao/qinggai其中一个,权益-quanyi 延保-yanbao 轻该-qinggai";
    final String QUERY_TYPE_DESC = "查询维度:day/week/month/self其中之一,日-day、周-week、月-month,自定义-self";
    final String RANK_FIELD_DESC = "排序字段:output/atv/yinliulv/zhuanhualv/shentoulv其中之一,产值-output、客单价-atv、引流率-yinliulv、转化率-zhuanhualv、渗透率-shentoulv";
    final String RANK_FIELD_TYPE_DESC = "升降序:asc/desc其中之一,升序-asc,desc-降序";

    @Autowired
    private HttpUtil httpUtil;


    @Tool(description = "获取门店列表")
    public String getMerchantList(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                   @ToolParam(description = "门店名称模糊匹配") String merchantname,
                                   @ToolParam(description = "门店id列表,逗号分隔") String ids

    ) {
        String method = "getMerchantList";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("merchantname", merchantname);
        params.put("ids", ids);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }



    @Tool(description = "查询门店总产值和客单价")
    public String queryMerchantOutputAndAtv(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                   @ToolParam(description = QUERY_TYPE_DESC) String queryType,
                                   @ToolParam(description = "开始时间") String startDay,
                                   @ToolParam(description = "结束时间") String endDay,
                                   @ToolParam(description = "门店Id") String merchantid
                                   ) {
        String method = "queryMerchantOutputAndAtv";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("queryType", queryType);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    @Tool(description = "查询门店产值趋势")
    public String queryMerchantOutputTrend(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                            @ToolParam(description = QUERY_TYPE_DESC) String queryType,
                                            @ToolParam(description = "开始时间") String startDay,
                                            @ToolParam(description = "结束时间") String endDay,
                                            @ToolParam(description = "门店Id") String merchantid
    ) {
        String method = "queryMerchantOutputTrend";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("queryType", queryType);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    @Tool(description = "查询门店新车交付数、新车到店流量、售后到店流量、成交量")
    public String queryMerchantBuyAndTostore(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                           @ToolParam(description = QUERY_TYPE_DESC) String queryType,
                                           @ToolParam(description = "开始时间") String startDay,
                                           @ToolParam(description = "结束时间") String endDay,
                                           @ToolParam(description = "门店Id") String merchantid
    ) {
        String method = "queryMerchantBuyAndTostore";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("queryType", queryType);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    @Tool(description = "查询门店内部员工排名")
    public String queryStaffRanking(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                    @ToolParam(description = QUERY_TYPE_DESC) String queryType,
                                    @ToolParam(description = "开始时间") String startDay,
                                    @ToolParam(description = "结束时间") String endDay,
                                    @ToolParam(description = "门店Id") String merchantid,
                                    @ToolParam(description = RANK_FIELD_DESC) String rankfield,
                                    @ToolParam(description = RANK_FIELD_TYPE_DESC) String rankType
    ) {
        String method = "queryStaffRanking";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("queryType", queryType);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);
        params.put("rankfield", rankfield);
        params.put("rankType", rankType);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    @Tool(description = "查询门店内部流量贡献排行")
    public String queryFlowContributeRanking(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                    @ToolParam(description = QUERY_TYPE_DESC) String queryType,
                                    @ToolParam(description = "开始时间") String startDay,
                                    @ToolParam(description = "结束时间") String endDay,
                                    @ToolParam(description = "门店Id") String merchantid,
                                    @ToolParam(description = RANK_FIELD_TYPE_DESC) String rankType
    ) {
        String method = "queryFlowContributeRanking";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("queryType", queryType);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);
        params.put("rankType", rankType);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    @Tool(description = "通过门店与业务场景,查询所属服务商老板、区域督导、销售名称")
    public String queryServiceSupervisionSale(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                             @ToolParam(description = "开始时间") String startDay,
                                             @ToolParam(description = "结束时间") String endDay,
                                             @ToolParam(description = "门店Id") String merchantid
    ) {
        String method = "queryServiceSupervisionSale";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    @Tool(description = "门店内部品类分析")
    public String queryProductOutput(@ToolParam(description = BUSINESS_TYPE_DESC) String business_type,
                                              @ToolParam(description = "开始时间") String startDay,
                                              @ToolParam(description = "结束时间") String endDay,
                                              @ToolParam(description = "门店Id") String merchantid
    ) {
        String method = "queryProductOutput";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type", business_type);
        params.put("startDay", startDay);
        params.put("endDay", endDay);
        params.put("merchantid", merchantid);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
            return response;
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }

    public static void main(String[] args) {
        final String HOST_URL = "https://glsx-bi-report.glsx.com.cn/merchant/";


        HttpUtil httpUtil = new HttpUtil();

        String method = "getMerchantList";
        String url = HOST_URL + method;

        Map<String, Object> params = new HashMap<>();
        params.put("business_type",  "yanbao");
//        params.put("merchantname", null);
//        params.put("ids", null);

        try {
            String response = httpUtil.doGet(url, params);
            log.info("返回成功: {}", response);
        } catch (Exception e) {
            log.error("返回失败", e);
            throw new RuntimeException("返回失败", e);
        }
    }
}