|
|
|
@ -1,25 +1,30 @@ |
|
|
|
package com.yvan.logisticsModel; |
|
|
|
|
|
|
|
import com.galaxis.rcs.common.entity.RcsTaskPlan; |
|
|
|
import com.galaxis.rcs.common.enums.BizTaskStatus; |
|
|
|
import com.galaxis.rcs.common.enums.BizTaskType; |
|
|
|
import com.galaxis.rcs.common.enums.PlanTaskType; |
|
|
|
import com.galaxis.rcs.connector.cl2.Cl2Item; |
|
|
|
import com.galaxis.rcs.inv.InvManager; |
|
|
|
import com.galaxis.rcs.plan.PlanTaskSequence; |
|
|
|
import com.galaxis.rcs.plan.path.NavigationGraph; |
|
|
|
import com.galaxis.rcs.plan.path.PathUtils; |
|
|
|
import com.galaxis.rcs.plan.path.PtrPathPlanner; |
|
|
|
import com.galaxis.rcs.ptr.AmrMessageHandler; |
|
|
|
import com.galaxis.rcs.ptr.PtrAgvItem; |
|
|
|
import com.galaxis.rcs.task.TaskDispatchFactory; |
|
|
|
import com.galaxis.rcs.task.TaskService; |
|
|
|
import com.google.common.base.Joiner; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.collect.Maps; |
|
|
|
import com.google.common.collect.Sets; |
|
|
|
import com.yvan.entity.AgvStatusVo; |
|
|
|
import com.yvan.entity.LccProject; |
|
|
|
import com.yvan.entity.LccProjectEnv; |
|
|
|
import com.yvan.event.AgvEventManager; |
|
|
|
import com.yvan.event.AgvEventType; |
|
|
|
import com.yvan.pusher.FrontendMessagePushService; |
|
|
|
import com.yvan.redis.LccRedisService; |
|
|
|
import com.yvan.entity.LccProject; |
|
|
|
import com.yvan.entity.LccProjectEnv; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.clever.core.BannerUtils; |
|
|
|
import org.clever.core.Conv; |
|
|
|
@ -28,7 +33,10 @@ import org.clever.data.jdbc.QueryDSL; |
|
|
|
import org.clever.data.redis.Redis; |
|
|
|
import org.clever.data.redis.RedisAdmin; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
/** |
|
|
|
* 物流运行时 |
|
|
|
@ -128,10 +136,10 @@ public class LogisticsRuntime { |
|
|
|
this.isVirtual = env.getIsVirtual(); |
|
|
|
this.serverId = serverId; |
|
|
|
|
|
|
|
this.setupEventHandle(); |
|
|
|
this.setupAgvEventHandle(); |
|
|
|
} |
|
|
|
|
|
|
|
private void setupEventHandle() { |
|
|
|
private void setupAgvEventHandle() { |
|
|
|
eventManager.subscribe((AgvEventType type, Object... args) -> { |
|
|
|
ExecutorItem sender = (ExecutorItem) args[0]; |
|
|
|
|
|
|
|
@ -139,6 +147,8 @@ public class LogisticsRuntime { |
|
|
|
for (int i = 1; i < args.length; i++) { |
|
|
|
eventArgs[i - 1] = Conv.asString(args[i]); |
|
|
|
} |
|
|
|
|
|
|
|
// ===================== 库存变化处理 =====================
|
|
|
|
if (type == AgvEventType.PLAN_TASK_COMPLETE) { |
|
|
|
PlanTaskSequence taskSequence = (PlanTaskSequence) args[1]; |
|
|
|
RcsTaskPlan taskPlan = (RcsTaskPlan) args[2]; |
|
|
|
@ -150,7 +160,72 @@ public class LogisticsRuntime { |
|
|
|
// 处理库存变化 agv -> rack
|
|
|
|
changeInvOfUnload(taskSequence, taskPlan); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ===================== 推送 AGV 事件到前端 =====================
|
|
|
|
switch (type) { |
|
|
|
case ONLINE: |
|
|
|
// AGV上线
|
|
|
|
this.frontendMessagePushService.pushDeviceAlive(sender.id, sender.getT(), true); |
|
|
|
break; |
|
|
|
|
|
|
|
case OFFLINE: |
|
|
|
// AGV下线
|
|
|
|
this.frontendMessagePushService.pushDeviceAlive(sender.id, sender.getT(), true); |
|
|
|
break; |
|
|
|
|
|
|
|
case FREE: |
|
|
|
case PLAN_TASK_SEQUENCE_COMPLETE: |
|
|
|
case PLAN_TASK_COMPLETE: |
|
|
|
case PLAN_TASK_EXCEPTION: |
|
|
|
case PLAN_TASK_SEQUENCE_ACCEPT: |
|
|
|
case PLAN_TASK_SEQUENCE_CANCEL: |
|
|
|
case PLAN_TASK_SEQUENCE_PAUSE: |
|
|
|
case PLAN_TASK_SEQUENCE_RESUME: |
|
|
|
case BLOCKED: |
|
|
|
case BLOCKED_RECOVER: |
|
|
|
case POS_CHANGED: |
|
|
|
case DIRECTION_CHANGED: |
|
|
|
case LOW_BATTERY: |
|
|
|
case MODE_CHANGED: |
|
|
|
// 设备状态变化
|
|
|
|
if (sender instanceof PtrAgvItem) { |
|
|
|
var ptr = (PtrAgvItem) sender; |
|
|
|
int taskCompleted = 0; |
|
|
|
int taskTotalCount = 0; |
|
|
|
if (ptr.planTaskSequence != null) { |
|
|
|
taskCompleted = ptr.planTaskSequence.completedCount(); |
|
|
|
taskTotalCount = ptr.planTaskSequence.taskTotalCount(); |
|
|
|
} |
|
|
|
var status = new AgvStatusVo( |
|
|
|
sender.id, |
|
|
|
sender.getT(), |
|
|
|
ptr.x, |
|
|
|
ptr.y, |
|
|
|
ptr.z, |
|
|
|
ptr.logicX, |
|
|
|
ptr.logicY, |
|
|
|
PathUtils.getDirectionByArmDirection(ptr.direction), |
|
|
|
ptr.orientation, |
|
|
|
ptr.battery.SOC, |
|
|
|
ptr.get__taskMode(), |
|
|
|
ptr.getTaskStatus(), |
|
|
|
ptr.isBlocked, |
|
|
|
taskCompleted, |
|
|
|
taskTotalCount, |
|
|
|
ptr.planTaskSequence == null ? null : ptr.planTaskSequence.bizTask.getBizTaskId(), |
|
|
|
ptr.planTaskSequence == null ? null : BizTaskType.fromString(ptr.planTaskSequence.bizTask.getBizType()), |
|
|
|
ptr.planTaskSequence == null ? null : BizTaskStatus.fromString(ptr.planTaskSequence.bizTask.getBizTaskStatus()), |
|
|
|
ptr.planTaskSequence == null ? null : ptr.planTaskSequence.bizTask.getTaskFrom(), |
|
|
|
ptr.planTaskSequence == null ? null : ptr.planTaskSequence.bizTask.getTaskTo(), |
|
|
|
ptr.planTaskSequence == null ? null : ptr.planTaskSequence.bizTask.getLpn() |
|
|
|
); |
|
|
|
this.frontendMessagePushService.pushDeviceStatus(sender.id, status); |
|
|
|
|
|
|
|
} else { |
|
|
|
log.error("AGV事件类型 {} 仅支持 PtrAgvItem 类型的执行器", type); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
BannerUtils.printConfig(log, this.projectUuid + "(" + this.envId + ") " + type + " AGV:" + sender.getId(), eventArgs); |
|
|
|
@ -161,28 +236,24 @@ public class LogisticsRuntime { |
|
|
|
* 库存转移 AGV->货架 |
|
|
|
*/ |
|
|
|
private void changeInvOfUnload(PlanTaskSequence taskSequence, RcsTaskPlan taskPlan) { |
|
|
|
queryDSL.beginTX(status -> { |
|
|
|
String lpn = taskSequence.carryLpn; |
|
|
|
|
|
|
|
queryDSL.beginTX(status -> { |
|
|
|
InvManager.invSave(this.envId, taskSequence.bizTask.getBizTaskId(), lpn, taskSequence.executorVo.getLocCode(), -taskSequence.carryQty); |
|
|
|
InvManager.invSave(this.envId, taskSequence.bizTask.getBizTaskId(), lpn, taskSequence.unloadBasLocationVo.getLocCode(), taskSequence.carryQty); |
|
|
|
|
|
|
|
this.frontendMessagePushService.pushInventoryUpdate(lpn, taskSequence.executorVo, taskSequence.unloadBasLocationVo, taskSequence.carryQty); |
|
|
|
}); |
|
|
|
this.frontendMessagePushService.pushInvUpdate(lpn, taskSequence.executorVo, taskSequence.unloadBasLocationVo, taskSequence.carryQty); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 库存转移 货架->AGV |
|
|
|
*/ |
|
|
|
private void changeInvOfLoad(PlanTaskSequence taskSequence, RcsTaskPlan taskPlan) { |
|
|
|
queryDSL.beginTX(status -> { |
|
|
|
String lpn = taskSequence.carryLpn; |
|
|
|
|
|
|
|
queryDSL.beginTX(status -> { |
|
|
|
InvManager.invSave(this.envId, taskSequence.bizTask.getBizTaskId(), lpn, taskSequence.loadBasLocationVo.getLocCode(), -taskSequence.carryQty); |
|
|
|
InvManager.invSave(this.envId, taskSequence.bizTask.getBizTaskId(), lpn, taskSequence.executorVo.getLocCode(), taskSequence.carryQty); |
|
|
|
|
|
|
|
this.frontendMessagePushService.pushInventoryUpdate(lpn, taskSequence.loadBasLocationVo, taskSequence.executorVo, taskSequence.carryQty); |
|
|
|
}); |
|
|
|
this.frontendMessagePushService.pushInvUpdate(lpn, taskSequence.loadBasLocationVo, taskSequence.executorVo, taskSequence.carryQty); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|