<%@ 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" %>
<jsp:useBean id="ResourceComInfo" class="weaver.hrm.resource.ResourceComInfo" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    String subcompanyid1 = "62";
    JSONObject jsonObject = new JSONObject();
    OptionVO optionVO = getPortalHomePlace(subcompanyid1);
    jsonObject.put("data",optionVO);

%>
<%=jsonObject.toString()  %>

<%!

    public OptionVO getPortalHomePlace(String subcompanyid1) {

        DecimalFormat df = new DecimalFormat("#.00");

        RecordSet rs = new RecordSet();
        LinkedList<SeriesParam> seriesData = new LinkedList<>();
        LinkedList<String> legendData = new LinkedList<>();
        String where  = " and (h.belongto is null or h.belongto = -1 ) and subcompanyid1 = "+subcompanyid1;

        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 "+where+" " +
                        " group by h.locationid,l.locationname");
        while (rs.next()) {
            String locationname = Util.null2String(rs.getString("locationname"));
            legendData.add(locationname);
            seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("num"))).name(locationname).build());
        }

//        List<Double>  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();

    }

%>


<%!
    /**
     * 平分legendData
     * @param nameSet
     */
    private LinkedList<String> treeSetSplitExample(LinkedList<String> nameSet) {
        int splitSize = nameSet.size() / 2;
        LinkedList<String> legendDataFirst = nameSet.stream()
                .collect(Collectors.partitioningBy(e -> nameSet.indexOf(e) < splitSize,
                        Collectors.toCollection(LinkedList::new)))
                .get(false);
        nameSet.removeAll(legendDataFirst);
        return legendDataFirst;
    }


%>



