Browse Source

feat:执行工艺实现

master
白凤吉 6 months ago
parent
commit
3f27d40401
  1. 14
      src/main/java/com/qyft/gd/device/service/DeviceStepService.java
  2. 2
      src/main/java/com/qyft/gd/service/CraftsService.java
  3. 133
      src/main/java/com/qyft/gd/service/CraftsStepService.java
  4. 6
      src/main/java/com/qyft/gd/service/impl/CraftsServiceImpl.java

14
src/main/java/com/qyft/gd/device/service/DeviceStepService.java

@ -23,8 +23,8 @@ public class DeviceStepService {
* *
* @param heaterId 加热区id * @param heaterId 加热区id
*/ */
public void upTray(String heaterId) {
deviceService.raiseTray(heaterId);
public boolean upTray(String heaterId) {
return deviceService.raiseTray(heaterId);
} }
/** /**
@ -32,8 +32,8 @@ public class DeviceStepService {
* *
* @param heaterId 加热区id * @param heaterId 加热区id
*/ */
public void downTray(String heaterId) {
deviceService.lowerTray(heaterId);
public boolean downTray(String heaterId) {
return deviceService.lowerTray(heaterId);
} }
/** /**
@ -126,11 +126,11 @@ public class DeviceStepService {
/** /**
* 等待 * 等待
* *
* @param millis
* @param second
*/ */
private boolean delay(int millis) {
public boolean delay(int second) {
try { try {
Thread.sleep(millis);
Thread.sleep(second * 1000L);
return true; return true;
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();

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

@ -20,4 +20,6 @@ public interface CraftsService extends IService<Crafts> {
boolean deleteCrafts(String idsStr); boolean deleteCrafts(String idsStr);
Crafts findCraftsById(Long oresId);
} }

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

@ -1,8 +1,16 @@
package com.qyft.gd.service; package com.qyft.gd.service;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.qyft.gd.device.service.DeviceStepService;
import com.qyft.gd.model.bo.TubeSol;
import com.qyft.gd.model.entity.Crafts;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -11,14 +19,17 @@ import java.util.concurrent.Future;
/** /**
* 工艺操作 * 工艺操作
*/ */
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class CraftsStepService { public class CraftsStepService {
private final CraftsService craftsService;
private final DeviceStepService deviceStepService;
private final ExecutorService executorService = Executors.newCachedThreadPool(); private final ExecutorService executorService = Executors.newCachedThreadPool();
private final ConcurrentHashMap<Long, Future<?>> taskMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Long, Future<?>> taskMap = new ConcurrentHashMap<>();
// 启动任务的方法 // 启动任务的方法
public synchronized boolean startCrafts(Long craftId, Long heatId) { public synchronized boolean startCrafts(Long craftId, Long heatId) {
Future<?> taskFuture = taskMap.get(heatId); Future<?> taskFuture = taskMap.get(heatId);
@ -45,7 +56,7 @@ public class CraftsStepService {
} }
static class CraftsTask implements Runnable {
class CraftsTask implements Runnable {
private final Long heatId; private final Long heatId;
private final Long craftId; private final Long craftId;
@ -56,16 +67,120 @@ public class CraftsStepService {
@Override @Override
public void run() { public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
System.out.println("加热区 " + heatId + " 工艺运行中...");
Thread.sleep(1000);
while (!Thread.currentThread().isInterrupted()) {
Crafts crafts = craftsService.findCraftsById(craftId);
log.info("开始执行工艺,加热区 {},工艺 {}", heatId, crafts.getName());
String steps = crafts.getSteps();
JSONArray stepsJsonArray = JSONUtil.parseArray(steps);
for (Object stepsJsonObject : stepsJsonArray) {
JSONObject stepsJson = (JSONObject) stepsJsonObject;
String method = stepsJson.get("method").toString();
JSONObject params = (JSONObject) stepsJson.get("params");
boolean result = switch (method) {
case "upTray" -> upTray(params);
case "downTray" -> downTray(params);
case "addLiquid" -> addLiquid(params);
case "moveToSol" -> moveToSol(params);
case "moveToHeater" -> moveToHeater(params);
case "shaking" -> shaking(params);
case "startHeating" -> startHeating(params);
case "stopHeating" -> stopHeating(params);
case "takePhoto" -> takePhoto();
case "moveToExc" -> delay(params);
default -> false;
};
if (!result) {
//TODO 向前端反馈执行失败
return;
}
} }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("加热区 " + heatId + " 工艺被中断");
} }
} }
} }
/**
* 抬起托盘
*/
private boolean upTray(JSONObject params) {
String heaterId = params.get("heaterId").toString();
return deviceStepService.upTray(heaterId);
}
/**
* 降下托盘
*/
private boolean downTray(JSONObject params) {
String heaterId = params.get("heaterId").toString();
return deviceStepService.downTray(heaterId);
}
/**
* 添加溶液
*/
private boolean addLiquid(JSONObject params) {
JSONArray tubeSolJSONArray = params.getJSONArray("tubeSolList");
List<TubeSol> tubeSolList = JSONUtil.toList(tubeSolJSONArray.toString(), TubeSol.class);
return deviceStepService.addLiquid(tubeSolList);
}
/**
* 将指定加热区的托盘移至加液区
*/
private boolean moveToSol(JSONObject params) {
String heaterId = params.get("heaterId").toString();
return deviceStepService.moveToSol(heaterId);
}
/**
* 移至加热
*/
private boolean moveToHeater(JSONObject params) {
String heaterId = params.get("heaterId").toString();
return deviceStepService.moveToHeater(heaterId);
}
//摇匀
private boolean shaking(JSONObject params) {
Integer second = params.getInt("second");
return deviceStepService.shaking(second);
}
//开始加热
private boolean startHeating(JSONObject params) {
String heaterId = params.get("heaterId").toString();
Double temperature = params.getDouble("temperature");
return deviceStepService.startHeating(heaterId, temperature);
}
//停止加热
private boolean stopHeating(JSONObject params) {
String heaterId = params.get("heaterId").toString();
return deviceStepService.stopHeating(heaterId);
}
//拍照
private boolean takePhoto() {
return deviceStepService.takePhoto();
}
//移至异常
private boolean moveToExc() {
return true;
}
//移除异常
private boolean moveOutToExc() {
return true;
}
/**
* 等待
*/
private boolean delay(JSONObject params) {
Integer second = params.getInt("second");
return deviceStepService.delay(second);
}
} }

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

@ -4,7 +4,6 @@ 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;
@ -47,4 +46,9 @@ public class CraftsServiceImpl extends ServiceImpl<CraftsMapper, Crafts> impleme
return this.removeByIds(ids); return this.removeByIds(ids);
} }
@Override
public Crafts findCraftsById(Long id) {
return this.baseMapper.selectById(id);
}
} }
Loading…
Cancel
Save