5 changed files with 159 additions and 74 deletions
-
14src/main/java/com/qyft/gd/controller/CraftsController.java
-
72src/main/java/com/qyft/gd/device/service/DeviceOperationService.java
-
1src/main/java/com/qyft/gd/service/CraftsService.java
-
144src/main/java/com/qyft/gd/service/CraftsStepService.java
-
2src/main/java/com/qyft/gd/service/impl/CraftsServiceImpl.java
@ -1,72 +0,0 @@ |
|||
package com.qyft.gd.device.service; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* 设备步骤操作 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class DeviceOperationService { |
|||
|
|||
private final DeviceService deviceService; |
|||
|
|||
//抬起托盘 |
|||
public void upTray(int heaterId){ |
|||
deviceService.raiseTray("11"); |
|||
} |
|||
//降下托盘 |
|||
public void downTray(int heaterId){ |
|||
deviceService.lowerTray("11"); |
|||
} |
|||
//添加溶液(先固定16个试管全进行加液) |
|||
public void addLiquid(){ |
|||
|
|||
} |
|||
//移至加液 |
|||
public void moveToSol(){ |
|||
|
|||
} |
|||
//移至加热 |
|||
public void moveToHeater(int heaterId){ |
|||
|
|||
} |
|||
//摇匀 |
|||
public void shaking(){ |
|||
|
|||
} |
|||
//开始加热 |
|||
public void startHeating(int heaterId){ |
|||
|
|||
} |
|||
//停止加热 |
|||
public void stopHeating(int heaterId){ |
|||
|
|||
} |
|||
//拍照 |
|||
public void takePhoto(){ |
|||
|
|||
} |
|||
//移至异常 |
|||
public void moveToExc(){ |
|||
|
|||
} |
|||
//移除异常 |
|||
public void moveOutToExc(){ |
|||
|
|||
} |
|||
/** |
|||
* 等待 |
|||
* @param millis 毫秒 |
|||
*/ |
|||
private boolean delay(int millis) { |
|||
try { |
|||
Thread.sleep(millis); |
|||
return true; |
|||
} catch (InterruptedException e) { |
|||
Thread.currentThread().interrupt(); |
|||
} |
|||
return false; |
|||
} |
|||
} |
@ -0,0 +1,144 @@ |
|||
package com.qyft.gd.service; |
|||
|
|||
import com.qyft.gd.device.service.DeviceService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.Executors; |
|||
import java.util.concurrent.Future; |
|||
|
|||
/** |
|||
* 设备步骤操作 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class CraftsStepService { |
|||
|
|||
private final DeviceService deviceService; |
|||
|
|||
private final ExecutorService executorService = Executors.newCachedThreadPool(); |
|||
private final ConcurrentHashMap<Long, Future<?>> taskMap = new ConcurrentHashMap<>(); |
|||
|
|||
|
|||
// 启动任务的方法 |
|||
public synchronized boolean startCrafts(Long craftId, Long heatId) { |
|||
Future<?> taskFuture = taskMap.get(heatId); |
|||
if (taskFuture != null) { |
|||
return false; |
|||
} |
|||
CraftsTask task = new CraftsTask(craftId, heatId); |
|||
taskFuture = executorService.submit(task); |
|||
taskMap.put(heatId, taskFuture); |
|||
return true; |
|||
} |
|||
|
|||
// 停止任务的方法,通过ID来指定 |
|||
public synchronized boolean stopCrafts(Long heatId) { |
|||
Future<?> taskFuture = taskMap.get(heatId); |
|||
if (taskFuture != null) { |
|||
boolean cancelled = taskFuture.cancel(true); |
|||
if (cancelled) { |
|||
taskMap.remove(heatId); |
|||
} |
|||
return cancelled; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
static class CraftsTask implements Runnable { |
|||
private final Long heatId; |
|||
private final Long craftId; |
|||
|
|||
public CraftsTask(Long craftId, Long heatId) { |
|||
this.heatId = heatId; |
|||
this.craftId = craftId; |
|||
} |
|||
|
|||
@Override |
|||
public void run() { |
|||
try { |
|||
while (!Thread.currentThread().isInterrupted()) { |
|||
System.out.println("加热区 " + heatId + " 工艺运行中..."); |
|||
Thread.sleep(1000); |
|||
} |
|||
} catch (InterruptedException e) { |
|||
Thread.currentThread().interrupt(); |
|||
System.out.println("加热区 " + heatId + " 工艺被中断"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
//抬起托盘 |
|||
public void upTray(int heaterId) { |
|||
deviceService.raiseTray("11"); |
|||
} |
|||
|
|||
//降下托盘 |
|||
public void downTray(int heaterId) { |
|||
deviceService.lowerTray("11"); |
|||
} |
|||
|
|||
//添加溶液(先固定16个试管全进行加液) |
|||
public void addLiquid() { |
|||
|
|||
} |
|||
|
|||
//移至加液 |
|||
public void moveToSol() { |
|||
|
|||
} |
|||
|
|||
//移至加热 |
|||
public void moveToHeater(int heaterId) { |
|||
|
|||
} |
|||
|
|||
//摇匀 |
|||
public void shaking() { |
|||
|
|||
} |
|||
|
|||
//开始加热 |
|||
public void startHeating(int heaterId) { |
|||
|
|||
} |
|||
|
|||
//停止加热 |
|||
public void stopHeating(int heaterId) { |
|||
|
|||
} |
|||
|
|||
//拍照 |
|||
public void takePhoto() { |
|||
|
|||
} |
|||
|
|||
//移至异常 |
|||
public void moveToExc() { |
|||
|
|||
} |
|||
|
|||
//移除异常 |
|||
public void moveOutToExc() { |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 等待 |
|||
* |
|||
* @param millis 毫秒 |
|||
*/ |
|||
private boolean delay(int millis) { |
|||
try { |
|||
Thread.sleep(millis); |
|||
return true; |
|||
} catch (InterruptedException e) { |
|||
Thread.currentThread().interrupt(); |
|||
} |
|||
return false; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue