1
zhang
3 天以前 c42a7c76e24940db9e81307dc67104d9068c3119
zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java
@@ -1,6 +1,10 @@
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;
@@ -8,6 +12,7 @@
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.*;
@@ -23,6 +28,7 @@
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
@@ -58,6 +64,11 @@
    private VehFaultRecService vehFaultRecService;
    @Autowired
    private FaultReportService faultReportService;
    @Autowired
    private ChargeService chargeService;
    @Autowired
    private ChargeCoreService chargeCoreService;
    @Scheduled(cron = "0/5 * * * * ? ")
    private synchronized void autoCharge(){
@@ -116,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()) {
@@ -217,4 +232,47 @@
        }
    }
    /**
     * 调度对接充电桩
     */
    @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");
                }
            }
        }
    }
}