|
@ -7,6 +7,7 @@ import com.iflytop.gd.app.common.enums.CraftStates; |
|
|
import com.iflytop.gd.app.core.CraftsContext; |
|
|
import com.iflytop.gd.app.core.CraftsContext; |
|
|
import com.iflytop.gd.app.mapper.CraftsMapper; |
|
|
import com.iflytop.gd.app.mapper.CraftsMapper; |
|
|
import com.iflytop.gd.app.model.entity.Crafts; |
|
|
import com.iflytop.gd.app.model.entity.Crafts; |
|
|
|
|
|
import com.iflytop.gd.app.model.vo.CraftStatusVO; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import org.springframework.statemachine.config.StateMachineFactory; |
|
|
import org.springframework.statemachine.config.StateMachineFactory; |
|
@ -27,7 +28,6 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> { |
|
|
private final WebSocketService webSocketService; |
|
|
private final WebSocketService webSocketService; |
|
|
|
|
|
|
|
|
private ExecutorService executor; |
|
|
private ExecutorService executor; |
|
|
|
|
|
|
|
|
private final ConcurrentHashMap<String, CraftsContext> contextMap = new ConcurrentHashMap<>(); |
|
|
private final ConcurrentHashMap<String, CraftsContext> contextMap = new ConcurrentHashMap<>(); |
|
|
private final ConcurrentHashMap<String, Future<?>> futureMap = new ConcurrentHashMap<>(); |
|
|
private final ConcurrentHashMap<String, Future<?>> futureMap = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
@ -40,7 +40,7 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> { |
|
|
* 开始执行工艺 |
|
|
* 开始执行工艺 |
|
|
*/ |
|
|
*/ |
|
|
public synchronized boolean startCrafts(Long craftId, String heatId) { |
|
|
public synchronized boolean startCrafts(Long craftId, String heatId) { |
|
|
if (futureMap.containsKey(heatId)) { // 已有任务在执行,不重复启动 |
|
|
|
|
|
|
|
|
if (futureMap.containsKey(heatId)) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
Crafts craft = this.getById(craftId); |
|
|
Crafts craft = this.getById(craftId); |
|
@ -97,7 +97,37 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: 如需提供查询当前执行状态,可添加 getStatus(heatId) 方法,返回 ctx.getCurrentIndex(), ctx.getSm().getState().getId(), ctx.getRemainingSteps() 等 |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 查询指定 heatId 的执行状态 |
|
|
|
|
|
*/ |
|
|
|
|
|
public synchronized CraftStatusVO getStatus(String heatId) { |
|
|
|
|
|
CraftsContext ctx = contextMap.get(heatId); |
|
|
|
|
|
if (ctx == null) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
CraftStatusVO vo = new CraftStatusVO(); |
|
|
|
|
|
vo.setHeatId(heatId); |
|
|
|
|
|
vo.setState(ctx.getSm().getState().getId()); |
|
|
|
|
|
vo.setCurrentIndex(ctx.getCurrentIndex()); |
|
|
|
|
|
vo.setSteps(ctx.getCraftsStepList()); |
|
|
|
|
|
return vo; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 查询所有正在执行的工艺状态 |
|
|
|
|
|
*/ |
|
|
|
|
|
public synchronized List<CraftStatusVO> getAllStatuses() { |
|
|
|
|
|
return contextMap.entrySet().stream().map(entry -> { |
|
|
|
|
|
String heatId = entry.getKey(); |
|
|
|
|
|
CraftsContext ctx = entry.getValue(); |
|
|
|
|
|
CraftStatusVO vo = new CraftStatusVO(); |
|
|
|
|
|
vo.setHeatId(heatId); |
|
|
|
|
|
vo.setState(ctx.getSm().getState().getId()); |
|
|
|
|
|
vo.setCurrentIndex(ctx.getCurrentIndex()); |
|
|
|
|
|
vo.setSteps(ctx.getCraftsStepList()); |
|
|
|
|
|
return vo; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public List<Crafts> selectAllByOresId(Long oresId) { |
|
|
public List<Crafts> selectAllByOresId(Long oresId) { |
|
|
return this.baseMapper.selectAllByOresId(oresId); |
|
|
return this.baseMapper.selectAllByOresId(oresId); |
|
@ -121,4 +151,4 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> { |
|
|
.collect(Collectors.toList()); |
|
|
.collect(Collectors.toList()); |
|
|
return this.removeByIds(ids); |
|
|
return this.removeByIds(ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |