<%@ 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 import="java.text.DecimalFormat" %> <%@ page language="java" contentType="text/html; charset=UTF-8" %> <% String subcompanyid1 = "62"; JSONObject jsonObject = new JSONObject(); OptionVO optionVO = getPortalEducational(subcompanyid1); jsonObject.put("data",optionVO); %> <%=jsonObject.toString() %> <%! public OptionVO getPortalEducational(String subcompanyid1) { DecimalFormat df = new DecimalFormat("#.0"); RecordSet rs = new RecordSet(); LinkedList seriesData = new LinkedList<>(); LinkedList nameSet = new LinkedList<>(); String sql =" select t.xl,d.name,count(1) as sum " + " from uf_jypxjl t\n" + " inner join hrmresource h on h.workcode = t.ygbh\n" + " left join hrmeducationlevel d on t.xl = d.id \n" + " where t.xl is not null \n" + " and h.status in(0,1,2,3)\n" + " and (h.belongto is null or h.belongto = -1 )\n" + " and h.subcompanyid1 = " + subcompanyid1 + " group by t.xl,d.name " + " order by t.xl desc " ; rs.executeQuery(sql); while (rs.next()) { String name = Util.formatMultiLang (Util.null2String(rs.getString("name"))); seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("sum"))).name(name).build()); nameSet.add(name); } // double percentage = seriesData.stream().mapToDouble(SeriesParam::getValue).sum(); // seriesData.forEach(item -> item.setValue(Double.valueOf(df.format((item.getValue() * 100) / percentage)))); // LinkedList legendDataFirst = new LinkedList<>(); // if (nameSet.size() > 2) { // legendDataFirst = treeSetSplitExample(nameSet); // } return OptionVO.builder() .titleText("学历分析") .legendDataFirst(nameSet) // .legendDataTwo(nameSet) .seriesData(seriesData) .build(); } %> <%! /** * 平分legendData * @param nameSet */ private LinkedList treeSetSplitExample(LinkedList nameSet) { int splitSize = nameSet.size() / 2; LinkedList legendDataFirst = nameSet.stream() .collect(Collectors.partitioningBy(e -> nameSet.indexOf(e) < splitSize, Collectors.toCollection(LinkedList::new))) .get(false); nameSet.removeAll(legendDataFirst); return legendDataFirst; } %>