package cn.iocoder.yudao.module.mes.service.collect;
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskDO;
|
import cn.iocoder.yudao.module.mes.dal.mysql.pro.task.MesProTaskMapper;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
/**
|
* MES 数采-生产任务关联解析
|
*
|
* @author 超级管理员
|
*/
|
@Service
|
public class MesCollectTaskResolver {
|
|
private static final long CACHE_MILLIS = 30_000L;
|
|
@Resource
|
private MesProTaskMapper taskMapper;
|
|
private final ConcurrentHashMap<Long, CachedTask> cache = new ConcurrentHashMap<>();
|
|
/**
|
* 查询工作站上正在运行的生产任务(生产中/部分完成/已停工)
|
*/
|
public MesProTaskDO resolve(Long workstationId) {
|
if (workstationId == null) {
|
return null;
|
}
|
long now = System.currentTimeMillis();
|
CachedTask cached = cache.get(workstationId);
|
if (cached != null && now - cached.time < CACHE_MILLIS) {
|
return cached.task;
|
}
|
MesProTaskDO task = taskMapper.selectRunningTaskByWorkstationId(workstationId);
|
cache.put(workstationId, new CachedTask(task, now));
|
return task;
|
}
|
|
private record CachedTask(MesProTaskDO task, long time) {
|
}
|
|
}
|