EchartsTool.java 3.49 KB
package com.lhcredit.project.business.calculateRatings;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.framework.web.domain.AjaxResult;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
@Controller
@RequestMapping("/web/echartsTool")
public class EchartsTool  {
    public static Map<Long,Object> map=new ConcurrentHashMap();
    public final static Integer timing=10;
    @RequestMapping("/ssss")
    public void ssss(){
        Object echartsRadar = getEchartsRadar(1L, 20, 30, 40, 50, 60);
        System.out.println(echartsRadar);
        remove(1L);
    }


    public void remove(Long id){
        map.remove(id);
    }

    @RequestMapping("/test")
    public ModelAndView test(ModelMap mmap){
        JSONArray jsonArray=JSONArray.parseArray("[{ \"name\": \"企业规模\", \"max\": 100 },{ \"name\": \"基本素质\", \"max\": 100 },{ \"name\": \"经营稳定性\", \"max\": 100 },{ \"name\": \"高管素质\", \"max\": 100 },{ \"name\": \"财务状况\", \"max\": 100 }]");

        mmap.put("indicator",jsonArray);
        mmap.put("dataValue", Arrays.asList(0,0,0,0,0));
        mmap.put("type", 1);
        mmap.put("cgId", 1L);;
        return  new ModelAndView("test");
    }
    @RequestMapping("updateImage")
    public AjaxResult updateImage(String  imageUrl,Long cgId){
        map.put(cgId,imageUrl);
        return AjaxResult.success(imageUrl);
    }
    /**
     * 获取雷达图
     * @return
     */
    public Object getEchartsRadar(Long cgId,double qygm,double jbsz,double jjwdx,double ggsz,double cwqk ){
        JSONObject jsonObject=new JSONObject();
        JSONArray jsonArray=JSONArray.parseArray("[{ \"name\": \"企业规模\", \"max\": 100 },{ \"name\": \"基本素质\", \"max\": 100 },{ \"name\": \"经营稳定性\", \"max\": 100 },{ \"name\": \"高管素质\", \"max\": 100 },{ \"name\": \"财务状况\", \"max\": 100 }]");
        jsonObject.put("indicator",jsonArray);
        jsonObject.put("dataValue", Arrays.asList(qygm,jbsz,jjwdx,ggsz,cwqk));
        jsonObject.put("type", 1);
        jsonObject.put("cgId", cgId);
        String post = HttpUtil.post("http://localhost:8089/web/echartsTool/test", jsonObject);
        ModelMap mmap=new ModelMap();
        mmap.put("indicator",jsonArray);
        mmap.put("dataValue", Arrays.asList(qygm,jbsz,jjwdx,ggsz,cwqk));
        mmap.put("type", 1);
        mmap.put("cgId", cgId);;
        Object image = getImage(cgId);
        return image;
    }
    public Object getImage(Long cgId){
        try {
            for (int i = 0; i < timing; i++) {
                if (map.containsKey(cgId)){
                    return  map.get(cgId);
                }
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            throw new RuntimeException("生成雷达图失败!");
        }
        return "";
    }

    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("http://localhost:8089/test.html");

        String title = driver.getTitle();
        System.out.printf(title);

        driver.close();
    }




}