更新考勤组班次/更换考勤班次立即生效
This commit is contained in:
parent
76c23e976b
commit
f477e9e0e5
@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.system.controller.admin.groupshift.vo.AttendanceG
|
||||
import cn.iocoder.yudao.module.system.controller.admin.groupshiftitem.vo.AttendanceGroupShiftItemSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.groupshift.AttendanceGroupShiftDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.groupshiftitem.AttendanceGroupShiftItemDO;
|
||||
import cn.iocoder.yudao.module.system.service.attendance.group.AttendanceGroupService;
|
||||
import cn.iocoder.yudao.module.system.service.attendance.groupshift.AttendanceGroupShiftService;
|
||||
import cn.iocoder.yudao.module.system.service.attendance.groupshiftitem.AttendanceGroupShiftItemService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -39,6 +40,9 @@ public class AttendanceGroupShiftController {
|
||||
|
||||
@Resource
|
||||
private AttendanceGroupShiftService groupShiftService;
|
||||
@Resource
|
||||
private AttendanceGroupService attendanceGroupService;
|
||||
|
||||
@Resource
|
||||
private AttendanceGroupShiftItemService groupShiftItemService;
|
||||
|
||||
@ -49,11 +53,19 @@ public class AttendanceGroupShiftController {
|
||||
return success(groupShiftService.createGroupShift(createReqVO));
|
||||
}
|
||||
|
||||
// TODO: 2024/6/5 如果返回的有值 (判断不是空数组) - 那么前端 跳出提示框 (该班次已有考勤组在使用请选择更新方式) 下面两个按钮 立即生效 和 (推荐)次日生效
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新考勤组班次")
|
||||
@PreAuthorize("@ss.hasPermission('attendance:group-shift:update')")
|
||||
public CommonResult<Boolean> updateGroupShift(@Valid @RequestBody AttendanceGroupShiftSaveReqVO updateReqVO) {
|
||||
groupShiftService.updateGroupShift(updateReqVO);
|
||||
public CommonResult<List<Long>> updateGroupShift(@Valid @RequestBody AttendanceGroupShiftSaveReqVO updateReqVO) {
|
||||
List<Long> groupIds = groupShiftService.updateGroupShift(updateReqVO);
|
||||
return success(groupIds);
|
||||
}
|
||||
|
||||
@PostMapping("/effectiveImmediately")
|
||||
@Operation(summary = "更换考勤班次立即生效")
|
||||
public CommonResult<Boolean> effectiveImmediately(@RequestBody List<Long> groupIds) {
|
||||
attendanceGroupService.effectiveImmediately(groupIds);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.attendance.fixed;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.fixed.AttendanceFixedDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 固定班制考勤设置 Mapper
|
||||
@ -24,4 +27,11 @@ public interface AttendanceFixedMapper extends BaseMapperX<AttendanceFixedDO> {
|
||||
.orderByDesc(AttendanceFixedDO::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取使用的考勤组ids
|
||||
*
|
||||
* @param shiftId
|
||||
* @return
|
||||
*/
|
||||
List<Long> getUseGroupIds(@Param("shiftId") Long shiftId);
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.attendance.scheduling;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.scheduling.vo.AttendanceSchedulingPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.scheduling.AttendanceSchedulingDO;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.scheduling.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -27,6 +29,15 @@ public interface AttendanceSchedulingMapper extends BaseMapperX<AttendanceSchedu
|
||||
.betweenIfPresent(AttendanceSchedulingDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(AttendanceSchedulingDO::getId));
|
||||
}
|
||||
|
||||
@MapKey("id")
|
||||
Map<Long, Integer> countGroupId();
|
||||
|
||||
/**
|
||||
* 获取使用的考勤组ids
|
||||
*
|
||||
* @param shiftId
|
||||
* @return
|
||||
*/
|
||||
List<Long> getUseGroupIds(@Param("shiftId") Long shiftId);
|
||||
}
|
@ -84,4 +84,12 @@ public interface AttendanceFixedService {
|
||||
* @return
|
||||
*/
|
||||
List<AttendanceFixedRespVO> getListByGroupId(Long attendanceGroupId);
|
||||
|
||||
/**
|
||||
* 查询使用的考勤组ids
|
||||
*
|
||||
* @param shiftId
|
||||
* @return
|
||||
*/
|
||||
List<Long> getUseGroupIds(Long shiftId);
|
||||
}
|
@ -182,6 +182,11 @@ public class AttendanceFixedServiceImpl implements AttendanceFixedService, Punch
|
||||
return respVOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUseGroupIds(Long shiftId) {
|
||||
return attendanceFixedMapper.getUseGroupIds(shiftId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttendancePunchPageVO getPunchPage(AttendancePunchPageDTO dto) {
|
||||
AttendancePunchPageVO vo = new AttendancePunchPageVO();
|
||||
|
@ -69,4 +69,19 @@ public interface AttendanceGroupService {
|
||||
* @return
|
||||
*/
|
||||
List<AttendanceGroupDO> getAll();
|
||||
|
||||
/**
|
||||
* 获取使用班次id的考勤组ids
|
||||
*
|
||||
* @param shiftId
|
||||
* @return
|
||||
*/
|
||||
List<Long> getUseGroupIds(Long shiftId);
|
||||
|
||||
/**
|
||||
* 立即生效
|
||||
*
|
||||
* @param groupIds
|
||||
*/
|
||||
void effectiveImmediately(List<Long> groupIds);
|
||||
}
|
@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.system.service.attendance.punchrecord.AttendanceP
|
||||
import cn.iocoder.yudao.module.system.service.attendance.scheduling.AttendanceSchedulingService;
|
||||
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.validation.annotation.Validated;
|
||||
|
||||
@ -67,6 +68,8 @@ public class AttendanceGroupServiceImpl implements AttendanceGroupService {
|
||||
private AttendanceFixedService attendanceFixedService;
|
||||
@Resource
|
||||
private AttendanceSchedulingService attendanceSchedulingService;
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
@ -194,6 +197,26 @@ public class AttendanceGroupServiceImpl implements AttendanceGroupService {
|
||||
return attendanceGroupMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUseGroupIds(Long shiftId) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
List<Long> fixedGroupIds = attendanceFixedService.getUseGroupIds(shiftId);
|
||||
ids.addAll(fixedGroupIds);
|
||||
List<Long> schedulingGroupIds = attendanceSchedulingService.getUseGroupIds(shiftId);
|
||||
ids.addAll(schedulingGroupIds);
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void effectiveImmediately(List<Long> groupIds) {
|
||||
String time = LocalDateTime.now().format(Constants.REPO_DATE_FORMAT);
|
||||
// TODO: 2024/6/5 删除当天redis中考勤记录 - 重新计算新的考勤记录到redis 和 数据库中
|
||||
for (Long groupId : groupIds) {
|
||||
String key = Constants.ATTENDANCE + Constants.UNDERLINE + groupId + Constants.UNDERLINE; // + 时间
|
||||
stringRedisTemplate.delete(key + time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Map<Long, Long> getAttendanceGroupShiftIdGroupByGroup(List<AttendanceGroupDO> attendanceGroupDOS, LocalDateTime localDateTime) {
|
||||
Map<Long, Long> map = new HashMap<>();
|
||||
|
@ -29,7 +29,7 @@ public interface AttendanceGroupShiftService {
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateGroupShift(@Valid AttendanceGroupShiftSaveReqVO updateReqVO);
|
||||
List<Long> updateGroupShift(@Valid AttendanceGroupShiftSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除考勤组班次
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.service.attendance.groupshift;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.iocoder.yudao.framework.common.Constants;
|
||||
@ -17,7 +18,9 @@ import cn.iocoder.yudao.module.system.dal.mysql.attendance.fixed.AttendanceFixed
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.attendance.groupshift.AttendanceGroupShiftMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.attendance.groupshiftitem.AttendanceGroupShiftItemMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.attendance.scheduling.AttendanceSchedulingMapper;
|
||||
import cn.iocoder.yudao.module.system.service.attendance.group.AttendanceGroupService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -48,6 +51,8 @@ public class AttendanceGroupShiftServiceImpl implements AttendanceGroupShiftServ
|
||||
private AttendanceFixedMapper attendanceFixedMapper;
|
||||
@Resource
|
||||
private AttendanceSchedulingMapper attendanceSchedulingMapper;
|
||||
@Resource
|
||||
private AttendanceGroupService attendanceGroupService;
|
||||
|
||||
|
||||
@Override
|
||||
@ -109,7 +114,7 @@ public class AttendanceGroupShiftServiceImpl implements AttendanceGroupShiftServ
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGroupShift(AttendanceGroupShiftSaveReqVO updateReqVO) {
|
||||
public List<Long> updateGroupShift(AttendanceGroupShiftSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateGroupShiftExists(updateReqVO.getId());
|
||||
// 更新
|
||||
@ -119,11 +124,18 @@ public class AttendanceGroupShiftServiceImpl implements AttendanceGroupShiftServ
|
||||
items = insertSpanDay(items);
|
||||
List<AttendanceGroupShiftItemDO> oldItems = groupShiftItemMapper.selectList(new LambdaQueryWrapper<AttendanceGroupShiftItemDO>()
|
||||
.eq(AttendanceGroupShiftItemDO::getKqAttendanceGroupShiftId, updateReqVO.getId()));
|
||||
|
||||
// -- 查询下有没有考勤组在用这个班次 - 如果有的话就要考虑更新 是立即更新 还是 次日更新
|
||||
List<Long> useGroupIds = attendanceGroupService.getUseGroupIds(updateReqVO.getId());
|
||||
// TODO: 2024/6/5 如果考勤组没有使用班次 则不需要更新
|
||||
|
||||
|
||||
boolean flag = false;
|
||||
if (CollectionUtil.isEmpty(oldItems)) {
|
||||
groupShiftItemMapper.insertBatch(items);
|
||||
flag = true;
|
||||
} else {
|
||||
Map<Long, AttendanceGroupShiftItemDO> map = oldItems.stream().collect(Collectors.toMap(AttendanceGroupShiftItemDO::getId, a -> a));
|
||||
//新增
|
||||
List<AttendanceGroupShiftItemDO> saveList = items.stream().filter(a -> a.getId() == null).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(saveList)) {
|
||||
@ -135,13 +147,17 @@ public class AttendanceGroupShiftServiceImpl implements AttendanceGroupShiftServ
|
||||
}
|
||||
//修改
|
||||
List<AttendanceGroupShiftItemDO> editList = items.stream().filter(a -> a.getId() != null).collect(Collectors.toList());
|
||||
//先查询一手 - 完了后判断下和修改的值有什么不同
|
||||
if (CollectionUtil.isNotEmpty(editList)) {
|
||||
int num = 0;
|
||||
groupShiftItemMapper.updateBatch(editList);
|
||||
for (AttendanceGroupShiftItemDO attendanceGroupShiftItemDO : editList) {
|
||||
int i = groupShiftItemMapper.updateById(attendanceGroupShiftItemDO);
|
||||
num += i;
|
||||
AttendanceGroupShiftItemDO item = map.get(attendanceGroupShiftItemDO.getId());
|
||||
boolean eqFlag = BeanUtil.isCommonFieldsEqual(attendanceGroupShiftItemDO, item, "createTime", "updateTime", "creator", "updater");
|
||||
if (!eqFlag) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
flag = num > 0;
|
||||
}
|
||||
//删除
|
||||
// -- 需要删除的 -
|
||||
@ -154,14 +170,11 @@ public class AttendanceGroupShiftServiceImpl implements AttendanceGroupShiftServ
|
||||
}
|
||||
groupShiftMapper.updateById(attendanceGroupShiftDO);
|
||||
}
|
||||
// -- 如果班次子表调整了 - 那么需要更新下明天和后天生成的数据
|
||||
if (flag) {
|
||||
// -- 获取考勤组ids
|
||||
|
||||
// TODO: 2024/6/5 如果有更新的话 - 那么需要调整
|
||||
// 查询这些班次 在哪里用到了
|
||||
// String key = Constants.ATTENDANCE + Constants.UNDERLINE + activationGroup.getId() + Constants.UNDERLINE; // + 时间
|
||||
// -- 如果班次子表调整了 - 并且有考勤组在使用 - 那么需要更新下明天和后天生成的数据
|
||||
if (flag && CollectionUtil.isNotEmpty(useGroupIds)) {
|
||||
return useGroupIds;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,4 +92,11 @@ public interface AttendanceSchedulingService {
|
||||
* @return
|
||||
*/
|
||||
List<AttendanceSchedulingRespVO> getListByGroupId(Long attendanceGroupId);
|
||||
|
||||
/**
|
||||
* 获取使用的考勤组ids
|
||||
* @param shiftId
|
||||
* @return
|
||||
*/
|
||||
List<Long> getUseGroupIds(Long shiftId);
|
||||
}
|
@ -5,12 +5,12 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.Constants;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.attendance.dto.AttendancePunchPageDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.AttendancePunchPageVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.groupshift.vo.AttendanceGroupShiftVO;
|
||||
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.controller.admin.attendance.dto.AttendancePunchPageDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.AttendancePunchPageVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.group.AttendanceGroupDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.scheduling.AttendanceSchedulingDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.attendance.scheduling.AttendanceSchedulingMapper;
|
||||
@ -177,6 +177,11 @@ public class AttendanceSchedulingServiceImpl implements AttendanceSchedulingServ
|
||||
return respVOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUseGroupIds(Long shiftId) {
|
||||
return schedulingMapper.getUseGroupIds(shiftId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttendancePunchPageVO getPunchPage(AttendancePunchPageDTO dto) {
|
||||
AttendancePunchPageVO vo = new AttendancePunchPageVO();
|
||||
|
@ -9,4 +9,11 @@
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
<select id="getUseGroupIds" resultType="java.lang.Long">
|
||||
select
|
||||
attendance_group_id
|
||||
from kq_attendance_fixed
|
||||
where attendance_group_shift_id = #{shiftId}
|
||||
and deleted = 0
|
||||
</select>
|
||||
</mapper>
|
@ -16,4 +16,10 @@
|
||||
from kq_attendance_scheduling
|
||||
group by attendance_group_id
|
||||
</select>
|
||||
<select id="getUseGroupIds" resultType="java.lang.Long">
|
||||
select attendance_group_id
|
||||
from kq_attendance_scheduling
|
||||
where attendance_group_shift_id = #{shiftId}
|
||||
and deleted = 0
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user