%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.*" %>
<%@ page import="com.engine.matfron.entity.OptionVO" %>
<%@ page import="com.engine.matfron.entity.SeriesParam" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
JSONObject jsonObject = new JSONObject();
OptionVO OptionVO = getHomePlace();
%>
<%=jsonObject.toString() %>
<%!
public OptionVO getHomePlace() {
RecordSet rs = new RecordSet();
List colorList = Arrays.asList("#ao20f0","#8ac9e9","#697695","#83d8ae","#faf0e6","#7cfc00","#6e94f3","#9933fa","#c0ff3e","#00ced1","#ffe4c4","#cd6090");
LinkedList seriesData = new LinkedList<>();
LinkedList legendData = new LinkedList<>();
rs.executeQuery("select h.locationid,l.locationname,count(1) as num from hrmresource h\n" +
" left join hrmlocations l on h.locationid = l.id\n" +
" where h.status < 4 and h.locationid is not null group by h.locationid,l.locationname");
while (rs.next()) {
String locationname = Util.null2String(rs.getString("locationname"));
legendData.add(locationname);
Random random = new Random();
String color = colorList.get(random.nextInt(colorList.size()));
seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("num"))).name(locationname).color(color).build());
}
List values = seriesData.stream().map(SeriesParam :: getValue).collect(Collectors.toList());
double percentage = values.stream().mapToDouble(Double::doubleValue).sum();
seriesData.forEach(item -> item.setValue(Double.valueOf(df.format((item.getValue() * 100) / percentage))));
return OptionVO.builder()
.titleText("归属地分析")
.legendDataFirst(legendData)
.seriesData(seriesData)
.build();
}
%>