leave_flow.jsp 11.9 KB
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="com.engine.kq.timer.KQQueue" %>
<%@ page import="com.engine.kq.timer.KQTaskBean" %>
<%@ page import="com.engine.kq.wfset.util.SplitActionUtil" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="com.engine.kq.enums.KqSplitFlowTypeEnum" %>
<%@ page import="com.engine.kq.wfset.bean.SplitBean" %>
<%@ page import="com.engine.kq.biz.KQTimesArrayComInfo" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.engine.kq.enums.FlowReportTypeEnum" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="com.engine.kq.biz.KQFlowDataBiz" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%

    try {
        String requestid = Util.null2String(request.getParameter("requestid"));
        String userId = Util.null2String(request.getParameter("userId"));
        String kqDate = Util.null2String(request.getParameter("kqDate"));
        if(userId.length() == 0){
            out.println("param userId is null:<br/>");
            return ;
        }
        if(kqDate.length() == 0){
            out.println("param kqDate is null:<br/>");
            return ;
        }
        String kqDateNext = DateUtil.addDate(kqDate, 1);

        Map<String,Object> flowMaps = new HashMap<>();
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();

        String tablename = "select a.* from "+ KqSplitFlowTypeEnum.LEAVE.getTablename()+"  a left join workflow_requestbase b on a.requestid = b.requestid where  b.requestid > 0 ";
        String leaveSql = "select * from ("+tablename+") t where 1=1 and status <> 1 ";

        String sqlWhere = "";
        if(userId.length() > 0){
            sqlWhere += " and resourceid in ( "+userId+" )";
        }
        if(requestid.length() > 0){
            sqlWhere += " and requestid in ( "+requestid+" )";
        }
        if(kqDate.length() > 0 && kqDateNext.length() > 0){
            sqlWhere += " and ( fromdate between '"+kqDate+"' and '"+kqDateNext+"' or todate between '"+kqDate+"' and '"+kqDateNext+"' )";
        }else{
            if(kqDate.length() > 0){
                sqlWhere += " and fromdate between '"+kqDate+"' and '"+kqDate+"' ";
            }
            if(kqDateNext.length() > 0){
                sqlWhere += " and todate between '"+kqDateNext+"' and '"+kqDateNext+"' ";
            }
        }

        if(sqlWhere.length() > 0){
            leaveSql += sqlWhere;
        }
        List<SplitBean> splitBeans = new ArrayList<>();
        KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();

        int[] initArrays = kqTimesArrayComInfo.getInitArr();

        rs.execute(leaveSql);
        out.println("param leaveSql is :"+leaveSql+"<br/>");
        while(rs.next()){
            SplitBean splitBean = new SplitBean();
            String requestId= rs.getString("requestId");
            String resourceid= rs.getString("resourceid");
            String fromdate= rs.getString("fromdate");
            String fromtime= rs.getString("fromtime");
            String todate= rs.getString("todate");
            String totime= rs.getString("totime");
            String newleavetype= rs.getString("newleavetype");
            String duration= rs.getString("duration");
            String durationrule= rs.getString("durationrule");
            String leavebackrequestid= Util.null2String(rs.getString("leavebackrequestid"));

            if(Util.getDoubleValue(duration) <= 0){
                continue;
            }
            //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
            String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";

            Map<String,String> infoMap = new HashMap<>();
            infoMap.put(newleavetype, duration);
            infoMap.put("requestId", requestId);
            infoMap.put("begintime", fromtime);
            infoMap.put("endtime", totime);
            infoMap.put("unitType", unitType);
            infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
            infoMap.put("newleavetype", newleavetype);

            String key = resourceid+"|"+fromdate;
            if(flowMaps != null){
                if(flowMaps.get(key) != null){
                    if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){
                        int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime);
                        int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime);
                        Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1);
                        leavebackrequestid = leavebackrequestid.substring(1);
                        String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'";
                        rs1.executeQuery(backSql);

                        while (rs1.next()){
                            String back_fromtime = rs1.getString("fromtime");
                            String back_totime = rs1.getString("totime");
                            if(back_fromtime.equalsIgnoreCase(fromtime)){
                                Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
                            }else{
                                Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
                            }
                        }
                        List<List<String>> backLists = new ArrayList<>();
                        List<String> backList = new ArrayList<>();
                        for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){
                            if(initArrays[i] == 1){
                                backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i));
                            }else{
                                if(!backList.isEmpty()){
                                    backLists.add(backList);
                                    backList = new ArrayList<>();
                                }else{
                                    continue;
                                }
                            }
                        }
                        if(!backList.isEmpty()){
                            backLists.add(backList);
                        }
                        if(backLists != null && !backLists.isEmpty()){
                            List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
                            for(int j = 0 ; j < backLists.size() ;j++){
                                List<String> backListTmp = backLists.get(j);
                                String back_tmp_fromtime = backListTmp.get(0);
                                String back_tmp_totime = backListTmp.get(backListTmp.size()-1);
                                infoMap = new HashMap<>();
                                infoMap.put("requestId", requestId);
                                infoMap.put(newleavetype, duration);
                                infoMap.put("begintime", back_tmp_fromtime);
                                infoMap.put("endtime", back_tmp_totime);
                                infoMap.put("unitType", unitType);
                                infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
                                infoMap.put("newleavetype", newleavetype);
                                time_list_tmp.add(infoMap);
                            }
                        }
                    }else{
                        List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
                        time_list_tmp.add(infoMap);
                    }
                }else{
                    if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){
                        int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime);
                        int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime);
                        Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1);
                        leavebackrequestid = leavebackrequestid.substring(1);
                        String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'";
                        rs1.executeQuery(backSql);

                        while (rs1.next()){
                            String back_fromtime = rs1.getString("fromtime");
                            String back_totime = rs1.getString("totime");
                            if(back_fromtime.equalsIgnoreCase(fromtime)){
                                Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
                            }else{
                                Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
                            }
                        }
                        List<List<String>> backLists = new ArrayList<>();
                        List<String> backList = new ArrayList<>();
                        for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){
                            if(initArrays[i] == 1){
                                backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i));
                            }else{
                                if(!backList.isEmpty()){
                                    backLists.add(backList);
                                    backList = new ArrayList<>();
                                }else{
                                    continue;
                                }
                            }
                        }
                        if(!backList.isEmpty()){
                            backLists.add(backList);
                        }
                        System.out.println("backLists::"+backLists);
                        if(backLists != null && !backLists.isEmpty()){
                            List<Map<String,String>> time_list = new ArrayList<>();
                            for(int j = 0 ; j < backLists.size() ;j++){
                                List<String> backListTmp = backLists.get(j);
                                String back_tmp_fromtime = backListTmp.get(0);
                                String back_tmp_totime = backListTmp.get(backListTmp.size()-1);
                                infoMap = new HashMap<>();
                                infoMap.put("requestId", requestId);
                                infoMap.put(newleavetype, duration);
                                infoMap.put("begintime", back_tmp_fromtime);
                                infoMap.put("endtime", back_tmp_totime);
                                infoMap.put("unitType", unitType);
                                infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
                                infoMap.put("newleavetype", newleavetype);
                                time_list.add(infoMap);
                            }
                            flowMaps.put(key, time_list);
                        }
                    }else{
                        List<Map<String,String>> time_list = new ArrayList<>();
                        time_list.add(infoMap);
                        flowMaps.put(key, time_list);
                    }
                }
            }

        }
        out.print(flowMaps);

    } catch (Exception e) {
        e.printStackTrace();
        out.print(e.getMessage());
    }

%>