refactor(job): 将外勤打卡权限变更逻辑移至FieldworkJob

将外勤打卡权限变更逻辑从BirthdayJob中提取并移至新的FieldworkJob,以专注于特定的定时任务职责。此更改通过在FieldworkJob中实施相同的逻辑,实现了定时任务的细分和清晰的责任分离。
This commit is contained in:
furongxin 2024-09-14 11:17:17 +08:00
parent 84a197b3a5
commit f8cfc157b1
2 changed files with 70 additions and 32 deletions

View File

@ -61,42 +61,10 @@ public class BirthdayJob {
// 生日提醒 // 生日提醒
birthdayRemind(); birthdayRemind();
// 外勤打卡权限变更
fieldworkPermissionChange();
// 返回执行成功 // 返回执行成功
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
private void fieldworkPermissionChange() {
try {
// 获取用户编号
Map<String, List<Long>> goOutList = goOutApi.getLeaveListByTime().getCheckedData();
if (CollectionUtil.isNotEmpty(goOutList.get("now"))) {
// 讲需要当天外出的用户设置外勤打卡权限
adminUserMapper.update(new AdminUserDO().setFieldworkFlag(1).setFieldworkType(2),
new LambdaQueryWrapper<AdminUserDO>()
.in(AdminUserDO::getId, goOutList.get("now"))
.ne(AdminUserDO::getFieldworkType, 1));
}
if (CollectionUtil.isNotEmpty(goOutList.get("yesterday"))) {
// 将昨日外出的用户关闭外勤打卡权限
adminUserMapper.update(new AdminUserDO().setFieldworkFlag(0).setFieldworkType(0),
new LambdaQueryWrapper<AdminUserDO>()
.in(AdminUserDO::getId, goOutList.get("yesterday"))
.eq(AdminUserDO::getFieldworkType, 2));
}
}catch (Exception ex) {
log.info(ex.toString());
}
}
private void birthdayRemind() { private void birthdayRemind() {
String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MM-dd")); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MM-dd"));

View File

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.system.job.fieldwork;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOAGoOutApi;
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Component
@Slf4j
@EnableScheduling
public class FieldworkJob {
@Resource
private AdminUserMapper adminUserMapper;
@Resource
private BpmOAGoOutApi goOutApi;
/**
* 外勤打卡权限调整 针对外出申请流程
*/
@XxlJob("fieldworkJob")
@TenantJob // --- 这个注解 会将租户列表拉出来 完了后逐个租户执行 定时任务需要注意
public ReturnT<String> execute() {
// 外勤打卡权限变更
try {
// 获取用户编号
Map<String, List<Long>> goOutList = goOutApi.getLeaveListByTime().getCheckedData();
if (CollectionUtil.isNotEmpty(goOutList.get("now"))) {
// 讲需要当天外出的用户设置外勤打卡权限
adminUserMapper.update(new AdminUserDO().setFieldworkFlag(1).setFieldworkType(2),
new LambdaQueryWrapper<AdminUserDO>()
.in(AdminUserDO::getId, goOutList.get("now"))
.ne(AdminUserDO::getFieldworkType, 1));
}
if (CollectionUtil.isNotEmpty(goOutList.get("yesterday"))) {
// 将昨日外出的用户关闭外勤打卡权限
adminUserMapper.update(new AdminUserDO().setFieldworkFlag(0).setFieldworkType(0),
new LambdaQueryWrapper<AdminUserDO>()
.in(AdminUserDO::getId, goOutList.get("yesterday"))
.eq(AdminUserDO::getFieldworkType, 2));
}
}catch (Exception ex) {
log.info(ex.toString());
}
// 返回执行成功
return ReturnT.SUCCESS;
}
}