一个时间区间,判断另一个区间是否嵌套

    //一个时间区间,判断另一个区间是否嵌套
    private boolean getErrSituation(Map<Integer, Map<String, Object>> mapAll) throws ParseException {
        SimpleDateFormat SDF_HM = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Map<Integer, Map<String, Object>> mapAllCopy = mapAll;
        for (Integer map : mapAll.keySet()) {
            for (Integer mapCopy : mapAllCopy.keySet()) {
                String allS = (String) mapAll.get(map).get("startdate");
                String allE = (String) mapAll.get(map).get("enddate");
                String copyS = (String) mapAllCopy.get(mapCopy).get("startdate");
                String copyE = (String) mapAllCopy.get(mapCopy).get("enddate");
                //etid为表id,itemno为唯一键
                if (mapAllCopy.get(mapCopy).get("etid").equals(mapAll.get(map).get("etid")) &&
                        !mapAllCopy.get(mapCopy).get("itemno").equals(mapAll.get(map).get("itemno"))) {
                    if (copyS.equals(allS) && copyE.equals(allE)) {
                        return true;
                    } else if ((SDF_HM.parse(copyS).compareTo(SDF_HM.parse(allS)) <= 0 && SDF_HM.parse(copyE).compareTo(SDF_HM.parse(allS)) >= 0) ||
                            (SDF_HM.parse(copyS).compareTo(SDF_HM.parse(allE)) <= 0 && SDF_HM.parse(copyE).compareTo(SDF_HM.parse(allE)) >= 0) ||
                            (SDF_HM.parse(copyS).compareTo(SDF_HM.parse(allS)) > 0 && SDF_HM.parse(copyE).compareTo(SDF_HM.parse(allE)) < 0)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

 

posted @ 2022-10-24 16:47  丶Ronnie  阅读(36)  评论(0)    收藏  举报