Commit 010828aaf658869d6afe0034d0d4914ad27a4b19
1 parent
8684c715
feat: 修改签退时间范围
Showing
4 changed files
with
100 additions
and
18 deletions
Bsth-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
| ... | ... | @@ -506,7 +506,7 @@ public class SignInServiceImpl implements ISignInService { |
| 506 | 506 | |
| 507 | 507 | private boolean driverCheckTimeOut(GlobalIndex globalIndex, SignIn signIn, List<DriverScheduling> dto, long now) { |
| 508 | 508 | try { |
| 509 | - Boolean result = true; | |
| 509 | + boolean result = true; | |
| 510 | 510 | DriverSignInRecommendation currentScheduling = schedulingService.computedTheCurrentClosestTimestamp(dto, now, 0); |
| 511 | 511 | LocalDateTime endTime = ConstDateUtil.getLocalDateTimeByLongTime(currentScheduling.getTimestamps()); |
| 512 | 512 | LocalDateTime nowTime = ConstDateUtil.getLocalDateTimeByLongTime(now); |
| ... | ... | @@ -516,49 +516,50 @@ public class SignInServiceImpl implements ISignInService { |
| 516 | 516 | return handlerExceptionRecord(dto, now, globalIndex, signIn); |
| 517 | 517 | } |
| 518 | 518 | // 不在有效时间范围内,判断当前是否有签到记录 当前应签到还是签退 |
| 519 | - if (!(Math.abs(nowBetween) <= 60)) { | |
| 519 | + if (checkTimerSign(nowBetween, currentScheduling.getBcType())) { | |
| 520 | 520 | // 签到一个逻辑 当前无记录 |
| 521 | 521 | if (currentScheduling.getBcType().equals(BC_TYPE_OUT) && Objects.isNull(currentScheduling.getSignInId())) { |
| 522 | 522 | DriverSignInRecommendation lastClosestTimestamp = schedulingService.computedTheCurrentClosestTimestamp(dto, now, -1); |
| 523 | 523 | // 给出签到范围 |
| 524 | 524 | // 上一次无记|签到,type:签退 当前时间小于最近签到时间 -> 超时签退 |
| 525 | 525 | if (nowBetween < -60L && Objects.isNull(lastClosestTimestamp.getSignInId()) && signIn.getType().equals(SIGN_OUT) && lastClosestTimestamp.getBcType().equals(BC_TYPE_IN)) { |
| 526 | - signIn.setRemark(SIGN_OUT_TIMEOUT + "请在" + ConstDateUtil.formatDate("HH:mm", new Date(lastClosestTimestamp.getTimestamps())) + "前后一小时内打卡。"); | |
| 526 | + signIn.setRemark(SIGN_OUT_TIMEOUT + getPrompt(lastClosestTimestamp)); | |
| 527 | 527 | globalIndex.setIndex(lastClosestTimestamp.getIndex()); |
| 528 | 528 | result = false; |
| 529 | 529 | } |
| 530 | 530 | // 上一次无记无|签到,type:签退 当前时间小于最近签到时间 -> 超时签退 |
| 531 | 531 | else if (nowBetween < -60L && Objects.isNull(lastClosestTimestamp.getSignInId()) && signIn.getType().equals(SIGN_OUT) && lastClosestTimestamp.getIndex().equals(currentScheduling.getIndex())) { |
| 532 | - signIn.setRemark(SIGN_IN_TIMEOUT + "请在" + ConstDateUtil.formatDate("HH:mm", new Date(currentScheduling.getTimestamps())) + "前后一小时内打卡。"); | |
| 532 | + signIn.setRemark(SIGN_IN_TIMEOUT + getPrompt(currentScheduling)); | |
| 533 | 533 | globalIndex.setIndex(currentScheduling.getIndex()); |
| 534 | 534 | result = false; |
| 535 | 535 | } |
| 536 | 536 | // 当前最近无记录|签到,type:签到|签退 -> 签到超时给上 |
| 537 | 537 | else { |
| 538 | - signIn.setRemark(SIGN_IN_TIMEOUT + "请在" + ConstDateUtil.formatDate("HH:mm", new Date(currentScheduling.getTimestamps())) + "前后一小时内打卡。"); | |
| 538 | + signIn.setRemark(SIGN_IN_TIMEOUT + getPrompt(currentScheduling)); | |
| 539 | 539 | globalIndex.setIndex(currentScheduling.getIndex()); |
| 540 | 540 | result = false; |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | + | |
| 543 | 544 | // 签退一个逻辑 当前无记录 |
| 544 | 545 | if (currentScheduling.getBcType().equals(BC_TYPE_IN) && Objects.isNull(currentScheduling.getSignInId())) { |
| 545 | 546 | DriverSignInRecommendation lastClosestTimestamp = schedulingService.computedTheCurrentClosestTimestamp(dto, now, -1); |
| 546 | 547 | // 上一次无记|签退,type:签到 当前时间小于最近签退时间 -> 签到异常 |
| 547 | 548 | if (nowBetween < -60L && Objects.isNull(lastClosestTimestamp.getSignInId()) && signIn.getType().equals(SIGN_IN)) { |
| 548 | - signIn.setRemark(SIGN_IN_TIMEOUT + "请在" + ConstDateUtil.formatDate("HH:mm", new Date(lastClosestTimestamp.getTimestamps())) + "前后一小时内打卡。"); | |
| 549 | + signIn.setRemark(SIGN_IN_TIMEOUT + getPrompt(lastClosestTimestamp)); | |
| 549 | 550 | globalIndex.setIndex(lastClosestTimestamp.getIndex()); |
| 550 | 551 | result = false; |
| 551 | 552 | } |
| 552 | 553 | // 当前无记|签退 , type:签退|签到 ——> 签退异常 |
| 553 | 554 | else { |
| 554 | - signIn.setRemark(SIGN_OUT_TIMEOUT + "请在" + ConstDateUtil.formatDate("HH:mm", new Date(currentScheduling.getTimestamps())) + "前后一小时内打卡。"); | |
| 555 | + signIn.setRemark(SIGN_OUT_TIMEOUT + getPrompt(currentScheduling)); | |
| 555 | 556 | globalIndex.setIndex(currentScheduling.getIndex()); |
| 556 | 557 | result = false; |
| 557 | 558 | } |
| 558 | 559 | } |
| 559 | 560 | // 签退|签到 当前有记录 |
| 560 | 561 | if (!Objects.isNull(currentScheduling.getSignInId())) { |
| 561 | - String prompt = "请在" + ConstDateUtil.formatDate("HH:mm", new Date(currentScheduling.getTimestamps())) + "前后一小时内打卡。"; | |
| 562 | + String prompt = getPrompt(currentScheduling); | |
| 562 | 563 | signIn.setRemark((currentScheduling.getBcType().equals(BC_TYPE_IN) ? SIGN_OUT_TIMEOUT : SIGN_IN_TIMEOUT) + prompt); |
| 563 | 564 | globalIndex.setIndex(currentScheduling.getIndex()); |
| 564 | 565 | result = false; |
| ... | ... | @@ -569,10 +570,36 @@ public class SignInServiceImpl implements ISignInService { |
| 569 | 570 | } |
| 570 | 571 | return result; |
| 571 | 572 | } catch (Exception e) { |
| 573 | + log.info(e.getMessage()); | |
| 572 | 574 | return true; |
| 573 | 575 | } |
| 574 | 576 | } |
| 575 | 577 | |
| 578 | + private String getPrompt(DriverSignInRecommendation currentScheduling) { | |
| 579 | + if (BC_TYPE_OUT.equals(currentScheduling.getBcType())) { | |
| 580 | + return "请在" + ConstDateUtil.formatDate("HH:mm", new Date(currentScheduling.getTimestamps())) + "前后一小时内打卡。"; | |
| 581 | + } else { | |
| 582 | + // 正两小时 负 1小时 | |
| 583 | + LocalDateTime time = ConstDateUtil.stringTransformLocalDateTime(ConstDateUtil.formatDate("yyyy-MM-dd HH:mm:ss", new Date(currentScheduling.getTimestamps())),"yyyy-MM-dd HH:mm:ss"); | |
| 584 | + LocalDateTime addHours = time.plusHours(2); | |
| 585 | + LocalDateTime hours = time.plusHours(-1); | |
| 586 | + return "请在" + ConstDateUtil.formatDate("HH:mm", hours) + "到" | |
| 587 | + + ConstDateUtil.formatDate("HH:mm", addHours) + "之间打卡"; | |
| 588 | + } | |
| 589 | + } | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + private static boolean checkTimerSign(long nowBetween, String bcType) { | |
| 594 | + // 如果是签到就是正负一小时内有效 | |
| 595 | + if (BC_TYPE_OUT.equals(bcType)) { | |
| 596 | + return !(Math.abs(nowBetween) <= 60); | |
| 597 | + } else { | |
| 598 | + // 如果是签退就是负1小时 正两小时有效 | |
| 599 | + return !((nowBetween >= 0 && nowBetween <= 120L) || (nowBetween < 0 && nowBetween >= -60L)); | |
| 600 | + } | |
| 601 | + } | |
| 602 | + | |
| 576 | 603 | private Boolean handlerExceptionRecord(List<DriverScheduling> dto, long now, GlobalIndex globalIndex, SignIn signIn) { |
| 577 | 604 | DriverSignInRecommendation currentScheduling = schedulingService.computedTheCurrentClosestTimestamp(dto, now, 0); |
| 578 | 605 | LocalDateTime endTime = ConstDateUtil.getLocalDateTimeByLongTime(currentScheduling.getTimestamps()); | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/SchedulingService.java
| ... | ... | @@ -142,7 +142,7 @@ public class SchedulingService { |
| 142 | 142 | DriverScheduling scheduling = dto.get(globalIndex); |
| 143 | 143 | long date = scheduling.getBcType().equals(BC_TYPE_IN) ? scheduling.getZdsjT() : scheduling.getFcsjT(); |
| 144 | 144 | long nowBetween = ChronoUnit.MINUTES.between(ConstDateUtil.getLocalDateTimeByLongTime(date), ConstDateUtil.getLocalDateTimeByLongTime(signIn.getCreateTime().getTime())); |
| 145 | - if (!(Math.abs(nowBetween) <= 60)) { | |
| 145 | + if (checkTimerSign(nowBetween, scheduling.getBcType())) { | |
| 146 | 146 | if (nowBetween < -60L) { |
| 147 | 147 | return "早签"; |
| 148 | 148 | } else { |
| ... | ... | @@ -152,6 +152,17 @@ public class SchedulingService { |
| 152 | 152 | return signIn.getRemark(); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | + private static boolean checkTimerSign(long nowBetween, String bcType) { | |
| 156 | + // 如果是签到就是正负一小时内有效 | |
| 157 | + if (BC_TYPE_OUT.equals(bcType)) { | |
| 158 | + return !(Math.abs(nowBetween) <= 60); | |
| 159 | + } else { | |
| 160 | + // 如果是签退就是负1小时 正两小时有效 | |
| 161 | + return !((nowBetween >= 0 && nowBetween <= 120L) || (nowBetween < 0 && nowBetween >= -60L)); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + | |
| 155 | 166 | private void handlerRecord(List<DriverScheduling> dto, SignIn signIn, GlobalIndex globalIndex) { |
| 156 | 167 | if (globalIndex.getIndex() == dto.size() - 1) { |
| 157 | 168 | return; |
| ... | ... | @@ -163,24 +174,36 @@ public class SchedulingService { |
| 163 | 174 | return; |
| 164 | 175 | } |
| 165 | 176 | int index = globalIndex.getIndex() + 1; |
| 166 | - // 之前是签到 | 目前有效记录 -》进行修改 变成无效 | |
| 167 | - if (signIn.getExType().equals(SIGN_NO_EX_NUM)) { | |
| 168 | - signIn.setStatus(SIGN_IN_FAIL); | |
| 169 | - signIn.setExType(SIGN_TIME_OUT_EX_NUM); | |
| 170 | - signInMapper.updateSignIn(signIn); | |
| 171 | - } | |
| 177 | + // 目前有效记录 -》进行修改 变成无效 | |
| 178 | +// if (signIn.getExType().equals(SIGN_NO_EX_NUM)) { | |
| 179 | +// signIn.setStatus(SIGN_IN_FAIL); | |
| 180 | +// signIn.setExType(SIGN_TIME_OUT_EX_NUM); | |
| 181 | +// signInMapper.updateSignIn(signIn); | |
| 182 | +// } | |
| 172 | 183 | DriverScheduling scheduling = dto.get(index); |
| 173 | 184 | long date = scheduling.getBcType().equals(BC_TYPE_IN) ? scheduling.getZdsjT() : scheduling.getFcsjT(); |
| 174 | - String prompt = "请在" + ConstDateUtil.formatDate("HH:mm", new Date(date)) + "前后一小时内打卡。"; | |
| 185 | + String prompt = getPrompt(new Date(date), scheduling.getBcType()); | |
| 175 | 186 | signIn.setRemark((scheduling.getBcType().equals(BC_TYPE_IN) ? SIGN_OUT_TIMEOUT : SIGN_IN_TIMEOUT) + prompt); |
| 176 | 187 | signIn.setRemark(signIn.getRemark().replaceFirst(",$", "。")); |
| 177 | - // 之前是签到 | 目前无效 -》往后更新 | |
| 178 | - | |
| 188 | + // 目前无效 -》往后更新 | |
| 179 | 189 | String remark = getRemark(dto, signIn, index); |
| 180 | 190 | schedulingMapper.updateRoster(scheduling, signIn.getId(), signIn.getExType(), signIn.getCreateTime(), remark, signIn.getType(), signIn.getAlcoholFlag(), signIn.getAlcoholIntake()); |
| 181 | 191 | nowSchedulingCache.updateCacheByJobCode(ConstDateUtil.formatDate(dto.get(0).getScheduleDate()), globalIndex.getIndex() + 1, signIn); |
| 182 | 192 | } |
| 183 | 193 | |
| 194 | + private String getPrompt(Date date, String bcType) { | |
| 195 | + if (BC_TYPE_OUT.equals(bcType)) { | |
| 196 | + return "请在" + ConstDateUtil.formatDate("HH:mm", date) + "前后一小时内打卡。"; | |
| 197 | + } else { | |
| 198 | + // 正两小时 负 1小时 | |
| 199 | + LocalDateTime time = ConstDateUtil.stringTransformLocalDateTime(ConstDateUtil.formatDate("yyyy-MM-dd HH:mm:ss", date),"yyyy-MM-dd HH:mm:ss"); | |
| 200 | + LocalDateTime addHours = time.plusHours(2); | |
| 201 | + LocalDateTime hours = time.plusHours(-1); | |
| 202 | + return "请在" + ConstDateUtil.formatDate("HH:mm", hours) + "到" | |
| 203 | + + ConstDateUtil.formatDate("HH:mm", addHours) + "之间打卡"; | |
| 204 | + } | |
| 205 | + } | |
| 206 | + | |
| 184 | 207 | public List<ReportViewResponseVo> queryReportTableResponseVo(ReportViewRequestVo requestVo, HttpServletResponse response) { |
| 185 | 208 | // 处理天 |
| 186 | 209 | if (requestVo.getExportFlag().equals(NOW)) { | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
| ... | ... | @@ -459,9 +459,28 @@ public class ThreadJobService { |
| 459 | 459 | bcList.add(scheduling3); |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | + // 测试用例 | |
| 463 | + bcList.add(getDriverSchedulingTest("2023-09-26 03:20:00","2023-09-26 09:30:00","out")); | |
| 464 | + bcList.add(getDriverSchedulingTest("2023-09-26 03:20:00","2023-09-26 09:30:00","in")); | |
| 462 | 465 | return bcList; |
| 463 | 466 | } |
| 464 | 467 | |
| 468 | + private DriverScheduling getDriverSchedulingTest(String startTime, String endTime,String bcType) { | |
| 469 | + DriverScheduling scheduling = new DriverScheduling(); | |
| 470 | + scheduling.setJobCode("700001"); | |
| 471 | + scheduling.setName("测试"); | |
| 472 | + scheduling.setPosts("测试"); | |
| 473 | + scheduling.setScheduleDate(new Date()); | |
| 474 | + scheduling.setLineName(""); | |
| 475 | + scheduling.setLpName(""); | |
| 476 | + scheduling.setNbbm(""); | |
| 477 | + scheduling.setFcsjT(ConstDateUtil.parseDate(startTime).getTime()); | |
| 478 | + scheduling.setZdsjT(ConstDateUtil.parseDate(endTime).getTime()); | |
| 479 | + scheduling.setFleetName(""); | |
| 480 | + scheduling.setBcType(bcType); | |
| 481 | + return scheduling; | |
| 482 | + } | |
| 483 | + | |
| 465 | 484 | private static DriverScheduling getDriverScheduling(RuleAttendanceMain ruleAttendanceMain) { |
| 466 | 485 | DriverScheduling scheduling = new DriverScheduling(); |
| 467 | 486 | scheduling.setPosts(ruleAttendanceMain.getPosts()); | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/utils/ConstDateUtil.java
| ... | ... | @@ -10,6 +10,13 @@ import java.util.Date; |
| 10 | 10 | import java.util.List; |
| 11 | 11 | |
| 12 | 12 | public class ConstDateUtil { |
| 13 | + | |
| 14 | + public static LocalDateTime stringTransformLocalDateTime(String dateString, String pattern){ | |
| 15 | + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); | |
| 16 | + return LocalDateTime.parse(dateString,formatter); | |
| 17 | + } | |
| 18 | + | |
| 19 | + | |
| 13 | 20 | public static String formatDate(String pattern){ |
| 14 | 21 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); |
| 15 | 22 | return simpleDateFormat.format(new Date()); |
| ... | ... | @@ -28,6 +35,12 @@ public class ConstDateUtil { |
| 28 | 35 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); |
| 29 | 36 | return simpleDateFormat.format(date); |
| 30 | 37 | } |
| 38 | + | |
| 39 | + public static String formatDate(String pattern,LocalDateTime date){ | |
| 40 | + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); | |
| 41 | + return date.format(formatter); | |
| 42 | + } | |
| 43 | + | |
| 31 | 44 | public static String formatDate(String pattern,LocalDate date){ |
| 32 | 45 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); |
| 33 | 46 | return simpleDateFormat.format(date); | ... | ... |