Commit 945047cb authored by hongguangwu's avatar hongguangwu

Merge remote-tracking branch 'origin/MVP1.7.21' into MVP1.7.21

parents 4418c5f6 92161033
...@@ -7,4 +7,6 @@ public interface ScheduleService { ...@@ -7,4 +7,6 @@ public interface ScheduleService {
void scheduleTask(EmployeeRegistrationPre record); void scheduleTask(EmployeeRegistrationPre record);
void executeTask(String aId); void executeTask(String aId);
void removeTask(String aId);
} }
...@@ -1039,6 +1039,16 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi ...@@ -1039,6 +1039,16 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi
return R.other(CommonConstants.TWO_INT,null,errorTemp.toString()); 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 natureItemBefore = null;
String natureItemAfter = null; String natureItemAfter = null;
...@@ -1114,6 +1124,12 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi ...@@ -1114,6 +1124,12 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi
} }
try { try {
baseMapper.updateById(employeeRegistrationPre); baseMapper.updateById(employeeRegistrationPre);
// 如果预计收集时间改变且新的时间不为空,添加新的定时任务
if (expectedCollectionTimeChanged && employeeRegistrationPre.getExpectedCollectionTime() != null) {
log.info("员工预入职 ID: {} 按新预计收集时间:{} 添加定时任务",
employeeRegistrationPre.getId(), employeeRegistrationPre.getExpectedCollectionTime());
scheduleService.scheduleTask(employeeRegistrationPre);
}
if (null != natureItemBefore) { if (null != natureItemBefore) {
comparePre.setEmpNature(natureItemBefore); comparePre.setEmpNature(natureItemBefore);
} }
...@@ -1132,7 +1148,7 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi ...@@ -1132,7 +1148,7 @@ public class EmployeeRegistrationPreServiceImpl extends ServiceImpl<EmployeeRegi
if (null != contractXfAfter) { if (null != contractXfAfter) {
employeeRegistrationPre.setContractSubName(contractXfAfter); employeeRegistrationPre.setContractSubName(contractXfAfter);
} }
// 添加日志并修改商险list // 添加日志并修改商险 list
tEmployeePreLogService.saveModifyAndUpdateInsurance(employeeRegistrationPre.getId(), comparePre tEmployeePreLogService.saveModifyAndUpdateInsurance(employeeRegistrationPre.getId(), comparePre
, employeeRegistrationPre, user, oldMap, contractOld); , employeeRegistrationPre, user, oldMap, contractOld);
......
...@@ -8,6 +8,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.vo.SendMessageUpdateVo; ...@@ -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 com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
...@@ -17,6 +18,9 @@ import java.time.LocalDateTime; ...@@ -17,6 +18,9 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
@Service @Service
public class ScheduleServiceImpl implements ScheduleService { public class ScheduleServiceImpl implements ScheduleService {
...@@ -24,10 +28,13 @@ public class ScheduleServiceImpl implements ScheduleService { ...@@ -24,10 +28,13 @@ public class ScheduleServiceImpl implements ScheduleService {
@Autowired @Autowired
private EmployeeRegistrationPreService registrationPreService; private EmployeeRegistrationPreService registrationPreService;
@Autowired @Autowired
private TaskScheduler taskScheduler; private ThreadPoolTaskScheduler taskScheduler;
@Autowired @Autowired
private TransactionTemplate transactionTemplate; private TransactionTemplate transactionTemplate;
// 用于存储任务 ID 和 ScheduledFuture 的映射关系
private final Map<String, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
// 应用启动时初始化未处理的任务 // 应用启动时初始化未处理的任务
@PostConstruct @PostConstruct
public void initSchedule() { public void initSchedule() {
...@@ -41,7 +48,14 @@ public class ScheduleServiceImpl implements ScheduleService { ...@@ -41,7 +48,14 @@ public class ScheduleServiceImpl implements ScheduleService {
@Override @Override
public void scheduleTask(EmployeeRegistrationPre record) { public void scheduleTask(EmployeeRegistrationPre record) {
Instant triggerTime = record.getExpectedCollectionTime().atZone(ZoneId.systemDefault()).toInstant(); 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 { ...@@ -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