Commit 6479109b authored by fangxinjiang's avatar fangxinjiang

入职确认修改时变更预计收集时间后更新定时任务-fxj

parent c80c2d61
......@@ -7,4 +7,6 @@ public interface ScheduleService {
void scheduleTask(EmployeeRegistrationPre record);
void executeTask(String aId);
void removeTask(String aId);
}
......@@ -1039,6 +1039,16 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi
return R.other(CommonConstants.TWO_INT,null,errorTemp.toString());
}
// 判断预计收集时间是否改变
boolean expectedCollectionTimeChanged = false;
if (employeeRegistrationPre.getExpectedCollectionTime() != null
&& !employeeRegistrationPre.getExpectedCollectionTime().equals(comparePre.getExpectedCollectionTime())) {
expectedCollectionTimeChanged = true;
} else if (employeeRegistrationPre.getExpectedCollectionTime() == null
&& comparePre.getExpectedCollectionTime() != null) {
expectedCollectionTimeChanged = true;
}
//操作记录中字典值的转化
String natureItemBefore = null;
String natureItemAfter = null;
......@@ -1114,6 +1124,12 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi
}
try {
baseMapper.updateById(employeeRegistrationPre);
// 如果预计收集时间改变且新的时间不为空,添加新的定时任务
if (expectedCollectionTimeChanged && employeeRegistrationPre.getExpectedCollectionTime() != null) {
log.info("员工预入职 ID: {} 按新预计收集时间:{} 添加定时任务",
employeeRegistrationPre.getId(), employeeRegistrationPre.getExpectedCollectionTime());
scheduleService.scheduleTask(employeeRegistrationPre);
}
if (null != natureItemBefore) {
comparePre.setEmpNature(natureItemBefore);
}
......@@ -1132,10 +1148,10 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi
if (null != contractXfAfter) {
employeeRegistrationPre.setContractSubName(contractXfAfter);
}
// 添加日志并修改商险list
// 添加日志并修改商险 list
tEmployeePreLogService.saveModifyAndUpdateInsurance(employeeRegistrationPre.getId(), comparePre
, employeeRegistrationPre, user, oldMap, contractOld);
} catch (Exception e) {
log.error("生成入职待确认信息修改操作日志异常", e);
}
......
......@@ -8,6 +8,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.vo.SendMessageUpdateVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
......@@ -17,6 +18,9 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
@Service
public class ScheduleServiceImpl implements ScheduleService {
......@@ -24,10 +28,13 @@ public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private EmployeeRegistrationPreService registrationPreService;
@Autowired
private TaskScheduler taskScheduler;
private ThreadPoolTaskScheduler taskScheduler;
@Autowired
private TransactionTemplate transactionTemplate;
// 用于存储任务 ID 和 ScheduledFuture 的映射关系
private final Map<String, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
// 应用启动时初始化未处理的任务
@PostConstruct
public void initSchedule() {
......@@ -41,7 +48,14 @@ public class ScheduleServiceImpl implements ScheduleService {
@Override
public void scheduleTask(EmployeeRegistrationPre record) {
Instant triggerTime = record.getExpectedCollectionTime().atZone(ZoneId.systemDefault()).toInstant();
taskScheduler.schedule(() -> executeTask(record.getId()), triggerTime);
String taskId = record.getId();
// 如果任务已存在,先取消旧任务
removeTask(taskId);
// 创建新任务并保存引用
ScheduledFuture<?> future = taskScheduler.schedule(() -> executeTask(taskId), triggerTime);
scheduledTasks.put(taskId, future);
}
// 执行发送短信操作(事务内处理)
......@@ -57,4 +71,20 @@ public class ScheduleServiceImpl implements ScheduleService {
});
}
/**
* @Author fxj
* @Description 删除已经存在的任务
* @Date 14:17 2026/4/3
* @Param
* @return
**/
@Override
public void removeTask(String aId) {
// 从调度器中取消任务
ScheduledFuture<?> future = scheduledTasks.remove(aId);
if (future != null) {
future.cancel(false); // false 表示不中断正在执行的任务
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment