zhang
20 小时以前 59365e74fcda73ce10cfab475de43f171bb99a2a
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.zy.acs.manager.core.service;
 
import com.alibaba.fastjson.JSON;
import com.zy.acs.common.domain.AgvProtocol;
import com.zy.acs.common.domain.protocol.AGV_03_UP;
import com.zy.acs.common.domain.protocol.IMessageBody;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.manager.entity.AgvDetail;
import com.zy.acs.manager.manager.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
import java.util.Date;
 
/**
 * Created by vincent on 2023/6/16
 */
@Slf4j
@Service
public class AgvDataHeartbeatService {
 
    private final static Boolean PRINT_LOG = Boolean.FALSE;
 
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
    @Autowired
    private AgvService agvService;
    @Autowired
    private AgvDetailService agvDetailService;
    @Autowired
    private CodeService codeService;
    @Autowired
    private WebsocketService websocketService;
    @Autowired
    private TrafficService trafficService;
    @Autowired
    private MapService mapService;
    @Autowired
    private ThreadPoolRegulator threadPoolRegulator;
    @Autowired
    private JamService jamService;
    @Autowired
    private AvoidWaveCalculator avoidWaveCalculator;
    @Autowired
    private FaultProcessor faultProcessor;
 
    @Async
    public void dataProcess(AgvProtocol protocol) {
        Date now = new Date();
 
        IMessageBody msgBody = protocol.getMessageBody();
        assert msgBody != null;
 
        Long agvId = agvService.getAgvId(protocol.getAgvNo());
        if (null == agvId) {
            log.warn("Agv [{}] 尚未鉴权 !!!", protocol.getAgvNo());
            return;
        }
        AgvDetail detail = agvDetailService.selectByAgvId(agvId);
        if (null == detail) {
            detail = new AgvDetail();
            detail.setAgvId(agvId);
            if (!agvDetailService.save(detail)) {
                log.error("Agv [{}] 详情更新失败 !!!", protocol.getAgvNo());
                return;
            }
        }
        detail.setUpdateTime(now);
 
 
        // 心跳包
        if (msgBody instanceof AGV_03_UP) {
            AGV_03_UP agv_03_up = (AGV_03_UP) msgBody;
            this.sync(agv_03_up, detail);
            if (PRINT_LOG) {
                log.info("Agv [{}] 心跳包 ===>> {}", protocol.getAgvNo(), JSON.toJSONString(agv_03_up));
            }
        }
 
        if (!agvDetailService.updateById(detail)) {
            log.error("Agv [{}] 详情更新失败 !!!", protocol.getAgvNo());
        }
 
    }
 
 
    // 心跳包
    private void sync(AGV_03_UP mesBody, AgvDetail detail) {
 
        detail.setVol(mesBody.getVoltage());
        detail.setSoc(mesBody.getSoc());
        detail.setSoh(mesBody.getSoh());
        detail.setBatteryFail(mesBody.getBatterFailSign());
 
        detail.setTempe(JSON.toJSONString(Cools
                .add("batteryTempe", mesBody.getBatteryTempe())
                .add("envirTempe", mesBody.getEnvirTempe())
                .add("leftMotorTempe", mesBody.getLeftMotorTempe())
                .add("rightMotorTempe", mesBody.getRightMotorTempe())
                .add("raiseMotorTempe", mesBody.getRaiseMotorTempe())
                .add("telescopicMotorTempe", mesBody.getTelescopicMotorTempe())
                .add("rotatingMotorTempe", mesBody.getRotatingMotorTempe())
        ));
 
        detail.setMotorFail(JSON.toJSONString(Cools
                .add("leftMotorFailSign", mesBody.getLeftMotorFailSign())
                .add("rightMotorFailSign", mesBody.getRightMotorFailSign())
                .add("raiseMotorFailSign", mesBody.getRaiseMotorFailSign())
                .add("telescopicMotorFailSign", mesBody.getTelescopicMotorFailSign())
                .add("rotatingMotorFailSign", mesBody.getRotatingMotorFailSign())
        ));
 
        detail.setFailSign(String.valueOf(mesBody.getFailSign()));
 
        detail.setBootTime(mesBody.getBootTime());
 
    }
 
 
}