#
Junjie
4 天以前 691f0d4c4836c75fefa1d3b7fba4a72153751dd4
src/main/java/com/zy/asrs/task/ShuttlePowerEarlyWarning.java
@@ -3,13 +3,14 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.common.utils.HttpHandler;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.protocol.NyShuttleProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.NyShuttleThread;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ShuttleThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
@@ -18,6 +19,7 @@
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
/**
 * 小车电量预警检测 => 强制预警
@@ -29,12 +31,13 @@
    @Autowired
    private ConfigService configService;
    @Autowired
    private SlaveProperties slaveProperties;
    private DeviceConfigService deviceConfigService;
    /**
     * 小车电量预警检测 => 强制预警
     * 每30分钟扫描一次
     */
    @Scheduled(cron = "1 * * * * ? ")
    @Scheduled(cron = "0 30 * * * ? ")
    public synchronized void shuttlePowerEarlyWarning() {
        Config config = configService.selectOne(new EntityWrapper<Config>().eq("code","dingdingReportUrl"));
        if (config == null) {
@@ -53,26 +56,32 @@
        }
        StringBuffer buffer = new StringBuffer();
        buffer.append("【通知】三凯四向库\n");//消息标题
        buffer.append("【通知】四向库\n");//消息标题
        boolean hasReport = false;//是否有需要报告的数据
        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
        for (DeviceConfig device : shuttleList) {
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
            if (shuttleThread == null) {
                continue;
            }
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null) {
                continue;
            }
            if (shuttleProtocol.getChargState() == 1) {
            if (shuttleThread.isCharging()) {
                continue;//充电中,无需通知
            }
            if (shuttleProtocol.getPowerPercent() < shuttlePowerEarlyValue) {
                buffer.append(shuttleProtocol.getShuttleNo()).append("号小车,电量").append(shuttleProtocol.getPowerPercent$()).append(",请注意。\n");
            if (shuttleProtocol.getBatteryPower() == null) {
                continue;
            }
            if (Integer.parseInt(shuttleProtocol.getBatteryPower()) < shuttlePowerEarlyValue) {
                buffer.append(shuttleProtocol.getShuttleNo()).append("号小车,电量").append(shuttleProtocol.getBatteryPower()).append(",请注意。\n");
                hasReport = true;
            }
        }