Browse Source

去掉 Model 全部换成 R. 前端 success==false 时显示异常原因

master
修宁 6 months ago
parent
commit
f2f0a9bc8a
  1. 14
      servo/src/main/java/com/galaxis/rcs/RCSService.java
  2. 30
      servo/src/main/java/com/yvan/LccUtils.java
  3. 34
      servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntime.java
  4. 11
      servo/src/main/java/com/yvan/workbench/controller/EnvController.java
  5. 117
      servo/src/main/java/com/yvan/workbench/controller/RcsController.java
  6. 59
      servo/src/main/java/com/yvan/workbench/model/entity/Model.java
  7. 44
      servo/src/main/java/com/yvan/workbench/service/LccMapService.java

14
servo/src/main/java/com/galaxis/rcs/RCSService.java

@ -143,12 +143,12 @@ public class RCSService {
wayPointId = parts[0]; wayPointId = parts[0];
direction = parts[1]; direction = parts[1];
if(Strings.isNullOrEmpty(wayPointId)){ if (Strings.isNullOrEmpty(wayPointId)) {
log.warn("wayPointId is empty for executorId: {}", item.get("executor_id")); log.warn("wayPointId is empty for executorId: {}", item.get("executor_id"));
continue; // 跳过wayPointId为空的执行器 continue; // 跳过wayPointId为空的执行器
} }
if(Strings.isNullOrEmpty(direction)) { if (Strings.isNullOrEmpty(direction)) {
log.warn("direction is empty for executorId: {}", item.get("executor_id")); log.warn("direction is empty for executorId: {}", item.get("executor_id"));
continue; // 跳过方向为空的执行器 continue; // 跳过方向为空的执行器
} }
@ -183,6 +183,16 @@ public class RCSService {
runtime.start(); runtime.start();
} }
public static void projectStop(String projectUuid, Long envId) {
LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.getByProjectEnv(projectUuid, envId);
if (runtime != null) {
LogisticsRuntimeService.INSTANCE.stopByProjectEnv(projectUuid, envId);
log.info("Project {} with envId {} has been stopped.", projectUuid, envId);
} else {
log.warn("Project {} with envId {} is not running.", projectUuid, envId);
}
}
// /** // /**
// * 初始化RCS服务 // * 初始化RCS服务
// */ // */

30
servo/src/main/java/com/yvan/LccUtils.java

@ -0,0 +1,30 @@
package com.yvan;
import com.google.common.base.Joiner;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.nio.charset.StandardCharsets;
@Slf4j
public class LccUtils {
public static String normalizePath(String path) {
return FilenameUtils.normalize(path, true);
}
@SneakyThrows
public static void saveFile(File file, String content, String reason) {
log.info("write file for {}: {}", reason, normalizePath(file.getAbsolutePath()));
FileUtils.writeStringToFile(file, content, StandardCharsets.UTF_8);
}
@SneakyThrows
public static String readFile(File file, String reason) {
log.info("load file for {}: {}", reason, normalizePath(file.getAbsolutePath()));
String path = file.getAbsolutePath();
return Joiner.on("\n").join(FileUtils.readLines(file, StandardCharsets.UTF_8));
}
}

34
servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntime.java

@ -97,11 +97,6 @@ public class LogisticsRuntime {
public final TaskDispatchFactory taskDispatchFactory = new TaskDispatchFactory(this); public final TaskDispatchFactory taskDispatchFactory = new TaskDispatchFactory(this);
/** /**
* 物流流动单元周转箱托盘纸箱等
*/
public final Map<String, FlowItem> flowItemMap = Maps.newConcurrentMap();
/**
* 物流任务执行单元(如拣货台小车AGV堆垛机人等) * 物流任务执行单元(如拣货台小车AGV堆垛机人等)
*/ */
public final Map<String, ExecutorItem> executorItemMap = Maps.newHashMap(); public final Map<String, ExecutorItem> executorItemMap = Maps.newHashMap();
@ -203,8 +198,9 @@ public class LogisticsRuntime {
case "pallet": case "pallet":
case "carton": case "carton":
item = new FlowItem(this, itemObject); // 库存不在运行时加载
this.flowItemMap.put(item.getId(), (FlowItem) item); // item = new FlowItem(this, itemObject);
// this.flowItemMap.put(item.getId(), (FlowItem) item);
break; break;
case "cl2": case "cl2":
@ -225,6 +221,19 @@ public class LogisticsRuntime {
if (this.isRunning) { if (this.isRunning) {
throw new RuntimeException("environment is already running"); throw new RuntimeException("environment is already running");
} }
BannerUtils.printConfig(log, "LogisticsRuntime Start", new String[]{
"projectUUID: " + this.projectUUID,
"envId: " + this.envId,
"projectPath: " + this.project.getProjectFileLocation(),
"envPath: " + this.env.getFileLocation(),
"virtual: " + this.isVirtual,
"floor: " + Joiner.on(",").join(this.floorMap.values().stream().map(Floor::toString).toList()),
"mqtt: " + this.env.getEnvConfig().getMqtt().getBrokerUrl(),
"clientId: " + this.clientId,
"executors: " + this.executorItemMap.size(),
});
this.isRunning = true; this.isRunning = true;
this.startTime = System.currentTimeMillis(); this.startTime = System.currentTimeMillis();
this.stopTime = 0L; this.stopTime = 0L;
@ -250,17 +259,6 @@ public class LogisticsRuntime {
// 启动任务指派服务 // 启动任务指派服务
this.taskDispatchFactory.startPolling(); this.taskDispatchFactory.startPolling();
BannerUtils.printConfig(log, "LogisticsRuntime Start Success", new String[]{
"projectUUID: " + this.projectUUID,
"envId: " + this.envId,
"virtual: " + this.isVirtual,
"floor: " + Joiner.on(",").join(this.floorMap.values().stream().map(Floor::toString).toList()),
"mqtt: " + this.env.getEnvConfig().getMqtt().getBrokerUrl(),
"clientId: " + this.clientId,
"executors: " + this.executorItemMap.size(),
"flowItems: " + this.flowItemMap.size(),
});
} }
public boolean isRunning() { public boolean isRunning() {

11
servo/src/main/java/com/yvan/workbench/controller/EnvController.java

@ -1,9 +1,7 @@
package com.yvan.workbench.controller; package com.yvan.workbench.controller;
import com.galaxis.rcs.RCSService;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.yvan.workbench.SpringContext; import com.yvan.workbench.SpringContext;
import com.yvan.workbench.model.entity.Model;
import com.yvan.workbench.service.LccMapService; import com.yvan.workbench.service.LccMapService;
import org.clever.core.Conv; import org.clever.core.Conv;
import org.clever.core.model.response.R; import org.clever.core.model.response.R;
@ -12,20 +10,17 @@ import org.clever.data.jdbc.QueryDSL;
import org.clever.data.jdbc.querydsl.utils.QueryDslUtils; import org.clever.data.jdbc.querydsl.utils.QueryDslUtils;
import org.clever.web.mvc.annotation.RequestBody; import org.clever.web.mvc.annotation.RequestBody;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import static com.galaxis.rcs.common.query.QLccBasContainer.lccBasContainer; import static com.galaxis.rcs.common.query.QLccBasContainer.lccBasContainer;
import static com.galaxis.rcs.common.query.QLccBasExecutor.lccBasExecutor; import static com.galaxis.rcs.common.query.QLccBasExecutor.lccBasExecutor;
import static com.galaxis.rcs.common.query.QLccBasLocation.lccBasLocation; import static com.galaxis.rcs.common.query.QLccBasLocation.lccBasLocation;
import static com.galaxis.rcs.common.query.QLccEnvInfo.lccEnvInfo;
import static com.galaxis.rcs.common.query.QLccInvLpn.lccInvLpn; import static com.galaxis.rcs.common.query.QLccInvLpn.lccInvLpn;
public class EnvController { public class EnvController {
static final QueryDSL queryDSL = DaoFactory.getQueryDSL(); static final QueryDSL queryDSL = DaoFactory.getQueryDSL();
public static Model<?> getAllEnv(@RequestBody Map<String, Object> params) { public static R<?> getAllEnv(@RequestBody Map<String, Object> params) {
// var list = queryDSL.select(QueryDslUtils.linkedMap(lccEnvInfo)) // var list = queryDSL.select(QueryDslUtils.linkedMap(lccEnvInfo))
// .from(lccEnvInfo) // .from(lccEnvInfo)
// .where(lccEnvInfo.worldId.eq(Conv.asString(params.get("worldId")))) // .where(lccEnvInfo.worldId.eq(Conv.asString(params.get("worldId"))))
@ -34,13 +29,13 @@ public class EnvController {
// 从文件系统中获取所有环境配置 // 从文件系统中获取所有环境配置
String worldId = Conv.asString(params.get("worldId")); String worldId = Conv.asString(params.get("worldId"));
if (Strings.isNullOrEmpty(worldId)) { if (Strings.isNullOrEmpty(worldId)) {
return Model.newFail("worldId must not be null"); return R.fail("worldId must not be null");
} }
var lccMapService = SpringContext.HOLDER.getBean(LccMapService.class); var lccMapService = SpringContext.HOLDER.getBean(LccMapService.class);
var list = lccMapService.getAllEnv(worldId); var list = lccMapService.getAllEnv(worldId);
return Model.newSuccess(list); return R.success(list);
} }
public static R<?> getAllInv(@RequestBody Map<String, Object> params) { public static R<?> getAllInv(@RequestBody Map<String, Object> params) {

117
servo/src/main/java/com/yvan/workbench/controller/RcsController.java

@ -15,7 +15,6 @@ import com.yvan.logisticsModel.ExecutorItem;
import com.yvan.logisticsModel.LogisticsRuntime; import com.yvan.logisticsModel.LogisticsRuntime;
import com.yvan.logisticsModel.LogisticsRuntimeService; import com.yvan.logisticsModel.LogisticsRuntimeService;
import com.yvan.logisticsModel.StaticItem; import com.yvan.logisticsModel.StaticItem;
import com.yvan.workbench.model.entity.Model;
import org.clever.core.Conv; import org.clever.core.Conv;
import org.clever.core.id.SnowFlake; import org.clever.core.id.SnowFlake;
import org.clever.core.model.response.R; import org.clever.core.model.response.R;
@ -39,25 +38,39 @@ public class RcsController {
RCSService.projectStart(projectUuid, envId); RCSService.projectStart(projectUuid, envId);
return R.success("Project started successfully"); return R.success("Project started successfully");
}
public static R<?> projectStop(@RequestBody Map<String, Object> params) {
String projectUuid = Conv.asString(params.get("projectUUID"));
Long envId = Conv.asLong(params.get("envId"));
if (Strings.isNullOrEmpty(projectUuid)) {
return R.fail("projectUUID Must not be empty");
}
if (envId == null || envId < 0) {
return R.fail("envId Must not be empty");
}
RCSService.projectStop(projectUuid, envId);
return R.success("Project stopped successfully");
} }
public static Model<?> agvToCharger(@RequestBody Map<String, Object> params) { public static R<?> agvToCharger(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<Object>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
String chargerId = Conv.asString(params.get("chargerId")); String chargerId = Conv.asString(params.get("chargerId"));
if (Strings.isNullOrEmpty(chargerId)) { if (Strings.isNullOrEmpty(chargerId)) {
return Model.newFail("chargerId Must not be empty"); return R.fail("chargerId Must not be empty");
} }
StaticItem toItem = ps.runtime.getStaticItemById(chargerId); StaticItem toItem = ps.runtime.getStaticItemById(chargerId);
if (toItem == null) { if (toItem == null) {
return Model.newFail("target wayPoint not found!"); return R.fail("target wayPoint not found!");
} }
ps.bizTask.setTaskTo(chargerId); ps.bizTask.setTaskTo(chargerId);
@ -73,20 +86,20 @@ public class RcsController {
ps.agv.logicY = ps.fromItem.logicY; ps.agv.logicY = ps.fromItem.logicY;
ps.agv.dispatchTask(ps.planSequence); ps.agv.dispatchTask(ps.planSequence);
return Model.newSuccess(ps.planSequence.toPrettyMap()); return R.success(ps.planSequence.toPrettyMap());
} }
public static Model<Object> agvMove(@RequestBody Map<String, Object> params) { public static R<?> agvMove(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<?>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
String targetWayPointId = Conv.asString(params.get("targetWayPointId")); String targetWayPointId = Conv.asString(params.get("targetWayPointId"));
if (Strings.isNullOrEmpty(targetWayPointId)) { if (Strings.isNullOrEmpty(targetWayPointId)) {
return Model.newFail("targetWayPointId Must not be empty"); return R.fail("targetWayPointId Must not be empty");
} }
String targetDirection = Conv.asString(params.get("targetDirection")); String targetDirection = Conv.asString(params.get("targetDirection"));
if (Strings.isNullOrEmpty(targetDirection)) { if (Strings.isNullOrEmpty(targetDirection)) {
@ -95,7 +108,7 @@ public class RcsController {
StaticItem toItem = ps.runtime.getStaticItemById(targetWayPointId); StaticItem toItem = ps.runtime.getStaticItemById(targetWayPointId);
if (toItem == null) { if (toItem == null) {
return Model.newFail("target wayPoint not found!"); return R.fail("target wayPoint not found!");
} }
ps.bizTask.setTaskTo(targetWayPointId); ps.bizTask.setTaskTo(targetWayPointId);
@ -111,42 +124,42 @@ public class RcsController {
ps.agv.logicY = ps.fromItem.logicY; ps.agv.logicY = ps.fromItem.logicY;
ps.agv.dispatchTask(ps.planSequence); ps.agv.dispatchTask(ps.planSequence);
return Model.newSuccess(ps.planSequence.toPrettyMap()); return R.success(ps.planSequence.toPrettyMap());
} }
public static Model<Object> agvInfo(@RequestBody Map<String, Object> params) { public static R<Object> agvInfo(@RequestBody Map<String, Object> params) {
String projectUUID = Conv.asString(params.get("projectUUID")); String projectUUID = Conv.asString(params.get("projectUUID"));
Long envId = Conv.asLong(params.get("envId")); Long envId = Conv.asLong(params.get("envId"));
String agvId = Conv.asString(params.get("agvId")); String agvId = Conv.asString(params.get("agvId"));
if (Strings.isNullOrEmpty(agvId)) { if (Strings.isNullOrEmpty(agvId)) {
return Model.newFail("agvId Must not be empty"); return R.fail("agvId Must not be empty");
} }
LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.INSTANCE.getByProjectEnv(projectUUID, envId); LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.INSTANCE.getByProjectEnv(projectUUID, envId);
ExecutorItem executorItem = logisticsRuntime.executorItemMap.get(agvId); ExecutorItem executorItem = logisticsRuntime.executorItemMap.get(agvId);
if (executorItem == null) { if (executorItem == null) {
return Model.newFail("executor not found: " + agvId); return R.fail("executor not found: " + agvId);
} }
if (!(executorItem instanceof PtrAgvItem)) { if (!(executorItem instanceof PtrAgvItem)) {
return Model.newFail("executor is not a PtrAgvItem id=" + agvId); return R.fail("executor is not a PtrAgvItem id=" + agvId);
} }
return Model.newSuccess(executorItem); return R.success(executorItem);
} }
public static Model<Object> agvUnload(@RequestBody Map<String, Object> params) { public static R<Object> agvUnload(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<Object>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
String targetStoreLoc = Conv.asString(params.get("targetStoreLoc")); String targetStoreLoc = Conv.asString(params.get("targetStoreLoc"));
if (Strings.isNullOrEmpty(targetStoreLoc)) { if (Strings.isNullOrEmpty(targetStoreLoc)) {
return Model.newFail("targetStoreLoc Must not be empty"); return R.fail("targetStoreLoc Must not be empty");
} }
StoreLocation targetLocation = StoreLocation.of(targetStoreLoc, "/"); StoreLocation targetLocation = StoreLocation.of(targetStoreLoc, "/");
@ -162,20 +175,20 @@ public class RcsController {
ps.agv.logicY = ps.fromItem.logicY; ps.agv.logicY = ps.fromItem.logicY;
ps.agv.dispatchTask(ps.planSequence); ps.agv.dispatchTask(ps.planSequence);
return Model.newSuccess(ps.planSequence.toPrettyMap()); return R.success(ps.planSequence.toPrettyMap());
} }
public static Model<Object> agvLoad(@RequestBody Map<String, Object> params) { public static R<?> agvLoad(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<?>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
String targetStoreLoc = Conv.asString(params.get("targetStoreLoc")); String targetStoreLoc = Conv.asString(params.get("targetStoreLoc"));
if (Strings.isNullOrEmpty(targetStoreLoc)) { if (Strings.isNullOrEmpty(targetStoreLoc)) {
return Model.newFail("targetStoreLoc Must not be empty"); return R.fail("targetStoreLoc Must not be empty");
} }
StoreLocation targetLocation = StoreLocation.of(targetStoreLoc, "/"); StoreLocation targetLocation = StoreLocation.of(targetStoreLoc, "/");
@ -191,26 +204,26 @@ public class RcsController {
ps.agv.logicY = ps.fromItem.logicY; ps.agv.logicY = ps.fromItem.logicY;
ps.agv.dispatchTask(ps.planSequence); ps.agv.dispatchTask(ps.planSequence);
return Model.newSuccess(ps.planSequence.toPrettyMap()); return R.success(ps.planSequence.toPrettyMap());
} }
public static Model<Object> cancelTasks(@RequestBody Map<String, Object> params) { public static R<?> cancelTasks(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<?>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
ps.agv.cancelTask(); ps.agv.cancelTask();
return Model.newSuccess("AGV tasks cancelled successfully"); return R.success("AGV tasks cancelled successfully");
} }
public static Model<Object> waitTaskFinish(@RequestBody Map<String, Object> params) { public static R<?> waitTaskFinish(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<?>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
@ -222,19 +235,19 @@ public class RcsController {
Thread.sleep(100); // 等待100毫秒 Thread.sleep(100); // 等待100毫秒
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); // 恢复中断状态 Thread.currentThread().interrupt(); // 恢复中断状态
return Model.newFail("Interrupted while waiting for task to finish"); return R.fail("Interrupted while waiting for task to finish");
} }
} }
var cost = System.currentTimeMillis() - now; var cost = System.currentTimeMillis() - now;
return Model.newSuccess(cost); return R.success(cost);
} }
public static Model<Object> agvCarry(@RequestBody Map<String, Object> params) { public static R<?> agvCarry(@RequestBody Map<String, Object> params) {
Object ret = getCommonParamAndCreateBizTask(params); Object ret = getCommonParamAndCreateBizTask(params);
if (ret instanceof Model) { if (ret instanceof R) {
// 异常 // 异常
return (Model<Object>) ret; return (R<?>) ret;
} }
RcsCommonParam ps = (RcsCommonParam) ret; RcsCommonParam ps = (RcsCommonParam) ret;
@ -242,10 +255,10 @@ public class RcsController {
String targetStoreLoc = Conv.asString(params.get("targetStoreLoc")); String targetStoreLoc = Conv.asString(params.get("targetStoreLoc"));
if (Strings.isNullOrEmpty(fromStoreLoc)) { if (Strings.isNullOrEmpty(fromStoreLoc)) {
return Model.newFail("fromStoreLoc Must not be empty"); return R.fail("fromStoreLoc Must not be empty");
} }
if (Strings.isNullOrEmpty(targetStoreLoc)) { if (Strings.isNullOrEmpty(targetStoreLoc)) {
return Model.newFail("targetStoreLoc Must not be empty"); return R.fail("targetStoreLoc Must not be empty");
} }
StoreLocation sourceLocation = StoreLocation.of(fromStoreLoc, "/"); StoreLocation sourceLocation = StoreLocation.of(fromStoreLoc, "/");
@ -253,11 +266,11 @@ public class RcsController {
StaticItem sourceItem = ps.runtime.getStaticItemById(sourceLocation.rackId()); StaticItem sourceItem = ps.runtime.getStaticItemById(sourceLocation.rackId());
if (sourceItem == null) { if (sourceItem == null) {
return Model.newFail("fromStoreLoc storePoint not found!"); return R.fail("fromStoreLoc storePoint not found!");
} }
StaticItem targetItem = ps.runtime.getStaticItemById(targetLocation.rackId()); StaticItem targetItem = ps.runtime.getStaticItemById(targetLocation.rackId());
if (targetItem == null) { if (targetItem == null) {
return Model.newFail("targetStoreLoc storePoint not found!"); return R.fail("targetStoreLoc storePoint not found!");
} }
ps.bizTask.setTaskFrom(fromStoreLoc); ps.bizTask.setTaskFrom(fromStoreLoc);
@ -276,7 +289,7 @@ public class RcsController {
ps.agv.logicY = ps.fromItem.logicY; ps.agv.logicY = ps.fromItem.logicY;
ps.agv.dispatchTask(ps.planSequence); ps.agv.dispatchTask(ps.planSequence);
return Model.newSuccess(ps.planSequence.toPrettyMap()); return R.success(ps.planSequence.toPrettyMap());
} }
@ -287,13 +300,13 @@ public class RcsController {
Map<String, Object> option = (Map<String, Object>) params.get("option"); Map<String, Object> option = (Map<String, Object>) params.get("option");
if (Strings.isNullOrEmpty(projectUUID)) { if (Strings.isNullOrEmpty(projectUUID)) {
return Model.newFail("projectUUID Must not be empty"); return R.fail("projectUUID Must not be empty");
} }
if (envId == null || envId < 0) { if (envId == null || envId < 0) {
return Model.newFail("envId Must not be empty"); return R.fail("envId Must not be empty");
} }
if (Strings.isNullOrEmpty(agvId)) { if (Strings.isNullOrEmpty(agvId)) {
return Model.newFail("agvId Must not be empty"); return R.fail("agvId Must not be empty");
} }
if (option == null) { if (option == null) {
option = Maps.newHashMap(); option = Maps.newHashMap();
@ -303,10 +316,10 @@ public class RcsController {
ExecutorItem executorItem = runtime.executorItemMap.get(agvId); ExecutorItem executorItem = runtime.executorItemMap.get(agvId);
if (executorItem == null) { if (executorItem == null) {
return Model.newFail("executor not found: " + agvId); return R.fail("executor not found: " + agvId);
} }
if (!(executorItem instanceof PtrAgvItem agv)) { if (!(executorItem instanceof PtrAgvItem agv)) {
return Model.newFail("executor is not a PtrAgvItem id=" + agvId); return R.fail("executor is not a PtrAgvItem id=" + agvId);
} }
// 获取机器人当前所在位置, 也可以前端强制指定 // 获取机器人当前所在位置, 也可以前端强制指定
@ -325,10 +338,10 @@ public class RcsController {
} }
if (fromItem == null) { if (fromItem == null) {
return Model.newFail("PtrAgvItem not found at current location: " + agv.logicX + "_" + agv.logicY + ", id=" + agvId); return R.fail("PtrAgvItem not found at current location: " + agv.logicX + "_" + agv.logicY + ", id=" + agvId);
} }
if (fromDirection == null) { if (fromDirection == null) {
return Model.newFail("PtrAgvItem unkown direction id=" + agvId); return R.fail("PtrAgvItem unkown direction id=" + agvId);
} }
RcsTaskBiz bizTask = new RcsTaskBiz(); RcsTaskBiz bizTask = new RcsTaskBiz();

59
servo/src/main/java/com/yvan/workbench/model/entity/Model.java

@ -1,59 +0,0 @@
package com.yvan.workbench.model.entity;
import com.fasterxml.jackson.annotation.JsonInclude;
public class Model<T> implements java.io.Serializable {
private boolean success = false;
private T data;
private String msg = "";
public static <T> Model<T> newSuccess(T data) {
return new Model<T>().setData(data).setSuccess(true).setMsg("操作成功");
}
public static <T> Model<T> newFail(Exception e, T data) {
return new Model<T>().setMsg(e.toString()).setSuccess(false).setData(data);
}
public static <T> Model<T> newFail(String msg) {
return new Model<T>().setMsg(msg).setSuccess(false);
}
public T getData() {
return data;
}
public Model<T> setData(T data) {
this.data = data;
return this;
}
public String getMsg() {
return msg;
}
public Model<T> setMsg(String msg) {
this.msg = msg;
return this;
}
public boolean isSuccess() {
return success;
}
public Model<T> setSuccess(boolean success) {
this.success = success;
return this;
}
@JsonInclude(JsonInclude.Include.NON_NULL)
private Throwable exception;
public Throwable getException() {
return exception;
}
public void setException(Throwable exception) {
this.exception = exception;
}
}

44
servo/src/main/java/com/yvan/workbench/service/LccMapService.java

@ -3,6 +3,7 @@ package com.yvan.workbench.service;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.yvan.LccUtils;
import com.yvan.workbench.autoconfigure.LccConfigProperties; import com.yvan.workbench.autoconfigure.LccConfigProperties;
import com.yvan.workbench.model.entity.LccProject; import com.yvan.workbench.model.entity.LccProject;
import com.yvan.workbench.model.entity.LccProjectEnv; import com.yvan.workbench.model.entity.LccProjectEnv;
@ -25,7 +26,6 @@ public class LccMapService {
this.config = lccConfigProperties; this.config = lccConfigProperties;
} }
@SneakyThrows
public LccProject getProjectById(String projectUuid) { public LccProject getProjectById(String projectUuid) {
checkProjectUuid(projectUuid, false); checkProjectUuid(projectUuid, false);
var projectFile = new File(this.config.getLocation() + "/" + projectUuid + "/project.json"); var projectFile = new File(this.config.getLocation() + "/" + projectUuid + "/project.json");
@ -36,16 +36,12 @@ public class LccMapService {
); );
} }
log.info("load project file: {}", projectFile.getAbsolutePath()); String content = LccUtils.readFile(projectFile, "project");
String content = Joiner.on("\n").join(FileUtils.readLines(projectFile, StandardCharsets.UTF_8));
var project = JacksonMapper.getInstance().fromJson(content, LccProject.class); var project = JacksonMapper.getInstance().fromJson(content, LccProject.class);
project.setProjectFileLocation( project.setProjectFileLocation(LccUtils.normalizePath(projectFile.getAbsolutePath()));
FilenameUtils.normalize(projectFile.getAbsolutePath(), true)
);
return project; return project;
} }
@SneakyThrows
public LccProjectEnv getEnvById(String projectUuid, Long envId) { public LccProjectEnv getEnvById(String projectUuid, Long envId) {
checkProjectUuid(projectUuid, false); checkProjectUuid(projectUuid, false);
var projectFile = new File(this.config.getLocation() + "/" + projectUuid + "/envs/" + envId + ".json"); var projectFile = new File(this.config.getLocation() + "/" + projectUuid + "/envs/" + envId + ".json");
@ -55,8 +51,7 @@ public class LccMapService {
); );
} }
log.info("load project file: {}", projectFile.getAbsolutePath()); String content = LccUtils.readFile(projectFile, "project");
String content = Joiner.on("\n").join(FileUtils.readLines(projectFile, StandardCharsets.UTF_8));
if (Strings.isNullOrEmpty(content)) { if (Strings.isNullOrEmpty(content)) {
throw new RuntimeException( throw new RuntimeException(
String.format("LccMapService.getEnvById() - env '%s' content is empty", projectFile.getAbsolutePath()) String.format("LccMapService.getEnvById() - env '%s' content is empty", projectFile.getAbsolutePath())
@ -68,13 +63,10 @@ public class LccMapService {
); );
} }
var envInfo = JacksonMapper.getInstance().fromJson(content, LccProjectEnv.class); var envInfo = JacksonMapper.getInstance().fromJson(content, LccProjectEnv.class);
envInfo.setFileLocation( envInfo.setFileLocation(LccUtils.normalizePath(projectFile.getAbsolutePath()));
FilenameUtils.normalize(projectFile.getAbsolutePath(), true)
);
return envInfo; return envInfo;
} }
@SneakyThrows
public List<LccProject> getAllProjects() { public List<LccProject> getAllProjects() {
var mapLoc = new File(this.config.getLocation()); var mapLoc = new File(this.config.getLocation());
@ -91,8 +83,7 @@ public class LccMapService {
File projectFile = new File(projectFolder, "project.json"); File projectFile = new File(projectFolder, "project.json");
if (projectFile.exists() && projectFile.isFile()) { if (projectFile.exists() && projectFile.isFile()) {
// 反序列化 project.json 文件为 LccProject 对象 // 反序列化 project.json 文件为 LccProject 对象
log.info("load project file: {}", projectFile.getAbsolutePath()); String content = LccUtils.readFile(projectFile, "project");
String content = Joiner.on("\n").join(FileUtils.readLines(projectFile, StandardCharsets.UTF_8));
if (Strings.isNullOrEmpty(content)) { if (Strings.isNullOrEmpty(content)) {
continue; continue;
} }
@ -101,9 +92,7 @@ public class LccMapService {
} }
var modelWorld = JacksonMapper.getInstance().fromJson(content, LccProject.class); var modelWorld = JacksonMapper.getInstance().fromJson(content, LccProject.class);
modelWorld.setProjectFileLocation( modelWorld.setProjectFileLocation(LccUtils.normalizePath(projectFile.getAbsolutePath()));
FilenameUtils.normalize(projectFile.getAbsolutePath(), true)
);
list.add(modelWorld); list.add(modelWorld);
} }
} }
@ -156,15 +145,7 @@ public class LccMapService {
var projectFile = new File(projectDir, "project.json"); var projectFile = new File(projectDir, "project.json");
// 如果 project.json 文件与 content 内容不一致,则跟新覆盖写入 // 如果 project.json 文件与 content 内容不一致,则跟新覆盖写入
String contentOrigin = projectFile.exists() ? Joiner.on("\n").join(FileUtils.readLines(projectFile, StandardCharsets.UTF_8)) : ""; LccUtils.saveFile(projectFile, JacksonMapper.getInstance().toJsonPretty(project), "project");
String content = JacksonMapper.getInstance().toJsonPretty(project);
if (!content.equals(contentOrigin)) {
// 内容不一致时,更新项目的更新时间和更新人
log.info("write project file: {}", projectFile.getAbsolutePath());
FileUtils.writeStringToFile(projectFile, content, StandardCharsets.UTF_8);
} else {
log.info("project file no change, ignore write, path:{}", projectFile.getAbsolutePath());
}
} }
@SneakyThrows @SneakyThrows
@ -189,8 +170,7 @@ public class LccMapService {
); );
} }
log.info("load floor file: {}", floorFile.getAbsolutePath()); String content = LccUtils.readFile(floorFile, "floor");
String content = Joiner.on("\n").join(FileUtils.readLines(floorFile, StandardCharsets.UTF_8));
if (Strings.isNullOrEmpty(content)) { if (Strings.isNullOrEmpty(content)) {
// 如果内容为空,则返回空数组 // 如果内容为空,则返回空数组
content = "[]"; content = "[]";
@ -224,8 +204,7 @@ public class LccMapService {
// 保存楼层数据到文件 // 保存楼层数据到文件
var floorFile = new File(floorDir, catalogCode + ".json"); var floorFile = new File(floorDir, catalogCode + ".json");
log.info("write floor file: {}", floorFile.getAbsolutePath()); LccUtils.saveFile(floorFile, items, "floor");
FileUtils.writeStringToFile(floorFile, items, StandardCharsets.UTF_8);
} }
@SneakyThrows @SneakyThrows
@ -245,8 +224,7 @@ public class LccMapService {
for (File propFile : Objects.requireNonNull(envLoc.listFiles())) { for (File propFile : Objects.requireNonNull(envLoc.listFiles())) {
if (propFile.exists() && propFile.isFile() && propFile.getName().endsWith(".json")) { if (propFile.exists() && propFile.isFile() && propFile.getName().endsWith(".json")) {
// 反序列化 project.json 文件为 LccProject 对象 // 反序列化 project.json 文件为 LccProject 对象
log.info("load env file: {}", propFile.getAbsolutePath()); String content = LccUtils.readFile(propFile, "env");
String content = Joiner.on("\n").join(FileUtils.readLines(propFile, StandardCharsets.UTF_8));
if (Strings.isNullOrEmpty(content)) { if (Strings.isNullOrEmpty(content)) {
continue; continue;
} }

Loading…
Cancel
Save