固定班次和排班班次 调整

This commit is contained in:
aikai 2024-05-24 11:11:43 +08:00
parent 7391de6ca6
commit 08d6b56449
9 changed files with 135 additions and 104 deletions

View File

@ -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<Long> createFixed(@Valid @RequestBody AttendanceFixedSaveReqVO createReqVO) {
return success(fixedService.createFixed(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新固定班制考勤设置")
@PreAuthorize("@ss.hasPermission('attendance:fixed:update')")
public CommonResult<Boolean> 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<Boolean> deleteFixed(@RequestParam("id") Long id) {
fixedService.deleteFixed(id);
return success(true);
public CommonResult batchCreateOrUpdate(@RequestParam Long attendanceGroupId,
@Valid @RequestBody List<AttendanceFixedSaveReqVO> 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<AttendanceFixedDO> list = fixedService.getFixedPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "固定班制考勤设置.xls", "数据", AttendanceFixedRespVO.class,
BeanUtils.toBean(list, AttendanceFixedRespVO.class));
BeanUtils.toBean(list, AttendanceFixedRespVO.class));
}
}

View File

@ -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<Long> createScheduling(@Valid @RequestBody AttendanceSchedulingSaveReqVO createReqVO) {
return success(schedulingService.createScheduling(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新排班制考勤设置")
@PreAuthorize("@ss.hasPermission('attendance:scheduling:update')")
public CommonResult<Boolean> 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<Boolean> deleteScheduling(@RequestParam("id") Long id) {
schedulingService.deleteScheduling(id);
return success(true);
public CommonResult batchCreateOrUpdate(@RequestParam Long attendanceGroupId,
@Valid @RequestBody List<AttendanceSchedulingSaveReqVO> 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<AttendanceSchedulingDO> list = schedulingService.getSchedulingPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "排班制考勤设置.xls", "数据", AttendanceSchedulingRespVO.class,
BeanUtils.toBean(list, AttendanceSchedulingRespVO.class));
BeanUtils.toBean(list, AttendanceSchedulingRespVO.class));
}
}

View File

@ -75,21 +75,33 @@ public class AttendanceStatisticsJob {
LocalDateTime tomorrowLocalDateTime = LocalDateTimeUtil.offset(LocalDateTime.now(), 1, ChronoUnit.DAYS);
// 获取到考勤组 - 班次 key/value 格式
Map<Long, Long> map = this.getAttendanceGroupShiftIdGroupByGroup(attendanceGroupDOS, tomorrowLocalDateTime);
Map<Long, AttendanceGroupDO> groupMap = attendanceGroupDOS.stream().collect(Collectors.toMap(AttendanceGroupDO::getId, v -> v));
// -- 获取班次子表列表
if (MapUtil.isNotEmpty(map)) {
List<AttendanceGroupShiftItemDO> attendanceGroupShiftItemDOList = attendanceGroupShiftItemService.getGroupShiftItemListByShiftIds(new ArrayList<>(map.values()));
Map<Long, List<AttendanceGroupShiftItemDO>> itemMaps = attendanceGroupShiftItemDOList.stream().collect(Collectors.groupingBy(AttendanceGroupShiftItemDO::getKqAttendanceGroupShiftId));
List<AttendancePunchRecordDO> attendancePunchRecordDOList = new ArrayList<>();
for (Map.Entry<Long, Long> entry : map.entrySet()) {
AttendanceGroupDO attendanceGroupDO = groupMap.get(entry.getKey());
List<Long> userIds = groupUserMap.get(entry.getKey());
//
List<AttendanceGroupShiftItemDO> attendanceGroupShiftItemDOS = itemMaps.get(entry.getValue());
List<AttendanceOnTheDayDTO> 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);
}

View File

@ -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);

View File

@ -21,10 +21,10 @@ public interface AttendanceFixedService {
/**
* 创建固定班制考勤设置
*
* @param createReqVO 创建信息
* @param vos 创建信息
* @return 编号
*/
Long createFixed(@Valid AttendanceFixedSaveReqVO createReqVO);
void batchCreateOrUpdate(Long attendanceGroupId, @Valid List<AttendanceFixedSaveReqVO> vos);
/**
* 更新固定班制考勤设置

View File

@ -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<AttendanceFixedSaveReqVO> vos) {
// 插入
AttendanceFixedDO fixed = BeanUtils.toBean(createReqVO, AttendanceFixedDO.class);
attendanceFixedMapper.insert(fixed);
// 返回
return fixed.getId();
List<AttendanceFixedDO> oldList = attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>().eq(AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId));
List<AttendanceFixedDO> fixedList = BeanUtils.toBean(vos, AttendanceFixedDO.class);
// -- 如果旧的没数据 则直接新增
if (oldList.isEmpty()) {
attendanceFixedMapper.insertBatch(fixedList);
} else {
//如果旧的有数据则区分下
// 插入
List<AttendanceFixedDO> saveList = fixedList.stream().filter(a -> a.getId() == null).collect(Collectors.toList());
List<AttendanceFixedDO> editList = fixedList.stream().filter(a -> a.getId() != null).collect(Collectors.toList());
if (!saveList.isEmpty()) {
attendanceFixedMapper.insertBatch(saveList);
}
if (!editList.isEmpty()) {
attendanceFixedMapper.updateBatch(editList);
}
// -- 需要删除的 -
List<Long> oldIds = oldList.stream().map(AttendanceFixedDO::getId).collect(Collectors.toList());
List<Long> newIds = editList.stream().map(AttendanceFixedDO::getId).collect(Collectors.toList());
List<Long> delIds = new ArrayList<>(CollectionUtil.subtract(oldIds, newIds));
if (!delIds.isEmpty()) {
attendanceFixedMapper.deleteBatchIds(delIds);
}
}
}
@Override

View File

@ -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;

View File

@ -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<AttendanceSchedulingSaveReqVO> createReqVO);
/**
* 更新排班制考勤设置

View File

@ -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<AttendanceSchedulingSaveReqVO> createReqVO) {
List<AttendanceSchedulingDO> oldList = schedulingMapper.selectList(new LambdaQueryWrapper<AttendanceSchedulingDO>().eq(AttendanceSchedulingDO::getAttendanceGroupId, attendanceGroupId));
List<AttendanceSchedulingDO> scheduling = BeanUtils.toBean(createReqVO, AttendanceSchedulingDO.class);
// -- 如果久的没数据 则直接新增
if (oldList.isEmpty()) {
schedulingMapper.insertBatch(scheduling);
} else {
//如果久的有数据则区分下
// 插入
List<AttendanceSchedulingDO> saveList = scheduling.stream().filter(a -> a.getId() == null).collect(Collectors.toList());
List<AttendanceSchedulingDO> editList = scheduling.stream().filter(a -> a.getId() != null).collect(Collectors.toList());
if (!saveList.isEmpty()) {
schedulingMapper.insertBatch(saveList);
}
if (!editList.isEmpty()) {
schedulingMapper.updateBatch(editList);
}
// -- 需要删除的 -
List<Long> oldIds = oldList.stream().map(AttendanceSchedulingDO::getId).collect(Collectors.toList());
List<Long> newIds = editList.stream().map(AttendanceSchedulingDO::getId).collect(Collectors.toList());
List<Long> delIds = new ArrayList<>(CollectionUtil.subtract(oldIds, newIds));
if (!delIds.isEmpty()) {
schedulingMapper.deleteBatchIds(delIds);
}
}
}
@Override