zhang
19 小时以前 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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_13_UP;
import com.zy.acs.common.domain.protocol.IMessageBody;
import com.zy.acs.common.enums.AgvStatusType;
import com.zy.acs.common.utils.GsonUtils;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.manager.core.domain.BackpackDto;
import com.zy.acs.manager.manager.entity.AgvDetail;
import com.zy.acs.manager.manager.entity.Code;
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.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * Created by vincent on 2023/6/16
 */
@Slf4j
@Service
public class AgvDataNoCodeService {
 
    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_13_UP) {
            AGV_13_UP agv_13_up = (AGV_13_UP) msgBody;
//            websocketService.agvInfoBroadcastWithOutPos(new WebsocketDto<AGV_13_UP>("agv", agv.getUuid(), agv_13_up));
            this.sync(agv_13_up, detail);
//            redis.setObject(RedisConstant.DIGITAL_AGV_FLAG, agv.getUuid(), agv_13_up);
            if (PRINT_LOG) {
                log.info("Agv [{}] 无码实时数据包 ===>> {}", protocol.getAgvNo(), JSON.toJSONString(agv_13_up));
            }
        }
 
        if (!agvDetailService.updateById(detail)) {
            log.error("Agv [{}] 详情更新失败 !!!", protocol.getAgvNo());
        }
 
    }
 
 
    // 无码实时数据包
    private void sync(AGV_13_UP mesBody, AgvDetail detail) {
        detail.setStatus(mesBody.getStatus());
 
        Code code = codeService.getCacheByData(mesBody.getQrCode());
        if (null != code) {
 
            if (!detail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                detail.setCode(null);
                detail.setLastCode(code.getId());
                detail.setPos(0);
            } else {
                detail.setCode(code.getId());
                detail.setLastCode(null);
                detail.setPos(1);
            }
 
 
        } else {
            log.error("Agv [{}] 更新定位数据失败 !!!上传条码:{}", agvService.getById(detail.getAgvId()).getUuid(), mesBody.getQrCode());
        }
 
        detail.setStraightVal((double) mesBody.getStraightDirectionPosition());
 
        detail.setAgvAngle((double) mesBody.getAGVCurrentAngle());
 
        detail.setGyroAngle((double) mesBody.getGyroAngle());
 
        detail.setEncoderAngle((double) mesBody.getEncoderAngle());
 
        detail.setHigh(mesBody.getCurrentAltitude());
 
        detail.setSensorSts((long) mesBody.getSensorStatusFlags());
 
        List<BackpackDto> backpackDtoList = new ArrayList<>();
        backpackDtoList.add(new BackpackDto(1, mesBody.isTempLoc1()));
        backpackDtoList.add(new BackpackDto(2, mesBody.isTempLoc2()));
        backpackDtoList.add(new BackpackDto(3, mesBody.isTempLoc3()));
        backpackDtoList.add(new BackpackDto(4, mesBody.isTempLoc4()));
        backpackDtoList.add(new BackpackDto(5, mesBody.isTempLoc5()));
        backpackDtoList.add(new BackpackDto(6, mesBody.isTempLoc6()));
        backpackDtoList.add(new BackpackDto(7, mesBody.isTempLoc7()));
        detail.setBackpack(GsonUtils.toJson(backpackDtoList));
 
    }
 
}