<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.*" %>
<%@ page import="com.engine.matfron.util.CommonUtils" %>
<%@ page import="com.engine.matfron.entity.OptionVO" %>
<%@ page import="java.time.YearMonth" %>
<%@ page import="com.engine.matfron.util.CommonDateUtil" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<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 = getPortalSubCompany(subcompanyid1);
    jsonObject.put("data",optionVO);
    jsonObject.put("status",true);

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

<%!

    public OptionVO getPortalSubCompany(String subcompanyid1) {
        RecordSet rs = new RecordSet();
        LinkedList<Integer> yData = new LinkedList<>();
        LinkedList<String> monthData = new LinkedList<>();
        String where  = " and (belongto is null or belongto = -1 ) and subcompanyid1 = "+subcompanyid1;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String nowMonth = sdf.format(new Date());

        List<YearMonth> yearMonths = CommonDateUtil.getYearMonths(LocalDate.now());
        yearMonths.forEach(yearMonth -> {
            String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(yearMonth));
            String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(yearMonth));

            String selectMonth = sdf.format(CommonDateUtil.toDateEndOfMonth(yearMonth));
            if(selectMonth.compareTo(nowMonth)<=0){
                rs.executeQuery("select count(1) as sum from hrmresource where status < 4  and companystartdate <= ?" + where ,endMonth);
                if (rs.next()) {
                    Integer sum = Util.getIntValue(rs.getString("sum"),0);
                    yData.add(sum);
                }
                monthData.add(selectMonth);
            }
        });

        int max = Collections.max(yData);
        int ceil =(int) Math.ceil((double) max / 5);
        ceil = CommonUtils.roundUpToNearestTen(ceil);
        int roundedMax = CommonUtils.roundedMax(ceil, 5);

        return OptionVO.builder()
                .titleText("各月份分部总人数")
                .yMin(0)
                .yMax(roundedMax)
                .yInterval(ceil)
                .yData(yData)
                .xData(monthData)
                .legendDataFirst(null)
                .legendDataTwo(null)
                .barSeriesData(null)
                .barSeriesDataTwo(null)
                .barSeriesDataThree(null)
                .seriesData(null)
                .build();
    }



%>






