<%@ 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.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 = getPortalEthnic(subcompanyid1);
    jsonObject.put("data",optionVO);

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

<%!

    public OptionVO getPortalEthnic(String subcompanyid1) {

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

        String fieldid = "27";
        String fieldname = "field"+fieldid ;
        RecordSet rs = new RecordSet();
        LinkedList<SeriesParam> seriesData = new LinkedList<>();
        LinkedList<String> nameSet = new LinkedList<>();

        rs.executeQuery(" select t."+fieldname+",k.selectname as name,count(1) as sums" +
                        "   from cus_fielddata t\n" +
                        "   inner join hrmresource h on h.id = t.id\n" +
                        "   left join cus_selectitem k on k.selectvalue = t."+fieldname+"\n" +
                        "   where k.fieldid="+fieldid+" \n" +
                        "   and t."+fieldname+" is not null \n" +
                        "   and t.scope = 'HrmCustomFieldByInfoType' and t.scopeid='3' \n" +
                        "   and h.status in(0,1,2,3) and h.subcompanyid1=" + subcompanyid1+
                        "   and (h.belongto is null or h.belongto = -1 ) " +
                        "   group by t."+fieldname+",k.selectname \n" +
                        "");
        while (rs.next()) {
            String name = Util.null2String(rs.getString("name"));
            seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("sums"))).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))));


        return OptionVO.builder()
                .titleText("人员类型")
                .legendDataTwo(nameSet)
                .seriesData(seriesData)
                .build();
    }

%>




