From c42a7c76e24940db9e81307dc67104d9068c3119 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期二, 07 四月 2026 15:04:21 +0800
Subject: [PATCH] 1

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java |   89 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 1 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java
index f5361cd..e8e0107 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java
@@ -1,12 +1,18 @@
 package com.zy.acs.manager.core.scheduler;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusRtuOverTcp;
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
+import com.zy.acs.charge.ChargeCoreService;
+import com.zy.acs.common.constant.RedisConstant;
 import com.zy.acs.common.enums.AgvStatusType;
 import com.zy.acs.common.utils.RedisSupport;
 import com.zy.acs.framework.common.Cools;
 import com.zy.acs.framework.common.DateUtils;
 import com.zy.acs.manager.common.config.UplinkProperties;
 import com.zy.acs.manager.core.integrate.wms.TaskReportService;
+import com.zy.acs.manager.core.integrate.wms.FaultReportService;
+import com.zy.acs.manager.core.service.ChargeService;
 import com.zy.acs.manager.core.service.MainLockWrapService;
 import com.zy.acs.manager.manager.entity.*;
 import com.zy.acs.manager.manager.enums.*;
@@ -17,9 +23,12 @@
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.time.Instant;
+import java.time.ZoneId;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 /**
  * judge whether agv go to funcSta which be charging or standby
@@ -51,9 +60,19 @@
     private SegmentService segmentService;
     @Autowired
     private TaskReportService taskReportService;
+    @Autowired
+    private VehFaultRecService vehFaultRecService;
+    @Autowired
+    private FaultReportService faultReportService;
+    @Autowired
+    private ChargeService chargeService;
+    @Autowired
+    private ChargeCoreService chargeCoreService;
+
 
     @Scheduled(cron = "0/5 * * * * ? ")
     private synchronized void autoCharge(){
+        if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; }
         List<Agv> agvList = agvService.list(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, StatusType.ENABLE.val));
         for (Agv agv : agvList) {
             AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
@@ -94,6 +113,7 @@
     @Scheduled(cron = "0/1 * * * * ? ")
 //    @Scheduled(cron = "0 */2 * * * ? ")
     private synchronized void autoStandby(){
+        if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; }
         if (!configService.getVal("automaticStandbyPosition", Boolean.class)) { return; }
 
         List<Agv> agvList = agvService.list(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, StatusType.ENABLE.val));
@@ -107,6 +127,10 @@
 //            if (agvDetailService.isPowerLoss(agv, agvDetail, agvModel)) {
 //                continue;
 //            }
+            // 瀛樺湪鍏呯數鏍囪锛岃烦杩�
+            if (redis.getMap(RedisConstant.AGV_CHARGE_FLAG, agv.getUuid()) != null) {
+                continue;
+            }
             // is charging ?
             if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                 if (agvDetail.getSoc() < agvModel.getQuaBattery()) {
@@ -156,8 +180,9 @@
     private void reportTaskToUplink() {
         if (!uplinkProperties.getEnabled()) { return; }
         List<Task> taskList = taskService.list(new LambdaQueryWrapper<Task>()
-                .eq(Task::getUplinkSts, TaskUplinkStateType.PENDING.toString())
+                .in(Task::getUplinkSts, TaskUplinkStateType.PENDING.toString(), TaskUplinkStateType.FAILED.toString())
                 .eq(Task::getTaskSts, TaskStsType.COMPLETE.val())
+                .isNotNull(Task::getBusId)
         );
         if (Cools.isEmpty(taskList)) { return; }
         for (Task task : taskList) {
@@ -188,4 +213,66 @@
         }
     }
 
+
+    @Scheduled(cron = "0/3 * * * * ? ")
+    private void reportFault() {
+        String reportFaultUrl = configService.getVal("reportFaultUrl", String.class);
+        if (Cools.isEmpty(reportFaultUrl)) { return; }
+        List<VehFaultRec> vehFaultRecList = vehFaultRecService.list((new LambdaQueryWrapper<VehFaultRec>().eq(VehFaultRec::getState, VehFaultRecStateType.PENDING).ge(VehFaultRec::getHappenTime, Instant.now().minusSeconds(3).atZone(ZoneId.systemDefault()).toLocalDateTime())));
+        if (Cools.isEmpty(vehFaultRecList)) { return; }
+        for (VehFaultRec vehFaultRec : vehFaultRecList) {
+            boolean finished = faultReportService.reportFinished(vehFaultRec,reportFaultUrl);
+            if (finished) {
+                vehFaultRec.setState(VehFaultRecStateType.REPORT_SUCCESS.name());
+            } else {
+                log.error("failed to report vehFaultRec to uplink");
+                vehFaultRec.setState(VehFaultRecStateType.REPORT_FAILED.name());
+            }
+            vehFaultRecService.updateById(vehFaultRec);
+        }
+
+    }
+
+    /**
+     * 璋冨害瀵规帴鍏呯數妗�
+     */
+    @Scheduled(cron = "0/5 * * * * ? ")
+    private synchronized void startCharge() {
+        Set<String> mapKeys = redis.getMapKeys(RedisConstant.AGV_CHARGE_FLAG);
+        for (String key : mapKeys) {
+            Integer status = redis.getMap(RedisConstant.AGV_CHARGE_FLAG, key);
+            AgvDetail agvDetail = agvDetailService.selectByAgvNo(key);
+            FuncSta funcSta = funcStaService.getByCodeAndType(agvDetail.getCode(), FuncStaType.CHARGE.toString());
+            ModbusRtuOverTcp modbusTcp = chargeService.get(funcSta.getUuid());
+            if (status != null && status == 1) {
+                // 鍚庨��淇″彿娑堝け锛岃鏄庨┈杈炬鍦ㄥ墠杩�
+                if (chargeCoreService.checkBackwardRelayOffline(modbusTcp)) {
+                    chargeCoreService.startCharging(modbusTcp);
+                }
+                while (chargeCoreService.checkForwardRelayOnline(modbusTcp)) {
+                    double current = chargeCoreService.getCurrent(modbusTcp);
+                    double voltage = chargeCoreService.getVoltage(modbusTcp);
+                    if (current > 0 && voltage > 0) {
+                        redis.setMap(RedisConstant.AGV_CHARGE_FLAG, key, 2);
+                        log.info("charge complete");
+                    }else {
+                        log.info("read charge current and voltage: {},{}", current, voltage);
+                    }
+                }
+            } else if (status != null && status == 2) {
+                // 鍚庨��淇″彿娑堝け锛岃鏄庨┈杈炬鍦ㄥ墠杩�
+                if (chargeCoreService.checkForwardRelayOnline(modbusTcp)) {
+                    chargeCoreService.startCharging(modbusTcp);
+                }
+                while (chargeCoreService.checkBackwardRelayOffline(modbusTcp)) {
+                    redis.deleteMap(RedisConstant.AGV_CHARGE_FLAG, key);
+                    log.info("charge over");
+                }
+            }
+        }
+    }
+
+
+
+
 }

--
Gitblit v1.9.1