Browse Source

feat:增加执行工艺控制功能

master
白凤吉 6 months ago
parent
commit
5cf2c567a3
  1. 14
      src/main/java/com/qyft/gd/controller/CraftsController.java
  2. 72
      src/main/java/com/qyft/gd/device/service/DeviceOperationService.java
  3. 1
      src/main/java/com/qyft/gd/service/CraftsService.java
  4. 144
      src/main/java/com/qyft/gd/service/CraftsStepService.java
  5. 2
      src/main/java/com/qyft/gd/service/impl/CraftsServiceImpl.java

14
src/main/java/com/qyft/gd/controller/CraftsController.java

@ -2,6 +2,7 @@ package com.qyft.gd.controller;
import com.qyft.gd.model.entity.Crafts; import com.qyft.gd.model.entity.Crafts;
import com.qyft.gd.service.CraftsService; import com.qyft.gd.service.CraftsService;
import com.qyft.gd.service.CraftsStepService;
import com.qyft.gd.system.common.result.Result; import com.qyft.gd.system.common.result.Result;
import com.qyft.gd.system.common.result.ResultCode; import com.qyft.gd.system.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -20,6 +21,7 @@ import java.util.List;
@Slf4j @Slf4j
public class CraftsController { public class CraftsController {
private final CraftsService craftsService; private final CraftsService craftsService;
private final CraftsStepService craftsStepService;
@Operation(summary = "根据矿石id获取工艺列表") @Operation(summary = "根据矿石id获取工艺列表")
@GetMapping("/list/{oresId}") @GetMapping("/list/{oresId}")
@ -72,12 +74,20 @@ public class CraftsController {
@Operation(summary = "开始执行工艺") @Operation(summary = "开始执行工艺")
@PostMapping("/start") @PostMapping("/start")
public Result<String> startCrafts(@Parameter(description = "工艺id") @RequestParam Long craftId, @Parameter(description = "加热区id") @RequestParam Long heatId) { public Result<String> startCrafts(@Parameter(description = "工艺id") @RequestParam Long craftId, @Parameter(description = "加热区id") @RequestParam Long heatId) {
return Result.success();
boolean isSuccess = craftsStepService.startCrafts(craftId, heatId);
if (isSuccess) {
return Result.success();
}
return Result.failed();
} }
@Operation(summary = "停止执行工艺") @Operation(summary = "停止执行工艺")
@PostMapping("/stop") @PostMapping("/stop")
public Result<String> stopCrafts(@Parameter(description = "加热区id") @RequestParam Long heatId) { public Result<String> stopCrafts(@Parameter(description = "加热区id") @RequestParam Long heatId) {
return Result.success();
boolean isSuccess = craftsStepService.stopCrafts(heatId);
if (isSuccess) {
return Result.success();
}
return Result.failed();
} }
} }

72
src/main/java/com/qyft/gd/device/service/DeviceOperationService.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;
}
}

1
src/main/java/com/qyft/gd/service/CraftsService.java

@ -19,4 +19,5 @@ public interface CraftsService extends IService<Crafts> {
boolean updateCrafts(Crafts crafts); boolean updateCrafts(Crafts crafts);
boolean deleteCrafts(String idsStr); boolean deleteCrafts(String idsStr);
} }

144
src/main/java/com/qyft/gd/service/CraftsStepService.java

@ -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;
}
}

2
src/main/java/com/qyft/gd/service/impl/CraftsServiceImpl.java

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qyft.gd.mapper.CraftsMapper; import com.qyft.gd.mapper.CraftsMapper;
import com.qyft.gd.model.entity.Crafts; import com.qyft.gd.model.entity.Crafts;
import com.qyft.gd.service.CraftsService; import com.qyft.gd.service.CraftsService;
import com.qyft.gd.service.CraftsStepService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -45,4 +46,5 @@ public class CraftsServiceImpl extends ServiceImpl<CraftsMapper, Crafts> impleme
.collect(Collectors.toList()); .collect(Collectors.toList());
return this.removeByIds(ids); return this.removeByIds(ids);
} }
} }
Loading…
Cancel
Save