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

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

<%!

    public OptionVO getJobType(String subcompanyid1) {
        String where  = " and 1=1";
        RecordSet rs = new RecordSet();
        LinkedList<Integer> yData1 = new LinkedList<>();
        LinkedList<Integer> yData2 = new LinkedList<>();
        LinkedList<String> xData = new LinkedList<>();

        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(f.id) as cnt from formtable_main_614 f,workflow_requestbase r where f.requestid= r.requestid and r.currentnodetype=3 " +
                        "  and  zgrq  >=? and zgrq<=? and bdyy='0'" ,selectMonth+"-01",selectMonth+"-31");
                if (rs.next()) {
                    Integer sum = Util.getIntValue(rs.getString("cnt"),0);
                    yData1.add(sum);
                }
                rs.executeQuery("select count(f.id) as cnt from formtable_main_614 f,workflow_requestbase r where f.requestid= r.requestid and r.currentnodetype=3 " +
                        "  and  zgrq  >=? and zgrq<=? and bdyy!='0'" ,selectMonth+"-01",selectMonth+"-31");
                if (rs.next()) {
                    Integer sum = Util.getIntValue(rs.getString("cnt"),0);
                    yData2.add(-sum);
                }
                xData.add(selectMonth);
          //  }
        });


        int max = Collections.max(yData2);
//        int max = 4;
        int ceil =(int) Math.ceil((double) max / 4);
//        ceil = CommonUtils.roundUpToNearestTen(ceil);
        ceil = 5;
        int roundedMax = CommonUtils.roundedMax(ceil, 1);
        int roundedMax2 = CommonUtils.roundedMax(ceil, 3);

        return OptionVO.builder()
                .titleText("年度转岗和晋升统计")
                .xData(xData)
                .yMin(-roundedMax)
                .yMax(roundedMax2)
                .yInterval(ceil)
                .barSeriesData(yData1)
                .barSeriesDataTwo(yData2)
                .build();
    }

%>



