From b3814333d786324bb81cca7d1bcf5ac8f2f1a7cf Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期三, 23 七月 2025 08:35:33 +0800
Subject: [PATCH] 保存一个版本

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |   80 ++++++++++++++++++++++++++++++----------
 1 files changed, 60 insertions(+), 20 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
index 1516ccf..2092f91 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -96,6 +96,10 @@
     private LaneService laneService;
     @Autowired
     private ActionSorter actionSorter;
+    @Autowired
+    private TaskReportService taskReportService;
+    @Autowired
+    private AgvDurationService agvDurationService;
 
     @SuppressWarnings("all")
     @Transactional
@@ -286,7 +290,9 @@
      */
     @Transactional(propagation = Propagation.REQUIRES_NEW)
     public void buildMajorTask(Long agvId, List<Task> taskList) {
-        if (Cools.isEmpty(agvId, taskList)) { return; }
+        if (Cools.isEmpty(agvId, taskList)) {
+            return;
+        }
         try {
             // valid -----------------------------------------------
             Agv agv = agvService.getById(agvId);
@@ -326,16 +332,18 @@
              * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType)
              */
             Map<String, List<TaskPosDto>> groups = new HashMap<>();
-            final String sameGroupXy = configService.getVal( "sameGroupXy", String.class);
+            final String sameGroupXy = configService.getVal("sameGroupXy", String.class);
 
             int backpackLev = 0;
             for (Task task : taskList) {
 
-                backpackLev ++;
+                backpackLev++;
                 Code startCode = null;
                 Code endCode = null;
-                Loc oriLoc = null; Loc destLoc = null;
-                Sta oriSta = null; Sta destSta = null;
+                Loc oriLoc = null;
+                Loc destLoc = null;
+                Sta oriSta = null;
+                Sta destSta = null;
                 switch (Objects.requireNonNull(TaskTypeType.get(task.getTaskTypeEl()))) {
                     case LOC_TO_LOC:
                         oriLoc = locService.getById(task.getOriLoc());
@@ -438,7 +446,7 @@
 
             // re-order by agv current position
             Code currCode = codeService.getCacheById(agvDetail.getRecentCode());
-            Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
+            Double[] currPosition = new Double[]{currCode.getX(), currCode.getY()};
 
             List<List<TaskPosDto>> pickGroups = new ArrayList<>();
             List<List<TaskPosDto>> dropGroups = new ArrayList<>();
@@ -484,7 +492,7 @@
             List<Segment> segmentList = new ArrayList<>();
             for (List<TaskPosDto> dtoList : list) {
                 for (TaskPosDto taskPosDto : dtoList) {
-                    segSerial ++;
+                    segSerial++;
                     AgvBackpackType backpackType = AgvBackpackDto.find(backpackDtoList, taskPosDto.getTaskId());
                     assert null != backpackType;
 
@@ -532,9 +540,12 @@
     /**
      * 鍏呯數 鍥炲緟鏈轰綅浠诲姟
      */
-    @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional
     public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) {
-        if (Cools.isEmpty(agvId, taskType)) { return false; }
+        if (Cools.isEmpty(agvId, taskType)) {
+            return false;
+        }
         try {
             String agvNo = agvService.getAgvNo(agvId);
             if (!agvService.judgeEnable(agvId)) {
@@ -581,7 +592,7 @@
             task.setAgvId(agvId);
             task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
             List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId));
-            task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum()));
+            task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks) ? null : lastTasks.get(0).getSeqNum()));
             task.setOriCode(agvDetail.getCode());
             task.setDestCode(endCode.getId());
             // lane
@@ -589,7 +600,7 @@
             if (null != destLane) {
                 task.setDestLaneHash(destLane.getHashCode());
             }
-            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE)?2:1);
+            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE) ? 2 : 1);
             task.setTaskSts(TaskStsType.ASSIGN.val());
             task.setTaskType(taskType.val());
             task.setIoTime(now);
@@ -597,6 +608,7 @@
             if (!taskService.save(task)) {
                 throw new BusinessException(task.getSeqNum() + " failed to save");
             }
+
 
             // generate travel
             Travel travel = new Travel();
@@ -611,13 +623,20 @@
             }
 
             // generate segment
-            int segSerial = 0;     segSerial ++;
+            int segSerial = 0;
+            segSerial++;
             List<Segment> segmentList = new ArrayList<>();
 
             String posType = "";
-            switch (taskType){
+            switch (taskType) {
                 case TO_CHARGE:
                     posType = TaskPosDto.PosType.TO_CHARGE.toString();
+                    //鎻掑叆鍏呯數浠诲姟
+                    AgvDuration agvDuration = new AgvDuration();
+                    agvDuration.setHappenTime(now);
+                    agvDuration.setAgvId(agvId);
+                    agvDuration.setTaskNo(task.getId());
+                    agvDurationService.save(agvDuration);
                     break;
                 case TO_STANDBY:
                     posType = TaskPosDto.PosType.TO_STANDBY.toString();
@@ -687,7 +706,9 @@
     @Transactional
     public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) {
         try {
-            if (Cools.isEmpty(agvId, segmentList)) { return; }
+            if (Cools.isEmpty(agvId, segmentList)) {
+                return;
+            }
             Date now = new Date();
             long actionPrepareSts = ActionStsType.PREPARE.val();
 //            JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
@@ -729,7 +750,9 @@
                     List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1);
 
                     for (int i = 0; i < pathListPart.size(); i++) {
-                        if (i == 0) { continue; }
+                        if (i == 0) {
+                            continue;
+                        }
 
                         String next = pathListPart.get(i);
 
@@ -938,7 +961,7 @@
                                 task.getBusId(),    // 鎬荤嚎
                                 task.getId(),    // 浠诲姟
                                 null,    // 鍔ㄤ綔鍙�
-                                 null,    // 浼樺厛绾�
+                                null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyReleaseToShelvesLoc.desc,    // 鍚嶇О
                                 (double) agvDirectionType.val,    // 灞炴�у��
                                 lastCode.getData(),    // 鍦伴潰鐮�
@@ -1439,9 +1462,9 @@
 
                 // segment list
                 List<Segment> segmentList = segmentService.list(new LambdaQueryWrapper<Segment>()
-                        .eq(Segment::getGroupId, serialNo)
+                                .eq(Segment::getGroupId, serialNo)
 //                        .eq(Segment::getState, SegmentStateType.RUNNING.toString())
-                        .orderByAsc(Segment::getSerial)
+                                .orderByAsc(Segment::getSerial)
                 );
 
                 // settlement
@@ -1471,8 +1494,10 @@
         for (Segment segment : segmentList) {
             boolean taskComplete = false;
 
-            Task task = taskService.getById(segment.getTaskId());   assert null != task;
-            TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());     assert null != typeType;
+            Task task = taskService.getById(segment.getTaskId());
+            assert null != task;
+            TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
+            assert null != typeType;
 
             TaskPosDto.PosType posType = TaskPosDto.queryPosType(segment.getPosType());
             switch (Objects.requireNonNull(posType)) {
@@ -1508,6 +1533,21 @@
                     log.error("Task [{}] 鏇存柊澶辫触 锛侊紒锛�", task.getSeqNum());
                 } else {
                     log.info("Task [{}] 浣滀笟瀹屾瘯 ==========>> ", task.getSeqNum());
+                    // TODO 鎻掑叆涓�鏉′笂鎶ヨ褰�
+                    TaskReport taskReport = new TaskReport();
+                    taskReport.setAgvId(task.getAgvId());
+                    taskReport.setBusNo(task.getBusId$());
+                    taskReport.setCreateTime(new Date());
+                    taskReport.setDestLoc(task.getDestLoc());
+                    taskReport.setDestSta(task.getDestSta());
+                    taskReport.setSeqNum(task.getSeqNum());
+                    taskReport.setTaskSts(task.getTaskSts());
+                    taskReport.setOriLoc(task.getOriLoc());
+                    taskReport.setOriSta(task.getOriSta());
+                    taskReport.setZpallet(task.getZpallet());
+                    if (!taskReportService.save(taskReport)) {
+                        log.info("TaskReport [{}] 鎻掑叆澶辫触 ==========>> ", JSON.toJSONString(taskReport));
+                    }
                 }
 
             }

--
Gitblit v1.9.1