EchartsTool.java
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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();
}
}