From 08d6b5644996e2251dea79f0a29316e70b244903 Mon Sep 17 00:00:00 2001 From: aikai Date: Fri, 24 May 2024 11:11:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E7=8F=AD=E6=AC=A1=E5=92=8C?= =?UTF-8?q?=E6=8E=92=E7=8F=AD=E7=8F=AD=E6=AC=A1=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixed/AttendanceFixedController.java | 70 +++++++------------ .../AttendanceSchedulingController.java | 70 +++++++------------ .../attendance/AttendanceStatisticsJob.java | 18 ++++- .../attendance/AttendanceServiceImpl.java | 2 + .../fixed/AttendanceFixedService.java | 4 +- .../fixed/AttendanceFixedServiceImpl.java | 31 ++++++-- .../punch/dto/AttendanceOnTheDayDTO.java | 3 + .../AttendanceSchedulingService.java | 5 +- .../AttendanceSchedulingServiceImpl.java | 36 ++++++++-- 9 files changed, 135 insertions(+), 104 deletions(-) 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 aecfc695..916a95ef 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 @@ -1,32 +1,31 @@ package cn.iocoder.yudao.module.system.controller.admin.fixed; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.*; +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.fixed.AttendanceFixedDO; import cn.iocoder.yudao.module.system.service.attendance.fixed.AttendanceFixedService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Tag(name = "管理后台 - 固定班制考勤设置") @RestController @@ -37,28 +36,13 @@ public class AttendanceFixedController { @Resource private AttendanceFixedService fixedService; - @PostMapping("/create") - @Operation(summary = "创建固定班制考勤设置") + @PostMapping("/batchCreateOrUpdate") + @Operation(summary = "批量新增修改固定班制考勤设置") @PreAuthorize("@ss.hasPermission('attendance:fixed:create')") - public CommonResult createFixed(@Valid @RequestBody AttendanceFixedSaveReqVO createReqVO) { - return success(fixedService.createFixed(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新固定班制考勤设置") - @PreAuthorize("@ss.hasPermission('attendance:fixed:update')") - public CommonResult updateFixed(@Valid @RequestBody AttendanceFixedSaveReqVO updateReqVO) { - fixedService.updateFixed(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除固定班制考勤设置") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('attendance:fixed:delete')") - public CommonResult deleteFixed(@RequestParam("id") Long id) { - fixedService.deleteFixed(id); - return success(true); + public CommonResult batchCreateOrUpdate(@RequestParam Long attendanceGroupId, + @Valid @RequestBody List vos) { + fixedService.batchCreateOrUpdate(attendanceGroupId, vos); + return success("ok"); } @GetMapping("/get") @@ -83,12 +67,12 @@ public class AttendanceFixedController { @PreAuthorize("@ss.hasPermission('attendance:fixed:export')") @OperateLog(type = EXPORT) public void exportFixedExcel(@Valid AttendanceFixedPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = fixedService.getFixedPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "固定班制考勤设置.xls", "数据", AttendanceFixedRespVO.class, - BeanUtils.toBean(list, AttendanceFixedRespVO.class)); + 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/scheduling/AttendanceSchedulingController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/scheduling/AttendanceSchedulingController.java index 6e0d34cc..bf6027de 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/scheduling/AttendanceSchedulingController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/scheduling/AttendanceSchedulingController.java @@ -1,32 +1,31 @@ package cn.iocoder.yudao.module.system.controller.admin.scheduling; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.system.controller.admin.scheduling.vo.*; +import cn.iocoder.yudao.module.system.controller.admin.scheduling.vo.AttendanceSchedulingPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.scheduling.vo.AttendanceSchedulingRespVO; +import cn.iocoder.yudao.module.system.controller.admin.scheduling.vo.AttendanceSchedulingSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.attendance.scheduling.AttendanceSchedulingDO; import cn.iocoder.yudao.module.system.service.attendance.scheduling.AttendanceSchedulingService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Tag(name = "管理后台 - 排班制考勤设置") @RestController @@ -37,28 +36,13 @@ public class AttendanceSchedulingController { @Resource private AttendanceSchedulingService schedulingService; - @PostMapping("/create") - @Operation(summary = "创建排班制考勤设置") + @PostMapping("/batchCreateOrUpdate") + @Operation(summary = "批量新增修改排班制考勤设置") @PreAuthorize("@ss.hasPermission('attendance:scheduling:create')") - public CommonResult createScheduling(@Valid @RequestBody AttendanceSchedulingSaveReqVO createReqVO) { - return success(schedulingService.createScheduling(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新排班制考勤设置") - @PreAuthorize("@ss.hasPermission('attendance:scheduling:update')") - public CommonResult updateScheduling(@Valid @RequestBody AttendanceSchedulingSaveReqVO updateReqVO) { - schedulingService.updateScheduling(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除排班制考勤设置") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('attendance:scheduling:delete')") - public CommonResult deleteScheduling(@RequestParam("id") Long id) { - schedulingService.deleteScheduling(id); - return success(true); + public CommonResult batchCreateOrUpdate(@RequestParam Long attendanceGroupId, + @Valid @RequestBody List createReqVO) { + schedulingService.batchCreateOrUpdate(attendanceGroupId, createReqVO); + return success("ok"); } @GetMapping("/get") @@ -83,12 +67,12 @@ public class AttendanceSchedulingController { @PreAuthorize("@ss.hasPermission('attendance:scheduling:export')") @OperateLog(type = EXPORT) public void exportSchedulingExcel(@Valid AttendanceSchedulingPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = schedulingService.getSchedulingPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "排班制考勤设置.xls", "数据", AttendanceSchedulingRespVO.class, - BeanUtils.toBean(list, AttendanceSchedulingRespVO.class)); + BeanUtils.toBean(list, AttendanceSchedulingRespVO.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/job/attendance/AttendanceStatisticsJob.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/attendance/AttendanceStatisticsJob.java index b0144640..d9311744 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/attendance/AttendanceStatisticsJob.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/attendance/AttendanceStatisticsJob.java @@ -75,21 +75,33 @@ public class AttendanceStatisticsJob { LocalDateTime tomorrowLocalDateTime = LocalDateTimeUtil.offset(LocalDateTime.now(), 1, ChronoUnit.DAYS); // 获取到考勤组 - 班次 key/value 格式 Map map = this.getAttendanceGroupShiftIdGroupByGroup(attendanceGroupDOS, tomorrowLocalDateTime); - + Map groupMap = attendanceGroupDOS.stream().collect(Collectors.toMap(AttendanceGroupDO::getId, v -> v)); // -- 获取班次子表列表 if (MapUtil.isNotEmpty(map)) { List attendanceGroupShiftItemDOList = attendanceGroupShiftItemService.getGroupShiftItemListByShiftIds(new ArrayList<>(map.values())); Map> itemMaps = attendanceGroupShiftItemDOList.stream().collect(Collectors.groupingBy(AttendanceGroupShiftItemDO::getKqAttendanceGroupShiftId)); + List attendancePunchRecordDOList = new ArrayList<>(); for (Map.Entry entry : map.entrySet()) { + AttendanceGroupDO attendanceGroupDO = groupMap.get(entry.getKey()); List userIds = groupUserMap.get(entry.getKey()); // List attendanceGroupShiftItemDOS = itemMaps.get(entry.getValue()); List attendanceOnTheDayDTOS = attendanceService.buildAttendanceOnTheDay(attendanceGroupShiftItemDOS); for (Long userId : userIds) { + for (AttendanceOnTheDayDTO attendanceOnTheDayDTO : attendanceOnTheDayDTOS) { + AttendancePunchRecordDO attendancePunchRecordDO = new AttendancePunchRecordDO(); + attendancePunchRecordDO.setUserId(userId); + attendancePunchRecordDO.setAttendanceGroupId(entry.getKey()); + attendancePunchRecordDO.setAttendanceGroupShiftId(attendanceOnTheDayDTO.getKqAttendanceGroupShiftId()); + attendancePunchRecordDO.setAttendanceGroupShiftItemId(attendanceOnTheDayDTO.getId()); + attendancePunchRecordDO.setType(attendanceGroupDO.getType()); + attendancePunchRecordDO.setPunchType(attendanceGroupDO.getPunchType()); + attendancePunchRecordDO.setWorkType(attendanceOnTheDayDTO.getType()); + attendancePunchRecordDO.setLevel(attendanceOnTheDayDTO.getLevel()); + attendancePunchRecordDOList.add(attendancePunchRecordDO); + } - AttendancePunchRecordDO attendancePunchRecordDO = new AttendancePunchRecordDO(); - attendancePunchRecordDO.setUserId(userId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java index 5eb53371..11be1539 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java @@ -346,6 +346,7 @@ public class AttendanceServiceImpl implements AttendanceService { for (AttendanceGroupShiftItemDO attendanceGroupShiftItemDO : attendanceGroupShiftItemDOList) { AttendanceOnTheDayDTO dto = new AttendanceOnTheDayDTO(); dto.setId(attendanceGroupShiftItemDO.getId()); + dto.setKqAttendanceGroupShiftId(attendanceGroupShiftItemDO.getKqAttendanceGroupShiftId()); dto.setTime(attendanceGroupShiftItemDO.getBeginTime()); dto.setPunchTime(StringUtils.EMPTY); dto.setType(UP_WORK); @@ -358,6 +359,7 @@ public class AttendanceServiceImpl implements AttendanceService { dto = new AttendanceOnTheDayDTO(); dto.setId(attendanceGroupShiftItemDO.getId()); + dto.setKqAttendanceGroupShiftId(attendanceGroupShiftItemDO.getKqAttendanceGroupShiftId()); dto.setTime(attendanceGroupShiftItemDO.getEndTime()); dto.setPunchTime(StringUtils.EMPTY); dto.setType(DOWN_WORK); 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 93a2cc27..6f5cd13e 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 @@ -21,10 +21,10 @@ public interface AttendanceFixedService { /** * 创建固定班制考勤设置 * - * @param createReqVO 创建信息 + * @param vos 创建信息 * @return 编号 */ - Long createFixed(@Valid AttendanceFixedSaveReqVO createReqVO); + void batchCreateOrUpdate(Long attendanceGroupId, @Valid List vos); /** * 更新固定班制考勤设置 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 ab491d06..7d2057f4 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 @@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -44,12 +45,32 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch private AttendanceService attendanceService; @Override - public Long createFixed(AttendanceFixedSaveReqVO createReqVO) { + public void batchCreateOrUpdate(Long attendanceGroupId, List vos) { // 插入 - AttendanceFixedDO fixed = BeanUtils.toBean(createReqVO, AttendanceFixedDO.class); - attendanceFixedMapper.insert(fixed); - // 返回 - return fixed.getId(); + List oldList = attendanceFixedMapper.selectList(new LambdaQueryWrapper().eq(AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId)); + List fixedList = BeanUtils.toBean(vos, AttendanceFixedDO.class); + // -- 如果旧的没数据 则直接新增 + if (oldList.isEmpty()) { + attendanceFixedMapper.insertBatch(fixedList); + } else { + //如果旧的有数据则区分下 + // 插入 + List saveList = fixedList.stream().filter(a -> a.getId() == null).collect(Collectors.toList()); + List editList = fixedList.stream().filter(a -> a.getId() != null).collect(Collectors.toList()); + if (!saveList.isEmpty()) { + attendanceFixedMapper.insertBatch(saveList); + } + if (!editList.isEmpty()) { + attendanceFixedMapper.updateBatch(editList); + } + // -- 需要删除的 - + List oldIds = oldList.stream().map(AttendanceFixedDO::getId).collect(Collectors.toList()); + List newIds = editList.stream().map(AttendanceFixedDO::getId).collect(Collectors.toList()); + List delIds = new ArrayList<>(CollectionUtil.subtract(oldIds, newIds)); + if (!delIds.isEmpty()) { + attendanceFixedMapper.deleteBatchIds(delIds); + } + } } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/punch/dto/AttendanceOnTheDayDTO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/punch/dto/AttendanceOnTheDayDTO.java index 0315eb72..44b87089 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/punch/dto/AttendanceOnTheDayDTO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/punch/dto/AttendanceOnTheDayDTO.java @@ -20,6 +20,9 @@ public class AttendanceOnTheDayDTO { @Schema(description = "子表id") private Long id; + @Schema(description = "班次id") + private Long kqAttendanceGroupShiftId; + @Schema(description = "类型 0上班 1下班") private Integer type; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingService.java index b2d7ed42..09207703 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingService.java @@ -21,10 +21,11 @@ public interface AttendanceSchedulingService { /** * 创建排班制考勤设置 * - * @param createReqVO 创建信息 + * @param attendanceGroupId + * @param createReqVO 创建信息 * @return 编号 */ - Long createScheduling(@Valid AttendanceSchedulingSaveReqVO createReqVO); + void batchCreateOrUpdate(Long attendanceGroupId, @Valid List createReqVO); /** * 更新排班制考勤设置 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingServiceImpl.java index 5857b8a1..b62138d1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/scheduling/AttendanceSchedulingServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.service.attendance.scheduling; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.Constants; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -19,13 +20,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.springframework.context.annotation.Lazy; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +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.SCHEDULING_NOT_EXISTS; @@ -52,12 +56,32 @@ public class AttendanceSchedulingServiceImpl implements AttendanceSchedulingServ private AttendanceService attendanceService; @Override - public Long createScheduling(AttendanceSchedulingSaveReqVO createReqVO) { - // 插入 - AttendanceSchedulingDO scheduling = BeanUtils.toBean(createReqVO, AttendanceSchedulingDO.class); - schedulingMapper.insert(scheduling); - // 返回 - return scheduling.getId(); + @Transactional(rollbackFor = Exception.class) + public void batchCreateOrUpdate(Long attendanceGroupId, List createReqVO) { + List oldList = schedulingMapper.selectList(new LambdaQueryWrapper().eq(AttendanceSchedulingDO::getAttendanceGroupId, attendanceGroupId)); + List scheduling = BeanUtils.toBean(createReqVO, AttendanceSchedulingDO.class); + // -- 如果久的没数据 则直接新增 + if (oldList.isEmpty()) { + schedulingMapper.insertBatch(scheduling); + } else { + //如果久的有数据则区分下 + // 插入 + List saveList = scheduling.stream().filter(a -> a.getId() == null).collect(Collectors.toList()); + List editList = scheduling.stream().filter(a -> a.getId() != null).collect(Collectors.toList()); + if (!saveList.isEmpty()) { + schedulingMapper.insertBatch(saveList); + } + if (!editList.isEmpty()) { + schedulingMapper.updateBatch(editList); + } + // -- 需要删除的 - + List oldIds = oldList.stream().map(AttendanceSchedulingDO::getId).collect(Collectors.toList()); + List newIds = editList.stream().map(AttendanceSchedulingDO::getId).collect(Collectors.toList()); + List delIds = new ArrayList<>(CollectionUtil.subtract(oldIds, newIds)); + if (!delIds.isEmpty()) { + schedulingMapper.deleteBatchIds(delIds); + } + } } @Override