自动化立体仓库 - WCS系统
1
zhangc
2025-04-14 710deccd42576ad2dcbdc22e75f18b455d5ce2ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
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.ShuttleProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.ShuttleThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
 
/**
 * 小车电量预警检测 => 强制预警
 */
@Component
@Slf4j
public class ShuttlePowerEarlyWarning {
 
    @Autowired
    private ConfigService configService;
    @Autowired
    private SlaveProperties slaveProperties;
 
    /**
     * 小车电量预警检测 => 强制预警
     * 每30分钟扫描一次
     */
    @Scheduled(cron = "0 30 * * * ? ")
    public synchronized void shuttlePowerEarlyWarning() {
        Config config = configService.selectOne(new EntityWrapper<Config>().eq("code","dingdingReportUrl"));
        if (config == null) {
            return;
        }
 
        if (config.getStatus() == 0) {
            return;//通知禁用
        }
 
        //小车电量预警阈值
        int shuttlePowerEarlyValue = 20;//默认20
        Config shuttlePowerEarlyConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttlePowerEarlyValue"));
        if (shuttlePowerEarlyConfig != null) {
            shuttlePowerEarlyValue = Integer.parseInt(shuttlePowerEarlyConfig.getValue());
        }
 
        StringBuffer buffer = new StringBuffer();
        buffer.append("【通知】四向库\n");//消息标题
 
        boolean hasReport = false;//是否有需要报告的数据
        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
            if (shuttleThread == null) {
                continue;
            }
 
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null) {
                continue;
            }
 
            if (shuttleThread.isCharging()) {
                continue;//充电中,无需通知
            }
 
            if (Integer.parseInt(shuttleProtocol.getBatteryPower()) < shuttlePowerEarlyValue) {
                buffer.append(shuttleProtocol.getShuttleNo()).append("号小车,电量").append(shuttleProtocol.getBatteryPower()).append(",请注意。\n");
                hasReport = true;
            }
        }
 
        if (hasReport) {
            try {
                HashMap<String, Object> param = new HashMap<>();
                HashMap<String, Object> data = new HashMap<>();
                data.put("content", buffer.toString());
                param.put("msgtype", "text");
                param.put("text", data);
                String response = new HttpHandler.Builder()
                        .setUri(config.getValue())
                        .setJson(JSON.toJSONString(param))
                        .setHttps(true)
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.get("errmsg").equals("ok")) {
                    return;//发送成功
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
    }
 
}