Commit e2edbcbed4ed05f18264efc3d624748ea1db0cbd
1 parent
010828aa
feat: 新增手动生成排班接口
Showing
8 changed files
with
306 additions
and
10 deletions
Bsth-admin/src/main/java/com/ruoyi/controller/AttendanceController.java
| ... | ... | @@ -150,4 +150,12 @@ public class AttendanceController extends BaseController { |
| 150 | 150 | return Result.OK(attendanceService.getTodayFreeUser(date)); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | + @ApiOperation("生成指定月份的排班") | |
| 154 | + @PostMapping("/create/attendance/{month}") | |
| 155 | + public Result<?> createAttendance(@PathVariable("month") String month){ | |
| 156 | + attendanceService.createAttendance(month); | |
| 157 | + return Result.OK(); | |
| 158 | + } | |
| 159 | + | |
| 160 | + | |
| 153 | 161 | } | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/mapper/RuleNumSettingMapper.java
| ... | ... | @@ -6,6 +6,7 @@ import com.ruoyi.driver.domain.Driver; |
| 6 | 6 | import com.ruoyi.pojo.dto.AttendanceDto; |
| 7 | 7 | import com.ruoyi.pojo.vo.SchedulingRequestVo; |
| 8 | 8 | import com.ruoyi.pojo.vo.SchedulingResponseVo; |
| 9 | +import org.apache.ibatis.annotations.Param; | |
| 9 | 10 | |
| 10 | 11 | import java.util.List; |
| 11 | 12 | |
| ... | ... | @@ -24,6 +25,13 @@ public interface RuleNumSettingMapper extends BaseMapper<RuleNumSetting> { |
| 24 | 25 | * @return |
| 25 | 26 | */ |
| 26 | 27 | List<AttendanceDto> getPeopleList(); |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 获取指定月份的日期 | |
| 31 | + * @param month | |
| 32 | + * @return | |
| 33 | + */ | |
| 34 | + List<AttendanceDto> getPeopleListByMonth(@Param("month") String month); | |
| 27 | 35 | } |
| 28 | 36 | |
| 29 | 37 | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/AttendanceService.java
Bsth-admin/src/main/java/com/ruoyi/service/RuleNumSettingService.java
| ... | ... | @@ -2,6 +2,7 @@ package com.ruoyi.service; |
| 2 | 2 | |
| 3 | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
| 4 | 4 | import com.ruoyi.domain.RuleNumSetting; |
| 5 | +import com.ruoyi.pojo.dto.AttendanceDto; | |
| 5 | 6 | import com.ruoyi.pojo.dto.RuleNumDto; |
| 6 | 7 | import com.ruoyi.pojo.vo.SchedulingRequestVo; |
| 7 | 8 | import com.ruoyi.pojo.vo.SchedulingResponseVo; |
| ... | ... | @@ -38,4 +39,11 @@ public interface RuleNumSettingService extends IService<RuleNumSetting> { |
| 38 | 39 | * 手动添加班次 |
| 39 | 40 | */ |
| 40 | 41 | void manualAddBcCache(); |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 获取指定月份的人员 | |
| 45 | + * @param month | |
| 46 | + * @return | |
| 47 | + */ | |
| 48 | + List<AttendanceDto> getPeopleListByMonth(String month); | |
| 41 | 49 | } | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/impl/AttendanceServiceImpl.java
| ... | ... | @@ -13,10 +13,7 @@ import com.ruoyi.domain.*; |
| 13 | 13 | import com.ruoyi.driver.mapper.DriverMapper; |
| 14 | 14 | import com.ruoyi.num.domain.RuleNum; |
| 15 | 15 | import com.ruoyi.num.service.IRuleNumService; |
| 16 | -import com.ruoyi.pojo.dto.DriverDto; | |
| 17 | -import com.ruoyi.pojo.dto.RuleSchedulingDto; | |
| 18 | -import com.ruoyi.pojo.dto.SchedulingDto; | |
| 19 | -import com.ruoyi.pojo.dto.SchedulingSettingDto; | |
| 16 | +import com.ruoyi.pojo.dto.*; | |
| 20 | 17 | import com.ruoyi.pojo.vo.*; |
| 21 | 18 | import com.ruoyi.scheduling.domain.RuleScheduling; |
| 22 | 19 | import com.ruoyi.scheduling.service.IRuleSchedulingService; |
| ... | ... | @@ -31,12 +28,14 @@ import org.springframework.transaction.annotation.Transactional; |
| 31 | 28 | import javax.validation.constraints.NotBlank; |
| 32 | 29 | import java.time.LocalDate; |
| 33 | 30 | import java.time.ZoneId; |
| 31 | +import java.time.temporal.ChronoUnit; | |
| 34 | 32 | import java.util.*; |
| 35 | 33 | import java.util.stream.Collectors; |
| 36 | 34 | import java.util.stream.Stream; |
| 37 | 35 | |
| 38 | 36 | import static com.ruoyi.common.RuleSchedulingProperties.*; |
| 39 | 37 | import static com.ruoyi.common.WeekEnum.FREE; |
| 38 | +import static com.ruoyi.service.impl.RuleNumSettingServiceImpl.getFreeRuleSchedulingDto; | |
| 40 | 39 | |
| 41 | 40 | /** |
| 42 | 41 | * @author 20412 |
| ... | ... | @@ -68,6 +67,9 @@ public class AttendanceServiceImpl implements AttendanceService { |
| 68 | 67 | private RuleAttendanceMainService attendanceMainService; |
| 69 | 68 | |
| 70 | 69 | @Autowired |
| 70 | + private IRuleSchedulingService schedulingService; | |
| 71 | + | |
| 72 | + @Autowired | |
| 71 | 73 | private RuleAttendanceMainHelpService helpService; |
| 72 | 74 | |
| 73 | 75 | @Autowired |
| ... | ... | @@ -179,7 +181,7 @@ public class AttendanceServiceImpl implements AttendanceService { |
| 179 | 181 | attendanceMainService.updateByJobCodeTotalQuantity(vo, mainList); |
| 180 | 182 | } |
| 181 | 183 | |
| 182 | - private static List<RuleAttendanceMain> handleRuleUpdate(UpdateAttendanceVo vo, RuleAttendanceMain main, RuleScheduling ruleScheduling) { | |
| 184 | + private static List<RuleAttendanceMain> handleRuleUpdate(UpdateAttendanceVo vo, RuleAttendanceMain main, RuleScheduling ruleScheduling) { | |
| 183 | 185 | List<RuleAttendanceMain> mainList = new ArrayList<>(); |
| 184 | 186 | LocalDate startDate = LocalDate.parse(vo.getStartDate()); |
| 185 | 187 | LocalDate endDate = LocalDate.parse(vo.getEndDate()); |
| ... | ... | @@ -192,7 +194,7 @@ public class AttendanceServiceImpl implements AttendanceService { |
| 192 | 194 | |
| 193 | 195 | private static void handleSegmentation(RuleAttendanceMain main, RuleScheduling ruleScheduling, List<RuleAttendanceMain> mainList, LocalDate startDate) { |
| 194 | 196 | RuleAttendanceMain nowMain = new RuleAttendanceMain(); |
| 195 | - BeanUtils.copyProperties(main,nowMain); | |
| 197 | + BeanUtils.copyProperties(main, nowMain); | |
| 196 | 198 | nowMain.setFirstWorkSignInTime(ConstDateUtil.dateAddition(startDate.toString(), ConstDateUtil.formatDate("HH:mm:ss", nowMain.getFirstWorkSignInTime()))); |
| 197 | 199 | if (HAVE_SEGMENTATION.equals(ruleScheduling.getSecondFlag())) { |
| 198 | 200 | nowMain.setFirstQuittingSignInTime(ConstDateUtil.dateAddition(startDate.toString(), ConstDateUtil.formatDate("HH:mm:ss", nowMain.getFirstQuittingSignInTime()))); |
| ... | ... | @@ -268,6 +270,219 @@ public class AttendanceServiceImpl implements AttendanceService { |
| 268 | 270 | return peopleList; |
| 269 | 271 | } |
| 270 | 272 | |
| 273 | + @Override | |
| 274 | + public void createAttendance(String month) { | |
| 275 | + if (StringUtils.isEmpty(month) || !StringUtils.contains(month, "-")) { | |
| 276 | + return; | |
| 277 | + } | |
| 278 | + // 不能生成以前的排班 | |
| 279 | + if (ConstDateUtil.formatDate("yyyy-MM").compareTo(month) > 0){ | |
| 280 | + throw new RuntimeException("只能生成未来的排班"); | |
| 281 | + } | |
| 282 | + String[] split = month.split("-"); | |
| 283 | + List<AttendanceDto> peopleList = ruleNumSettingService.getPeopleListByMonth(month); | |
| 284 | + List<Integer> settingList = peopleList.stream().map(AttendanceDto::getSettingId).distinct().collect(Collectors.toList()); | |
| 285 | + // 获取规则集合 | |
| 286 | + List<RuleSchedulingDto> ruleList = schedulingService.selectRuleSchedulingListVoBySettingIds(settingList); | |
| 287 | + // 获取班次 | |
| 288 | + List<RuleNumDto> ruleNumDtoList = ruleNumSettingService.selectRuleNumBySettingId(settingList); | |
| 289 | + // 处理规则 | |
| 290 | + List<LocalDate> dateList = ConstDateUtil.getDateSetFromTheCurrentDayToTheEndOfTheMonth(Integer.parseInt(split[0]), Integer.parseInt(split[1])); | |
| 291 | + List<RuleAttendanceMain> attendanceMains = handleAttendanceMain(peopleList, ruleList, ruleNumDtoList, dateList, month); | |
| 292 | + attendanceMainService.saveBatch(attendanceMains); | |
| 293 | + } | |
| 294 | + | |
| 295 | + | |
| 296 | + private List<RuleAttendanceMain> handleAttendanceMain(List<AttendanceDto> peopleList, List<RuleSchedulingDto> ruleList, List<RuleNumDto> ruleNumDtoList, List<LocalDate> dateList, String month) { | |
| 297 | + if (CollectionUtil.isEmpty(peopleList)) { | |
| 298 | + return null; | |
| 299 | + } | |
| 300 | + Map<Integer, List<AttendanceDto>> peopleMap = transformMapByPeople(peopleList); | |
| 301 | + Map<Integer, RuleNumDto> ruleNumMap = transformMapByRuleNum(ruleNumDtoList); | |
| 302 | + Map<Integer, List<RuleSchedulingDto>> ruleMap = transformMapByRule(ruleList); | |
| 303 | + List<RuleAttendanceMain> ruleAttendanceMainList = new ArrayList<>(); | |
| 304 | + for (Map.Entry<Integer, List<AttendanceDto>> entry : peopleMap.entrySet()) { | |
| 305 | + Integer settingId = entry.getKey(); | |
| 306 | + List<AttendanceDto> attendanceDtoList = entry.getValue(); | |
| 307 | + RuleNumDto dto = ruleNumMap.get(settingId); | |
| 308 | + List<RuleAttendanceMain> mainList = new ArrayList<>(entry.getValue().size() * dateList.size()); | |
| 309 | + for (AttendanceDto attendanceDto : attendanceDtoList) { | |
| 310 | + for (LocalDate date : dateList) { | |
| 311 | + // 处理固定规则翻班 | |
| 312 | + if (RULE_TYPE_FIXED.equals(dto.getRuleType())) { | |
| 313 | + handleFixed(date, mainList, ruleMap.get(settingId), attendanceDto, dto.getRuleDictName()); | |
| 314 | + } | |
| 315 | + // 处理星期翻班 | |
| 316 | + else { | |
| 317 | + handleWeek(date, mainList, ruleMap.get(settingId), attendanceDto, dto.getRuleDictName()); | |
| 318 | + } | |
| 319 | + } | |
| 320 | + } | |
| 321 | + ruleAttendanceMainList.addAll(mainList); | |
| 322 | + } | |
| 323 | + backCreatePeopleListLog(peopleList, ruleNumMap, dateList); | |
| 324 | + return ruleAttendanceMainList; | |
| 325 | + } | |
| 326 | + | |
| 327 | + private void handleFixed(LocalDate nowDate, List<RuleAttendanceMain> mainList, List<RuleSchedulingDto> ruleSchedulingDtoList, AttendanceDto attendanceDto, String ruleDictName) { | |
| 328 | + RuleAttendanceMain main = new RuleAttendanceMain(); | |
| 329 | + main.setPosts(attendanceDto.getPosts()); | |
| 330 | + main.setRuleDictName(ruleDictName); | |
| 331 | + main.setSchedulingDate(Date.from(nowDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); | |
| 332 | + main.setFleetName(attendanceDto.getFleetName()); | |
| 333 | + Date startDate = attendanceDto.getStartDate(); | |
| 334 | + // 匹配当天应设置的规则 | |
| 335 | + RuleSchedulingDto dto = getNowRuleByFixed(nowDate, startDate, ruleSchedulingDtoList); | |
| 336 | + main.setWorkFlag(dto.getId() == 0 ? FREE_FLAG : WORK_FLAG); | |
| 337 | + BeanUtils.copyProperties(dto, main); | |
| 338 | + main.setName(attendanceDto.getName()); | |
| 339 | + main.setJobCode(attendanceDto.getJobCode()); | |
| 340 | + // 处理是否分段 | |
| 341 | + handleSegmentationByDate(nowDate, main, dto); | |
| 342 | + mainList.add(main); | |
| 343 | + } | |
| 344 | + | |
| 345 | + private RuleSchedulingDto getNowRuleByFixed(LocalDate nowDate, Date startDate, List<RuleSchedulingDto> ruleSchedulingDtoList) { | |
| 346 | + LocalDate start = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | |
| 347 | + int daysDifference = new Long(ChronoUnit.DAYS.between(start, nowDate)).intValue(); | |
| 348 | + if (daysDifference < 0) { | |
| 349 | + return getFreeRuleSchedulingDto(startDate); | |
| 350 | + } | |
| 351 | + int length = ruleSchedulingDtoList.size(); | |
| 352 | + return ruleSchedulingDtoList.get(daysDifference % length); | |
| 353 | + } | |
| 354 | + | |
| 355 | + | |
| 356 | + public static void handleSegmentationByDate(LocalDate date, RuleAttendanceMain main, RuleSchedulingDto dto) { | |
| 357 | + main.setFirstWorkSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getFirstWorkSignInTime()))); | |
| 358 | + // 不存在分段 | |
| 359 | + if (NO_SEGMENTATION.equals(dto.getSecondFlag())) { | |
| 360 | + if (TOMORROW_YES.equals(dto.getFirstSignInDayTomorrow())) { | |
| 361 | + main.setFirstQuittingSignInTime(handleTimeTomorrowByRule(date, main.getFirstQuittingSignInTime())); | |
| 362 | + } else { | |
| 363 | + main.setFirstQuittingSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getFirstQuittingSignInTime()))); | |
| 364 | + } | |
| 365 | + } | |
| 366 | + // 存在分段 | |
| 367 | + else { | |
| 368 | + main.setFirstQuittingSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getFirstQuittingSignInTime()))); | |
| 369 | + main.setSecondWorkSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getSecondWorkSignInTime()))); | |
| 370 | + if (TOMORROW_YES.equals(dto.getFirstSignInDayTomorrow())) { | |
| 371 | + main.setSecondQuittingSignInTime(handleTimeTomorrowByRule(date, main.getSecondQuittingSignInTime())); | |
| 372 | + } else { | |
| 373 | + main.setSecondQuittingSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getSecondQuittingSignInTime()))); | |
| 374 | + } | |
| 375 | + } | |
| 376 | + } | |
| 377 | + | |
| 378 | + private static Date handleTimeTomorrowByRule(LocalDate date, Date time) { | |
| 379 | + // 隔天日期需要加1 | |
| 380 | + return ConstDateUtil.dateAddition(date.plusDays(1).toString(), ConstDateUtil.formatDate("HH:mm:ss", time)); | |
| 381 | + } | |
| 382 | + | |
| 383 | + | |
| 384 | + private void handleWeek(LocalDate date, List<RuleAttendanceMain> mainList, List<RuleSchedulingDto> ruleSchedulingDtoList, AttendanceDto attendanceDto, String ruleDictName) { | |
| 385 | + RuleAttendanceMain main = new RuleAttendanceMain(); | |
| 386 | + main.setSchedulingDate(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant())); | |
| 387 | + main.setPosts(attendanceDto.getPosts()); | |
| 388 | + main.setRuleDictName(ruleDictName); | |
| 389 | + main.setFleetName(attendanceDto.getFleetName()); | |
| 390 | + RuleSchedulingDto dto = null; | |
| 391 | + dto = getRuleByWeek(main, ruleSchedulingDtoList, date, attendanceDto.getStartDate()); | |
| 392 | + main.setWorkFlag(dto.getId() == 0 ? FREE_FLAG : WORK_FLAG); | |
| 393 | + BeanUtils.copyProperties(dto, main); | |
| 394 | + main.setName(attendanceDto.getName()); | |
| 395 | + main.setJobCode(attendanceDto.getJobCode()); | |
| 396 | + handleSegmentationByDate(date, main, dto); | |
| 397 | + mainList.add(main); | |
| 398 | + } | |
| 399 | + | |
| 400 | + private static RuleSchedulingDto getRuleByWeek(RuleAttendanceMain main, List<RuleSchedulingDto> ruleSchedulingDtoList, LocalDate nowDate, Date startDate) { | |
| 401 | + RuleSchedulingDto dto = null; | |
| 402 | + switch (nowDate.getDayOfWeek().toString()) { | |
| 403 | + case "MONDAY": | |
| 404 | + dto = ruleSchedulingDtoList.get(0); | |
| 405 | + break; | |
| 406 | + case "TUESDAY": | |
| 407 | + dto = ruleSchedulingDtoList.get(1); | |
| 408 | + break; | |
| 409 | + case "WEDNESDAY": | |
| 410 | + dto = ruleSchedulingDtoList.get(2); | |
| 411 | + break; | |
| 412 | + case "THURSDAY": | |
| 413 | + dto = ruleSchedulingDtoList.get(3); | |
| 414 | + break; | |
| 415 | + case "FRIDAY": | |
| 416 | + dto = ruleSchedulingDtoList.get(4); | |
| 417 | + break; | |
| 418 | + case "SATURDAY": | |
| 419 | + dto = ruleSchedulingDtoList.get(5); | |
| 420 | + break; | |
| 421 | + case "SUNDAY": | |
| 422 | + dto = ruleSchedulingDtoList.get(6); | |
| 423 | + break; | |
| 424 | + } | |
| 425 | + LocalDate start = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | |
| 426 | + int daysDifference = new Long(ChronoUnit.DAYS.between(start, nowDate)).intValue(); | |
| 427 | + if (daysDifference < 0) { | |
| 428 | + return getFreeRuleSchedulingDto(startDate); | |
| 429 | + } | |
| 430 | + return dto; | |
| 431 | + } | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + private Map<Integer, List<AttendanceDto>> transformMapByPeople(List<AttendanceDto> peopleList) { | |
| 436 | + Map<Integer, List<AttendanceDto>> map = new HashMap<>(16); | |
| 437 | + for (AttendanceDto dto : peopleList) { | |
| 438 | + List<AttendanceDto> dtoList = map.get(dto.getSettingId()); | |
| 439 | + if (CollectionUtil.isEmpty(dtoList)) { | |
| 440 | + map.put(dto.getSettingId(), new ArrayList<>(Arrays.asList(dto))); | |
| 441 | + } else { | |
| 442 | + dtoList.add(dto); | |
| 443 | + } | |
| 444 | + } | |
| 445 | + return map; | |
| 446 | + } | |
| 447 | + | |
| 448 | + private Map<Integer, RuleNumDto> transformMapByRuleNum(List<RuleNumDto> ruleNumDtoList) { | |
| 449 | + Map<Integer, RuleNumDto> map = new HashMap<>(16); | |
| 450 | + for (RuleNumDto ruleNumDto : ruleNumDtoList) { | |
| 451 | + map.put(ruleNumDto.getSettingId(), ruleNumDto); | |
| 452 | + } | |
| 453 | + return map; | |
| 454 | + } | |
| 455 | + | |
| 456 | + private Map<Integer, List<RuleSchedulingDto>> transformMapByRule(List<RuleSchedulingDto> ruleList) { | |
| 457 | + Map<Integer, List<RuleSchedulingDto>> map = new HashMap<>(16); | |
| 458 | + for (RuleSchedulingDto dto : ruleList) { | |
| 459 | + List<RuleSchedulingDto> dtoList = map.get(dto.getSettingId()); | |
| 460 | + if (CollectionUtil.isEmpty(dtoList)) { | |
| 461 | + map.put(dto.getSettingId(), new ArrayList<>(Arrays.asList(dto))); | |
| 462 | + } else { | |
| 463 | + dtoList.add(dto); | |
| 464 | + } | |
| 465 | + } | |
| 466 | + for (Map.Entry<Integer, List<RuleSchedulingDto>> entry : map.entrySet()) { | |
| 467 | + entry.getValue().sort(Comparator.comparing(RuleSchedulingDto::getSort)); | |
| 468 | + } | |
| 469 | + return map; | |
| 470 | + } | |
| 471 | + | |
| 472 | + private void backCreatePeopleListLog(List<AttendanceDto> peopleList, Map<Integer, RuleNumDto> ruleNumDtoList, List<LocalDate> dateList) { | |
| 473 | + List<RuleAttendanceMainHelp> helpList = new ArrayList<>(peopleList.size()); | |
| 474 | + LocalDate localDate = dateList.get(0); | |
| 475 | + Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); | |
| 476 | + for (AttendanceDto dto : peopleList) { | |
| 477 | + RuleAttendanceMainHelp help = new RuleAttendanceMainHelp(); | |
| 478 | + BeanUtils.copyProperties(dto, help); | |
| 479 | + help.setDateFlag(date); | |
| 480 | + help.setRuleDictName(ruleNumDtoList.get(dto.getSettingId()).getRuleDictName()); | |
| 481 | + helpList.add(help); | |
| 482 | + } | |
| 483 | + helpService.saveBatch(helpList); | |
| 484 | + } | |
| 485 | + | |
| 271 | 486 | private List<PeopleResponseVo> mainTransformPeopleResponseVo(List<RuleAttendanceMain> mainList) { |
| 272 | 487 | List<PeopleResponseVo> vos = new ArrayList<>(mainList.size()); |
| 273 | 488 | for (RuleAttendanceMain main : mainList) { | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/impl/RuleNumSettingServiceImpl.java
| ... | ... | @@ -89,7 +89,8 @@ public class RuleNumSettingServiceImpl extends ServiceImpl<RuleNumSettingMapper, |
| 89 | 89 | // 获取班次 |
| 90 | 90 | List<RuleNumDto> ruleNumDtoList = ruleNumSettingService.selectRuleNumBySettingId(settingList); |
| 91 | 91 | // 处理规则 |
| 92 | - List<RuleAttendanceMain> attendanceMains = handleAttendanceMain(peopleList, ruleList, ruleNumDtoList); | |
| 92 | + List<LocalDate> dateList = ConstDateUtil.getDateSetFromTheCurrentDayToTheEndOfTheMonth(); | |
| 93 | + List<RuleAttendanceMain> attendanceMains = handleAttendanceMain(peopleList, ruleList, ruleNumDtoList, dateList); | |
| 93 | 94 | attendanceMainService.saveBatch(attendanceMains); |
| 94 | 95 | log.info("排班明细生成完毕"); |
| 95 | 96 | } catch (Exception e) { |
| ... | ... | @@ -111,7 +112,7 @@ public class RuleNumSettingServiceImpl extends ServiceImpl<RuleNumSettingMapper, |
| 111 | 112 | helpService.saveBatch(helpList); |
| 112 | 113 | } |
| 113 | 114 | |
| 114 | - private List<RuleAttendanceMain> handleAttendanceMain(List<AttendanceDto> peopleList, List<RuleSchedulingDto> ruleList, List<RuleNumDto> ruleNumDtoList) { | |
| 115 | + private List<RuleAttendanceMain> handleAttendanceMain(List<AttendanceDto> peopleList, List<RuleSchedulingDto> ruleList, List<RuleNumDto> ruleNumDtoList, List<LocalDate> dateList) { | |
| 115 | 116 | if (CollectionUtil.isEmpty(peopleList)) { |
| 116 | 117 | return null; |
| 117 | 118 | } |
| ... | ... | @@ -119,7 +120,6 @@ public class RuleNumSettingServiceImpl extends ServiceImpl<RuleNumSettingMapper, |
| 119 | 120 | Map<Integer, RuleNumDto> ruleNumMap = transformMapByRuleNum(ruleNumDtoList); |
| 120 | 121 | Map<Integer, List<RuleSchedulingDto>> ruleMap = transformMapByRule(ruleList); |
| 121 | 122 | List<RuleAttendanceMain> ruleAttendanceMainList = new ArrayList<>(); |
| 122 | - List<LocalDate> dateList = ConstDateUtil.getDateSetFromTheCurrentDayToTheEndOfTheMonth(); | |
| 123 | 123 | for (Map.Entry<Integer, List<AttendanceDto>> entry : peopleMap.entrySet()) { |
| 124 | 124 | Integer settingId = entry.getKey(); |
| 125 | 125 | List<AttendanceDto> attendanceDtoList = entry.getValue(); |
| ... | ... | @@ -245,6 +245,7 @@ public class RuleNumSettingServiceImpl extends ServiceImpl<RuleNumSettingMapper, |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * 获取休息rule |
| 248 | + * | |
| 248 | 249 | * @param startDate |
| 249 | 250 | * @return |
| 250 | 251 | */ |
| ... | ... | @@ -333,6 +334,11 @@ public class RuleNumSettingServiceImpl extends ServiceImpl<RuleNumSettingMapper, |
| 333 | 334 | cacheScheduling.putAll(resultMap); |
| 334 | 335 | } |
| 335 | 336 | |
| 337 | + @Override | |
| 338 | + public List<AttendanceDto> getPeopleListByMonth(String month) { | |
| 339 | + return baseMapper.getPeopleListByMonth(month); | |
| 340 | + } | |
| 341 | + | |
| 336 | 342 | private List<DriverScheduling> handleOtherPostsScheduling() { |
| 337 | 343 | QueryWrapper<RuleAttendanceMain> qw = new QueryWrapper<>(); |
| 338 | 344 | qw.lambda() | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/utils/ConstDateUtil.java
| ... | ... | @@ -104,6 +104,29 @@ public class ConstDateUtil { |
| 104 | 104 | return dateList; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | + public static List<LocalDate> getDateSetFromTheCurrentDayToTheEndOfTheMonth(int year,int month){ | |
| 108 | + LocalDate today = LocalDate.of(year,month,1); | |
| 109 | + | |
| 110 | + // 获取本月的最后一天 | |
| 111 | + LocalDate endDay; | |
| 112 | + if (month == 12) { | |
| 113 | + endDay = LocalDate.of(year, month, 31); | |
| 114 | + } else { | |
| 115 | + endDay = LocalDate.of(year, month + 1, 1).minusDays(1); | |
| 116 | + } | |
| 117 | + | |
| 118 | + // 生成日期列表 | |
| 119 | + List<LocalDate> dateList = new ArrayList<>(); | |
| 120 | + LocalDate currentDay = today; | |
| 121 | + while (!currentDay.isAfter(endDay)) { | |
| 122 | + dateList.add(currentDay); | |
| 123 | + currentDay = currentDay.plusDays(1); | |
| 124 | + } | |
| 125 | + | |
| 126 | + return dateList; | |
| 127 | + } | |
| 128 | + | |
| 129 | + | |
| 107 | 130 | /** |
| 108 | 131 | * 获取指定月份所有日期 |
| 109 | 132 | */ | ... | ... |
Bsth-admin/src/main/resources/mapper/RuleNumSettingMapper.xml
| ... | ... | @@ -87,7 +87,29 @@ |
| 87 | 87 | FROM |
| 88 | 88 | rule_attendance_main |
| 89 | 89 | WHERE |
| 90 | - DATE_FORMAT( scheduling_date, '%y-%m' ) = DATE_FORMAT( NOW(), '%y-%m' ) | |
| 90 | + DATE_FORMAT( scheduling_date, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' ) | |
| 91 | + ) | |
| 92 | + </select> | |
| 93 | + <select id="getPeopleListByMonth" resultType="com.ruoyi.pojo.dto.AttendanceDto" resultMap="AttendanceResult"> | |
| 94 | + SELECT | |
| 95 | + driver.job_code, | |
| 96 | + driver.personnel_name, | |
| 97 | + driver.fleet_name, | |
| 98 | + driver.posts, | |
| 99 | + rule_setting_driver.setting_id, | |
| 100 | + rule_setting_driver.start_date | |
| 101 | + FROM | |
| 102 | + driver, | |
| 103 | + rule_setting_driver | |
| 104 | + WHERE | |
| 105 | + driver.job_code = rule_setting_driver.job_code | |
| 106 | + AND rule_setting_driver.job_code NOT IN ( | |
| 107 | + SELECT DISTINCT | |
| 108 | + job_code | |
| 109 | + FROM | |
| 110 | + rule_attendance_main | |
| 111 | + WHERE | |
| 112 | + DATE_FORMAT( scheduling_date, '%Y-%m' ) = #{month} | |
| 91 | 113 | ) |
| 92 | 114 | </select> |
| 93 | 115 | ... | ... |