判断48小时内的俩个时间段是否重叠

 public boolean dispatcherTimeVerify(List<DriverRewardBusinessRuleDTO> businessRuleDTOList) {
        boolean overlapFlag = false;
        for (int i = 0; i < businessRuleDTOList.size(); i++) {
            String startTime = businessRuleDTOList.get(i).getDispatchTime().split("-")[0].trim();
            String endTime = businessRuleDTOList.get(i).getDispatchTime().split("-")[1].trim();
            String startTruckTimeType = businessRuleDTOList.get(i).getStartTruckTimeType().trim();
            //跳过第一个时间段不做判断
            if (businessRuleDTOList.size() - i > 1) {
                for (int j = i + 1; j <= businessRuleDTOList.size() - 1; j++) {
                    if (!overlapFlag) {
                        String otherStartTime = businessRuleDTOList.get(j).getDispatchTime().split("-")[0].trim();
                        String otherEndTime = businessRuleDTOList.get(j).getDispatchTime().split("-")[1].trim();
                        String otherStartTruckTimeType = businessRuleDTOList.get(j).getStartTruckTimeType().trim();
                        // 调度时间不重叠且发车时间类型相同时
                        overlapFlag = isOverlap(startTime, endTime, otherStartTime, otherEndTime) && StringUtils.equals(startTruckTimeType, otherStartTruckTimeType);
                    }
                }
            }
        }
        return overlapFlag;
    }

    /**
     * 判断俩个时间段是否重叠 重叠为true 不重叠为false
     */
    private boolean isOverlap(String startTime, String endTime, String otherStartTime, String otherEndTime) {
        return StringUtils.compare(startTime, otherEndTime) <= 0 && StringUtils.compare(endTime, otherStartTime) >= 0;
    }
    @Test
    public void testDeleteTestData() {

        // [{"dispatchTime":"00:00 - 01:01","startTruckTime":"00:01","startTruckTimeType":"0"},{"dispatchTime":"00:00 - 01:01","startTruckTime":"00:01","startTruckTimeType":"0"}]
        List<DriverRewardBusinessRuleDTO> list = Lists.newArrayList();
        DriverRewardBusinessRuleDTO dto = new DriverRewardBusinessRuleDTO();
        DriverRewardBusinessRuleDTO dto1 = new DriverRewardBusinessRuleDTO();
        dto.setDispatchTime("00:00 - 01:01");
        dto1.setDispatchTime("01:00 - 01:01");
        dto.setStartTruckTimeType("0");
        dto1.setStartTruckTimeType("0");
        list.add(dto);
        list.add(dto1);
        boolean b = driverRewardRuleService.dispatcherTimeVerify(list);
        System.out.println(b);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值