From b755b53c5aee731616edc0bb68956081ef99f0ee Mon Sep 17 00:00:00 2001 From: aikai Date: Wed, 18 Dec 2024 14:34:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(attendance):=20=E5=A2=9E=E5=8A=A0=E8=80=83?= =?UTF-8?q?=E5=8B=A4=E7=89=B9=E6=AE=8A=E6=97=A5=E6=9C=9F=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=9B=BA=E5=AE=9A=E7=8F=AD=E5=88=B6?= =?UTF-8?q?=E8=80=83=E5=8B=A4=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增考勤特殊日期相关接口和实现类 - 优化固定班制考勤设置批量更新逻辑- 增加特殊日期处理逻辑,支持必打卡和无需打卡日期 - 调整考勤信息查询接口,支持特殊日期查询 --- .../system/enums/ErrorCodeConstants.java | 1 + .../fixed/AttendanceFixedController.java | 21 ++- .../admin/fixed/dto/AttendanceFixedDTO.java | 18 ++ .../admin/fixed/vo/AttendanceFixedRespVO.java | 3 +- .../AttendanceSpecialDO.java | 13 +- .../attendance/fixed/AttendanceFixedDO.java | 9 +- .../AttendanceSpecialService.java | 49 ++++++ .../AttendanceSpecialServiceImpl.java | 70 ++++++++ .../fixed/AttendanceFixedService.java | 11 +- .../fixed/AttendanceFixedServiceImpl.java | 159 +++++++++++++----- 10 files changed, 293 insertions(+), 61 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/dto/AttendanceFixedDTO.java diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 8befb466..155dc463 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -209,6 +209,7 @@ public interface ErrorCodeConstants { ErrorCode INSUFFICIENT_NUMBER_OF_CARD_REFILLS = new ErrorCode(1_003_016_000, "补卡次数不足"); ErrorCode ABNORMAL_CARD_REPLENISHMENT = new ErrorCode(1_003_017_000, "补卡异常"); ErrorCode CANNOT_FIND_THE_RECORD_THAT_NEEDS_TO_BE_REPLACED = new ErrorCode(1_003_018_000, "查询不到需要补卡的记录"); + ErrorCode THERE_ARE_DUPLICATE_SPECIAL_DATES = new ErrorCode(1_003_019_000, "存在重复的特殊日期,请检查!"); ErrorCode LOG_FORM_NOT_USE = new ErrorCode(1_009_010_004, "你不能使用该日志模板"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/AttendanceFixedController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/AttendanceFixedController.java index b7f4596b..0b375458 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/AttendanceFixedController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/AttendanceFixedController.java @@ -6,10 +6,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.system.controller.admin.fixed.dto.AttendanceFixedDTO; import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedRespVO; -import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedSaveReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.fixed.AttendanceFixedDO; +import cn.iocoder.yudao.module.system.service.attendance.attendancespecial.AttendanceSpecialService; import cn.iocoder.yudao.module.system.service.attendance.fixed.AttendanceFixedService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -35,13 +37,14 @@ public class AttendanceFixedController { @Resource private AttendanceFixedService fixedService; + @Resource + private AttendanceSpecialService attendanceSpecialService; @PostMapping("/batchCreateOrUpdate") @Operation(summary = "批量新增修改固定班制考勤设置") @PreAuthorize("@ss.hasPermission('attendance:fixed:create')") - public CommonResult batchCreateOrUpdate(@RequestParam Long attendanceGroupId, - @Valid @RequestBody List vos) { - Long groupId = fixedService.batchCreateOrUpdate(attendanceGroupId, vos); + public CommonResult batchCreateOrUpdate(@RequestBody AttendanceFixedDTO dto) { + Long groupId = fixedService.batchCreateOrUpdate(dto.getAttendanceGroupId(), dto.getVos(), dto.getSpecialDOS()); return success(groupId); } @@ -58,6 +61,14 @@ public class AttendanceFixedController { return success(BeanUtils.toBean(fixed, AttendanceFixedRespVO.class)); } + + @GetMapping("/getAttendanceSpecialByGroupId") + @Operation(summary = "获取特殊日期列表") + public CommonResult> getAttendanceSpecialByGroupId(@RequestParam("id") Long id) { + List list = attendanceSpecialService.getByGroupId(id); + return success(list); + } + @GetMapping("/getListByGroupId") @Operation(summary = "根据考勤组ID获得固定班制考勤设置列表") public CommonResult> getListByGroupId(@RequestParam Long attendanceGroupId) { @@ -86,4 +97,4 @@ public class AttendanceFixedController { BeanUtils.toBean(list, AttendanceFixedRespVO.class)); } -} \ No newline at end of file +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/dto/AttendanceFixedDTO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/dto/AttendanceFixedDTO.java new file mode 100644 index 00000000..377b7707 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/dto/AttendanceFixedDTO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.system.controller.admin.fixed.dto; + +import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedSaveReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Data +public class AttendanceFixedDTO { + @Schema(description = "考勤组id", example = "19908") + private Long attendanceGroupId; + @Schema(description = "固定班制考勤设置", example = "19908") + private List vos; + @Schema(description = "考勤特殊日期设置", example = "19908") + private List specialDOS; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/vo/AttendanceFixedRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/vo/AttendanceFixedRespVO.java index 1b2050d6..271aba77 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/vo/AttendanceFixedRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/fixed/vo/AttendanceFixedRespVO.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.controller.admin.fixed.vo; -import cn.iocoder.yudao.module.system.controller.admin.groupshift.vo.AttendanceGroupShiftRespVO; import cn.iocoder.yudao.module.system.controller.admin.groupshift.vo.AttendanceGroupShiftVO; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; @@ -38,4 +37,4 @@ public class AttendanceFixedRespVO { @ExcelProperty("班次对象") private AttendanceGroupShiftVO shiftVO; -} \ No newline at end of file +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/attendancespecial/AttendanceSpecialDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/attendancespecial/AttendanceSpecialDO.java index e7340f55..2b9a00c5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/attendancespecial/AttendanceSpecialDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/attendancespecial/AttendanceSpecialDO.java @@ -1,11 +1,10 @@ package cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial; -import lombok.*; -import java.util.*; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.*; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; /** * 考勤特殊日期 DO @@ -44,4 +43,8 @@ public class AttendanceSpecialDO extends BaseDO { */ private String dateTime; + /** + * 提示 + */ + private String tips; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/fixed/AttendanceFixedDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/fixed/AttendanceFixedDO.java index 086c5de6..763d9004 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/fixed/AttendanceFixedDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/attendance/fixed/AttendanceFixedDO.java @@ -1,11 +1,8 @@ package cn.iocoder.yudao.module.system.dal.dataobject.attendance.fixed; -import lombok.*; -import java.util.*; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.*; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.*; +import lombok.*; /** * 固定班制考勤设置 DO @@ -41,4 +38,4 @@ public class AttendanceFixedDO extends BaseDO { @TableField(updateStrategy = FieldStrategy.IGNORED) private Long attendanceGroupShiftId; -} \ No newline at end of file +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialService.java index f57fbcec..af9af2e5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialService.java @@ -1,10 +1,59 @@ package cn.iocoder.yudao.module.system.service.attendance.attendancespecial; +import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO; + +import java.util.List; + /** * 考勤特殊日期 Service 接口 * * @author 艾楷 */ public interface AttendanceSpecialService { + /** + * 根据条件搜索 + * + * @param groupId + * @param time + * @param type + * @return + */ + AttendanceSpecialDO getByGroupIdAndTimeAndType(Long groupId, String time, int type); + /** + * 根据条件搜索 + * + * @param groupId + * @param time + * @return + */ + List getByGroupIdAndTime(Long groupId, String time); + + /** + * @param groupIds + * @param time + * @return + */ + List getByGroupIdsAndTime(List groupIds, String time); + + /** + * @param groupId + * @param times + * @return + */ + List getByGroupIdAndTimes(Long groupId, List times); + + /** + * @param attendanceGroupId + * @return + */ + List getByGroupId(Long attendanceGroupId); + + /** + * 批处理 + * + * @param attendanceGroupId + * @param attendanceSpecialList + */ + void insertUpdateDeleteBatch(Long attendanceGroupId, List> attendanceSpecialList); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialServiceImpl.java index d87f0968..0f5ee521 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/attendancespecial/AttendanceSpecialServiceImpl.java @@ -1,8 +1,18 @@ package cn.iocoder.yudao.module.system.service.attendance.attendancespecial; +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO; +import cn.iocoder.yudao.module.system.dal.mysql.attendance.attendancespecial.AttendanceSpecialMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + /** * 考勤特殊日期 Service 实现类 * @@ -11,5 +21,65 @@ import org.springframework.validation.annotation.Validated; @Service @Validated public class AttendanceSpecialServiceImpl implements AttendanceSpecialService { + @Resource + private AttendanceSpecialMapper attendanceSpecialMapper; + @Override + public AttendanceSpecialDO getByGroupIdAndTimeAndType(Long groupId, String time, int type) { + List attendanceSpecialDOS = attendanceSpecialMapper.selectList(new LambdaQueryWrapper() + .eq(AttendanceSpecialDO::getAttendanceGroupId, groupId) + .eq(AttendanceSpecialDO::getDateTime, time) + .eq(AttendanceSpecialDO::getType, type)); + if (CollUtil.isNotEmpty(attendanceSpecialDOS)) { + return attendanceSpecialDOS.get(0); + } + return null; + } + + @Override + public List getByGroupIdAndTime(Long groupId, String time) { + return attendanceSpecialMapper.selectList(new LambdaQueryWrapper() + .eq(AttendanceSpecialDO::getAttendanceGroupId, groupId) + .eq(AttendanceSpecialDO::getDateTime, time)); + } + + @Override + public List getByGroupIdsAndTime(List groupIds, String time) { + if (CollUtil.isEmpty(groupIds)) { + return Collections.emptyList(); + } + return attendanceSpecialMapper.selectList(new LambdaQueryWrapper() + .in(AttendanceSpecialDO::getAttendanceGroupId, groupIds) + .eq(AttendanceSpecialDO::getDateTime, time)); + } + + @Override + public List getByGroupIdAndTimes(Long groupId, List times) { + if (CollUtil.isEmpty(times)) { + return Collections.emptyList(); + } + return attendanceSpecialMapper.selectList(new LambdaQueryWrapper() + .eq(AttendanceSpecialDO::getAttendanceGroupId, groupId) + .in(AttendanceSpecialDO::getDateTime, times)); + } + + @Override + public List getByGroupId(Long attendanceGroupId) { + return attendanceSpecialMapper.selectList(new LambdaQueryWrapper() + .eq(AttendanceSpecialDO::getAttendanceGroupId, attendanceGroupId)); + } + + @Override + public void insertUpdateDeleteBatch(Long attendanceGroupId, List> attendanceSpecialList) { + if (CollUtil.isNotEmpty(attendanceSpecialList.get(0))) { + attendanceSpecialList.get(0).forEach(a -> a.setAttendanceGroupId(attendanceGroupId)); + attendanceSpecialMapper.insertBatch(attendanceSpecialList.get(0)); + } + if (CollUtil.isNotEmpty(attendanceSpecialList.get(1))) { + attendanceSpecialMapper.updateBatch(attendanceSpecialList.get(1)); + } + if (CollUtil.isNotEmpty(attendanceSpecialList.get(2))) { + attendanceSpecialMapper.deleteBatchIds(convertList(attendanceSpecialList.get(2), AttendanceSpecialDO::getId)); + } + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedService.java index 49e4267c..b0560772 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedService.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedRespVO; import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedSaveReqVO; -import cn.iocoder.yudao.module.system.controller.admin.groupuser.vo.AttendanceGroupUserCreateOrDelVO; +import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.fixed.AttendanceFixedDO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.group.AttendanceGroupDO; @@ -23,10 +23,11 @@ public interface AttendanceFixedService { /** * 创建固定班制考勤设置 * - * @param vos 创建信息 + * @param vos 创建信息 + * @param specialDOS * @return 编号 */ - Long batchCreateOrUpdate(Long attendanceGroupId, @Valid List vos); + Long batchCreateOrUpdate(Long attendanceGroupId, List vos, List specialDOS); /** * 更新固定班制考勤设置 @@ -67,6 +68,8 @@ public interface AttendanceFixedService { */ AttendanceFixedDO getByGroupIdAndWeek(Long attendanceGroupId, Integer week); + List getByGroupIdAndWeeks(Long attendanceGroupId, List weeks); + List getByGroupId(Long attendanceGroupId); List getByGroupIdAndWeek(List attendanceGroupIds, Integer week); @@ -95,4 +98,4 @@ public interface AttendanceFixedService { * @return */ List getUseGroupIds(Long shiftId); -} \ No newline at end of file +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedServiceImpl.java index 740f4c20..c0fe8728 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/fixed/AttendanceFixedServiceImpl.java @@ -4,8 +4,10 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.Constants; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.attendance.dto.AttendanceTimeRangeInfoDTO; @@ -18,11 +20,13 @@ import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedP import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedRespVO; import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedSaveReqVO; import cn.iocoder.yudao.module.system.controller.admin.groupshift.vo.AttendanceGroupShiftVO; +import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.fixed.AttendanceFixedDO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.group.AttendanceGroupDO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.groupshiftitem.AttendanceGroupShiftItemDO; import cn.iocoder.yudao.module.system.dal.mysql.attendance.fixed.AttendanceFixedMapper; import cn.iocoder.yudao.module.system.service.attendance.AttendanceService; +import cn.iocoder.yudao.module.system.service.attendance.attendancespecial.AttendanceSpecialService; import cn.iocoder.yudao.module.system.service.attendance.groupshift.AttendanceGroupShiftService; import cn.iocoder.yudao.module.system.service.attendance.groupshiftitem.AttendanceGroupShiftItemService; import cn.iocoder.yudao.module.system.service.attendance.punch.PunchService; @@ -40,6 +44,7 @@ import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.FIXED_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.THERE_ARE_DUPLICATE_SPECIAL_DATES; /** * 固定班制考勤设置 Service 实现类 @@ -59,10 +64,12 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch private AttendanceGroupShiftService attendanceGroupShiftService; @Resource private AttendanceGroupShiftItemService attendanceGroupShiftItemService; + @Resource + private AttendanceSpecialService attendanceSpecialService; @Override @Transactional(rollbackFor = Exception.class) - public Long batchCreateOrUpdate(Long attendanceGroupId, List vos) { + public Long batchCreateOrUpdate(Long attendanceGroupId, List vos, List specialDOS) { Long groupId = null; // 插入 List oldList = attendanceFixedMapper.selectList(new LambdaQueryWrapper() @@ -105,6 +112,22 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch attendanceFixedMapper.deleteBatchIds(delIds); } } + // - - - - - - - - - 特殊考勤日期 - - - - - - - - + if (CollUtil.isEmpty(specialDOS)) { + specialDOS = Collections.emptyList(); + } + // -- 验证是否有同一天的数据 如果有则返回提醒 + Map> map = specialDOS.stream().collect(Collectors.groupingBy(AttendanceSpecialDO::getDateTime)); + for (Map.Entry> entry : map.entrySet()) { + if (entry.getValue().size() > 1) { + throw exception(THERE_ARE_DUPLICATE_SPECIAL_DATES); + } + } + //查询旧的 + List oldAttendanceSpecialDOS = attendanceSpecialService.getByGroupId(attendanceGroupId); + List> attendanceSpecialList = CollectionUtils.diffList(oldAttendanceSpecialDOS, specialDOS, + (saveVal, newVal) -> ObjectUtil.equal(saveVal.getId(), newVal.getId())); + attendanceSpecialService.insertUpdateDeleteBatch(attendanceGroupId, attendanceSpecialList); return groupId; } @@ -152,6 +175,13 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch return null; } + @Override + public List getByGroupIdAndWeeks(Long attendanceGroupId, List weeks) { + return attendanceFixedMapper.selectList(new LambdaQueryWrapper() + .eq(attendanceGroupId != null, AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId) + .in(CollUtil.isNotEmpty(weeks), AttendanceFixedDO::getWeekTime, weeks)); + } + @Override public List getByGroupId(Long attendanceGroupId) { return attendanceFixedMapper.selectList(new LambdaQueryWrapper() @@ -176,7 +206,23 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch List makeUpClassList = this.getByGroupIdAndWeek(groupIds, 8); Map> makeUpClassListMap = makeUpClassList.stream().collect(Collectors.groupingBy(AttendanceFixedDO::getAttendanceGroupId)); Map> attendanceFixedMap = attendanceFixedDOS.stream().collect(Collectors.groupingBy(AttendanceFixedDO::getAttendanceGroupId)); + // -- 这里是考勤预设 - 不需要把加班的考勤规则考虑在内 - 需要考虑 必须打卡时间 - 和非必须打卡时间即可 + List specialDOS = attendanceSpecialService.getByGroupIdsAndTime(groupIds, localDateTime.format(Constants.REPO_DATE_FORMAT)); + Map specialMap = specialDOS.stream().collect(Collectors.toMap(a -> a.getAttendanceGroupId() + "_" + a.getType(), a -> a)); for (AttendanceGroupDO activationGroup : fixedList) { + AttendanceSpecialDO mustClockInTime = specialMap.get(activationGroup.getId() + "_" + 1); + // -- 判断是否有必须打卡时间 - 如果有的话直接摄入进去即可 + if (mustClockInTime != null && mustClockInTime.getAttendanceGroupShiftId() != null) { + map.put(activationGroup.getId(), mustClockInTime.getAttendanceGroupShiftId()); + continue; + } + + // -- 判断是否有无需打卡时间 - 如果有的话直接返回 --- 无需打卡 直接返回结果 + AttendanceSpecialDO noNeedToClockIn = specialMap.get(activationGroup.getId() + "_" + 0); + if (noNeedToClockIn != null) { + continue; + } + // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来 Boolean isHolidayFlag = Constants.TRUE.equals(activationGroup.getAutoHolidaysFlag()) ? attendanceService.isHoliday(localDateTime) : null; @@ -233,29 +279,47 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch AttendancePunchPageVO vo = new AttendancePunchPageVO(); vo.setActivationGroup(dto.getActivationGroup()); AttendanceGroupDO activationGroup = dto.getActivationGroup(); - // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来 - Boolean isHolidayFlag = Constants.TRUE.equals(activationGroup.getAutoHolidaysFlag()) ? - attendanceService.isHoliday(dto.getLocalDateTime()) : null; - // -- 先判断当前是否是节假日放假的日子 - 如果是的话 设为 -1 查询加班加班班次 如果不是的话 判断当前是否是补班 如果是的话设为8 为补班日 - 最后获取当前是周几(后续判断这个周几是否是有班次 - 没有的话再查询下 -1 是否有加班班次) - int week = isHolidayFlag != null && isHolidayFlag ? -1 : (isHolidayFlag != null ? 8 : dto.getLocalDateTime().getDayOfWeek().getValue()); - AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), week); - // -- 当前没有班次 - 不需要考勤 - if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { - // -- 再获取一次加班班次 - 判断下是否有加班日 没有的话直接返回 - if (week != -1) { - attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), -1); - if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { - return vo.setTodayNeedAttendance(Constants.FALSE); - } else { - vo.setWorkOvertimeFlag(Constants.ONE); - } - } else { + Long attendanceGroupShiftId = null; + // todo aiKai 获取特殊打卡日期 - 判断是否有存在 - 如果有的话 - 则按照必打卡日期所设置的班次返回 - 如果没有的话再 去 判断其他 + List specialDOS = attendanceSpecialService.getByGroupIdAndTime(activationGroup.getId(), dto.getLocalDateTime().format(Constants.REPO_DATE_FORMAT)); + Map map = specialDOS.stream().collect(Collectors.toMap(AttendanceSpecialDO::getType, a -> a)); + if (map.get(1) != null && map.get(1).getAttendanceGroupShiftId() != null) { + attendanceGroupShiftId = map.get(1).getAttendanceGroupShiftId(); + } else if (map.get(0) != null) { + // 当前为 不需要打卡时间 - 判断是否有加班班次 - 如果没有的话 直接跳过 + AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), -1); + if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { return vo.setTodayNeedAttendance(Constants.FALSE); + } else { + vo.setWorkOvertimeFlag(Constants.ONE); + attendanceGroupShiftId = attendanceFixedDO.getAttendanceGroupShiftId(); } - } else if (week == -1) { - vo.setWorkOvertimeFlag(Constants.ONE); + } else { + // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来 + Boolean isHolidayFlag = Constants.TRUE.equals(activationGroup.getAutoHolidaysFlag()) ? + attendanceService.isHoliday(dto.getLocalDateTime()) : null; + // -- 先判断当前是否是节假日放假的日子 - 如果是的话 设为 -1 查询加班加班班次 如果不是的话 判断当前是否是补班 如果是的话设为8 为补班日 - 最后获取当前是周几(后续判断这个周几是否是有班次 - 没有的话再查询下 -1 是否有加班班次) + int week = isHolidayFlag != null && isHolidayFlag ? -1 : (isHolidayFlag != null ? 8 : dto.getLocalDateTime().getDayOfWeek().getValue()); + AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), week); + // -- 当前没有班次 - 不需要考勤 + if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { + // -- 再获取一次加班班次 - 判断下是否有加班日 没有的话直接返回 + if (week != -1) { + attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), -1); + if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { + return vo.setTodayNeedAttendance(Constants.FALSE); + } else { + vo.setWorkOvertimeFlag(Constants.ONE); + } + } else { + return vo.setTodayNeedAttendance(Constants.FALSE); + } + } else if (week == -1) { + vo.setWorkOvertimeFlag(Constants.ONE); + } + attendanceGroupShiftId = attendanceFixedDO.getAttendanceGroupShiftId(); } - vo.setAttendanceGroupShiftId(attendanceFixedDO.getAttendanceGroupShiftId()); + vo.setAttendanceGroupShiftId(attendanceGroupShiftId); attendanceService.calculatePunch(dto, vo); vo.setAttendanceGroupId(activationGroup.getId()); vo.setUser(dto.getUser()); @@ -300,30 +364,47 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch @Override public Map getAttendanceInfoByTimeRange(AttendanceTimeRangeInfoDTO dto) { Map map = new HashMap<>(); + List attendanceSpecials = attendanceSpecialService.getByGroupIdAndTimes(dto.getGroupId(), dto.getTimes()); + Map specialDOMap = attendanceSpecials.stream().collect(Collectors.toMap(a -> a.getDateTime() + "_" + a.getType(), a -> a)); //不在考勤组 for (String time : dto.getTimes()) { AttendanceTimeRangeInfoVO attendanceTimeRangeInfoVO = new AttendanceTimeRangeInfoVO(); - // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来 - LocalDateTime localDateTime = LocalDateTimeUtil.parseDate(time, Constants.REPO_DATE_FORMAT).atStartOfDay(); - Boolean holiday = attendanceService.isHoliday(localDateTime); - // -- 如果是节假日的话先插入下是节假日 - 不管上不上班 - Boolean isHolidayFlag = Constants.TRUE.equals(dto.getAutoHolidaysFlag()) ? - holiday : null; - attendanceTimeRangeInfoVO.setDatType(isHolidayFlag != null && isHolidayFlag ? Constants.THREE : Constants.ONE); - // -- 当前是节假日 并且是放假 - if (isHolidayFlag != null && isHolidayFlag) { - map.put(time, attendanceTimeRangeInfoVO); - continue; - } - //获取到当天是周几 - 如果是节假日补班的话 - 班次日期就是8 - int week = isHolidayFlag != null ? 8 : localDateTime.getDayOfWeek().getValue(); - AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(dto.getGroupId(), week); - // -- 当前没有班次 - 不需要考勤 - if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { + Long attendanceGroupShiftId = null; + // -- 判断是否有必须打卡时间 - 如果有的话直接摄入进去即可 + AttendanceSpecialDO mustClockInTime = specialDOMap.get(time + "_" + 1); + // -- 判断是否有无需打卡时间 - 如果有的话直接返回 --- 无需打卡 直接返回结果 + AttendanceSpecialDO noNeedToClockIn = specialDOMap.get(time + "_" + 0); + if (mustClockInTime != null && mustClockInTime.getAttendanceGroupShiftId() != null) { + attendanceGroupShiftId = mustClockInTime.getAttendanceGroupShiftId(); + map.put(time, attendanceTimeRangeInfoVO.setDatType(Constants.ONE)); + } else if (noNeedToClockIn != null) { map.put(time, attendanceTimeRangeInfoVO.setDatType(Constants.TWO)); continue; + } else { + // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来 + LocalDateTime localDateTime = LocalDateTimeUtil.parseDate(time, Constants.REPO_DATE_FORMAT).atStartOfDay(); + Boolean holiday = attendanceService.isHoliday(localDateTime); + // -- 如果是节假日的话先插入下是节假日 - 不管上不上班 + Boolean isHolidayFlag = Constants.TRUE.equals(dto.getAutoHolidaysFlag()) ? + holiday : null; + attendanceTimeRangeInfoVO.setDatType(isHolidayFlag != null && isHolidayFlag ? Constants.THREE : Constants.ONE); + // -- 当前是节假日 并且是放假 + if (isHolidayFlag != null && isHolidayFlag) { + map.put(time, attendanceTimeRangeInfoVO); + continue; + } + //获取到当天是周几 - 如果是节假日补班的话 - 班次日期就是8 + int week = isHolidayFlag != null ? 8 : localDateTime.getDayOfWeek().getValue(); + AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(dto.getGroupId(), week); + // -- 当前没有班次 - 不需要考勤 + if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) { + map.put(time, attendanceTimeRangeInfoVO.setDatType(Constants.TWO)); + continue; + } + attendanceGroupShiftId = attendanceFixedDO.getAttendanceGroupShiftId(); } - List attendanceGroupShiftItemDOList = attendanceGroupShiftItemService.getGroupShiftItemListByShiftId(attendanceFixedDO.getAttendanceGroupShiftId()); + // - 如果当前有班次 - 但是又不是需要打卡的时间 - 那么看有没有加班班次 - 有的话按照加班班次来 - 没有的话设为不需要打卡 - 解决单双休场景 + List attendanceGroupShiftItemDOList = attendanceGroupShiftItemService.getGroupShiftItemListByShiftId(attendanceGroupShiftId); if (CollectionUtil.isNotEmpty(attendanceGroupShiftItemDOList)) { List items = BeanUtil.copyToList(attendanceGroupShiftItemDOList, AttendanceGroupShiftItemVO.class); map.put(time, attendanceTimeRangeInfoVO.setNeedAttendance(1).setItems(items));