<%@ page import="com.engine.custom.sl.entity.EsbRequestHeader" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="com.engine.custom.sl.entity.TravelToEsbBean" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="com.engine.util.SocketClientUtil" %>
<%@ page import="com.engine.util.XMLUtils" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.engine.common.util.ParamUtil" %>
<%@ page import="java.net.Socket" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.StringUtil" %>
<%@ page import="java.io.*" %>
<%@ page import="weaver.conn.RecordSetDataSource" %>
<%@ page import="java.time.LocalDateTime" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="com.engine.custom.corn.util.ReportUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>


<%

    out.print(getMeetCountByUserid(new RecordSet(),"758"));

%>
<%!
    /**
     * 获取今年发送的消息总数
     * @return
     */
    public static int getMsgCount(){
        String dateFormat = "yyyy-MM-dd HH:mm:ss.SSS";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        RecordSetDataSource rs = new RecordSetDataSource("emp_msg");
        String getMsgCountSql = "select count(1) cnt from HISTORYMSG where DATETIME >= '"+ startEndOfYear[0] +"' and DATETIME <= '"+ startEndOfYear[1]+"'";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }

    /**
     * 根据传入的格式化字符串获取当前年份的开始时间和结束时间
     * @param dateFormat
     * @return
     */
    public static String[] getStartEndOfYear(String dateFormat) {
        LocalDateTime startOfYear = LocalDateTime.of(LocalDateTime.now().getYear(), 1, 1, 0, 0, 0, 0);
        LocalDateTime endOfYear = LocalDateTime.of(LocalDateTime.now().getYear(), 12, 31, 23, 59, 59, 999000000);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
        String start = startOfYear.format(formatter);
        String end = endOfYear.format(formatter);

        return new String[] {start, end};
    }



    /**
     * 获取今年共享文档数量
     * @return
     */
    public static int getShareDOCCount(){
        String dateFormat = "yyyy-MM-dd";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        RecordSet rs = new RecordSet();
        String getMsgCountSql = "select count(1) cnt from DOCDETAIL where seccategory = 98 and doccreatedate >= '"+startEndOfYear[0]+"' and doccreatedate <= '"+startEndOfYear[1]+"'";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }


    /**
     * 获取今年指定用户的共享文档数量
     * @return
     */
    public static int getShareDOCCountbyUserid(RecordSet rs , String userid){
        String dateFormat = "yyyy-MM-dd";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        String getMsgCountSql = "select count(1) cnt from DOCDETAIL where seccategory = 98 and doccreatedate >= '"+startEndOfYear[0]+"' and doccreatedate <= '"+startEndOfYear[1]+"' and doccreaterid = "+userid ;
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }


    /**
     * 获取今年会议数量
     * @return
     */
    public static int getMeetCount(){
        String dateFormat = "yyyy-MM-dd HH:mm";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        RecordSet rs = new RecordSet();
        String getMsgCountSql = "select count(1) cnt from meeting_videolist where  VIDEOMTBEGINDATE >= '"+startEndOfYear[0]+"' and VIDEOMTBEGINDATE <= '"+startEndOfYear[1]+"'";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }


    /**
     * 获取今年会议数量
     * @return
     */
    public static int getMeetCountByUserid(RecordSet rs , String userid){
        String dateFormat = "yyyy-MM-dd HH:mm";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        String getMsgCountSql = "select count(1) cnt from meeting_videolist where  VIDEOMTBEGINDATE >= '"+startEndOfYear[0]+"' and VIDEOMTBEGINDATE <= '"+startEndOfYear[1]+"' and VIDEOMTCREATER = "+userid;
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }

    /**
     * 获取最早办理公文日期
     * @param rs
     * @param userid
     * @return
     */
    public static int getLastOfficialWfDate(RecordSet rs , String userid ,String OfficialWfid){
        String getMsgCountSql = "select min(OPERATEDATE) from WORKFLOW_REQUESTLOG where OPERATOR = "+userid+" and  workflowid in ( "+OfficialWfid+" )";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }


    /**
     * 获取今年办理公文数
     * @param rs
     * @param userid
     * @return
     */
    public static int getYearOfficialWfCount(RecordSet rs , String userid ,String OfficialWfid ,String holidayStr){
        String dateFormat = "yyyy-MM-dd";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        String getMsgCountSql = "select count(1) cnt from WORKFLOW_REQUESTLOG where OPERATOR = "+userid+" and  workflowid in ( "+OfficialWfid+" ) " +
                " and OPERATEDATE >= '"+startEndOfYear[0]+"' and OPERATEDATE <= '"+startEndOfYear[1]+"'";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }


    /**
     * 获取节假日办理公文数
     * @param rs
     * @param userid
     * @return
     */
    public static int getHolidayOfficialWfCount(RecordSet rs , String userid ,String OfficialWfid ,String holidayStr){
        String getMsgCountSql = "select count(1) cnt from WORKFLOW_REQUESTLOG where OPERATOR = "+userid+" and  workflowid in ( "+OfficialWfid+" ) and OPERATEDATE in ( "+holidayStr+" )";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }

    /**
     * 获取公文办理超越数
     * @param rs
     * @param userid
     * @return
     */
    public static int getOfficialWfCountPercentage(RecordSet rs , String userid ,String OfficialWfid ,String holidayStr,int total){
        String dateFormat = "yyyy-MM-dd";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        String getMsgCountSql = "select rank from  (select * ,  RANK() OVER (ORDER BY cnt DESC) AS rank from" +
                " (select OPERATOR, count(1) cnt from  WORKFLOW_REQUESTLOG" +
                " where WORKFLOWID in ("+ OfficialWfid +") and OPERATEDATE >= '"+startEndOfYear[0]+"' and OPERATEDATE <= '"+startEndOfYear[1]+"'  group by OPERATOR)) a  where a.OPERATOR = "+ userid;
        rs.execute(getMsgCountSql);
        rs.next();
        int rank = rs.getInt("rank");
        return (int)(100.0 * (total - rank) / (total - 1));
    }


    /**
     * 获取最晚公文办理时间的日期
     * @param rs
     * @param userid
     * @return
     */
    public static String getOfficialWflastTimeDate(RecordSet rs , String userid , String OfficialWfid ){
        String dateFormat = "yyyy-MM-dd";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        String getMsgCountSql = "SELECT * FROM ( " +
                "         SELECT * FROM WORKFLOW_REQUESTLOG where OPERATETIME <= '05:00:00' and WORKFLOWID in ("+ OfficialWfid +") " +
                "  and OPERATEDATE >= '"+startEndOfYear[0]+"' and OPERATEDATE <= '"+startEndOfYear[1]+"'"+
                "  and OPERATOR = "+ userid +
                "         ORDER BY OPERATETIME DESC" +
                "     )WHERE ROWNUM = 1";
        rs.execute(getMsgCountSql);
        rs.next();
        int counts = rs.getCounts();
        if (counts != 0){
            return rs.getString("OPERATEDATE")+" "+rs.getString("OPERATETIME");
        }else {
            getMsgCountSql = "SELECT * FROM ( " +
                    "         SELECT * FROM WORKFLOW_REQUESTLOG where  WORKFLOWID in ("+ OfficialWfid +") " +
                    "  and OPERATEDATE >= '"+startEndOfYear[0]+"' and OPERATEDATE <= '"+startEndOfYear[1]+"'"+
                    "  and OPERATOR = "+ userid +
                    "         ORDER BY OPERATETIME DESC" +
                    "     )WHERE ROWNUM = 1";
            rs.execute(getMsgCountSql);
            rs.next();
            return rs.getString("OPERATEDATE")+" "+rs.getString("OPERATETIME");
        }
    }

    //获取登录天数
    public static int getLoginDayCount(RecordSet rs , String userid  ){
        String dateFormat = "yyyy-MM-dd";
        String[] startEndOfYear = getStartEndOfYear(dateFormat);
        System.out.println("Start of Year: " + startEndOfYear[0]);
        System.out.println("End of Year: " + startEndOfYear[1]);
        String getMsgCountSql = "select count(*)  from ( " +
                "    select OPERATEDATE from hrmsysmaintenancelog where RELATEDID = " + userid + ""+
                "  and OPERATEDATE >= '"+startEndOfYear[0]+"' and OPERATEDATE <= '"+startEndOfYear[1]+"'"+
                "    group by OPERATEDATE)";
        rs.execute(getMsgCountSql);
        rs.next();
        return rs.getInt("cnt");
    }
%>